Skip to content

Commit

Permalink
Umount the device first during mount_usb_storage() (#1587) (BugFix) (#…
Browse files Browse the repository at this point in the history
…1599)

* Umount the device first during mount_usb_storage() (Bugfix) (#1587)

To prevent the inserted storage from failing to mount twice, first ensure it is unmounted.

Because the OS will auto-mount the inserted storage, the existing subprocess.call(["mount", device_to_mount, FOLDER_TO_MOUNT]) command will cause an error if the format of inserted storage is NTFS.

Perform an umount on device_to_mount (e.g., for the media card in #1587, it would be umount /dev/mmcblk0p1) before attempting to mount it again to avoid this issue.

* Update usb_read_write.py

* Update usb_read_write.py

update the comment correctly

* Update usb_read_write.py

Correct the blank line
  • Loading branch information
Jefferyyen authored Dec 3, 2024
1 parent 355ecf0 commit d0c208e
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions checkbox-support/checkbox_support/scripts/usb_read_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,15 @@ def mount_usb_storage(partition):

try:
device_to_mount = os.path.join("/dev", partition)
# use pipe so I could hide message like
# "umount: /tmp/tmpjzwb6lys: not mounted"

# Unmounting the folder ignoring any "not mounted" error messages.
subprocess.call(["umount", FOLDER_TO_MOUNT], stderr=subprocess.PIPE)

# Unmounting the device (e.g., "/dev/mmcblk0p1") to ensure the storage
# device is fully detached. This prevents issues with certain
# filesystem types like NTFS, which cannot be mounted multiple times.
subprocess.call(["umount", device_to_mount], stderr=subprocess.PIPE)

# mount the target device/partition
# if the return code of the shell command is non-zero,
# means something wrong.
Expand Down

0 comments on commit d0c208e

Please sign in to comment.