• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #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 CloudDiskFile {
62     int type{CLOUD_DISK_FILE_TYPE_UNKNOWN};
63     int fileDirty{CLOUD_DISK_FILE_UNKNOWN};
64     int32_t fd{-1};
65     std::atomic<int> refCount{0};
66     std::shared_ptr<CloudFile::CloudAssetReadSession> readSession{nullptr};
67     bool isWriteOpen{false};
68     uint64_t mtime;
69     ffrt::mutex readLock;
70     ffrt::mutex openLock;
71 };
72 
73 struct CloudDiskInode {
74     int layer{CLOUD_DISK_INODE_ZERO_LAYER};
75     struct stat stat;
76     std::string cloudId{"rootId"};
77     std::string bundleName;
78     std::string fileName;
79     fuse_ino_t parent{0};
80     std::atomic<int> refCount{0};
81     std::string path; // just used in local file operation
82     std::shared_mutex sessionLock;
83 
84     /* ops means file operation that uses local or database */
85     std::shared_ptr<FileOperationsBase> ops{nullptr};
86 };
87 
88 struct CloudDiskFuseData {
89     int userId;
90     int64_t bundleNameId{1};
91     int64_t fileId{0};
92     std::shared_ptr<CloudDiskInode> rootNode{nullptr};
93     std::unordered_map<std::string, std::shared_ptr<CloudFile::CloudAssetReadSession>> readSessionCache;
94     std::unordered_map<int64_t, std::shared_ptr<CloudDiskInode>> inodeCache;
95     std::unordered_map<int64_t, std::shared_ptr<CloudDiskFile>> fileCache;
96     std::unordered_map<std::string, int64_t> localIdCache;
97     std::shared_mutex bundleNameIdLock;
98     std::shared_mutex cacheLock;
99     std::shared_mutex fileLock;
100     std::shared_mutex fileIdLock;
101     std::shared_mutex localIdLock;
102     struct fuse_session *se;
103 };
104 } // namespace CloudDisk
105 } // namespace FileManagement
106 } // namespace OHOS
107 #endif // CLOUD_FILE_DAEMON_CLOUD_DISK_INODE_H
108