• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 
16 #include "volume/volume_manager_service_ext.h"
17 
18 #include <dlfcn.h>
19 #include <sys/xattr.h>
20 
21 #include "disk.h"
22 #include "disk/disk_manager_service.h"
23 #include "safe_map.h"
24 #include "securec.h"
25 #include "storage_daemon_communication/storage_daemon_communication.h"
26 #include "storage_service_errno.h"
27 #include "storage_service_log.h"
28 #include "utils/storage_radar.h"
29 #include "utils/storage_utils.h"
30 #include "utils/file_utils.h"
31 #include "utils/string_utils.h"
32 #include "volume/notification.h"
33 
34 using namespace OHOS::StorageService;
35 namespace OHOS {
36 namespace StorageManager {
37 
38 namespace {
39 typedef int32_t (*FuncMount)(int, const std::string&, const std::string&);
40 typedef int32_t (*FuncUMount)(const std::string&);
41 }
42 
VolumeManagerServiceExt()43 VolumeManagerServiceExt::VolumeManagerServiceExt()
44 {
45     Init();
46     LOGI("Instance created.");
47 }
48 
~VolumeManagerServiceExt()49 VolumeManagerServiceExt::~VolumeManagerServiceExt()
50 {
51     UnInit();
52     LOGI("Instance destroyed.");
53 }
54 
Init()55 void VolumeManagerServiceExt::Init()
56 {
57     handler_ = dlopen("/system/lib64/libspace_ability_fuse_ext.z.so", RTLD_LAZY);
58     if (handler_ == nullptr) {
59         LOGE("Policy not exist, just start service.");
60         return;
61     }
62 }
63 
UnInit()64 void VolumeManagerServiceExt::UnInit()
65 {
66     LOGI("UnInit start");
67     if (handler_) {
68         dlclose(handler_);
69         handler_ = nullptr;
70     }
71 }
72 
NotifyUsbFuseMount(int fuseFd,const std::string & volumeId,const std::string & fsUuid)73 int32_t VolumeManagerServiceExt::NotifyUsbFuseMount(int fuseFd, const std::string &volumeId, const std::string &fsUuid)
74 {
75     LOGI("NotifyUsbFuseMount in");
76     if (handler_ == nullptr) {
77         LOGE("Handler is nullptr");
78         return E_NOTIFY_FAILED;
79     }
80     FuncMount funcMount = (FuncMount)dlsym(handler_, "NotifyExternalVolumeFuseMount");
81     if (funcMount == nullptr) {
82         LOGE("Failed to get function pointer for NotifyExternalVolumeFuseMount");
83         return E_NOTIFY_FAILED;
84     }
85     if (funcMount(fuseFd, volumeId, fsUuid) != E_OK) {
86         LOGE("NotifyUsbFuseMount fail");
87         return E_NOTIFY_FAILED;
88     }
89     return E_OK;
90 }
91 
NotifyUsbFuseUmount(const std::string & volumeId)92 int32_t VolumeManagerServiceExt::NotifyUsbFuseUmount(const std::string &volumeId)
93 {
94     LOGI("NotifyUsbFuseUmount in");
95     if (handler_ == nullptr) {
96         LOGE("Handler is nullptr");
97         return E_NOTIFY_FAILED;
98     }
99     FuncUMount funcUMount = (FuncUMount)dlsym(handler_, "NotifyExternalVolumeFuseUmount");
100     if (funcUMount == nullptr) {
101         LOGE("Failed to get function pointer for NotifyExternalVolumeFuseUmount");
102         return E_NOTIFY_FAILED;
103     }
104     if (funcUMount(volumeId) != E_OK) {
105         LOGE("NotifyUsbFuseUmount fail");
106         return E_NOTIFY_FAILED;
107     }
108     return E_OK;
109 }
110 } // StorageManager
111 } // OHOS