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
chown(const char * path,uid_t owner,gid_t group)27 int chown(const char *path, uid_t owner, gid_t group)
28 {
29 return FuseAssistant::ins->chown(path, owner, group);
30 }
31
chmod(const char * path,mode_t mode)32 int chmod(const char *path, mode_t mode)
33 {
34 return FuseAssistant::ins->chmod(path, mode);
35 }
36
AccessMock(const char * name,int type)37 int AccessMock(const char *name, int type)
38 {
39 if (name == nullptr) {
40 return 0;
41 }
42 const char *dentryPath = "/data/service/el2/100/hmdfs/cache/account_cache/dentry_cache/cloud";
43 if (strcmp(name, dentryPath) == 0) {
44 return -1;
45 }
46 return 0;
47 }
48
StrdupMock(const char * path)49 char* StrdupMock(const char *path)
50 {
51 const char *str1 = "/mnt/data/234/cloud";
52 const char *str2 = "/mnt/data/234/cloud_fuse";
53 if (path == nullptr) {
54 return nullptr;
55 }
56 if (strcmp(path, str1) == 0 || strcmp(path, str2) == 0) {
57 return nullptr;
58 }
59 size_t len = strlen(path);
60 if (len <= 0) {
61 return nullptr;
62 }
63 char* dstStr = static_cast<char*>(malloc(len + 1));
64 if (dstStr == nullptr) {
65 return nullptr;
66 }
67 if (memcpy_s(dstStr, len + 1, path, len + 1) != 0) {
68 free(dstStr);
69 dstStr = nullptr;
70 return nullptr;
71 }
72 return dstStr;
73 }