• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 #ifndef CLOUD_FILE_DAEMON_CLOUD_FILE_UTILS_H
16 #define CLOUD_FILE_DAEMON_CLOUD_FILE_UTILS_H
17 
18 #include <string>
19 #include <sys/stat.h>
20 namespace OHOS {
21 namespace FileManagement {
22 namespace CloudDisk {
23 struct CloudDiskFileInfo {
24     std::string name;
25     std::string cloudId;
26     std::string parentCloudId;
27     uint32_t location{1};
28     uint32_t mode{S_IFREG};
29     int64_t localId{0};
30     unsigned long long rowId{0};
31     unsigned long long size{0};
32     unsigned long long atime{0};
33     unsigned long long ctime{0};
34     unsigned long long mtime{0};
35     bool IsDirectory{false};
36     off_t nextOff{0};
37 };
38 
39 namespace {
40     static const std::string CLOUD_CLOUD_ID_XATTR = "user.cloud.cloudid";
41     static const std::string CLOUD_FILE_LOCATION = "user.cloud.location";
42     static const std::string HMDFS_PERMISSION_XATTR = "user.hmdfs.perm";
43     static const std::string CLOUD_CLOUD_RECYCLE_XATTR = "user.cloud.recycle";
44     static const std::string IS_FAVORITE_XATTR = "user.cloud.favorite";
45     static const std::string IS_FILE_STATUS_XATTR = "user.cloud.filestatus";
46     static const std::string CLOUD_EXT_ATTR = "extended_attributes";
47     static const std::string CLOUD_HAS_LCD = "user.cloud.hasLcdThumbnail";
48     static const std::string CLOUD_HAS_THM = "user.cloud.hasThumbnail";
49     static const std::string CLOUD_TIME_RECYCLED = "user.cloud.deletetime";
50 }
51 
52 class CloudFileUtils final {
53 public:
54     static bool CheckIsCloud(const std::string &key);
55     static bool CheckIsCloudLocation(const std::string &key);
56     static bool CheckIsHasLCD(const std::string &key);
57     static bool CheckIsHasTHM(const std::string &key);
58     static bool CheckIsHmdfsPermission(const std::string &key);
59     static bool CheckIsCloudRecycle(const std::string &key);
60     static bool CheckIsFavorite(const std::string &key);
61     static bool CheckFileStatus(const std::string &key);
62     static bool CheckIsTimeRecycled(const std::string &key);
63     static std::string GetLocalBucketPath(std::string cloudId, std::string bundleName,
64                                           int32_t userId);
65     static std::string GetLocalFilePath(std::string cloudId, std::string bundleName,
66                                         int32_t userId);
67     static std::string GetPathWithoutTmp(const std::string &path);
68     static std::string GetCloudId(const std::string &path);
69     static std::string GetRealPath(const std::string &path);
70     static uint32_t GetBucketId(std::string cloudId);
71     static int64_t Timespec2Milliseconds(const struct timespec &time);
72     static bool LocalWriteOpen(const std::string &dfsPath);
73     static bool ClearCache(const std::string &dfsPath);
74     static uint32_t DentryHash(const std::string &cloudId);
75     static void TeaTransform(uint32_t buf[4], uint32_t const in[]);
76     static void Str2HashBuf(const char *msg, size_t len, uint32_t *buf, int num);
77     static bool IsDotDotdot(const std::string &name);
78     static const std::string TMP_SUFFIX;
79 private:
80     static bool EndsWith(const std::string &fullString, const std::string &ending);
81 };
82 } // namespace CloudDisk
83 } // namespace FileManagement
84 } // namespace OHOS
85 #endif // CLOUD_FILE_DAEMON_CLOUD_FILE_UTILS_H
86