• 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_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 "dk_asset_read_session.h"
29 #include "dk_database.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_FILE_DIRTY {
43     CLOUD_DISK_FILE_UNKNOWN = 0,
44     CLOUD_DISK_FILE_CREATE,
45     CLOUD_DISK_FILE_WRITE
46 };
47 
48 struct CloudDiskInode {
49     int layer{CLOUD_DISK_INODE_ZERO_LAYER};
50     struct stat stat;
51     std::string cloudId{"rootId"};
52     std::string bundleName;
53     std::string location;
54     std::string fileName;
55     fuse_ino_t parent{0};
56     std::atomic<int> refCount{0};
57     std::string path; // just used in local file operation
58 
59     /* ops means file operation that uses local or database */
60     std::shared_ptr<FileOperationsBase> ops{nullptr};
61     std::shared_ptr<DriveKit::DKAssetReadSession> readSession{nullptr};
62     std::atomic<int> sessionRefCount{0};
63     std::shared_mutex sessionLock;
64 };
65 
66 struct CloudDiskFile {
67     int fileDirty{CLOUD_DISK_FILE_UNKNOWN};
68     std::atomic<int> refCount{0};
69 };
70 
71 struct CloudDiskFuseData {
72     int userId;
73     std::shared_ptr<CloudDiskInode> rootNode{nullptr};
74     std::unordered_map<std::string, std::shared_ptr<CloudDiskInode>> inodeCache;
75     std::unordered_map<std::string, std::shared_ptr<CloudDiskFile>> fileCache;
76     std::shared_mutex cacheLock;
77     std::shared_mutex fileLock;
78     struct fuse_session *se;
79 };
80 } // namespace CloudDisk
81 } // namespace FileManagement
82 } // namespace OHOS
83 #endif // CLOUD_FILE_DAEMON_CLOUD_DISK_INODE_H
84