diff --git a/README.md b/README.md index b7b50492e673ae376a2f30f969765337629762a7..a0731e9238237c7f765313d4fa1ee242d3b1d612 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 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 f16c8d7b9fafbe8435a67037b6b21221ec392de0..5aef701e6389d3f2e822b948fd03d66f2e3e00bf 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 865a694155839b8426257ef7caa7de15a63d84f9..e00669fac59934ecf2bf20bcf1b532405cd749d1 100644 --- a/services/remote_file_share/src/remote_file_share.cpp +++ b/services/remote_file_share/src/remote_file_share.cpp @@ -32,20 +32,41 @@ 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_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 = "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"; 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 +184,60 @@ 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 std::string &filesName) +{ + std::string dstUri = URI_MASK; + + dstUri.insert(URI_BUNDLENAME_INSERT, bundleName); + dstUri += filesName; + + return 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 +293,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, filesName); +} + } // namespace ModuleRemoteFileShare } // namespace AppFileService } // namespace OHOS