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 #include <fcntl.h>
17 #include <sys/types.h>
18 #include <sys/stat.h>
19 #include <unistd.h>
20
21 #include "file_operations_base.h"
22 #include "fuse_assistant.h"
23 #include "securec.h"
24
25 using namespace OHOS::FileManagement::CloudFile;
26
mkdir(const char * path,mode_t mode)27 int mkdir(const char *path, mode_t mode)
28 {
29 return FuseAssistant::ins->mkdir(path, mode);
30 }
31
chown(const char * path,uid_t owner,gid_t group)32 int chown(const char *path, uid_t owner, gid_t group)
33 {
34 return FuseAssistant::ins->chown(path, owner, group);
35 }
36
chmod(const char * path,mode_t mode)37 int chmod(const char *path, mode_t mode)
38 {
39 return FuseAssistant::ins->chmod(path, mode);
40 }
41
AccessMock(const char * name,int type)42 int AccessMock(const char *name, int type)
43 {
44 if (name == nullptr) {
45 return 0;
46 }
47 const char *dentryPath = "/data/service/el2/100/hmdfs/cache/account_cache/dentry_cache/cloud";
48 if (strcmp(name, dentryPath) == 0) {
49 return -1;
50 }
51 return 0;
52 }
53
StrdupMock(const char * path)54 char* StrdupMock(const char *path)
55 {
56 const char *str1 = "/mnt/data/234/cloud";
57 const char *str2 = "/mnt/data/234/cloud_fuse";
58 if (path == nullptr) {
59 return nullptr;
60 }
61 if (strcmp(path, str1) == 0 || strcmp(path, str2) == 0) {
62 return nullptr;
63 }
64 size_t len = strlen(path);
65 if (len <= 0) {
66 return nullptr;
67 }
68 char* dstStr = static_cast<char*>(malloc(len + 1));
69 if (dstStr == nullptr) {
70 return nullptr;
71 }
72 if (memcpy_s(dstStr, len + 1, path, len + 1) != 0) {
73 free(dstStr);
74 dstStr = nullptr;
75 return nullptr;
76 }
77 return dstStr;
78 }