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 static const std::string CLOUD_RECYCLE_PATH = "user.cloud.recyclePath"; 51 } 52 53 class CloudFileUtils final { 54 public: 55 static bool CheckIsCloud(const std::string &key); 56 static bool CheckIsCloudLocation(const std::string &key); 57 static bool CheckIsHasLCD(const std::string &key); 58 static bool CheckIsHasTHM(const std::string &key); 59 static bool CheckIsHmdfsPermission(const std::string &key); 60 static bool CheckIsCloudRecycle(const std::string &key); 61 static bool CheckIsFavorite(const std::string &key); 62 static bool CheckFileStatus(const std::string &key); 63 static bool CheckIsTimeRecycled(const std::string &key); 64 static bool CheckIsRecyclePath(const std::string &key); 65 static std::string GetLocalBaseDir(std::string bundleName, int32_t userId); 66 static std::string GetLocalBucketPath(std::string cloudId, std::string bundleName, 67 int32_t userId); 68 static std::string GetLocalDKCachePath(std::string cloudId, std::string bundleName, int32_t userId); 69 static std::string GetLocalFilePath(std::string cloudId, std::string bundleName, 70 int32_t userId); 71 static std::string GetPathWithoutTmp(const std::string &path); 72 static std::string GetCloudId(const std::string &path); 73 static std::string GetRealPath(const std::string &path); 74 static uint32_t GetBucketId(std::string cloudId); 75 static int64_t Timespec2Milliseconds(const struct timespec &time); 76 static bool LocalWriteOpen(const std::string &dfsPath); 77 static bool ClearCache(const std::string &dfsPath, const std::string &cloudPath); 78 static uint32_t DentryHash(const std::string &cloudId); 79 static void TeaTransform(uint32_t buf[4], uint32_t const in[]); 80 static void Str2HashBuf(const char *msg, size_t len, uint32_t *buf, int num); 81 static bool IsDotDotdot(const std::string &name); 82 static const std::string TMP_SUFFIX; 83 private: 84 static bool EndsWith(const std::string &fullString, const std::string &ending); 85 }; 86 } // namespace CloudDisk 87 } // namespace FileManagement 88 } // namespace OHOS 89 #endif // CLOUD_FILE_DAEMON_CLOUD_FILE_UTILS_H 90