15bebb993Sopenharmony_ci/* 25bebb993Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 35bebb993Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 45bebb993Sopenharmony_ci * you may not use this file except in compliance with the License. 55bebb993Sopenharmony_ci * You may obtain a copy of the License at 65bebb993Sopenharmony_ci * 75bebb993Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 85bebb993Sopenharmony_ci * 95bebb993Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 105bebb993Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 115bebb993Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 125bebb993Sopenharmony_ci * See the License for the specific language governing permissions and 135bebb993Sopenharmony_ci * limitations under the License. 145bebb993Sopenharmony_ci */ 155bebb993Sopenharmony_ci 165bebb993Sopenharmony_ci#ifndef OHOS_FILE_FS_UTILS_H 175bebb993Sopenharmony_ci#define OHOS_FILE_FS_UTILS_H 185bebb993Sopenharmony_ci 195bebb993Sopenharmony_ci#include "uv.h" 205bebb993Sopenharmony_ci#include "fd_guard.h" 215bebb993Sopenharmony_ci#include <string> 225bebb993Sopenharmony_ci#if !defined(WIN_PLATFORM) && !defined(IOS_PLATFORM) 235bebb993Sopenharmony_ci#include "iremote_broker.h" 245bebb993Sopenharmony_ci#endif 255bebb993Sopenharmony_ci 265bebb993Sopenharmony_cinamespace OHOS { 275bebb993Sopenharmony_cinamespace CJSystemapi { 285bebb993Sopenharmony_ci 295bebb993Sopenharmony_ciconstexpr int RDONLY = UV_FS_O_RDONLY; 305bebb993Sopenharmony_ciconstexpr int WRONLY = UV_FS_O_WRONLY; 315bebb993Sopenharmony_ciconstexpr int RDWR = UV_FS_O_RDWR; 325bebb993Sopenharmony_ciconstexpr int CREATE = UV_FS_O_CREAT; 335bebb993Sopenharmony_ciconstexpr int TRUNC = UV_FS_O_TRUNC; 345bebb993Sopenharmony_ciconstexpr int APPEND = UV_FS_O_APPEND; 355bebb993Sopenharmony_ciconstexpr int NONBLOCK = UV_FS_O_NONBLOCK; 365bebb993Sopenharmony_ciconstexpr int DIRECTORY = UV_FS_O_DIRECTORY; 375bebb993Sopenharmony_ciconstexpr int NOFOLLOW = UV_FS_O_NOFOLLOW; 385bebb993Sopenharmony_ciconstexpr int SYNC = UV_FS_O_SYNC; 395bebb993Sopenharmony_ci 405bebb993Sopenharmony_ciconstexpr unsigned int USR_READ_ONLY = 00; 415bebb993Sopenharmony_ciconstexpr unsigned int USR_WRITE_ONLY = 01; 425bebb993Sopenharmony_ciconstexpr unsigned int USR_RDWR = 02; 435bebb993Sopenharmony_ciconstexpr unsigned int USR_CREATE = 0100; 445bebb993Sopenharmony_ciconstexpr unsigned int USR_TRUNC = 01000; 455bebb993Sopenharmony_ciconstexpr unsigned int USR_APPEND = 02000; 465bebb993Sopenharmony_ciconstexpr unsigned int USR_NONBLOCK = 04000; 475bebb993Sopenharmony_ciconstexpr unsigned int USR_DIRECTORY = 0200000; 485bebb993Sopenharmony_ciconstexpr unsigned int USR_NOFOLLOW = 0400000; 495bebb993Sopenharmony_ciconstexpr unsigned int USR_SYNC = 04010000; 505bebb993Sopenharmony_ci 515bebb993Sopenharmony_ciconst double NS = 1e9; 525bebb993Sopenharmony_ciconst double MS = 1e3; 535bebb993Sopenharmony_ci 545bebb993Sopenharmony_ci#if !defined(WIN_PLATFORM) && !defined(IOS_PLATFORM) 555bebb993Sopenharmony_ciclass FileIoToken : public IRemoteBroker { 565bebb993Sopenharmony_cipublic: 575bebb993Sopenharmony_ci DECLARE_INTERFACE_DESCRIPTOR(u"ohos.fileio.open"); 585bebb993Sopenharmony_ci 595bebb993Sopenharmony_ci FileIoToken() = default; 605bebb993Sopenharmony_ci virtual ~FileIoToken() noexcept = default; 615bebb993Sopenharmony_ci}; 625bebb993Sopenharmony_ci#endif 635bebb993Sopenharmony_ci 645bebb993Sopenharmony_cistruct FileInfo { 655bebb993Sopenharmony_ci bool isPath = false; 665bebb993Sopenharmony_ci std::unique_ptr<char[]> path = { nullptr }; 675bebb993Sopenharmony_ci std::unique_ptr<DistributedFS::FDGuard> fdg = { nullptr }; 685bebb993Sopenharmony_ci}; 695bebb993Sopenharmony_ci 705bebb993Sopenharmony_cistruct CommonFunc { 715bebb993Sopenharmony_ci static unsigned int ConvertCjFlags(unsigned int &flags); 725bebb993Sopenharmony_ci static void FsReqCleanup(uv_fs_t* req); 735bebb993Sopenharmony_ci static std::string GetModeFromFlags(unsigned int flags); 745bebb993Sopenharmony_ci}; 755bebb993Sopenharmony_ci 765bebb993Sopenharmony_cistruct ConflictFiles { 775bebb993Sopenharmony_ci std::string srcFiles; 785bebb993Sopenharmony_ci std::string destFiles; 795bebb993Sopenharmony_ci ConflictFiles(const std::string& src, const std::string& dest) : srcFiles(src), destFiles(dest) {} 805bebb993Sopenharmony_ci ~ConflictFiles() = default; 815bebb993Sopenharmony_ci}; 825bebb993Sopenharmony_ci 835bebb993Sopenharmony_cistruct CConflictFiles { 845bebb993Sopenharmony_ci char* srcFiles; 855bebb993Sopenharmony_ci char* destFiles; 865bebb993Sopenharmony_ci CConflictFiles() : srcFiles(nullptr), destFiles(nullptr) {} 875bebb993Sopenharmony_ci}; 885bebb993Sopenharmony_ci 895bebb993Sopenharmony_cistruct CArrConflictFiles { 905bebb993Sopenharmony_ci CConflictFiles* head; 915bebb993Sopenharmony_ci int64_t size; 925bebb993Sopenharmony_ci}; 935bebb993Sopenharmony_ci 945bebb993Sopenharmony_cistruct RetDataCArrConflictFiles { 955bebb993Sopenharmony_ci int code; 965bebb993Sopenharmony_ci CArrConflictFiles data; 975bebb993Sopenharmony_ci}; 985bebb993Sopenharmony_ci} 995bebb993Sopenharmony_ci} 1005bebb993Sopenharmony_ci 1015bebb993Sopenharmony_ci#endif // OHOS_FILE_FS_UTILS_H