1 /*
2 * Copyright (c) 2023-2025 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 #include "cloud_file_utils.h"
16 #include <ctime>
17 #include <fcntl.h>
18 #include <filesystem>
19 #include <sys/xattr.h>
20 #include <sys/ioctl.h>
21 #include <unistd.h>
22 #include "utils_log.h"
23 namespace OHOS {
24 namespace FileManagement {
25 namespace CloudDisk {
26 using namespace std;
27 namespace {
28 static const string LOCAL_PATH_DATA_SERVICE_EL2 = "/data/service/el2/";
29 static const string LOCAL_PATH_HMDFS_CLOUD_DATA = "/hmdfs/cloud/data/";
30 static const string CLOUD_FILE_CLOUD_ID_XATTR = "user.cloud.cloudid";
31 static const int64_t SECOND_TO_MILLISECOND = 1e3;
32 static const int64_t MILLISECOND_TO_NANOSECOND = 1e6;
33 }
34
35 #define HMDFS_IOC_GET_WRITEOPEN_CNT _IOR(HMDFS_IOC, WRITEOPEN_CMD, uint32_t)
36 const string CloudFileUtils::TMP_SUFFIX = ".temp.download";
37
IsDotDotdot(const std::string & name)38 bool CloudFileUtils::IsDotDotdot(const std::string &name)
39 {
40 return name == "." || name == "..";
41 }
42
Str2HashBuf(const char * msg,size_t len,uint32_t * buf,int num)43 void CloudFileUtils::Str2HashBuf(const char *msg, size_t len, uint32_t *buf, int num)
44 {
45 }
46
TeaTransform(uint32_t buf[4],uint32_t const in[])47 void CloudFileUtils::TeaTransform(uint32_t buf[4], uint32_t const in[])
48 {
49 }
50
DentryHash(const std::string & inputStr)51 uint32_t CloudFileUtils::DentryHash(const std::string &inputStr)
52 {
53 return 0;
54 }
55
GetBucketId(string cloudId)56 uint32_t CloudFileUtils::GetBucketId(string cloudId)
57 {
58 return 0;
59 }
60
Timespec2Milliseconds(const struct timespec & time)61 int64_t CloudFileUtils::Timespec2Milliseconds(const struct timespec &time)
62 {
63 return time.tv_sec * SECOND_TO_MILLISECOND + time.tv_nsec / MILLISECOND_TO_NANOSECOND;
64 }
65
GetLocalBucketPath(string cloudId,string bundleName,int32_t userId)66 string CloudFileUtils::GetLocalBucketPath(string cloudId, string bundleName, int32_t userId)
67 {
68 return "";
69 }
70
GetLocalFilePath(string cloudId,string bundleName,int32_t userId)71 string CloudFileUtils::GetLocalFilePath(string cloudId, string bundleName, int32_t userId)
72 {
73 if (userId == 0) {
74 return "mock";
75 }
76 return "/data";
77 }
78
GetPathWithoutTmp(const string & path)79 string CloudFileUtils::GetPathWithoutTmp(const string &path)
80 {
81 return "";
82 }
83
EndsWith(const string & fullString,const string & ending)84 bool CloudFileUtils::EndsWith(const string &fullString, const string &ending)
85 {
86 return false;
87 }
88
GetCloudId(const string & path)89 string CloudFileUtils::GetCloudId(const string &path)
90 {
91 return "";
92 }
93
CheckIsCloud(const string & key)94 bool CloudFileUtils::CheckIsCloud(const string &key)
95 {
96 return key == CLOUD_CLOUD_ID_XATTR;
97 }
98
CheckIsCloudLocation(const string & key)99 bool CloudFileUtils::CheckIsCloudLocation(const string &key)
100 {
101 return key == CLOUD_FILE_LOCATION;
102 }
103
CheckIsHmdfsPermission(const string & key)104 bool CloudFileUtils::CheckIsHmdfsPermission(const string &key)
105 {
106 return key == HMDFS_PERMISSION_XATTR;
107 }
108
CheckIsCloudRecycle(const string & key)109 bool CloudFileUtils::CheckIsCloudRecycle(const string &key)
110 {
111 return key == CLOUD_CLOUD_RECYCLE_XATTR;
112 }
113
CheckIsFavorite(const string & key)114 bool CloudFileUtils::CheckIsFavorite(const string &key)
115 {
116 return key == IS_FAVORITE_XATTR;
117 }
118
CheckFileStatus(const string & key)119 bool CloudFileUtils::CheckFileStatus(const string &key)
120 {
121 return key == IS_FILE_STATUS_XATTR;
122 }
123
LocalWriteOpen(const string & dfsPath)124 bool CloudFileUtils::LocalWriteOpen(const string &dfsPath)
125 {
126 return false;
127 }
128 } // namespace CloudDisk
129 } // namespace FileManagement
130 } // namespace OHOS