mirror of
https://gitee.com/openharmony/startup_init
synced 2024-11-27 02:10:33 +00:00
!2812 init_cmd新增dm设备删除及创建指令
Merge pull request !2812 from dinglei/master
This commit is contained in:
commit
27818b1b85
@ -28,6 +28,7 @@
|
||||
#include "param/init_param.h"
|
||||
#include "securec.h"
|
||||
#ifdef SUPPORT_HVB
|
||||
#include "fs_dm.h"
|
||||
#include "dm_verity.h"
|
||||
#endif
|
||||
#include "init_filesystems.h"
|
||||
@ -563,6 +564,55 @@ int UmountAllWithFstabFile(const char *fstabFile)
|
||||
fstab = NULL;
|
||||
return rc;
|
||||
}
|
||||
|
||||
int FsManagerDmRemoveDevice(const char *devName)
|
||||
{
|
||||
#ifdef SUPPORT_HVB
|
||||
return FsDmRemoveDevice(devName);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
int MountOneWithFstabFile(const char *fstabFile, const char *devName, bool required)
|
||||
{
|
||||
bool isFile = fstabFile == NULL || *fstabFile == '\0';
|
||||
BEGET_CHECK(!isFile, return -1);
|
||||
|
||||
Fstab *fstab = NULL;
|
||||
fstab = ReadFstabFromFile(fstabFile, false);
|
||||
BEGET_ERROR_CHECK(fstab != NULL, return -1, "Read fstab file \" %s \" failed.", fstabFile);
|
||||
|
||||
FstabItem *item = NULL;
|
||||
int rc = -1;
|
||||
|
||||
#ifdef SUPPORT_HVB
|
||||
if (required) {
|
||||
rc = HvbDmVerityinit(fstab);
|
||||
if (rc != 0) {
|
||||
BEGET_LOGE("set dm_verity init, ret = 0x%x", rc);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
for (item = fstab->head; item != NULL; item = item->next) {
|
||||
if (strcmp(item->mountPoint, devName) == 0) {
|
||||
rc = CheckRequiredAndMount(item, required);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef SUPPORT_HVB
|
||||
if (required) {
|
||||
HvbDmVerityFinal();
|
||||
}
|
||||
#endif
|
||||
|
||||
ReleaseFstab(fstab);
|
||||
fstab = NULL;
|
||||
return rc;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
|
@ -160,7 +160,7 @@ static int LoadDmDeviceTable(int fd, const char *devName,
|
||||
break;
|
||||
}
|
||||
} while (0);
|
||||
|
||||
|
||||
free(parasBuf);
|
||||
|
||||
return rc;
|
||||
@ -300,6 +300,38 @@ int FsDmInitDmDev(char *devPath, bool useSocket)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int FsDmRemoveDevice(const char *devName)
|
||||
{
|
||||
int rc;
|
||||
int fd = -1;
|
||||
struct dm_ioctl io;
|
||||
|
||||
fd = open(DEVICE_MAPPER_PATH, O_RDWR | O_CLOEXEC);
|
||||
if (fd < 0) {
|
||||
BEGET_LOGE("error 0x%x, open %s", errno, DEVICE_MAPPER_PATH);
|
||||
return -1;
|
||||
}
|
||||
|
||||
rc = InitDmIo(&io, devName);
|
||||
if (rc != 0) {
|
||||
close(fd);
|
||||
BEGET_LOGE("error 0x%x, init dm io", rc);
|
||||
return -1;
|
||||
}
|
||||
|
||||
io.flags |= DM_READONLY_FLAG;
|
||||
|
||||
rc = ioctl(fd, DM_DEV_REMOVE, &io);
|
||||
if (rc != 0) {
|
||||
close(fd);
|
||||
BEGET_LOGE("error, DM_DEV_REMOVE failed for %s, ret=%d", devName, rc);
|
||||
return -1;
|
||||
}
|
||||
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
|
@ -36,6 +36,7 @@ typedef struct {
|
||||
|
||||
int FsDmInitDmDev(char *devPath, bool useSocket);
|
||||
int FsDmCreateDevice(char **dmDevPath, const char *devName, DmVerityTarget *target);
|
||||
int FsDmRemoveDevice(const char *devName);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
|
@ -97,6 +97,8 @@ MountStatus GetMountStatusForMountPoint(const char *mp);
|
||||
int MountAllWithFstabFile(const char *fstabFile, bool required);
|
||||
int MountAllWithFstab(const Fstab *fstab, bool required);
|
||||
int UmountAllWithFstabFile(const char *file);
|
||||
int MountOneWithFstabFile(const char *fstabFile, const char *devName, bool required);
|
||||
int FsManagerDmRemoveDevice(const char *devName);
|
||||
unsigned long GetMountFlags(char *mountFlag, char *fsSpecificFlags, size_t fsSpecificFlagSize,
|
||||
const char *mountPoint);
|
||||
|
||||
|
@ -389,6 +389,28 @@ static void DoUmount(const struct CmdArgs *ctx)
|
||||
}
|
||||
}
|
||||
|
||||
static void DoRemoveDmDevice(const struct CmdArgs *ctx)
|
||||
{
|
||||
INIT_LOGI("DoRemoveDmDevice %s", ctx->argv[0]);
|
||||
int ret = FsManagerDmRemoveDevice(ctx->argv[0]);
|
||||
if (ret < 0) {
|
||||
INIT_LOGE("Failed to remove dm device %s", ctx->argv[0]);
|
||||
} else {
|
||||
INIT_LOGI("Successed to remove dm device %s", ctx->argv[0]);
|
||||
}
|
||||
}
|
||||
|
||||
static void DoMountOneFstabFile(const struct CmdArgs *ctx)
|
||||
{
|
||||
INIT_LOGI("Mount %s from fstab file \" %s \"", ctx->argv[1], ctx->argv[0]);
|
||||
int ret = MountOneWithFstabFile(ctx->argv[0], ctx->argv[1], 1);
|
||||
if (ret < 0) {
|
||||
INIT_LOGE("Failed to mount dm device %d", ret);
|
||||
} else {
|
||||
INIT_LOGI("Successed to mount dm device %d", ret);
|
||||
}
|
||||
}
|
||||
|
||||
static void DoSync(const struct CmdArgs *ctx)
|
||||
{
|
||||
sync();
|
||||
@ -558,6 +580,8 @@ static const struct CmdTable g_cmdTable[] = {
|
||||
{ "ifup ", 1, 1, 1, DoIfup },
|
||||
{ "mount_fstab ", 1, 1, 0, DoMountFstabFile },
|
||||
{ "umount_fstab ", 1, 1, 0, DoUmountFstabFile },
|
||||
{ "remove_dm_device", 1, 1, 0, DoRemoveDmDevice },
|
||||
{ "mount_one_fstab", 2, 2, 0, DoMountOneFstabFile },
|
||||
{ "restorecon ", 1, 2, 1, DoRestorecon },
|
||||
{ "stopAllServices ", 0, 10, 0, DoStopAllServices },
|
||||
{ "umount ", 1, 1, 0, DoUmount },
|
||||
|
Loading…
Reference in New Issue
Block a user