From 2bb77fcf129b05c78765e0d80ada3d8fb982ea47 Mon Sep 17 00:00:00 2001 From: liuzerun Date: Wed, 28 Jun 2023 04:10:10 +0000 Subject: [PATCH 01/11] test --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index b7b50492e..a0731e923 100644 --- a/README.md +++ b/README.md @@ -34,3 +34,5 @@ Software architecture description 4. The most valuable open source project [GVP](https://gitee.com/gvp) 5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help) 6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) + +add -- Gitee From 4a2c96d77a4c20c6ea3fecf4589f73f274aba7c0 Mon Sep 17 00:00:00 2001 From: liuzerun Date: Wed, 28 Jun 2023 12:49:55 +0000 Subject: [PATCH 02/11] file_remote_share_add --- .../native/file_remote_share/BUILD.gn | 40 +++++++ .../include/file_remote_share.h | 48 ++++++++ .../src/file_remote_share.cpp | 109 ++++++++++++++++++ 3 files changed, 197 insertions(+) create mode 100644 interfaces/innerkits/native/file_remote_share/BUILD.gn create mode 100644 interfaces/innerkits/native/file_remote_share/include/file_remote_share.h create mode 100644 interfaces/innerkits/native/file_remote_share/src/file_remote_share.cpp diff --git a/interfaces/innerkits/native/file_remote_share/BUILD.gn b/interfaces/innerkits/native/file_remote_share/BUILD.gn new file mode 100644 index 000000000..6f9b24ff6 --- /dev/null +++ b/interfaces/innerkits/native/file_remote_share/BUILD.gn @@ -0,0 +1,40 @@ +# 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. + +import("//build/ohos.gni") + +config("file_share_config") { + visibility = [ ":*" ] + include_dirs = [ + "include", + "../common", + ] +} + +ohos_shared_library("fileshare_native") { + sources = [ "src/file_share.cpp" ] + + public_configs = [ ":file_share_config" ] + + external_deps = [ + "ability_base:base", + "ability_base:want", + "ability_base:zuri", + "access_token:libaccesstoken_sdk", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + + part_name = "app_file_service" + subsystem_name = "filemanagement" +} diff --git a/interfaces/innerkits/native/file_remote_share/include/file_remote_share.h b/interfaces/innerkits/native/file_remote_share/include/file_remote_share.h new file mode 100644 index 000000000..c656872bc --- /dev/null +++ b/interfaces/innerkits/native/file_remote_share/include/file_remote_share.h @@ -0,0 +1,48 @@ +/* + * 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 APP_FILE_SERVICE_FILE_REMOTE_SHARE +#define APP_FILE_SERVICE_FILE_REMOTE_SHARE + +#include +#include + +namespace OHOS { +namespace AppFileService { +using namespace std; + +#define HMDFS_IOC 0xf2 +#define HMDFS_IOC_GET_DRAG_PATH _IOR(HMDFS_IOC, 3, __u32) + +namespace { +const int URI_BUNDLENAME_BEGIN = 7; +const int LOOP_TIMES = 6; +const int SRC_USERID_INSERT = 14; +const int SRC_BUNDLENAME_INSERT = 20; +const int DST_BUNDLENAME_INSERT = 48; +const int MAX_PATH_LENGTH = 255; +const string FILE_SCHEME = "file://"; +const string SRC_DIR_MASK = "/data/app/el2//base//files/"; +const string DST_DIR_MASK = "/data/service/el2/hmdfs/account/merge_view/data//"; +const std::string SHAER_PATH_HEAD = "/mnt/hmdfs/"; +const std::string SHAER_PATH_MID = "/account/merge_view/data/remote_share.txt"; +} + +static string ChangeUriFromLocalToCloud (const string &uriStr, const int userId); + +} // namespace AppFileService +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/interfaces/innerkits/native/file_remote_share/src/file_remote_share.cpp b/interfaces/innerkits/native/file_remote_share/src/file_remote_share.cpp new file mode 100644 index 000000000..b39000d32 --- /dev/null +++ b/interfaces/innerkits/native/file_remote_share/src/file_remote_share.cpp @@ -0,0 +1,109 @@ +/* + * 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_drag.h" + +#include +#include +#include +#include +#include +#include + +namespace OHOS { +namespace AppFileService { + +struct hmdfs_drag_info{ + unsigned long localLen; + unsigned long localPath; + unsigned long cloudLen; + unsigned long cloudPath; +}; + +static string GetBundleName (const string &uriStr) +{ + int bundlenameEnd = uriStr.find('/', URI_BUNDLENAME_BEGIN); + return uriStr.substr(URI_BUNDLENAME_BEGIN, + bundlenameEnd - URI_BUNDLENAME_BEGIN); + +} + +static string GetFilesName (const string &uriStr) +{ + int filesEnd = BUNDLENAME_BEGIN - 1; + for(int i = 0; i < LOOP_TIMES; i++){ + filesEnd = uriStr.find('/', filesEnd + 1); + } + return uriStr.substr(filesEnd + 1, + int(uri.size()) - filesEnd); +} + +static string CreateSrcStr(const string &bundleName, const int &userId, const string &filesName) +{ + string srcStr = SRC_DIR_MASK; + + srcStr.substr(SRC_BUNDLENAME_INSERT, bundleName); + srcStr.substr(SRC_USERID_INSERT, to_string(userId)); + srcStr += filesName; + + return srcStr; +} + +static string CreateDstStr(const string &bundleName, const string &filesName) +{ + string dstStr = DST_DIR_MASK; + + dstStr.substr(DST_BUNDLENAME_INSERT, bundleName); + dstStr += filesName; + + return dstStr; +} + +static GetSharePath(const int &userId) +{ + return SHAER_PATH_HEAD + to_string(userId) + SHAER_PATH_MID; +} + +static string ChangeUriFromLocalToCloud (const string &uriStr, const int &userId) +{ + const char *srcCh; + const char *dstCh; + string bundleName = GetBundleName(uriStr); + string filesName = GetFilesName(uriStr); + + string srcStr = CreateSrcStr(bundleName, userId, filesName); + string dstStr = CreateDstStr(bundleName, filesName); + + string dstUriStr = FILE_SCHEME + bundleName + dstStr; + + file hmdfsDevFd = open(GetSharePath(userId), O_RDONLY); + + hmdfs_drag_info hdi; + + srcCh = srcStr.c_str(); + dstCh = dstStr.c_str(); + + hdi.localLen = MAX_PATH_LENGTH; + hdi.localPath = static_cast (srcCh);; + hdi.cloudLen = MAX_PATH_LENGTH; + hdi.cloudPath = static_cast (dstCh); + + ioctl(hmdfsDevFd, HMDFS_IOC_GET_DRAG_PATH, hdi); + + return dstUriStr; +} + +} +} \ No newline at end of file -- Gitee From 841fe8bf032395e15fd9aad877dac0acd6059723 Mon Sep 17 00:00:00 2001 From: runrunya Date: Thu, 29 Jun 2023 04:48:36 +0000 Subject: [PATCH 03/11] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20RE?= =?UTF-8?q?ADME.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 38 -------------------------------------- 1 file changed, 38 deletions(-) delete mode 100644 README.md diff --git a/README.md b/README.md deleted file mode 100644 index a0731e923..000000000 --- a/README.md +++ /dev/null @@ -1,38 +0,0 @@ -# app_file_service - -#### Description -{**When you're done, you can delete the content in this README and update the file with details for others getting started with your repository**} - -#### Software Architecture -Software architecture description - -#### Installation - -1. xxxx -2. xxxx -3. xxxx - -#### Instructions - -1. xxxx -2. xxxx -3. xxxx - -#### Contribution - -1. Fork the repository -2. Create Feat_xxx branch -3. Commit your code -4. Create Pull Request - - -#### Gitee Feature - -1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md -2. Gitee blog [blog.gitee.com](https://blog.gitee.com) -3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore) -4. The most valuable open source project [GVP](https://gitee.com/gvp) -5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help) -6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) - -add -- Gitee From 55abd4bcfec1c38fb4d02c99d22b1979e6fb3054 Mon Sep 17 00:00:00 2001 From: runrunya Date: Thu, 29 Jun 2023 04:56:45 +0000 Subject: [PATCH 04/11] =?UTF-8?q?Revert=20"=E5=88=A0=E9=99=A4=E6=96=87?= =?UTF-8?q?=E4=BB=B6=20README.md"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 841fe8bf032395e15fd9aad877dac0acd6059723. --- README.md | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 000000000..a0731e923 --- /dev/null +++ b/README.md @@ -0,0 +1,38 @@ +# app_file_service + +#### Description +{**When you're done, you can delete the content in this README and update the file with details for others getting started with your repository**} + +#### Software Architecture +Software architecture description + +#### Installation + +1. xxxx +2. xxxx +3. xxxx + +#### Instructions + +1. xxxx +2. xxxx +3. xxxx + +#### Contribution + +1. Fork the repository +2. Create Feat_xxx branch +3. Commit your code +4. Create Pull Request + + +#### Gitee Feature + +1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md +2. Gitee blog [blog.gitee.com](https://blog.gitee.com) +3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore) +4. The most valuable open source project [GVP](https://gitee.com/gvp) +5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help) +6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) + +add -- Gitee From 44303a323a982c0c742ddf02751bee2d3fa7e735 Mon Sep 17 00:00:00 2001 From: liuzerun Date: Thu, 29 Jun 2023 06:38:19 +0000 Subject: [PATCH 05/11] file_remote_share Signed-off-by: liuzerun --- .../include/file_remote_share.h | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/interfaces/innerkits/native/file_remote_share/include/file_remote_share.h b/interfaces/innerkits/native/file_remote_share/include/file_remote_share.h index c656872bc..7ad4b0acf 100644 --- a/interfaces/innerkits/native/file_remote_share/include/file_remote_share.h +++ b/interfaces/innerkits/native/file_remote_share/include/file_remote_share.h @@ -26,21 +26,7 @@ using namespace std; #define HMDFS_IOC 0xf2 #define HMDFS_IOC_GET_DRAG_PATH _IOR(HMDFS_IOC, 3, __u32) -namespace { -const int URI_BUNDLENAME_BEGIN = 7; -const int LOOP_TIMES = 6; -const int SRC_USERID_INSERT = 14; -const int SRC_BUNDLENAME_INSERT = 20; -const int DST_BUNDLENAME_INSERT = 48; -const int MAX_PATH_LENGTH = 255; -const string FILE_SCHEME = "file://"; -const string SRC_DIR_MASK = "/data/app/el2//base//files/"; -const string DST_DIR_MASK = "/data/service/el2/hmdfs/account/merge_view/data//"; -const std::string SHAER_PATH_HEAD = "/mnt/hmdfs/"; -const std::string SHAER_PATH_MID = "/account/merge_view/data/remote_share.txt"; -} - -static string ChangeUriFromLocalToCloud (const string &uriStr, const int userId); +static string ChangeUriFromLocalToCloud (const string &uriStr, const int &userId); } // namespace AppFileService } // namespace OHOS -- Gitee From d91fcd8af1a4f255fffcb24ffa6477218dfa1005 Mon Sep 17 00:00:00 2001 From: liuzerun Date: Thu, 29 Jun 2023 07:04:42 +0000 Subject: [PATCH 06/11] file_remote_share2 Signed-off-by: liuzerun --- .../src/file_remote_share.cpp | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/interfaces/innerkits/native/file_remote_share/src/file_remote_share.cpp b/interfaces/innerkits/native/file_remote_share/src/file_remote_share.cpp index b39000d32..c3794ac12 100644 --- a/interfaces/innerkits/native/file_remote_share/src/file_remote_share.cpp +++ b/interfaces/innerkits/native/file_remote_share/src/file_remote_share.cpp @@ -25,28 +25,42 @@ namespace OHOS { namespace AppFileService { -struct hmdfs_drag_info{ +namespace { +const int URI_BUNDLENAME_BEGIN = 7; +const int LOOP_TIMES = 6; +const int SRC_USERID_INSERT = 14; +const int SRC_BUNDLENAME_INSERT = 20; +const int DST_BUNDLENAME_INSERT = 48; +const int MAX_PATH_LENGTH = 255; +const string FILE_SCHEME = "file://"; +const string SRC_DIR_MASK = "/data/app/el2//base//files/"; +const string DST_DIR_MASK = "/data/service/el2/hmdfs/account/merge_view/data//"; +const std::string SHAER_PATH_HEAD = "/mnt/hmdfs/"; +const std::string SHAER_PATH_MID = "/account/merge_view/data/remote_share.txt"; +} + +struct hmdfs_drag_info { unsigned long localLen; unsigned long localPath; unsigned long cloudLen; unsigned long cloudPath; }; -static string GetBundleName (const string &uriStr) +static string GetBundleName(const string &uriStr) { int bundlenameEnd = uriStr.find('/', URI_BUNDLENAME_BEGIN); - return uriStr.substr(URI_BUNDLENAME_BEGIN, + return uriStr.insert(URI_BUNDLENAME_BEGIN, bundlenameEnd - URI_BUNDLENAME_BEGIN); } -static string GetFilesName (const string &uriStr) +static string GetFilesName(const string &uriStr) { int filesEnd = BUNDLENAME_BEGIN - 1; for(int i = 0; i < LOOP_TIMES; i++){ filesEnd = uriStr.find('/', filesEnd + 1); } - return uriStr.substr(filesEnd + 1, + return uriStr.insert(filesEnd + 1, int(uri.size()) - filesEnd); } @@ -54,8 +68,8 @@ static string CreateSrcStr(const string &bundleName, const int &userId, const st { string srcStr = SRC_DIR_MASK; - srcStr.substr(SRC_BUNDLENAME_INSERT, bundleName); - srcStr.substr(SRC_USERID_INSERT, to_string(userId)); + srcStr.insert(SRC_BUNDLENAME_INSERT, bundleName); + srcStr.insert(SRC_USERID_INSERT, to_string(userId)); srcStr += filesName; return srcStr; @@ -65,7 +79,7 @@ static string CreateDstStr(const string &bundleName, const string &filesName) { string dstStr = DST_DIR_MASK; - dstStr.substr(DST_BUNDLENAME_INSERT, bundleName); + dstStr.insert(DST_BUNDLENAME_INSERT, bundleName); dstStr += filesName; return dstStr; -- Gitee From 39b1681d5829f2b765a6bc9b2fdc34208cf4563d Mon Sep 17 00:00:00 2001 From: liuzerun Date: Thu, 29 Jun 2023 07:24:31 +0000 Subject: [PATCH 07/11] file_remote_share2 Signed-off-by: liuzerun --- .../native/file_remote_share/src/file_remote_share.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/interfaces/innerkits/native/file_remote_share/src/file_remote_share.cpp b/interfaces/innerkits/native/file_remote_share/src/file_remote_share.cpp index c3794ac12..ebb95fcb1 100644 --- a/interfaces/innerkits/native/file_remote_share/src/file_remote_share.cpp +++ b/interfaces/innerkits/native/file_remote_share/src/file_remote_share.cpp @@ -30,11 +30,12 @@ const int URI_BUNDLENAME_BEGIN = 7; const int LOOP_TIMES = 6; const int SRC_USERID_INSERT = 14; const int SRC_BUNDLENAME_INSERT = 20; -const int DST_BUNDLENAME_INSERT = 48; +const int DST_USERID_INSERT = 18; +const int DST_BUNDLENAME_INSERT = 36; const int MAX_PATH_LENGTH = 255; const string FILE_SCHEME = "file://"; const string SRC_DIR_MASK = "/data/app/el2//base//files/"; -const string DST_DIR_MASK = "/data/service/el2/hmdfs/account/merge_view/data//"; +const string DST_DIR_MASK = "/mnt/hmdfs//account/merge_view/data//"; const std::string SHAER_PATH_HEAD = "/mnt/hmdfs/"; const std::string SHAER_PATH_MID = "/account/merge_view/data/remote_share.txt"; } @@ -75,11 +76,12 @@ static string CreateSrcStr(const string &bundleName, const int &userId, const st return srcStr; } -static string CreateDstStr(const string &bundleName, const string &filesName) +static string CreateDstStr(const string &bundleName, const int &userId, const string &filesName) { string dstStr = DST_DIR_MASK; dstStr.insert(DST_BUNDLENAME_INSERT, bundleName); + srcStr.insert(DST_USERID_INSERT, to_string(userId)); dstStr += filesName; return dstStr; -- Gitee From 5b5cd0f9aeb0a588eb303cc4983e1d6bf6f4c63c Mon Sep 17 00:00:00 2001 From: liuzerun Date: Thu, 29 Jun 2023 12:27:43 +0000 Subject: [PATCH 08/11] file_remote_share2 Signed-off-by: liuzerun --- .../innerkits/native/file_remote_share/BUILD.gn | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/interfaces/innerkits/native/file_remote_share/BUILD.gn b/interfaces/innerkits/native/file_remote_share/BUILD.gn index 6f9b24ff6..279cadd5d 100644 --- a/interfaces/innerkits/native/file_remote_share/BUILD.gn +++ b/interfaces/innerkits/native/file_remote_share/BUILD.gn @@ -13,7 +13,7 @@ import("//build/ohos.gni") -config("file_share_config") { +config("file_remote_share_config") { visibility = [ ":*" ] include_dirs = [ "include", @@ -21,19 +21,10 @@ config("file_share_config") { ] } -ohos_shared_library("fileshare_native") { - sources = [ "src/file_share.cpp" ] +ohos_shared_library("fileremoteshare_native") { + sources = [ "src/file_remote_share.cpp" ] - public_configs = [ ":file_share_config" ] - - external_deps = [ - "ability_base:base", - "ability_base:want", - "ability_base:zuri", - "access_token:libaccesstoken_sdk", - "c_utils:utils", - "hiviewdfx_hilog_native:libhilog", - ] + public_configs = [ ":file_remote_share_config" ] part_name = "app_file_service" subsystem_name = "filemanagement" -- Gitee From 61f619d111997668898b901a1a7aab8df708a93b Mon Sep 17 00:00:00 2001 From: liuzerun Date: Thu, 29 Jun 2023 12:29:19 +0000 Subject: [PATCH 09/11] file_remote_share2 Signed-off-by: liuzerun --- .../src/file_remote_share.cpp | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/interfaces/innerkits/native/file_remote_share/src/file_remote_share.cpp b/interfaces/innerkits/native/file_remote_share/src/file_remote_share.cpp index ebb95fcb1..f6f93accc 100644 --- a/interfaces/innerkits/native/file_remote_share/src/file_remote_share.cpp +++ b/interfaces/innerkits/native/file_remote_share/src/file_remote_share.cpp @@ -26,25 +26,25 @@ namespace OHOS { namespace AppFileService { namespace { -const int URI_BUNDLENAME_BEGIN = 7; -const int LOOP_TIMES = 6; -const int SRC_USERID_INSERT = 14; -const int SRC_BUNDLENAME_INSERT = 20; -const int DST_USERID_INSERT = 18; -const int DST_BUNDLENAME_INSERT = 36; -const int MAX_PATH_LENGTH = 255; -const string FILE_SCHEME = "file://"; -const string SRC_DIR_MASK = "/data/app/el2//base//files/"; -const string DST_DIR_MASK = "/mnt/hmdfs//account/merge_view/data//"; -const std::string SHAER_PATH_HEAD = "/mnt/hmdfs/"; -const std::string SHAER_PATH_MID = "/account/merge_view/data/remote_share.txt"; + const int URI_BUNDLENAME_BEGIN = 7; + const int LOOP_TIMES = 6; + const int SRC_USERID_INSERT = 14; + const int SRC_BUNDLENAME_INSERT = 20; + const int DST_USERID_INSERT = 18; + const int DST_BUNDLENAME_INSERT = 36; + const int MAX_PATH_LENGTH = 255; + const string FILE_SCHEME = "file://"; + const string SRC_DIR_MASK = "/data/app/el2//base//files/"; + const string DST_DIR_MASK = "/mnt/hmdfs//account/merge_view/data//"; + const std::string SHAER_PATH_HEAD = "/mnt/hmdfs/"; + const std::string SHAER_PATH_MID = "/account/merge_view/data/remote_share.txt"; } struct hmdfs_drag_info { - unsigned long localLen; - unsigned long localPath; - unsigned long cloudLen; - unsigned long cloudPath; + unsigned long localLen; + unsigned long localPath; + unsigned long cloudLen; + unsigned long cloudPath; }; static string GetBundleName(const string &uriStr) -- Gitee From 0ffb1ad03bcac8fbcccc86e34b4d8e054e1c3f22 Mon Sep 17 00:00:00 2001 From: liuzerun Date: Thu, 29 Jun 2023 17:11:31 +0000 Subject: [PATCH 10/11] file_remote_share Signed-off-by: liuzerun --- .../native/file_remote_share/BUILD.gn | 31 ----- .../include/file_remote_share.h | 34 ----- .../src/file_remote_share.cpp | 125 ------------------ .../native/remote_file_share.h | 1 + .../src/remote_file_share.cpp | 112 ++++++++++++++++ 5 files changed, 113 insertions(+), 190 deletions(-) delete mode 100644 interfaces/innerkits/native/file_remote_share/BUILD.gn delete mode 100644 interfaces/innerkits/native/file_remote_share/include/file_remote_share.h delete mode 100644 interfaces/innerkits/native/file_remote_share/src/file_remote_share.cpp diff --git a/interfaces/innerkits/native/file_remote_share/BUILD.gn b/interfaces/innerkits/native/file_remote_share/BUILD.gn deleted file mode 100644 index 279cadd5d..000000000 --- a/interfaces/innerkits/native/file_remote_share/BUILD.gn +++ /dev/null @@ -1,31 +0,0 @@ -# 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. - -import("//build/ohos.gni") - -config("file_remote_share_config") { - visibility = [ ":*" ] - include_dirs = [ - "include", - "../common", - ] -} - -ohos_shared_library("fileremoteshare_native") { - sources = [ "src/file_remote_share.cpp" ] - - public_configs = [ ":file_remote_share_config" ] - - part_name = "app_file_service" - subsystem_name = "filemanagement" -} diff --git a/interfaces/innerkits/native/file_remote_share/include/file_remote_share.h b/interfaces/innerkits/native/file_remote_share/include/file_remote_share.h deleted file mode 100644 index 7ad4b0acf..000000000 --- a/interfaces/innerkits/native/file_remote_share/include/file_remote_share.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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 APP_FILE_SERVICE_FILE_REMOTE_SHARE -#define APP_FILE_SERVICE_FILE_REMOTE_SHARE - -#include -#include - -namespace OHOS { -namespace AppFileService { -using namespace std; - -#define HMDFS_IOC 0xf2 -#define HMDFS_IOC_GET_DRAG_PATH _IOR(HMDFS_IOC, 3, __u32) - -static string ChangeUriFromLocalToCloud (const string &uriStr, const int &userId); - -} // namespace AppFileService -} // namespace OHOS - -#endif \ No newline at end of file diff --git a/interfaces/innerkits/native/file_remote_share/src/file_remote_share.cpp b/interfaces/innerkits/native/file_remote_share/src/file_remote_share.cpp deleted file mode 100644 index f6f93accc..000000000 --- a/interfaces/innerkits/native/file_remote_share/src/file_remote_share.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/* - * 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_drag.h" - -#include -#include -#include -#include -#include -#include - -namespace OHOS { -namespace AppFileService { - -namespace { - const int URI_BUNDLENAME_BEGIN = 7; - const int LOOP_TIMES = 6; - const int SRC_USERID_INSERT = 14; - const int SRC_BUNDLENAME_INSERT = 20; - const int DST_USERID_INSERT = 18; - const int DST_BUNDLENAME_INSERT = 36; - const int MAX_PATH_LENGTH = 255; - const string FILE_SCHEME = "file://"; - const string SRC_DIR_MASK = "/data/app/el2//base//files/"; - const string DST_DIR_MASK = "/mnt/hmdfs//account/merge_view/data//"; - const std::string SHAER_PATH_HEAD = "/mnt/hmdfs/"; - const std::string SHAER_PATH_MID = "/account/merge_view/data/remote_share.txt"; -} - -struct hmdfs_drag_info { - unsigned long localLen; - unsigned long localPath; - unsigned long cloudLen; - unsigned long cloudPath; -}; - -static string GetBundleName(const string &uriStr) -{ - int bundlenameEnd = uriStr.find('/', URI_BUNDLENAME_BEGIN); - return uriStr.insert(URI_BUNDLENAME_BEGIN, - bundlenameEnd - URI_BUNDLENAME_BEGIN); - -} - -static string GetFilesName(const string &uriStr) -{ - int filesEnd = BUNDLENAME_BEGIN - 1; - for(int i = 0; i < LOOP_TIMES; i++){ - filesEnd = uriStr.find('/', filesEnd + 1); - } - return uriStr.insert(filesEnd + 1, - int(uri.size()) - filesEnd); -} - -static string CreateSrcStr(const string &bundleName, const int &userId, const string &filesName) -{ - string srcStr = SRC_DIR_MASK; - - srcStr.insert(SRC_BUNDLENAME_INSERT, bundleName); - srcStr.insert(SRC_USERID_INSERT, to_string(userId)); - srcStr += filesName; - - return srcStr; -} - -static string CreateDstStr(const string &bundleName, const int &userId, const string &filesName) -{ - string dstStr = DST_DIR_MASK; - - dstStr.insert(DST_BUNDLENAME_INSERT, bundleName); - srcStr.insert(DST_USERID_INSERT, to_string(userId)); - dstStr += filesName; - - return dstStr; -} - -static GetSharePath(const int &userId) -{ - return SHAER_PATH_HEAD + to_string(userId) + SHAER_PATH_MID; -} - -static string ChangeUriFromLocalToCloud (const string &uriStr, const int &userId) -{ - const char *srcCh; - const char *dstCh; - string bundleName = GetBundleName(uriStr); - string filesName = GetFilesName(uriStr); - - string srcStr = CreateSrcStr(bundleName, userId, filesName); - string dstStr = CreateDstStr(bundleName, filesName); - - string dstUriStr = FILE_SCHEME + bundleName + dstStr; - - file hmdfsDevFd = open(GetSharePath(userId), O_RDONLY); - - hmdfs_drag_info hdi; - - srcCh = srcStr.c_str(); - dstCh = dstStr.c_str(); - - hdi.localLen = MAX_PATH_LENGTH; - hdi.localPath = static_cast (srcCh);; - hdi.cloudLen = MAX_PATH_LENGTH; - hdi.cloudPath = static_cast (dstCh); - - ioctl(hmdfsDevFd, HMDFS_IOC_GET_DRAG_PATH, hdi); - - return dstUriStr; -} - -} -} \ No newline at end of file diff --git a/interfaces/innerkits/remote_file_share/native/remote_file_share.h b/interfaces/innerkits/remote_file_share/native/remote_file_share.h index f16c8d7b9..5aef701e6 100644 --- a/interfaces/innerkits/remote_file_share/native/remote_file_share.h +++ b/interfaces/innerkits/remote_file_share/native/remote_file_share.h @@ -29,6 +29,7 @@ public: RemoteFileShare() {} static int CreateSharePath(const int &fd, std::string &sharePath, const int &userId, const std::string &deviceId = SHARE_ALL_DEVICE); + static std::string GetDfsUriFromLocal (const std::string &uriStr, const int &userId); ~RemoteFileShare() {} }; } // namespace ModuleRemoteFileShare diff --git a/services/remote_file_share/src/remote_file_share.cpp b/services/remote_file_share/src/remote_file_share.cpp index 865a69415..479adc243 100644 --- a/services/remote_file_share/src/remote_file_share.cpp +++ b/services/remote_file_share/src/remote_file_share.cpp @@ -32,20 +32,42 @@ namespace ModuleRemoteFileShare { namespace { const int HMDFS_CID_SIZE = 64; const int USER_ID_INIT = 100; + const int LOOP_TIMES = 6; + const int LOOP_BEGIN = 7; + const int SRC_USERID_INSERT = 14; + const int SRC_BUNDLENAME_INSERT = 20; + const int DST_USERID_INSERT = 18; + const int DST_BUNDLENAME_INSERT = 49; + const int URI_USERID_INSERT = 11; + const int URI_BUNDLENAME_INSERT = 36; const unsigned HMDFS_IOC = 0xf2; + const unsigned MAX_PATH_LENGTH = 255; + const std::string FILE_SCHEME = "file://"; + const std::string SRC_DIR_MASK = "/data/app/el2//base//files/"; + const std::string DST_DIR_MASK = "/data/service/el2//hmdfs/account/merge_view/data//"; + const std::string URI_MASK = "/mnt/hmdfs//account/merge_view/data//"; const std::string SHAER_PATH_HEAD = "/mnt/hmdfs/"; const std::string SHAER_PATH_MID = "/account/merge_view/services/"; + const std::string SHAER_FILE_PATH = "/account/merge_view/data/remote_share.txt"; const std::string LOWER_SHARE_PATH_HEAD = "/mnt/hmdfs/"; const std::string LOWER_SHARE_PATH_MID = "/account/device_view/local/services/"; } #define HMDFS_IOC_SET_SHARE_PATH _IOW(HMDFS_IOC, 1, struct HmdfsShareControl) +#define HMDFS_IOC_GET_DRAG_PATH _IOR(HMDFS_IOC, 3, unsigned int) struct HmdfsShareControl { int fd; char deviceId[HMDFS_CID_SIZE]; }; +struct hmdfs_drag_info { + unsigned long localLen; + unsigned long localPath; + unsigned long cloudLen; + unsigned long cloudPath; +}; + static std::string GetProcessName() { char pthreadName[PATH_MAX]; @@ -163,6 +185,61 @@ static int CheckInputValidity(const int &fd, const int &userId, const std::strin deviceId.size() != HMDFS_CID_SIZE); } +static std::string GetBundleName(const std::string &uriStr) +{ + int bundlenameEnd = uriStr.find('/', LOOP_BEGIN); + return uriStr.substr(LOOP_BEGIN, bundlenameEnd - LOOP_BEGIN); +} + +static std::string GetFilesName(const std::string &uriStr) +{ + int filesEnd = LOOP_BEGIN - 1; + for(int i = 0; i < LOOP_TIMES; i++){ + filesEnd = uriStr.find('/', filesEnd + 1); + } + return uriStr.substr(filesEnd + 1, + int(uriStr.size()) - filesEnd); +} + +static std::string GetSrcStr(const std::string &bundleName, const int &userId, const std::string &filesName) +{ + std::string srcStr = SRC_DIR_MASK; + + srcStr.insert(SRC_BUNDLENAME_INSERT, bundleName); + srcStr.insert(SRC_USERID_INSERT, std::to_string(userId)); + srcStr += filesName; + + return srcStr; +} + +static std::string GetDstStr(const std::string &bundleName, const int &userId, const std::string &filesName) +{ + std::string dstStr = DST_DIR_MASK; + + dstStr.insert(DST_BUNDLENAME_INSERT, bundleName); + dstStr.insert(DST_USERID_INSERT, std::to_string(userId)); + dstStr += filesName; + + return dstStr; +} + +static std::string GetDstUri(const std::string &bundleName, const int &userId, const std::string &filesName) +{ + std::string dstUri = URI_MASK; + + dstUri.insert(URI_BUNDLENAME_INSERT, bundleName); + dstUri.insert(URI_USERID_INSERT, std::to_string(userId)); + dstUri += filesName; + + return FILE_SCHEME + bundleName + dstUri; +} + +static std::string GetShareFile(const int &userId) +{ + return SHAER_PATH_HEAD + std::to_string(userId) + SHAER_FILE_PATH; +} + + int RemoteFileShare::CreateSharePath(const int &fd, std::string &sharePath, const int &userId, const std::string &deviceId) { @@ -218,6 +295,41 @@ int RemoteFileShare::CreateSharePath(const int &fd, std::string &sharePath, LOGI("RemoteFileShare::CreateSharePath, create %{public}s successfully", sharePath.c_str()); return 0; } + + +std::string RemoteFileShare::GetDfsUriFromLocal(const std::string &uriStr, const int &userId) +{ + const char *srcCh; + const char *dstCh; + std::string bundleName = GetBundleName(uriStr); + std::string filesName = GetFilesName(uriStr); + + std::string srcStr = GetSrcStr(bundleName, userId, filesName); + std::string dstStr = GetDstStr(bundleName, userId, filesName); + + std::string dstUriStr = FILE_SCHEME + bundleName + dstStr; + + int32_t hmdfsDevFd = open(GetShareFile(userId).c_str(), O_RDONLY); + if (hmdfsDevFd < 0) { + LOGE("RemoteFileShare::CreateShareFile, open share path failed with %{public}d", errno); + return "error"; + } + + hmdfs_drag_info hdi; + + srcCh = srcStr.c_str(); + dstCh = dstStr.c_str(); + + hdi.localLen = MAX_PATH_LENGTH; + hdi.localPath = (unsigned long)(srcCh);; + hdi.cloudLen = MAX_PATH_LENGTH; + hdi.cloudPath = (unsigned long)(dstCh); + + ioctl(hmdfsDevFd, HMDFS_IOC_GET_DRAG_PATH, hdi); + + return GetDstUri(bundleName, userId, filesName); +} + } // namespace ModuleRemoteFileShare } // namespace AppFileService } // namespace OHOS -- Gitee From 6deabcd6ed5bdbda61b28f4ef41b118a7961da78 Mon Sep 17 00:00:00 2001 From: liuzerun Date: Fri, 30 Jun 2023 03:47:09 +0000 Subject: [PATCH 11/11] file_remote_share Signed-off-by: liuzerun --- services/remote_file_share/src/remote_file_share.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/services/remote_file_share/src/remote_file_share.cpp b/services/remote_file_share/src/remote_file_share.cpp index 479adc243..e00669fac 100644 --- a/services/remote_file_share/src/remote_file_share.cpp +++ b/services/remote_file_share/src/remote_file_share.cpp @@ -38,14 +38,13 @@ namespace { const int SRC_BUNDLENAME_INSERT = 20; const int DST_USERID_INSERT = 18; const int DST_BUNDLENAME_INSERT = 49; - const int URI_USERID_INSERT = 11; - const int URI_BUNDLENAME_INSERT = 36; + const int URI_BUNDLENAME_INSERT = 7; const unsigned HMDFS_IOC = 0xf2; const unsigned MAX_PATH_LENGTH = 255; const std::string FILE_SCHEME = "file://"; const std::string SRC_DIR_MASK = "/data/app/el2//base//files/"; const std::string DST_DIR_MASK = "/data/service/el2//hmdfs/account/merge_view/data//"; - const std::string URI_MASK = "/mnt/hmdfs//account/merge_view/data//"; + const std::string URI_MASK = "file:///data/storage/el2/base/files/"; const std::string SHAER_PATH_HEAD = "/mnt/hmdfs/"; const std::string SHAER_PATH_MID = "/account/merge_view/services/"; const std::string SHAER_FILE_PATH = "/account/merge_view/data/remote_share.txt"; @@ -223,15 +222,14 @@ static std::string GetDstStr(const std::string &bundleName, const int &userId, c return dstStr; } -static std::string GetDstUri(const std::string &bundleName, const int &userId, const std::string &filesName) +static std::string GetDstUri(const std::string &bundleName, const std::string &filesName) { std::string dstUri = URI_MASK; dstUri.insert(URI_BUNDLENAME_INSERT, bundleName); - dstUri.insert(URI_USERID_INSERT, std::to_string(userId)); dstUri += filesName; - return FILE_SCHEME + bundleName + dstUri; + return dstUri; } static std::string GetShareFile(const int &userId) @@ -327,7 +325,7 @@ std::string RemoteFileShare::GetDfsUriFromLocal(const std::string &uriStr, const ioctl(hmdfsDevFd, HMDFS_IOC_GET_DRAG_PATH, hdi); - return GetDstUri(bundleName, userId, filesName); + return GetDstUri(bundleName, filesName); } } // namespace ModuleRemoteFileShare -- Gitee