add block uevent replay

Signed-off-by: jiahaoluo <luojiahao5@huawei.com>
This commit is contained in:
jiahaoluo 2022-02-08 10:06:25 +08:00
parent d2c9554cd8
commit 421591498d
28 changed files with 504 additions and 37 deletions

View File

@ -50,7 +50,8 @@
"//third_party/fsck_msdos:fsck_msdos",
"//third_party/gptfdisk:sgdisk",
"//third_party/newfs_msdos:newfs_msdos",
"//third_party/ntfs-3g:ntfsprogs"
"//third_party/ntfs-3g:ntfsprogs",
"//third_party/e2fsprogs/misc:blkid"
],
"inner_kits": [
{

View File

@ -34,8 +34,8 @@ public:
virtual std::vector<int64_t> GetBundleStats(std::string uuid, std::string pkgName) = 0;
virtual void NotifyVolumeCreated(VolumeCore vc) = 0;
virtual void NotifyVolumeMounted(std::string volumeId, int fsType, std::string fsUuid,
std::string path, std::string description) = 0;
virtual void NotifyVolumeDestoryed(std::string volumeId) = 0;
std::string path, std::string description) = 0;
virtual void NotifyVolumeDestroyed(std::string volumeId) = 0;
virtual int32_t Mount(std::string volumeId) = 0;
virtual int32_t Unmount(std::string volumeId) = 0;
virtual std::vector<VolumeExternal> GetAllVolumes() = 0;
@ -61,7 +61,7 @@ public:
GET_BUNDLE_STATUS,
NOTIFY_VOLUME_CREATED,
NOTIFY_VOLUME_MOUNTED,
NOTIFY_VOLUME_DESTORYED,
NOTIFY_VOLUME_DESTROYED,
MOUNT,
UNMOUNT,
GET_ALL_VOLUMES,

View File

@ -20,7 +20,6 @@ ohos_prebuilt_etc("storage_daemon_cfg") {
part_name = "storage_service"
subsystem_name = "filemanagement"
}
## Install storage_daemon.cfg to /system/etc/init/storage_daemon.cfg }}}
config("storage_daemon_config") {
@ -28,6 +27,10 @@ config("storage_daemon_config") {
"include",
"//utils/native/base/include",
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy/include",
"../storage_manager/include",
"//foundation/aafwk/standard/interfaces/innerkits/base/include",
"//foundation/distributedschedule/safwk/interfaces/innerkits/safwk",
"//foundation/filemanagement/storage_service/interfaces/innerkits/storage_manager/native",
"//base/startup/syspara_lite/interfaces/innerkits/native/syspara/include",
"//foundation/filemanagement/storage_service/utils/include",
]
@ -37,6 +40,11 @@ ohos_executable("storage_daemon") {
sources = [
"ipc/src/storage_daemon.cpp",
"ipc/src/storage_daemon_stub.cpp",
"ipc/src/storage_manager_client.cpp",
"../storage_manager/ipc/src/storage_manager_proxy.cpp",
"../storage_manager/innerkits_impl/src/volume_core.cpp",
"../storage_manager/innerkits_impl/src/disk.cpp",
"../storage_manager/innerkits_impl/src/volume_external.cpp",
"main.cpp",
"netlink/src/netlink_data.cpp",
"netlink/src/netlink_handler.cpp",

View File

@ -34,7 +34,6 @@ const std::string sgdiskPartCmd = " --new=0:0:-0 --typeconde=0:0c00 --gpttombr=1
DiskInfo::DiskInfo(std::string sysPath, std::string devPath, dev_t device, int flag)
{
id_ = StringPrintf("disk-%d-%d", major(device), minor(device));
sysPath_ = sysPath;
eventPath_ = devPath;
@ -59,6 +58,26 @@ std::string DiskInfo::GetDevPath() const
return devPath_;
}
uint64_t DiskInfo::GetDevDSize() const
{
return size_;
}
std::string DiskInfo::GetSysPath() const
{
return sysPath_;
}
std::string DiskInfo::GetDevVendor() const
{
return vendor_;
}
int DiskInfo::GetDevFlag() const
{
return flags_;
}
DiskInfo::~DiskInfo()
{
DestroyDiskNode(devPath_);

View File

@ -21,7 +21,9 @@
#include "storage_service_errno.h"
#include "storage_service_log.h"
#include "ipc/storage_manager_client.h"
#include "utils/string_utils.h"
#include "utils/file_utils.h"
#include "utils/disk_utils.h"
namespace OHOS {
@ -57,6 +59,17 @@ void DiskManager::HandleDiskEvent(NetlinkData *data)
std::string devPath = data->GetDevpath();
std::string devType = data->GetParam("DEVTYPE");
LOGI("GetAction %{public}d", data->GetAction());
LOGI("GetDevpath %{public}s", data->GetDevpath().c_str());
LOGI("GetSyspath %{public}s", data->GetSyspath().c_str());
LOGI("GetSubsystem %{public}s", data->GetSubsystem().c_str());
LOGI("GetParam MAJOR %{public}s", data->GetParam("MAJOR").c_str());
LOGI("GetParam MINOR %{public}s", data->GetParam("MINOR").c_str());
LOGI("GetParam DEVNAME %{public}s", data->GetParam("DEVNAME").c_str());
LOGI("GetParam DEVTYPE %{public}s", data->GetParam("DEVTYPE").c_str());
LOGI("GetParam SEQNUM %{public}s", data->GetParam("SEQNUM").c_str());
LOGI("Disk type is %{public}s", devType.c_str());
if (devType != "disk") {
return;
}
@ -100,8 +113,15 @@ void DiskManager::HandleDiskEvent(NetlinkData *data)
void DiskManager::CreateDisk(std::shared_ptr<DiskInfo> &diskInfo)
{
int ret;
diskInfo->Create();
disk_.push_back(diskInfo);
StorageManagerClient client;
ret = client.NotifyDiskCreated(diskInfo);
if (ret != E_OK) {
LOGI("Notify Disk Destroyed failed");
}
}
void DiskManager::ChangeDisk(dev_t device)
@ -116,9 +136,17 @@ void DiskManager::ChangeDisk(dev_t device)
void DiskManager::DestoryDisk(dev_t device)
{
int ret;
for (auto i = disk_.begin(); i != disk_.end();) {
if ((*i)->GetDevice() == device) {
(*i)->Destroy();
StorageManagerClient client;
ret = client.NotifyDiskDestroyed((*i)->GetId());
if (ret != E_OK) {
LOGI("Notify Disk Destroyed failed");
}
i = disk_.erase(i);
} else {
i++;
@ -142,5 +170,24 @@ void DiskManager::AddDiskConfig(std::shared_ptr<DiskConfig> &diskConfig)
diskConfig_.push_back(diskConfig);
}
void DiskManager::ReplayUevent()
{
TraverseDirUevent(sysBlockPath_, true);
}
int32_t DiskManager::HandlePartition(std::string diskId, int32_t type)
{
int32_t ret = E_NON_EXIST;
for (auto i = disk_.begin(); i != disk_.end();) {
if ((*i)->GetId() == diskId) {
ret = (*i)->Partition();
break;
}
}
return ret;
}
} // namespace STORAGE_DAEMON
} // namespace OHOS

View File

@ -46,6 +46,10 @@ public:
dev_t GetDevice() const;
std::string GetId() const;
std::string GetDevPath() const;
uint64_t GetDevDSize() const;
std::string GetSysPath() const;
std::string GetDevVendor() const;
int GetDevFlag() const;
private:
std::string id_;

View File

@ -19,6 +19,7 @@
#include <list>
#include <memory>
#include <mutex>
#include <cstring>
#include <nocopyable.h>
#include <sys/types.h>
@ -39,15 +40,21 @@ public:
void ChangeDisk(dev_t device);
std::shared_ptr<DiskInfo> GetDisk(dev_t device);
void HandleDiskEvent(NetlinkData *data);
int32_t HandlePartition(std::string diskId, int32_t type);
void AddDiskConfig(std::shared_ptr<DiskConfig> &diskConfig);
void ReplayUevent();
private:
DiskManager();
std::mutex lock_;
std::list<std::shared_ptr<DiskInfo>> disk_;
std::list<std::shared_ptr<DiskConfig>> diskConfig_;
static DiskManager* instance_;
DISALLOW_COPY_AND_MOVE(DiskManager);
const std::string sysBlockPath_ = "/sys/block";
};
} // STORAGE_DAEMON
} // OHOS

View File

@ -30,11 +30,13 @@ public:
UMOUNT,
CHECK,
FORMAT,
PARTITION,
PREPARE_USER_DIRS,
DESTROY_USER_DIRS,
START_USER,
STOP_USER,
INIT_GLOBAL_KEY,
INIT_GLOBAL_USER_KEYS,
CREATE_USER_KEYS,
@ -55,6 +57,7 @@ public:
virtual int32_t UMount(std::string volId) = 0;
virtual int32_t Check(std::string volId) = 0;
virtual int32_t Format(std::string voldId) = 0;
virtual int32_t Partition(std::string diskId, int32_t type) = 0;
virtual int32_t StartUser(int32_t userId) = 0;
virtual int32_t StopUser(int32_t userId) = 0;

View File

@ -31,6 +31,7 @@ public:
virtual int32_t UMount(std::string volId) override;
virtual int32_t Check(std::string volId) override;
virtual int32_t Format(std::string voldId) override;
virtual int32_t Partition(std::string diskId, int32_t type) override;
virtual int32_t StartUser(int32_t userId) override;
virtual int32_t StopUser(int32_t userId) override;

View File

@ -30,6 +30,7 @@ public:
virtual int32_t UMount(std::string volId) override;
virtual int32_t Check(std::string volId) override;
virtual int32_t Format(std::string voldId) override;
virtual int32_t Partition(std::string diskId, int32_t type) override;
virtual int32_t StartUser(int32_t userId) override;
virtual int32_t StopUser(int32_t userId) override;

View File

@ -33,6 +33,7 @@ private:
int32_t HandleUMount(MessageParcel &data, MessageParcel &reply);
int32_t HandleCheck(MessageParcel &data, MessageParcel &reply);
int32_t HandleFormat(MessageParcel &data, MessageParcel &reply);
int32_t HandlePartition(MessageParcel &data, MessageParcel &reply);
int32_t HandleStartUser(MessageParcel &data, MessageParcel &reply);
int32_t HandleStopUser(MessageParcel &data, MessageParcel &reply);

View File

@ -0,0 +1,50 @@
/*
* Copyright (c) 2021 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 OHOS_STORAGE_MANAGER_STORAGE_DAEMON_COMMUNICATION_H
#define OHOS_STORAGE_MANAGER_STORAGE_DAEMON_COMMUNICATION_H
#include <nocopyable.h>
#include "ipc/storage_manager.h"
#include "disk/disk_info.h"
#include "volume/volume_info.h"
namespace OHOS {
namespace StorageDaemon {
class StorageManagerClient final {
public:
StorageManagerClient() = default;
int32_t NotifyDiskCreated(std::shared_ptr<DiskInfo> &diskInfo);
int32_t NotifyDiskDestroyed(std::string id);
int32_t NotifyVolumeCreated(VolumeInfo volumeInfo);
int32_t NotifyVolumeMounted(VolumeInfo volumeInfo);
int32_t NotifyVolumeDestroyed(VolumeInfo volumeInfo);
int32_t GetAllDisks();
private:
DISALLOW_COPY_AND_MOVE(StorageManagerClient);
int32_t GetClient();
sptr<OHOS::StorageManager::IStorageManager> storageManager_;
};
} // StorageManager
} // OHOS
#endif

View File

@ -44,6 +44,7 @@ void ReadDigitDir(const std::string &path, std::vector<FileList> &dirInfo);
bool StringToUint32(const std::string &str, uint32_t &num);
bool ReadFile(std::string path, std::string *str);
int ForkExec(std::vector<std::string> &cmd, std::vector<std::string> *output = nullptr);
void TraverseDirUevent(const std::string &path, bool flag);
}
}

View File

@ -15,6 +15,7 @@
#include "ipc/storage_daemon.h"
#include "user/user_manager.h"
#include "disk/disk_manager.h"
#include "storage_service_errno.h"
#include "crypto/key_manager.h"
#include "storage_service_log.h"
@ -28,24 +29,34 @@ int32_t StorageDaemon::Shutdown()
int32_t StorageDaemon::Mount(std::string volId, uint32_t flags)
{
LOGI("Handle Mount");
return E_OK;
}
int32_t StorageDaemon::UMount(std::string volId)
{
LOGI("Handle UMount");
return E_OK;
}
int32_t StorageDaemon::Check(std::string volId)
{
LOGI("Handle Check");
return E_OK;
}
int32_t StorageDaemon::Format(std::string voldId)
{
LOGI("Handle Format");
return E_OK;
}
int32_t StorageDaemon::Partition(std::string diskId, int32_t type)
{
LOGI("Handle Partition");
return DiskManager::Instance()->HandlePartition(diskId, type);
}
int32_t StorageDaemon::PrepareUserDirs(int32_t userId, uint32_t flags)
{
return UserManager::GetInstance()->PrepareUserDirs(userId, flags);

View File

@ -36,22 +36,110 @@ int32_t StorageDaemonProxy::Shutdown()
int32_t StorageDaemonProxy::Mount(std::string volId, uint32_t flags)
{
return E_OK;
MessageParcel data, reply;
MessageOption option(MessageOption::TF_SYNC);
if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
return E_IPC_ERROR;
}
if (!data.WriteString(volId)) {
return E_IPC_ERROR;
}
if (!data.WriteUint32(flags)) {
return E_IPC_ERROR;
}
int err = Remote()->SendRequest(MOUNT, data, reply, option);
if (err != E_OK) {
return E_IPC_ERROR;
}
return reply.ReadInt32();
}
int32_t StorageDaemonProxy::UMount(std::string volId)
{
return E_OK;
MessageParcel data, reply;
MessageOption option(MessageOption::TF_SYNC);
if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
return E_IPC_ERROR;
}
if (!data.WriteString(volId)) {
return E_IPC_ERROR;
}
int err = Remote()->SendRequest(UMOUNT, data, reply, option);
if (err != E_OK) {
return E_IPC_ERROR;
}
return reply.ReadInt32();
}
int32_t StorageDaemonProxy::Check(std::string volId)
{
return E_OK;
MessageParcel data, reply;
MessageOption option(MessageOption::TF_SYNC);
if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
return E_IPC_ERROR;
}
if (!data.WriteString(volId)) {
return E_IPC_ERROR;
}
int err = Remote()->SendRequest(CHECK, data, reply, option);
if (err != E_OK) {
return E_IPC_ERROR;
}
return reply.ReadInt32();
}
int32_t StorageDaemonProxy::Format(std::string voldId)
{
return E_OK;
MessageParcel data, reply;
MessageOption option(MessageOption::TF_SYNC);
if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
return E_IPC_ERROR;
}
if (!data.WriteString(voldId)) {
return E_IPC_ERROR;
}
int err = Remote()->SendRequest(FORMAT, data, reply, option);
if (err != E_OK) {
return E_IPC_ERROR;
}
return reply.ReadInt32();
}
int32_t StorageDaemonProxy::Partition(std::string diskId, int32_t type)
{
MessageParcel data, reply;
MessageOption option(MessageOption::TF_SYNC);
if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
return E_IPC_ERROR;
}
if (!data.WriteString(diskId)) {
return E_IPC_ERROR;
}
if (!data.WriteInt32(type)) {
return E_IPC_ERROR;
}
int err = Remote()->SendRequest(PARTITION, data, reply, option);
if (err != E_OK) {
return E_IPC_ERROR;
}
return reply.ReadInt32();
}
int32_t StorageDaemonProxy::PrepareUserDirs(int32_t userId, uint32_t flags)
@ -76,7 +164,7 @@ int32_t StorageDaemonProxy::PrepareUserDirs(int32_t userId, uint32_t flags)
return E_IPC_ERROR;
}
return reply.ReadUint32();
return reply.ReadInt32();
}
int32_t StorageDaemonProxy::DestroyUserDirs(int32_t userId, uint32_t flags)
@ -101,7 +189,7 @@ int32_t StorageDaemonProxy::DestroyUserDirs(int32_t userId, uint32_t flags)
return E_IPC_ERROR;
}
return reply.ReadUint32();
return reply.ReadInt32();
}
int32_t StorageDaemonProxy::StartUser(int32_t userId)
@ -122,7 +210,7 @@ int32_t StorageDaemonProxy::StartUser(int32_t userId)
return E_IPC_ERROR;
}
return reply.ReadUint32();
return reply.ReadInt32();
}
int32_t StorageDaemonProxy::StopUser(int32_t userId)

View File

@ -20,7 +20,7 @@
namespace OHOS {
namespace StorageDaemon {
int32_t StorageDaemonStub::OnRemoteRequest(uint32_t code, MessageParcel &data,
MessageParcel &reply, MessageOption &option)
MessageParcel &reply, MessageOption &option)
{
auto remoteDescriptor = data.ReadInterfaceToken();
if (GetDescriptor() != remoteDescriptor) {
@ -33,6 +33,21 @@ int32_t StorageDaemonStub::OnRemoteRequest(uint32_t code, MessageParcel &data,
case SHUTDOWN:
err = HandleShutdown();
break;
case CHECK:
err = HandleCheck(data, reply);
break;
case MOUNT:
err = HandleMount(data, reply);
break;
case UMOUNT:
err =HandleUMount(data, reply);
break;
case PARTITION:
err = HandlePartition(data, reply);
break;
case FORMAT:
err = HandleFormat(data, reply);
break;
case PREPARE_USER_DIRS:
err = HandlePrepareUserDirs(data, reply);
break;
@ -84,21 +99,63 @@ int32_t StorageDaemonStub::HandleShutdown()
int32_t StorageDaemonStub::HandleMount(MessageParcel &data, MessageParcel &reply)
{
std::string volId = data.ReadString();
uint32_t flags = data.ReadUint32();
int err = Mount(volId, flags);
if (!reply.WriteInt32(err)) {
return E_IPC_ERROR;
}
return E_OK;
}
int32_t StorageDaemonStub::HandleUMount(MessageParcel &data, MessageParcel &reply)
{
std::string volId = data.ReadString();
int err = UMount(volId);
if (!reply.WriteInt32(err)) {
return E_IPC_ERROR;
}
return E_OK;
}
int32_t StorageDaemonStub::HandleCheck(MessageParcel &data, MessageParcel &reply)
{
std::string volId = data.ReadString();
int err = Check(volId);
if (!reply.WriteInt32(err)) {
return E_IPC_ERROR;
}
return E_OK;
}
int32_t StorageDaemonStub::HandleFormat(MessageParcel &data, MessageParcel &reply)
{
std::string volId = data.ReadString();
int err = Format(volId);
if (!reply.WriteInt32(err)) {
return E_IPC_ERROR;
}
return E_OK;
}
int32_t StorageDaemonStub::HandlePartition(MessageParcel &data, MessageParcel &reply)
{
std::string volId = data.ReadString();
int32_t type = data.ReadInt32();
int err = Partition(volId, type);
if (!reply.WriteInt32(err)) {
return E_IPC_ERROR;
}
return E_OK;
}
@ -108,7 +165,7 @@ int32_t StorageDaemonStub::HandlePrepareUserDirs(MessageParcel &data, MessagePar
uint32_t flags = data.ReadUint32();
int err = PrepareUserDirs(userId, flags);
if (!reply.WriteUint32(err)) {
if (!reply.WriteInt32(err)) {
return E_IPC_ERROR;
}
@ -121,7 +178,7 @@ int32_t StorageDaemonStub::HandleDestroyUserDirs(MessageParcel &data, MessagePar
uint32_t flags = data.ReadUint32();
int err = DestroyUserDirs(userId, flags);
if (!reply.WriteUint32(err)) {
if (!reply.WriteInt32(err)) {
return E_IPC_ERROR;
}
@ -176,6 +233,7 @@ int32_t StorageDaemonStub::HandleGenerateUserKeys(MessageParcel &data, MessagePa
{
uint32_t userId = data.ReadUint32();
uint32_t flags = data.ReadUint32();
int err = GenerateUserKeys(userId, flags);
if (!reply.WriteInt32(err)) {
return E_IPC_ERROR;
@ -187,6 +245,7 @@ int32_t StorageDaemonStub::HandleGenerateUserKeys(MessageParcel &data, MessagePa
int32_t StorageDaemonStub::HandleDeleteUserKeys(MessageParcel &data, MessageParcel &reply)
{
uint32_t userId = data.ReadUint32();
int err = DeleteUserKeys(userId);
if (!reply.WriteInt32(err)) {
return E_IPC_ERROR;
@ -200,6 +259,7 @@ int32_t StorageDaemonStub::HandleUpdateUserAuth(MessageParcel &data, MessageParc
uint32_t userId = data.ReadUint32();
std::string auth = "";
std::string secret = "";
int err = UpdateUserAuth(userId, auth, secret);
if (!reply.WriteInt32(err)) {
return E_IPC_ERROR;
@ -213,6 +273,7 @@ int32_t StorageDaemonStub::HandleActiveUserKey(MessageParcel &data, MessageParce
uint32_t userId = data.ReadUint32();
std::string auth = "";
std::string secret = "";
int err = ActiveUserKey(userId, auth, secret);
if (!reply.WriteInt32(err)) {
return E_IPC_ERROR;
@ -224,6 +285,7 @@ int32_t StorageDaemonStub::HandleActiveUserKey(MessageParcel &data, MessageParce
int32_t StorageDaemonStub::HandleInactiveUserKey(MessageParcel &data, MessageParcel &reply)
{
uint32_t userId = data.ReadUint32();
int err = InactiveUserKey(userId);
if (!reply.WriteInt32(err)) {
return E_IPC_ERROR;

View File

@ -0,0 +1,124 @@
/*
* Copyright (c) 2021 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 "ipc/storage_manager_client.h"
#include <system_ability_definition.h>
#include <iservice_registry.h>
#include "storage_service_log.h"
#include "storage_service_errno.h"
#include "disk.h"
namespace OHOS {
namespace StorageDaemon {
int32_t StorageManagerClient::GetClient()
{
if (storageManager_ == nullptr) {
auto sam = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (sam == nullptr) {
LOGE("get system ability manager error");
return E_IPC_ERROR;
}
auto object = sam->GetSystemAbility(STORAGE_MANAGER_MANAGER_ID);
if (object == nullptr) {
LOGE("get storage manager object error");
return E_IPC_ERROR;
}
storageManager_ = iface_cast<OHOS::StorageManager::IStorageManager>(object);
if (storageManager_ == nullptr) {
LOGE("iface_cast error");
return E_IPC_ERROR;
}
}
return E_OK;
}
int32_t StorageManagerClient::NotifyDiskCreated(std::shared_ptr<DiskInfo> &diskInfo)
{
if (GetClient() != E_OK) {
return E_IPC_ERROR;
}
StorageManager::Disk disk(diskInfo->GetId(), diskInfo->GetDevDSize(),
diskInfo->GetSysPath(), diskInfo->GetDevVendor(),
diskInfo->GetDevFlag());
storageManager_->NotifyDiskCreated(disk);
return E_OK;
}
int32_t StorageManagerClient::NotifyDiskDestroyed(std::string id)
{
if (GetClient() != E_OK) {
return E_IPC_ERROR;
}
storageManager_->NotifyDiskDestroyed(id);
return E_OK;
}
int32_t StorageManagerClient::NotifyVolumeCreated(VolumeInfo volumeInfo)
{
if (GetClient() != E_OK) {
return E_IPC_ERROR;
}
StorageManager::VolumeCore vc;
storageManager_->NotifyVolumeCreated(vc);
return E_OK;
}
int32_t StorageManagerClient::NotifyVolumeMounted(VolumeInfo volumeInfo)
{
if (GetClient() != E_OK) {
return E_IPC_ERROR;
}
storageManager_->NotifyVolumeMounted("", 0, "", "", "");
return E_OK;
}
int32_t StorageManagerClient::NotifyVolumeDestroyed(VolumeInfo volumeInfo)
{
if (GetClient() != E_OK) {
return E_IPC_ERROR;
}
storageManager_->NotifyVolumeDestroyed("");
return E_OK;
}
int32_t StorageManagerClient::GetAllDisks()
{
if (GetClient() != E_OK) {
return E_IPC_ERROR;
}
std::vector<StorageManager::Disk> ret = storageManager_->GetAllDisks();
for (auto i : ret) {
LOGI("diskId: %{public}s, sizeb: %{public}lld, syspath: %{public}s, vendor: %{public}s, flag: %{public}d",i.GetDiskId().c_str(), i.GetSizeBytes(), i.GetSysPath().c_str(), i.GetVendor().c_str(), i.GetFlag());
}
return E_OK;
}
} // StorageDaemon
} // OHOS

View File

@ -18,6 +18,7 @@
#include "ipc_skeleton.h"
#include "iservice_registry.h"
#include "netlink/netlink_manager.h"
#include "disk/disk_manager.h"
#include "storage_service_log.h"
using namespace OHOS;
@ -44,6 +45,8 @@ int main()
}
} while (true);
StorageDaemon::DiskManager::Instance()->ReplayUevent();
IPCSkeleton::JoinWorkThread();
return 0;

View File

@ -21,6 +21,7 @@
#include <cstring>
#include <dirent.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/wait.h>
@ -333,5 +334,39 @@ int ForkExec(std::vector<std::string> &cmd, std::vector<std::string> *output)
}
return E_OK;
}
void TraverseDirUevent(const std::string &path, bool flag)
{
DIR *dir = opendir(path.c_str());
if (dir == nullptr) {
return;
}
int dirFd = dirfd(dir);
int fd = openat(dirFd, "uevent", O_WRONLY | O_CLOEXEC);
if (fd >= 0) {
write(fd, "add\n", 4);
close(fd);
}
for (struct dirent *ent = readdir(dir); ent != nullptr; ent = readdir(dir)) {
if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0) {
continue;
}
if (ent->d_type != DT_DIR && !flag) {
continue;
}
// fd = openat(dirFd, ent->d_name, O_RDONLY | O_DIRECTORY | O_CLOEXEC);
// if (fd < 0) {
// continue;
// }
TraverseDirUevent(path + "/" + ent->d_name, false);
}
closedir(dir);
}
} // STORAGE_DAEMON
} // OHOS

View File

@ -43,7 +43,7 @@ public:
void NotifyVolumeCreated(VolumeCore vc) override;
void NotifyVolumeMounted(std::string volumeId, int32_t fsType, std::string fsUuid,
std::string path, std::string description) override;
void NotifyVolumeDestoryed(std::string volumeId) override;
void NotifyVolumeDestroyed(std::string volumeId) override;
int32_t Mount(std::string volumeId) override;
int32_t Unmount(std::string volumeId) override;

View File

@ -36,8 +36,8 @@ public:
std::vector<int64_t> GetBundleStats(std::string uuid, std::string pkgName) override;
void NotifyVolumeCreated(VolumeCore vc) override;
void NotifyVolumeMounted(std::string volumeId, int32_t fsType, std::string fsUuid,
std::string path, std::string description) override;
void NotifyVolumeDestoryed(std::string volumeId) override;
std::string path, std::string description) override;
void NotifyVolumeDestroyed(std::string volumeId) override;
int32_t Mount(std::string volumeId) override;
int32_t Unmount(std::string volumeId) override;
std::vector<VolumeExternal> GetAllVolumes() override;

View File

@ -35,7 +35,7 @@ private:
int32_t HandleGetBundleStatus(MessageParcel &data, MessageParcel &reply);
int32_t HandleNotifyVolumeCreated(MessageParcel &data, MessageParcel &reply);
int32_t HandleNotifyVolumeMounted(MessageParcel &data, MessageParcel &reply);
int32_t HandleNotifyVolumeDestoryed(MessageParcel &data, MessageParcel &reply);
int32_t HandleNotifyVolumeDestroyed(MessageParcel &data, MessageParcel &reply);
int32_t HandleMount(MessageParcel &data, MessageParcel &reply);
int32_t HandleUnmount(MessageParcel &data, MessageParcel &reply);
int32_t HandleGetAllVolumes(MessageParcel &data, MessageParcel &reply);

View File

@ -32,7 +32,7 @@ public:
void OnVolumeCreated(VolumeCore vc);
void OnVolumeMounted(std::string volumeId, int32_t fsType, std::string fsUuid,
std::string path, std::string description);
void OnVolumeDestoryed(std::string volumeId);
void OnVolumeDestroyed(std::string volumeId);
std::vector<VolumeExternal> GetAllVolumes();
std::shared_ptr<VolumeExternal> GetVolumeByUuid(std::string volumeUuid);
private:

View File

@ -108,10 +108,10 @@ void StorageManager::NotifyVolumeMounted(std::string volumeId, int32_t fsType, s
DelayedSingleton<VolumeManagerService>::GetInstance()->OnVolumeMounted(volumeId, fsType, fsUuid, path, description);
}
void StorageManager::NotifyVolumeDestoryed(std::string volumeId)
void StorageManager::NotifyVolumeDestroyed(std::string volumeId)
{
LOGI("StorageManger::NotifyVolumeDestoryed start");
DelayedSingleton<VolumeManagerService>::GetInstance()->OnVolumeDestoryed(volumeId);
LOGI("StorageManger::NotifyVolumeDestroyed start");
DelayedSingleton<VolumeManagerService>::GetInstance()->OnVolumeDestroyed(volumeId);
}
int32_t StorageManager::Mount(std::string volumeId)

View File

@ -322,7 +322,7 @@ void StorageManagerProxy::NotifyVolumeCreated(VolumeCore vc)
}
void StorageManagerProxy::NotifyVolumeMounted(std::string volumeId, int32_t fsType, std::string fsUuid,
std::string path, std::string description)
std::string path, std::string description)
{
LOGI("StorageManagerProxy::NotifyVolumeMounted, volumeUuid:%{public}s", volumeId.c_str());
MessageParcel data, reply;
@ -362,23 +362,24 @@ void StorageManagerProxy::NotifyVolumeMounted(std::string volumeId, int32_t fsTy
LOGE("StorageManagerProxy::NotifyVolumeMounted, SendRequest failed");
}
}
void StorageManagerProxy::NotifyVolumeDestoryed(std::string volumeId)
void StorageManagerProxy::NotifyVolumeDestroyed(std::string volumeId)
{
LOGI("StorageManagerProxy::NotifyVolumeDestoryed, volumeId:%{public}s", volumeId.c_str());
MessageParcel data, reply;
MessageOption option(MessageOption::TF_SYNC);
if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
LOGE("StorageManagerProxy::NotifyVolumeDestoryed, WriteInterfaceToken failed");
return;
}
if (!data.WriteString(volumeId)) {
LOGE("StorageManagerProxy::NotifyVolumeDestoryed, WriteInterfaceToken failed");
LOGE("StorageManagerProxy::NotifyVolumeDestroyed, WriteInterfaceToken failed");
return;
}
int err = Remote()->SendRequest(NOTIFY_VOLUME_DESTORYED, data, reply, option);
int err = Remote()->SendRequest(NOTIFY_VOLUME_DESTROYED, data, reply, option);
if (err != E_OK) {
LOGE("StorageManagerProxy::NotifyVolumeDestoryed, SendRequest failed");
LOGE("StorageManagerProxy::NotifyVolumeDestroyed, SendRequest failed");
}
}

View File

@ -56,8 +56,8 @@ int32_t StorageManagerStub::OnRemoteRequest(uint32_t code,
case NOTIFY_VOLUME_MOUNTED:
HandleNotifyVolumeMounted(data, reply);
break;
case NOTIFY_VOLUME_DESTORYED:
HandleNotifyVolumeDestoryed(data, reply);
case NOTIFY_VOLUME_DESTROYED:
HandleNotifyVolumeDestroyed(data, reply);
break;
case MOUNT:
HandleMount(data, reply);
@ -229,11 +229,11 @@ int32_t StorageManagerStub::HandleNotifyVolumeMounted(MessageParcel &data, Messa
return E_OK;
}
int32_t StorageManagerStub::HandleNotifyVolumeDestoryed(MessageParcel &data, MessageParcel &reply)
int32_t StorageManagerStub::HandleNotifyVolumeDestroyed(MessageParcel &data, MessageParcel &reply)
{
std::string volumeId = data.ReadString();
NotifyVolumeDestoryed(volumeId);
LOGI("StorageManagerStub::HandleNotifyVolumeDestoryed");
NotifyVolumeDestroyed(volumeId);
LOGI("StorageManagerStub::HandleNotifyVolumeDestroyed");
return E_OK;
}

View File

@ -44,10 +44,10 @@ namespace StorageManager {
Mount(volumePtr->GetId());
}
void VolumeManagerService::OnVolumeDestoryed(string volumeId)
void VolumeManagerService::OnVolumeDestroyed(string volumeId)
{
if (!volumeMap_.Contains(volumeId)) {
LOGE("VolumeManagerService::OnVolumeDestoryed volumeId %{public}s not exists", volumeId.c_str());
LOGE("VolumeManagerService::OnVolumeDestroyed volumeId %{public}s not exists", volumeId.c_str());
return;
}
std::shared_ptr<VolumeExternal> volumePtr = volumeMap_[volumeId];

View File

@ -27,7 +27,7 @@ enum ErrNo {
E_EXIST = 3, // exist
E_WRONG_TYPE = 4, // wrong file type
E_USER_STATE = 5, // wrong user state
E_NON_EXIST = 6, // no such user
E_NON_EXIST = 6, // no such item
E_PREPARE_DIR = 7, // failed to prepare dir
E_DESTROY_DIR = 8, // failed to destroy dir
E_MOUNT, // mount error