1 /*
2  * Copyright (c) 2023-2024 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_FILE_OPERATIONS_HELPER_H
16 #define CLOUD_FILE_DAEMON_FILE_OPERATIONS_HELPER_H
17 
18 #include "cloud_disk_inode.h"
19 
20 namespace OHOS {
21 namespace FileManagement {
22 namespace CloudDisk {
23 class FileOperationsHelper {
24 public:
25     static int32_t GetNextLayer(std::shared_ptr<CloudDiskInode> inoPtr, fuse_ino_t parent);
26     static int32_t GetFixedLayerRootId(int32_t layer);
27     static std::string GetCloudDiskRootPath(int32_t userId);
28     static std::string GetCloudDiskLocalPath(int32_t userId, std::string fileName);
29     static void GetInodeAttr(std::shared_ptr<CloudDiskInode> ino, struct stat *statBuf);
30     static std::shared_ptr<CloudDiskInode> FindCloudDiskInode(struct CloudDiskFuseData *data,
31                                                               int64_t key);
32     static std::shared_ptr<CloudDiskFile> FindCloudDiskFile(struct CloudDiskFuseData *data,
33                                                             int64_t key);
34     static int64_t FindLocalId(struct CloudDiskFuseData *data, const std::string &key);
35     static void AddDirEntry(fuse_req_t req, std::string &buf, size_t &size, const char *name,
36                             std::shared_ptr<CloudDiskInode> ino);
37     static void FuseReplyLimited(fuse_req_t req, const char *buf, size_t bufSize,
38                                  off_t off, size_t maxSize);
39     static void PutCloudDiskInode(struct CloudDiskFuseData *data,
40                                   std::shared_ptr<CloudDiskInode> inoPtr, uint64_t num, int64_t key);
41     static void PutCloudDiskFile(struct CloudDiskFuseData *data,
42                                  std::shared_ptr<CloudDiskFile> filePtr, int64_t key);
43     static void PutLocalId(struct CloudDiskFuseData *data,
44                            std::shared_ptr<CloudDiskInode> inoPtr, uint64_t num, const std::string &key);
45     static std::shared_ptr<CloudDiskInode> GenerateCloudDiskInode(struct CloudDiskFuseData *data,
46                                                                   fuse_ino_t parent,
47                                                                   const std::string &fileName,
48                                                                   const std::string &path);
49 };
50 } // namespace CloudDisk
51 } // namespace FileManagement
52 } // namespace OHOS
53 #endif // CLOUD_FILE_DAEMON_FILE_OPERATIONS_HELPER_H
54