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
26namespace OHOS {
27namespace CJSystemapi {
28
29constexpr int RDONLY = UV_FS_O_RDONLY;
30constexpr int WRONLY = UV_FS_O_WRONLY;
31constexpr int RDWR = UV_FS_O_RDWR;
32constexpr int CREATE = UV_FS_O_CREAT;
33constexpr int TRUNC = UV_FS_O_TRUNC;
34constexpr int APPEND = UV_FS_O_APPEND;
35constexpr int NONBLOCK = UV_FS_O_NONBLOCK;
36constexpr int DIRECTORY = UV_FS_O_DIRECTORY;
37constexpr int NOFOLLOW = UV_FS_O_NOFOLLOW;
38constexpr int SYNC = UV_FS_O_SYNC;
39
40constexpr unsigned int USR_READ_ONLY = 00;
41constexpr unsigned int USR_WRITE_ONLY = 01;
42constexpr unsigned int USR_RDWR = 02;
43constexpr unsigned int USR_CREATE = 0100;
44constexpr unsigned int USR_TRUNC = 01000;
45constexpr unsigned int USR_APPEND = 02000;
46constexpr unsigned int USR_NONBLOCK = 04000;
47constexpr unsigned int USR_DIRECTORY = 0200000;
48constexpr unsigned int USR_NOFOLLOW = 0400000;
49constexpr unsigned int USR_SYNC = 04010000;
50
51const double NS = 1e9;
52const double MS = 1e3;
53
54#if !defined(WIN_PLATFORM) && !defined(IOS_PLATFORM)
55class FileIoToken : public IRemoteBroker {
56public:
57    DECLARE_INTERFACE_DESCRIPTOR(u"ohos.fileio.open");
58
59    FileIoToken() = default;
60    virtual ~FileIoToken() noexcept = default;
61};
62#endif
63
64struct FileInfo {
65    bool isPath = false;
66    std::unique_ptr<char[]> path = { nullptr };
67    std::unique_ptr<DistributedFS::FDGuard> fdg = { nullptr };
68};
69
70struct 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
76struct ConflictFiles {
77    std::string srcFiles;
78    std::string destFiles;
79    ConflictFiles(const std::string& src, const std::string& dest) : srcFiles(src), destFiles(dest) {}
80    ~ConflictFiles() = default;
81};
82
83struct CConflictFiles {
84    char* srcFiles;
85    char* destFiles;
86    CConflictFiles() : srcFiles(nullptr), destFiles(nullptr) {}
87};
88
89struct CArrConflictFiles {
90    CConflictFiles* head;
91    int64_t size;
92};
93
94struct RetDataCArrConflictFiles {
95    int code;
96    CArrConflictFiles data;
97};
98}
99}
100
101#endif // OHOS_FILE_FS_UTILS_H