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_DISK_INODE_H 16 #define CLOUD_FILE_DAEMON_CLOUD_DISK_INODE_H 17 18 #include <atomic> 19 #include <memory> 20 #include <mutex> 21 #include <shared_mutex> 22 #include <string> 23 #include <sys/stat.h> 24 #include <sys/types.h> 25 #include <unistd.h> 26 #include <unordered_map> 27 28 #include "cloud_asset_read_session.h" 29 #include "ffrt_inner.h" 30 #include "file_operations_base.h" 31 32 namespace OHOS { 33 namespace FileManagement { 34 namespace CloudDisk { 35 36 enum CLOUD_DISK_INODE_LAYER { 37 CLOUD_DISK_INODE_ZERO_LAYER = 0, // data 38 CLOUD_DISK_INODE_FIRST_LAYER, // bundleName 39 CLOUD_DISK_INODE_OTHER_LAYER // others 40 }; 41 42 enum CLOUD_DISK_INODE_LAYER_LOCALID { 43 CLOUD_DISK_INODE_LAYER_LOCALID_UNKNOWN = 0, // placeholder 44 CLOUD_DISK_INODE_ROOT_LAYER_LOCALID, // / 45 CLOUD_DISK_INODE_ZERO_LAYER_LOCALID, // data 46 CLOUD_DISK_INODE_FIRST_LAYER_LOCALID // bundleName 47 }; 48 49 enum CLOUD_DISK_FILE_DIRTY { 50 CLOUD_DISK_FILE_UNKNOWN = 0, 51 CLOUD_DISK_FILE_CREATE, 52 CLOUD_DISK_FILE_WRITE 53 }; 54 55 enum CLOUD_DISK_FILE_TYPE { 56 CLOUD_DISK_FILE_TYPE_UNKNOWN = 0, 57 CLOUD_DISK_FILE_TYPE_LOCAL, 58 CLOUD_DISK_FILE_TYPE_CLOUD 59 }; 60 61 struct CloudDiskInode { 62 int layer{CLOUD_DISK_INODE_ZERO_LAYER}; 63 struct stat stat; 64 std::string cloudId{"rootId"}; 65 std::string bundleName; 66 std::string fileName; 67 fuse_ino_t parent{0}; 68 std::atomic<int> refCount{0}; 69 std::string path; // just used in local file operation 70 71 /* ops means file operation that uses local or database */ 72 std::shared_ptr<FileOperationsBase> ops{nullptr}; 73 }; 74 75 struct CloudDiskFile { 76 int type{CLOUD_DISK_FILE_TYPE_UNKNOWN}; 77 int fileDirty{CLOUD_DISK_FILE_UNKNOWN}; 78 int32_t fd{-1}; 79 std::atomic<int> refCount{0}; 80 std::shared_ptr<CloudFile::CloudAssetReadSession> readSession{nullptr}; 81 bool isWriteOpen{false}; 82 ffrt::mutex readLock; 83 ffrt::mutex openLock; 84 }; 85 86 struct CloudDiskFuseData { 87 int userId; 88 int64_t bundleNameId{1}; 89 int64_t fileId{0}; 90 std::shared_ptr<CloudDiskInode> rootNode{nullptr}; 91 std::unordered_map<int64_t, std::shared_ptr<CloudDiskInode>> inodeCache; 92 std::unordered_map<int64_t, std::shared_ptr<CloudDiskFile>> fileCache; 93 std::unordered_map<std::string, int64_t> localIdCache; 94 std::shared_mutex bundleNameIdLock; 95 std::shared_mutex cacheLock; 96 std::shared_mutex fileLock; 97 std::shared_mutex fileIdLock; 98 std::shared_mutex localIdLock; 99 struct fuse_session *se; 100 }; 101 } // namespace CloudDisk 102 } // namespace FileManagement 103 } // namespace OHOS 104 #endif // CLOUD_FILE_DAEMON_CLOUD_DISK_INODE_H 105