1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_FILE_FS_UTILS_H 17 #define OHOS_FILE_FS_UTILS_H 18 19 #include "uv.h" 20 #include "fd_guard.h" 21 #include <string> 22 #if !defined(WIN_PLATFORM) && !defined(IOS_PLATFORM) 23 #include "iremote_broker.h" 24 #endif 25 26 namespace OHOS { 27 namespace CJSystemapi { 28 29 constexpr int RDONLY = UV_FS_O_RDONLY; 30 constexpr int WRONLY = UV_FS_O_WRONLY; 31 constexpr int RDWR = UV_FS_O_RDWR; 32 constexpr int CREATE = UV_FS_O_CREAT; 33 constexpr int TRUNC = UV_FS_O_TRUNC; 34 constexpr int APPEND = UV_FS_O_APPEND; 35 constexpr int NONBLOCK = UV_FS_O_NONBLOCK; 36 constexpr int DIRECTORY = UV_FS_O_DIRECTORY; 37 constexpr int NOFOLLOW = UV_FS_O_NOFOLLOW; 38 constexpr int SYNC = UV_FS_O_SYNC; 39 40 constexpr unsigned int USR_READ_ONLY = 00; 41 constexpr unsigned int USR_WRITE_ONLY = 01; 42 constexpr unsigned int USR_RDWR = 02; 43 constexpr unsigned int USR_CREATE = 0100; 44 constexpr unsigned int USR_TRUNC = 01000; 45 constexpr unsigned int USR_APPEND = 02000; 46 constexpr unsigned int USR_NONBLOCK = 04000; 47 constexpr unsigned int USR_DIRECTORY = 0200000; 48 constexpr unsigned int USR_NOFOLLOW = 0400000; 49 constexpr unsigned int USR_SYNC = 04010000; 50 51 const double NS = 1e9; 52 const double MS = 1e3; 53 54 #if !defined(WIN_PLATFORM) && !defined(IOS_PLATFORM) 55 class FileIoToken : public IRemoteBroker { 56 public: 57 DECLARE_INTERFACE_DESCRIPTOR(u"ohos.fileio.open"); 58 59 FileIoToken() = default; 60 virtual ~FileIoToken() noexcept = default; 61 }; 62 #endif 63 64 struct FileInfo { 65 bool isPath = false; 66 std::unique_ptr<char[]> path = { nullptr }; 67 std::unique_ptr<DistributedFS::FDGuard> fdg = { nullptr }; 68 }; 69 70 struct CommonFunc { 71 static unsigned int ConvertCjFlags(unsigned int &flags); 72 static void FsReqCleanup(uv_fs_t* req); 73 static std::string GetModeFromFlags(unsigned int flags); 74 }; 75 76 struct ConflictFiles { 77 std::string srcFiles; 78 std::string destFiles; ConflictFilesConflictFiles79 ConflictFiles(const std::string& src, const std::string& dest) : srcFiles(src), destFiles(dest) {} 80 ~ConflictFiles() = default; 81 }; 82 83 struct CConflictFiles { 84 char* srcFiles; 85 char* destFiles; CConflictFilesCConflictFiles86 CConflictFiles() : srcFiles(nullptr), destFiles(nullptr) {} 87 }; 88 89 struct CArrConflictFiles { 90 CConflictFiles* head; 91 int64_t size; 92 }; 93 94 struct RetDataCArrConflictFiles { 95 int code; 96 CArrConflictFiles data; 97 }; 98 } 99 } 100 101 #endif // OHOS_FILE_FS_UTILS_H