diff --git a/services/cloudfiledaemon/BUILD.gn b/services/cloudfiledaemon/BUILD.gn index aa9a4c658584d077d41b2145246b6edf49556aed..dd3ede85ed420f7856913fe4597f9c8ba702ee51 100644 --- a/services/cloudfiledaemon/BUILD.gn +++ b/services/cloudfiledaemon/BUILD.gn @@ -22,12 +22,21 @@ ohos_shared_library("cloudfiledaemon") { debug = false } + cloud_disk = [ + "src/cloud_disk/file_operations_base.cpp", + "src/cloud_disk/file_operations_cloud.cpp", + "src/cloud_disk/file_operations_local.cpp", + "src/cloud_disk/fuse_operations.cpp", + ] + sources = [ "src/fuse_manager/fuse_manager.cpp", "src/ipc/cloud_daemon.cpp", "src/ipc/cloud_daemon_stub.cpp", ] + sources += cloud_disk + configs = [ "${utils_path}:compiler_configs" ] defines = [ "LOG_TAG=\"CloudFileDaemon\"" ] @@ -37,6 +46,7 @@ ohos_shared_library("cloudfiledaemon") { "//third_party/libfuse/include", "//third_party/libfuse/lib", "${innerkits_native_path}/cloud_daemon_kit_inner", + "${services_path}/cloudfiledaemon/include/cloud_disk/", "${services_path}/cloudsyncservice/include/data_sync/", ] diff --git a/services/cloudfiledaemon/include/cloud_disk/cloud_disk_inode.h b/services/cloudfiledaemon/include/cloud_disk/cloud_disk_inode.h new file mode 100644 index 0000000000000000000000000000000000000000..e3039bde11188e4a3970dbe459cc6c4fb380eb5b --- /dev/null +++ b/services/cloudfiledaemon/include/cloud_disk/cloud_disk_inode.h @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef CLOUD_FILE_DAEMON_CLOUD_DISK_INODE_H +#define CLOUD_FILE_DAEMON_CLOUD_DISK_INODE_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "dk_asset_read_session.h" +#include "dk_database.h" +#include "file_operations_base.h" + +namespace OHOS { +namespace FileManagement { +namespace CloudDisk { + +enum CLOUD_DISK_INODE_LAYER { + CLOUD_DISK_INODE_ZERO_LAYER = 0, // data + CLOUD_DISK_INODE_FIRST_LAYER, // bundleName + CLOUD_DISK_INODE_OTHER_LAYER // others +}; + +struct CloudDiskInode { + int layer{CLOUD_DISK_INODE_ZERO_LAYER}; + struct stat stat; + std::string cloudId; + std::string bundleName; + fuse_ino_t parent{0}; + std::atomic refCount{0}; + std::string path; // just used in local file operation + + /* ops means file operation that uses local or database */ + std::shared_ptr ops{nullptr}; + std::shared_ptr readSession{nullptr}; + std::atomic sessionRefCount{0}; + std::shared_mutex sessionLock; +}; + +struct CloudDiskFuseData { + int userId; + std::shared_ptr rootNode{nullptr}; + std::unordered_map> inodeCache; + std::shared_mutex cacheLock; + struct fuse_session *se; +}; +} // namespace CloudDisk +} // namespace FileManagement +} // namespace OHOS +#endif // CLOUD_FILE_DAEMON_CLOUD_DISK_INODE_H diff --git a/services/cloudfiledaemon/include/cloud_disk/file_operations_base.h b/services/cloudfiledaemon/include/cloud_disk/file_operations_base.h new file mode 100644 index 0000000000000000000000000000000000000000..69c2d45d7b957d77b2aa813f9e756511eec51097 --- /dev/null +++ b/services/cloudfiledaemon/include/cloud_disk/file_operations_base.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef CLOUD_FILE_DAEMON_FILE_OPERATIONS_BASE_H +#define CLOUD_FILE_DAEMON_FILE_OPERATIONS_BASE_H + +#define FUSE_USE_VERSION 34 + +#include +#include +#include + +namespace OHOS { +namespace FileManagement { +namespace CloudDisk { +class FileOperationsBase { +public: + virtual void Lookup(fuse_req_t req, fuse_ino_t parent, const char *name); + virtual void Access(fuse_req_t req, fuse_ino_t ino, int mask); + virtual void GetAttr(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi); + virtual void Open(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi); + virtual void Forget(fuse_req_t req, fuse_ino_t ino, uint64_t nLookup); + virtual void ForgetMulti(fuse_req_t req, size_t count, struct fuse_forget_data *forgets); + virtual void MkNod(fuse_req_t req, fuse_ino_t parent, const char *name, + mode_t mode, dev_t rdev); + virtual void Create(fuse_req_t req, fuse_ino_t parent, const char *name, + mode_t mode, struct fuse_file_info *fi); + virtual void ReadDir(fuse_req_t req, fuse_ino_t ino, size_t size, off_t off, + struct fuse_file_info *fi); + virtual void SetXattr(fuse_req_t req, fuse_ino_t ino, const char *name, + const char *value, size_t size, int flags); + virtual void GetXattr(fuse_req_t req, fuse_ino_t ino, const char *name, + size_t size); +}; +} // namespace CloudDisk +} // namespace FileManagement +} // namespace OHOS +#endif // CLOUD_FILE_DAEMON_FILE_OPERATIONS_BASE_H diff --git a/services/cloudfiledaemon/include/cloud_disk/file_operations_cloud.h b/services/cloudfiledaemon/include/cloud_disk/file_operations_cloud.h new file mode 100644 index 0000000000000000000000000000000000000000..7424158f7b003f2fd280922b15e4318d6b09fcf7 --- /dev/null +++ b/services/cloudfiledaemon/include/cloud_disk/file_operations_cloud.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef CLOUD_FILE_DAEMON_FILE_OPERATIONS_CLOUD_H +#define CLOUD_FILE_DAEMON_FILE_OPERATIONS_CLOUD_H + +#include "file_operations_base.h" + +namespace OHOS { +namespace FileManagement { +namespace CloudDisk { +class FileOperationsCloud final : public FileOperationsBase { +public: + void Lookup(fuse_req_t req, fuse_ino_t parent, const char *name) override; + void Access(fuse_req_t req, fuse_ino_t ino, int mask) override; + void GetAttr(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi) override; + void Open(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi) override; + void Forget(fuse_req_t req, fuse_ino_t ino, uint64_t nLookup) override; + void ForgetMulti(fuse_req_t req, size_t count, struct fuse_forget_data *forgets) override; + void MkNod(fuse_req_t req, fuse_ino_t parent, const char *name, + mode_t mode, dev_t rdev) override; + void Create(fuse_req_t req, fuse_ino_t parent, const char *name, + mode_t mode, struct fuse_file_info *fi) override; + void ReadDir(fuse_req_t req, fuse_ino_t ino, size_t size, off_t off, + struct fuse_file_info *fi) override; + void SetXattr(fuse_req_t req, fuse_ino_t ino, const char *name, + const char *value, size_t size, int flags) override; + void GetXattr(fuse_req_t req, fuse_ino_t ino, const char *name, + size_t size) override; +}; +} // namespace CloudDisk +} // namespace FileManagement +} // namespace OHOS +#endif // CLOUD_FILE_DAEMON_FILE_OPERATIONS_CLOUD_H diff --git a/services/cloudfiledaemon/include/cloud_disk/file_operations_local.h b/services/cloudfiledaemon/include/cloud_disk/file_operations_local.h new file mode 100644 index 0000000000000000000000000000000000000000..768d3582c7f9ee9702a879079053cc364cc5d0a6 --- /dev/null +++ b/services/cloudfiledaemon/include/cloud_disk/file_operations_local.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef CLOUD_FILE_DAEMON_FILE_OPERATIONS_LOCAL_H +#define CLOUD_FILE_DAEMON_FILE_OPERATIONS_LOCAL_H + +#include "file_operations_base.h" + +namespace OHOS { +namespace FileManagement { +namespace CloudDisk { +class FileOperationsLocal final : public FileOperationsBase { +public: + void Lookup(fuse_req_t req, fuse_ino_t parent, const char *name) override; + void GetAttr(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi) override; + void Forget(fuse_req_t req, fuse_ino_t ino, uint64_t nLookup) override; + void ForgetMulti(fuse_req_t req, size_t count, struct fuse_forget_data *forgets) override; + void ReadDir(fuse_req_t req, fuse_ino_t ino, size_t size, off_t off, + struct fuse_file_info *fi) override; +}; +} // namespace CloudDisk +} // namespace FileManagement +} // namespace OHOS +#endif // CLOUD_FILE_DAEMON_FILE_OPERATIONS_LOCAL_H diff --git a/services/cloudfiledaemon/include/cloud_disk/fuse_operations.h b/services/cloudfiledaemon/include/cloud_disk/fuse_operations.h new file mode 100644 index 0000000000000000000000000000000000000000..85a209ee43dc49e3c1b1572d6bbd415dae916ad4 --- /dev/null +++ b/services/cloudfiledaemon/include/cloud_disk/fuse_operations.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef CLOUD_FILE_DAEMON_FUSE_OPERATIONS_H +#define CLOUD_FILE_DAEMON_FUSE_OPERATIONS_H + +#include "file_operations_base.h" + +namespace OHOS { +namespace FileManagement { +namespace CloudDisk { +class FuseOperations final { +public: + static void Lookup(fuse_req_t req, fuse_ino_t parent, const char *name); + static void Access(fuse_req_t req, fuse_ino_t ino, int mask); + static void GetAttr(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi); + static void Open(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi); + static void Forget(fuse_req_t req, fuse_ino_t ino, uint64_t nLookup); + static void ForgetMulti(fuse_req_t req, size_t count, struct fuse_forget_data *forgets); + static void MkNod(fuse_req_t req, fuse_ino_t parent, const char *name, + mode_t mode, dev_t rdev); + static void Create(fuse_req_t req, fuse_ino_t parent, const char *name, + mode_t mode, struct fuse_file_info *fi); + static void ReadDir(fuse_req_t req, fuse_ino_t ino, size_t size, off_t off, + struct fuse_file_info *fi); + static void SetXattr(fuse_req_t req, fuse_ino_t ino, const char *name, + const char *value, size_t size, int flags); + static void GetXattr(fuse_req_t req, fuse_ino_t ino, const char *name, + size_t size); +}; +} // CloudDisk +} // FileManagement +} // OHOS +#endif // CLOUD_FILE_DAEMON_FUSE_OPERATIONS_H diff --git a/services/cloudfiledaemon/src/cloud_disk/file_operations_base.cpp b/services/cloudfiledaemon/src/cloud_disk/file_operations_base.cpp new file mode 100644 index 0000000000000000000000000000000000000000..41cf8ae4f698754bf26e10edbc8cf969be32623b --- /dev/null +++ b/services/cloudfiledaemon/src/cloud_disk/file_operations_base.cpp @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "file_operations_base.h" + +#include + +#include "utils_log.h" + +namespace OHOS { +namespace FileManagement { +namespace CloudDisk { +void FileOperationsBase::Lookup(fuse_req_t req, fuse_ino_t parent, const char *name) +{ + LOGE("Lookup operation is not supported!"); + fuse_reply_err(req, ENOSYS); +} + +void FileOperationsBase::Access(fuse_req_t req, fuse_ino_t ino, int mask) +{ + LOGE("Access operation is not supported!"); + fuse_reply_err(req, ENOSYS); +} + +void FileOperationsBase::GetAttr(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi) +{ + LOGE("GetAttr operation is not supported!"); + fuse_reply_err(req, ENOSYS); +} + +void FileOperationsBase::Open(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi) +{ + LOGE("Open operation is not supported!"); + fuse_reply_err(req, ENOSYS); +} + +void FileOperationsBase::Forget(fuse_req_t req, fuse_ino_t ino, uint64_t nLookup) +{ + LOGE("Forget operation is not supported!"); + fuse_reply_err(req, ENOSYS); +} + +void FileOperationsBase::ForgetMulti(fuse_req_t req, size_t count, struct fuse_forget_data *forgets) +{ + LOGE("ForgetMulti operation is not supported!"); + fuse_reply_err(req, ENOSYS); +} + +void FileOperationsBase::MkNod(fuse_req_t req, fuse_ino_t parent, const char *name, + mode_t mode, dev_t rdev) +{ + LOGE("MkNod operation is not supported!"); + fuse_reply_err(req, ENOSYS); +} + +void FileOperationsBase::Create(fuse_req_t req, fuse_ino_t parent, const char *name, + mode_t mode, struct fuse_file_info *fi) +{ + LOGE("Create operation is not supported!"); + fuse_reply_err(req, ENOSYS); +} + +void FileOperationsBase::ReadDir(fuse_req_t req, fuse_ino_t ino, size_t size, off_t off, + struct fuse_file_info *fi) +{ + LOGE("ReadDir operation is not supported!"); + fuse_reply_err(req, ENOSYS); +} + +void FileOperationsBase::SetXattr(fuse_req_t req, fuse_ino_t ino, const char *name, + const char *value, size_t size, int flags) +{ + LOGE("SetXattr operation is not supported!"); + fuse_reply_err(req, ENOSYS); +} + +void FileOperationsBase::GetXattr(fuse_req_t req, fuse_ino_t ino, const char *name, + size_t size) +{ + LOGE("GetXattr operation is not supported!"); + fuse_reply_err(req, ENOSYS); +} +} // namespace CloudDisk +} // namespace FileManagement +} // namespace OHOS diff --git a/services/cloudfiledaemon/src/cloud_disk/file_operations_cloud.cpp b/services/cloudfiledaemon/src/cloud_disk/file_operations_cloud.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2332ae06431b3db63b71bce13dd7673ef050004e --- /dev/null +++ b/services/cloudfiledaemon/src/cloud_disk/file_operations_cloud.cpp @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "file_operations_cloud.h" + +#include + +#include "utils_log.h" + +namespace OHOS { +namespace FileManagement { +namespace CloudDisk { +void FileOperationsCloud::Lookup(fuse_req_t req, fuse_ino_t parent, const char *name) +{ + LOGE("Lookup operation is not supported!"); + fuse_reply_err(req, ENOSYS); +} + +void FileOperationsCloud::Access(fuse_req_t req, fuse_ino_t ino, int mask) +{ + LOGE("Access operation is not supported!"); + fuse_reply_err(req, ENOSYS); +} + +void FileOperationsCloud::GetAttr(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi) +{ + LOGE("GetAttr operation is not supported!"); + fuse_reply_err(req, ENOSYS); +} + +void FileOperationsCloud::Open(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi) +{ + LOGE("Open operation is not supported!"); + fuse_reply_err(req, ENOSYS); +} + +void FileOperationsCloud::Forget(fuse_req_t req, fuse_ino_t ino, uint64_t nLookup) +{ + LOGE("Forget operation is not supported!"); + fuse_reply_err(req, ENOSYS); +} + +void FileOperationsCloud::ForgetMulti(fuse_req_t req, size_t count, struct fuse_forget_data *forgets) +{ + LOGE("ForgetMulti operation is not supported!"); + fuse_reply_err(req, ENOSYS); +} + +void FileOperationsCloud::MkNod(fuse_req_t req, fuse_ino_t parent, const char *name, + mode_t mode, dev_t rdev) +{ + LOGE("MkNod operation is not supported!"); + fuse_reply_err(req, ENOSYS); +} + +void FileOperationsCloud::Create(fuse_req_t req, fuse_ino_t parent, const char *name, + mode_t mode, struct fuse_file_info *fi) +{ + LOGE("Create operation is not supported!"); + fuse_reply_err(req, ENOSYS); +} + +void FileOperationsCloud::ReadDir(fuse_req_t req, fuse_ino_t ino, size_t size, off_t off, + struct fuse_file_info *fi) +{ + LOGE("ReadDir operation is not supported!"); + fuse_reply_err(req, ENOSYS); +} + +void FileOperationsCloud::SetXattr(fuse_req_t req, fuse_ino_t ino, const char *name, + const char *value, size_t size, int flags) +{ + LOGE("SetXattr operation is not supported!"); + fuse_reply_err(req, ENOSYS); +} + +void FileOperationsCloud::GetXattr(fuse_req_t req, fuse_ino_t ino, const char *name, + size_t size) +{ + LOGE("GetXattr operation is not supported!"); + fuse_reply_err(req, ENOSYS); +} +} // namespace CloudDisk +} // namespace FileManagement +} // namespace OHOS diff --git a/services/cloudfiledaemon/src/cloud_disk/file_operations_local.cpp b/services/cloudfiledaemon/src/cloud_disk/file_operations_local.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ae166e7a80669076b7e2384142513e08612f03fa --- /dev/null +++ b/services/cloudfiledaemon/src/cloud_disk/file_operations_local.cpp @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "file_operations_local.h" + +#include + +#include "utils_log.h" + +namespace OHOS { +namespace FileManagement { +namespace CloudDisk { +void FileOperationsLocal::Lookup(fuse_req_t req, fuse_ino_t parent, const char *name) +{ + LOGE("Lookup operation is not supported!"); + fuse_reply_err(req, ENOSYS); +} + +void FileOperationsLocal::GetAttr(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi) +{ + LOGE("GetAttr operation is not supported!"); + fuse_reply_err(req, ENOSYS); +} + +void FileOperationsLocal::Forget(fuse_req_t req, fuse_ino_t ino, uint64_t nLookup) +{ + LOGE("Forget operation is not supported!"); + fuse_reply_err(req, ENOSYS); +} + +void FileOperationsLocal::ForgetMulti(fuse_req_t req, size_t count, struct fuse_forget_data *forgets) +{ + LOGE("ForgetMulti operation is not supported!"); + fuse_reply_err(req, ENOSYS); +} + +void FileOperationsLocal::ReadDir(fuse_req_t req, fuse_ino_t ino, size_t size, off_t off, + struct fuse_file_info *fi) +{ + LOGE("ReadDir operation is not supported!"); + fuse_reply_err(req, ENOSYS); +} +} // namespace CloudDisk +} // namespace FileManagement +} // namespace OHOS diff --git a/services/cloudfiledaemon/src/cloud_disk/fuse_operations.cpp b/services/cloudfiledaemon/src/cloud_disk/fuse_operations.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dff914bf19792d8656bc8836960fbad593ed800f --- /dev/null +++ b/services/cloudfiledaemon/src/cloud_disk/fuse_operations.cpp @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "fuse_operations.h" + +#include "cloud_disk_inode.h" + +namespace OHOS { +namespace FileManagement { +namespace CloudDisk { +void FuseOperations::Lookup(fuse_req_t req, fuse_ino_t parent, const char *name) +{ + struct CloudDiskInode *inoPtr = reinterpret_cast(parent); + inoPtr->ops->Lookup(req, parent, name); +} + +void FuseOperations::Access(fuse_req_t req, fuse_ino_t ino, int mask) +{ + struct CloudDiskInode *inoPtr = reinterpret_cast(ino); + inoPtr->ops->Access(req, ino, mask); +} + +void FuseOperations::GetAttr(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi) +{ + struct CloudDiskInode *inoPtr = reinterpret_cast(ino); + inoPtr->ops->GetAttr(req, ino, fi); +} + +void FuseOperations::Open(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi) +{ + struct CloudDiskInode *inoPtr = reinterpret_cast(ino); + inoPtr->ops->Open(req, ino, fi); +} + +void FuseOperations::Forget(fuse_req_t req, fuse_ino_t ino, uint64_t nLookup) +{ + struct CloudDiskInode *inoPtr = reinterpret_cast(ino); + inoPtr->ops->Forget(req, ino, nLookup); +} + +void FuseOperations::ForgetMulti(fuse_req_t req, size_t count, struct fuse_forget_data *forgets) +{ + if (count == 0) { + return; + } + struct CloudDiskInode *inoPtr = reinterpret_cast(forgets[0].ino); + inoPtr->ops->ForgetMulti(req, count, forgets); +} + +void FuseOperations::MkNod(fuse_req_t req, fuse_ino_t parent, const char *name, + mode_t mode, dev_t rdev) +{ + struct CloudDiskInode *inoPtr = reinterpret_cast(parent); + inoPtr->ops->MkNod(req, parent, name, mode, rdev); +} + +void FuseOperations::Create(fuse_req_t req, fuse_ino_t parent, const char *name, + mode_t mode, struct fuse_file_info *fi) +{ + struct CloudDiskInode *inoPtr = reinterpret_cast(parent); + inoPtr->ops->Create(req, parent, name, mode, fi); +} + +void FuseOperations::ReadDir(fuse_req_t req, fuse_ino_t ino, size_t size, off_t off, + struct fuse_file_info *fi) +{ + struct CloudDiskInode *inoPtr = reinterpret_cast(ino); + inoPtr->ops->ReadDir(req, ino, size, off, fi); +} + +void FuseOperations::SetXattr(fuse_req_t req, fuse_ino_t ino, const char *name, + const char *value, size_t size, int flags) +{ + struct CloudDiskInode *inoPtr = reinterpret_cast(ino); + inoPtr->ops->SetXattr(req, ino, name, value, size, flags); +} + +void FuseOperations::GetXattr(fuse_req_t req, fuse_ino_t ino, const char *name, + size_t size) +{ + struct CloudDiskInode *inoPtr = reinterpret_cast(ino); + inoPtr->ops->GetXattr(req, ino, name, size); +} +} // namespace CloudDisk +} // namespace FileManagement +} // namespace OHOS \ No newline at end of file diff --git a/services/cloudfiledaemon/src/fuse_manager/fuse_manager.cpp b/services/cloudfiledaemon/src/fuse_manager/fuse_manager.cpp index 638d4d92047875e534071f9a2fd25d898bf883a2..417bc892033b2124d9b2fe558894b2865a9030b0 100644 --- a/services/cloudfiledaemon/src/fuse_manager/fuse_manager.cpp +++ b/services/cloudfiledaemon/src/fuse_manager/fuse_manager.cpp @@ -13,8 +13,6 @@ * limitations under the License. */ -#define FUSE_USE_VERSION 34 - #include "fuse_manager/fuse_manager.h" #include @@ -37,16 +35,14 @@ #include #include -#include -#include -#include /* for fuse_cmdline_opts */ - +#include "cloud_disk_inode.h" #include "datetime_ex.h" #include "dfs_error.h" #include "directory_ex.h" #include "dk_database.h" #include "dk_asset_read_session.h" #include "drive_kit.h" +#include "fuse_operations.h" #include "meta_file.h" #include "sdk_helper.h" #include "utils_log.h" @@ -485,8 +481,18 @@ static void CloudRead(fuse_req_t req, fuse_ino_t ino, size_t size, off_t off, } } -static const struct fuse_lowlevel_ops cloudFuseOps = { - .readdir = CloudReadDir, +static const struct fuse_lowlevel_ops cloudDiskFuseOps = { + .lookup = CloudDisk::FuseOperations::Lookup, + .forget = CloudDisk::FuseOperations::Forget, + .getattr = CloudDisk::FuseOperations::GetAttr, + .readdir = CloudDisk::FuseOperations::ReadDir, + .forget_multi = CloudDisk::FuseOperations::ForgetMulti, + .create = CloudDisk::FuseOperations::Create, + .open = CloudDisk::FuseOperations::Open, + .access = CloudDisk::FuseOperations::Access, + .setxattr = CloudDisk::FuseOperations::SetXattr, + .getxattr = CloudDisk::FuseOperations::GetXattr, + .mknod = CloudDisk::FuseOperations::MkNod, }; static const struct fuse_lowlevel_ops cloudMediaFuseOps = { @@ -504,6 +510,7 @@ int32_t FuseManager::StartFuse(int32_t userId, int32_t devFd, const string &path { struct fuse_loop_config config; struct fuse_args args = FUSE_ARGS_INIT(0, nullptr); + struct CloudDisk::CloudDiskFuseData cloudDiskData; struct FuseData data; struct fuse_session *se = nullptr; int ret; @@ -514,22 +521,24 @@ int32_t FuseManager::StartFuse(int32_t userId, int32_t devFd, const string &path } if (path.find("cloud_fuse") != string::npos) { - se = fuse_session_new(&args, &cloudFuseOps, - sizeof(cloudFuseOps), &data); + se = fuse_session_new(&args, &cloudDiskFuseOps, + sizeof(cloudDiskFuseOps), &cloudDiskData); + if (se == nullptr) { + LOGE("cloud disk fuse_session_new error"); + return -EINVAL; + } + cloudDiskData.userId = userId; + cloudDiskData.se = se; } else { se = fuse_session_new(&args, &cloudMediaFuseOps, sizeof(cloudMediaFuseOps), &data); - if (se != nullptr) { - sessions_[userId] = se; + if (se == nullptr) { + LOGE("cloud media fuse_session_new error"); + return -EINVAL; } + data.userId = userId; + data.se = se; } - if (se == nullptr) { - LOGE("fuse_session_new error"); - return -EINVAL; - } - - data.userId = userId; - data.se = se; LOGI("fuse_session_new success, userId: %{public}d", userId); se->fd = devFd; diff --git a/test/unittests/services_daemon/BUILD.gn b/test/unittests/services_daemon/BUILD.gn index 2adef2636090886e3aefbb8afb631c736ba3a764..5db3eeb3961c527c3e8f82b6971d3fe5f6921e10 100644 --- a/test/unittests/services_daemon/BUILD.gn +++ b/test/unittests/services_daemon/BUILD.gn @@ -29,11 +29,21 @@ ohos_unittest("fuse_manager_test") { "fuse_manager_test.cpp", ] + cloud_disk = [ + "${services_path}/cloudfiledaemon/src/cloud_disk/file_operations_base.cpp", + "${services_path}/cloudfiledaemon/src/cloud_disk/file_operations_cloud.cpp", + "${services_path}/cloudfiledaemon/src/cloud_disk/file_operations_local.cpp", + "${services_path}/cloudfiledaemon/src/cloud_disk/fuse_operations.cpp", + ] + + sources += cloud_disk + include_dirs = [ "../../../../../communication/ipc/interfaces/innerkits/ipc_core/include", "${distributedfile_path}/services/cloudfiledaemon/include", "//third_party/libfuse/include", "//third_party/libfuse/lib", + "${services_path}/cloudfiledaemon/include/cloud_disk/", "${services_path}/cloudsyncservice/include/data_sync/", "${distributedfile_path}/adapter/cloud_adapter_example/include", ] @@ -80,11 +90,21 @@ ohos_unittest("cloud_daemon_test") { "cloud_daemon_test.cpp", ] + cloud_disk = [ + "${services_path}/cloudfiledaemon/src/cloud_disk/file_operations_base.cpp", + "${services_path}/cloudfiledaemon/src/cloud_disk/file_operations_cloud.cpp", + "${services_path}/cloudfiledaemon/src/cloud_disk/file_operations_local.cpp", + "${services_path}/cloudfiledaemon/src/cloud_disk/fuse_operations.cpp", + ] + + sources += cloud_disk + include_dirs = [ "../../../../../communication/ipc/interfaces/innerkits/ipc_core/include", "${distributedfile_path}/services/cloudfiledaemon/include", "//third_party/libfuse/include", "//third_party/libfuse/lib", + "${services_path}/cloudfiledaemon/include/cloud_disk/", "${services_path}/cloudsyncservice/include/data_sync/", "${distributedfile_path}/adapter/cloud_adapter_example/include", ]