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_FFI_H
17 #define OHOS_FILE_FS_FFI_H
18 
19 #include <cstdint>
20 
21 #include "cj_common_ffi.h"
22 #include "copy_dir.h"
23 #include "ffi_remote_data.h"
24 #include "file_fs_impl.h"
25 #include "list_file.h"
26 
27 extern "C" {
28     FFI_EXPORT RetDataI64 FfiOHOSFileFsStatByID(int32_t file);
29     FFI_EXPORT RetDataI64 FfiOHOSFileFsStatByString(const char* file);
30     FFI_EXPORT RetDataI64 FfiOHOSFileFsCreateStream(const char* path, const char* mode);
31     FFI_EXPORT RetDataI64 FfiOHOSFileFsFdopenStream(int32_t fd, const char* mode);
32     FFI_EXPORT RetDataI64 FfiOHOSFileFsLstat(const char* path);
33     FFI_EXPORT RetDataI64 FfiOHOSFileFsCreateRandomAccessFileByString(const char* file, int64_t mode);
34     FFI_EXPORT RetDataI64 FfiOHOSFileFsCreateRandomAccessFileByID(int64_t file, int64_t mode);
35     FFI_EXPORT int32_t FfiOHOSRandomAccessFileGetFd(int64_t id);
36     FFI_EXPORT int64_t FfiOHOSRandomAccessFileGetFPointer(int64_t id);
37     FFI_EXPORT void FfiOHOSRandomAccessFileSetFilePointerSync(int64_t id, int64_t fd);
38     FFI_EXPORT void FfiOHOSRandomAccessFileClose(int64_t id);
39     FFI_EXPORT RetDataI64 FfiOHOSRandomAccessFileWrite(int64_t id, char* buf, size_t len, int64_t offset);
40     FFI_EXPORT RetDataI64 FfiOHOSRandomAccessFileRead(int64_t id, char* buf, size_t len, int64_t offset);
41     FFI_EXPORT int32_t FfiOHOSFileFsMkdir(const char* path, bool recursion, bool isTwoArgs);
42     FFI_EXPORT int32_t FfiOHOSFileFsRmdir(const char* path);
43     FFI_EXPORT OHOS::CJSystemapi::RetDataCArrConflictFiles FfiOHOSFileFsMoveDir(const char* src, const char* dest,
44         int32_t mode);
45     FFI_EXPORT int32_t FfiOHOSFileFsRename(const char* oldFile, const char* newFile);
46     FFI_EXPORT int32_t FfiOHOSFileFsUnlink(const char* path);
47     FFI_EXPORT RetDataBool FfiOHOSFileFsAccess(const char* path);
48     FFI_EXPORT RetDataI64 FfiOHOSFileFsOpen(const char* path, uint64_t mode);
49     FFI_EXPORT RetDataI64 FfiOHOSFileFsRead(int32_t fd, char* buffer, int64_t bufLen, size_t length, int64_t offset);
50     FFI_EXPORT RetDataI64 FfiOHOSFileFsReadCur(int32_t fd, char* buffer, int64_t bufLen, size_t length);
51     FFI_EXPORT RetDataI64 FfiOHOSFileFsWrite(int32_t fd, char* buffer, size_t length, int64_t offset,
52         const char* encode);
53     FFI_EXPORT RetDataI64 FfiOHOSFileFsWriteCur(int32_t fd, char* buffer, size_t length, const char* encode);
54     FFI_EXPORT OHOS::CJSystemapi::RetDataCArrConflictFiles FfiOHOSFileFsCopyDir(const char* src, const char* dest,
55         int mode);
56     FFI_EXPORT int FfiOHOSFileFsCopyFile(const char* src, const char* dest, int mode);
57     FFI_EXPORT int FfiOHOSFileFsCopyFileSI(const char* src, int32_t dest, int mode);
58     FFI_EXPORT int FfiOHOSFileFsCopyFileIS(int32_t src, const char* dest, int mode);
59     FFI_EXPORT int FfiOHOSFileFsCopyFileII(int32_t src, int32_t dest, int mode);
60     FFI_EXPORT int FfiOHOSFileFsMoveFile(const char* src, const char* dest, int mode);
61     FFI_EXPORT RetDataCString FfiOHOSFileFsMkdtemp(const char* prefix);
62     FFI_EXPORT int32_t FfiOHOSFileFsTruncateByString(const char* file, int64_t len);
63     FFI_EXPORT int32_t FfiOHOSFileFsTruncateByFd(int32_t file, int64_t len);
64     FFI_EXPORT RetDataI64 FfiOHOSFileFsReadLines(char* path, char* encoding);
65     FFI_EXPORT RetDataCString FfiOHOSFileFsReadText(char* path, int64_t offset, bool hasLen, int64_t len,
66         char* encoding);
67     FFI_EXPORT int32_t FfiOHOSFileFsUtimes(char* path, double mtime);
68     FFI_EXPORT RetDataI64 FfiOHOSFileFsCreateWatcher(char* path, uint32_t events,
69         void (*callback)(OHOS::CJSystemapi::CWatchEvent));
70     FFI_EXPORT int32_t FfiOHOSFileFsWatcherStart(int64_t id);
71     FFI_EXPORT int32_t FfiOHOSFileFsWatcherStop(int64_t id);
72 
73     struct RetReaderIteratorResult {
74         int32_t code;
75         bool done;
76         char* data;
77     };
78     FFI_EXPORT RetReaderIteratorResult FfiOHOSFileFsReaderIteratorNext(int64_t id);
79     FFI_EXPORT OHOS::CJSystemapi::RetDataCArrStringN FfiOHOSFileListFile(const char* path,
80         OHOS::CJSystemapi::CListFileOptions options);
81     FFI_EXPORT RetDataI64 FfiOHOSFileFsLseek(int32_t fd, int64_t offset, int whence);
82     FFI_EXPORT int FfiOHOSFileFsFdatasync(int32_t fd);
83     FFI_EXPORT int FfiOHOSFileFsFsync(int32_t fd);
84     FFI_EXPORT int FfiOHOSFileFsSymlink(const char* target, const char* srcPath);
85 }
86 #endif