From a20c85b76c088a260407156cbfbab5afb142f83a Mon Sep 17 00:00:00 2001 From: INSUN PYO Date: Tue, 11 May 2021 16:50:27 +0900 Subject: [PATCH] Support /dev/mapper/rootfs root device Root device is /dev/mapper/rootfs on RPI4 with dm-verity. So, the actual root device is not correctly found, and /dev/mmcblk0 is not recognized as an internal device. Storaged recognizes the partitions of /dev/mmcblk0p* as external devices, and storaged mounts them to /opt/media/SDCard@*. /////////////////////////////////////////////////////////////////// /dev/mmcblk0p1 65390 20830 44560 32% /opt/media/SDCard@1 /dev/mmcblk0p10 59365 1299 53480 3% /opt/media/SDCard@10 /dev/mmcblk0p11 120355 1555 109805 2% /opt/media/SDCard@11 /////////////////////////////////////////////////////////////////// Change-Id: I42f211684e519371a23ee0b403bd3d941d243bb0 --- packaging/storaged.spec | 1 + src/block/CMakeLists.txt | 1 + src/block/block.c | 65 +++++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 63 insertions(+), 4 deletions(-) diff --git a/packaging/storaged.spec b/packaging/storaged.spec index c32783d..2d3ad40 100644 --- a/packaging/storaged.spec +++ b/packaging/storaged.spec @@ -29,6 +29,7 @@ BuildRequires: pkgconfig(blkid) BuildRequires: pkgconfig(mount) BuildRequires: pkgconfig(libsyscommon) BuildRequires: pkgconfig(json-c) +BuildRequires: pkgconfig(devmapper) BuildRequires: pkgconfig(capi-ui-efl-util) BuildRequires: pkgconfig(capi-appfw-application) diff --git a/src/block/CMakeLists.txt b/src/block/CMakeLists.txt index 8346018..f72f5e3 100644 --- a/src/block/CMakeLists.txt +++ b/src/block/CMakeLists.txt @@ -17,6 +17,7 @@ SET(REQUIRES_LIST ${REQUIRES_LIST} vconf capi-system-device libsyscommon + devmapper ) IF(EXTENDED_STORAGE) diff --git a/src/block/block.c b/src/block/block.c index c796b1b..878729f 100644 --- a/src/block/block.c +++ b/src/block/block.c @@ -49,6 +49,8 @@ #ifdef EXTENDED_STORAGE #include #endif +#include +#include #include "log.h" #include "module-intf.h" @@ -59,17 +61,16 @@ #include "apps.h" #include "storaged_common.h" -/** - * TODO Assume root device is always mmcblk0*. - */ #define MMC_PATH "*/mmcblk[0-9]*" #define MMC_PARTITION_PATH "mmcblk[0-9]p[0-9]" /* Emulator send devlink for sdcard as \*\/sdcard\/\* */ #define MMC_LINK_PATH "*/sdcard/*" +#define MMC_LINK_PARTITION_PATH "vd[a-z][0-9]" #define SCSI_PATH "*/sd[a-z]*" #define SCSI_PARTITION_PATH "sd[a-z][0-9]" #define SCSI_PARTITION_LENGTH 9 #define EXTENDEDSD_NODE_PATH "/dev/mapper/extendedsd" +#define DEVICE_MAPPER_ROOT_NODE_PATH "/dev/mapper/rootfs" #define FILESYSTEM_NAME "filesystem" @@ -2395,6 +2396,58 @@ static int remove_block_device(struct udev_device *dev, const char *devnode) return 0; } +static void get_internal_storage_number_from_device_mapper(char *root_name) +{ + int major, minor; + char dev_name[PATH_MAX]; + struct dm_task *dmt; + struct dm_info info; + struct dm_deps *deps; + + _D("Searching device mapper root device: %s", DEVICE_MAPPER_ROOT_NODE_PATH); + + if (!root_name) + return; + + dmt = dm_task_create(DM_DEVICE_DEPS); + if (!dmt) + return; + + if (!dm_task_set_name(dmt, root_name)) + goto out; + + if (!dm_task_run(dmt)) + goto out; + + if (!dm_task_get_info(dmt, &info) || !info.exists) + goto out; + + deps = dm_task_get_deps(dmt); + if (!deps || deps->count != 1) + goto out; + + major = (int) MAJOR(deps->device[0]); + minor = (int) MINOR(deps->device[0]); + + if (!dm_device_get_name(major, minor, 1, dev_name, PATH_MAX)) + goto out; + + /* Ex: dev_name is mmcblk0p2 */ + _D("Found actual device associated with root device of device mapper: %s", dev_name); + + if (!is_emulator()) { + if (!fnmatch(MMC_PARTITION_PATH, dev_name, 0)) + sscanf(dev_name, "mmcblk%d", &dev_internal); + else if (!fnmatch(SCSI_PARTITION_PATH, dev_name, 0)) + sscanf(dev_name, "sd%c", &dev_internal_scsi); + } else + if (!fnmatch(MMC_LINK_PARTITION_PATH, dev_name, 0)) + sscanf(dev_name, "vd%c", &dev_internal_emul); + +out: + dm_task_destroy(dmt); +} + static int get_internal_storage_number(void) { struct libmnt_table *t = NULL; @@ -2437,7 +2490,9 @@ static int get_internal_storage_number(void) name++; /* Boot from USB is not handled */ - if (!is_emulator()) { + if (!strcmp(temp, DEVICE_MAPPER_ROOT_NODE_PATH)) + get_internal_storage_number_from_device_mapper(name); + else if (!is_emulator()) { if (!fnmatch(MMC_PATH, temp, 0)) sscanf(name, "mmcblk%d", &dev_internal); else if (!fnmatch(SCSI_PATH, temp, 0)) @@ -2492,6 +2547,8 @@ static int check_external_storage(const char* devnode) } } + _D("%s is external storage.", devnode); + return 1; } -- 2.7.4