From bd754bbc9eb6e77146b3689530f55076c5b6bc32 Mon Sep 17 00:00:00 2001 From: Kichan Kwon Date: Fri, 10 Jul 2020 12:34:35 +0900 Subject: [PATCH] Mount USB storage - Mount /dev/sdXX - Mount only ext4 or vfat file system - Mountpoint : /opt/media/USBDriveXX - Same with storaged Change-Id: I7c2fb5b83f0c63a39979189bfe0bddc8a4273f03 Signed-off-by: Kichan Kwon --- src/system-recovery/recovery-init.in | 46 ++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/system-recovery/recovery-init.in b/src/system-recovery/recovery-init.in index bdf5338..df9988b 100644 --- a/src/system-recovery/recovery-init.in +++ b/src/system-recovery/recovery-init.in @@ -9,6 +9,11 @@ BLKID="/usr/sbin/blkid" REBOOT="@INITRD_RECOVERY_LIBEXEC_DIR@/minireboot" SYNC="/usr/bin/sync" UMOUNT="/usr/bin/umount" +CUT="/usr/bin/cut" +LS="/usr/bin/ls" +MKDIR="/usr/bin/mkdir" +RMDIR="/usr/bin/rmdir" +TR="/usr/bin/tr" #------------------------------------------------ # get partition id @@ -20,6 +25,30 @@ get_partition_id() { } #------------------------------------------------ +# mount_usb_partitions +#------------------------------------------------ +USB_MOUNTPOINT_PREFIX=${FAKE_ROOT}/opt/media/USBDrive +mount_usb_partitions() { + echo "mount USB partitions" + DEVICE_TYPE_LIST=( + ext4 + vfat + ) + + for DEVICE_TYPE in ${DEVICE_TYPE_LIST[@]} + do + DEVICES=$("$BLKID" /dev/sd?? -t TYPE="${DEVICE_TYPE}" -o device) + for DEVICE in ${DEVICES} + do + USB_MOUNTPOINT_INDEX=$(echo ${DEVICE} | "$CUT" -b 8- | "$TR" '[:lower:]' '[:upper:]') + USB_MOUNTPOINT=${USB_MOUNTPOINT_PREFIX}${USB_MOUNTPOINT_INDEX} + "$MKDIR" ${USB_MOUNTPOINT} + "$MOUNT" -t ${DEVICE_TYPE} ${DEVICE} ${USB_MOUNTPOINT} + done + done +} + +#------------------------------------------------ # mount_partitions #------------------------------------------------ mount_partitions() { @@ -36,6 +65,21 @@ mount_partitions() { "$MOUNT" -t devtmpfs devtmpfs ${FAKE_ROOT}/dev "$MOUNT" -t devpts devpts ${FAKE_ROOT}/dev/pts "$MOUNT" -t tmpfs tmpfs ${FAKE_ROOT}/tmp -o mode=1777,smackfsroot=* + + mount_usb_partitions +} + +#------------------------------------------------ +# umount_usb_partitions +#------------------------------------------------ +umount_usb_partitions() { + echo "umount USB partitions" + USB_MOUNTPOINTS=$("$LS" -d ${USB_MOUNTPOINT_PREFIX}*) + for USB_MOUNTPOINT in ${USB_MOUNTPOINTS} + do + "$UMOUNT" ${USB_MOUNTPOINT} + "$RMDIR" ${USB_MOUNTPOINT} + done } #------------------------------------------------ @@ -45,6 +89,8 @@ umount_partitions() { echo "umount partitions" "$SYNC" + umount_usb_partitions + "$UMOUNT" ${FAKE_ROOT}/opt/usr "$UMOUNT" ${FAKE_ROOT}/opt "$UMOUNT" ${FAKE_ROOT} -- 2.7.4