Mount USB storage 75/238275/1
authorKichan Kwon <k_c.kwon@samsung.com>
Fri, 10 Jul 2020 03:34:35 +0000 (12:34 +0900)
committerKichan Kwon <k_c.kwon@samsung.com>
Fri, 10 Jul 2020 07:28:35 +0000 (16:28 +0900)
- 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 <k_c.kwon@samsung.com>
src/system-recovery/recovery-init.in

index bdf5338..df9988b 100644 (file)
@@ -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}