From 0c14203a29145d1d6f19d4f5d76d94a48a116e8e Mon Sep 17 00:00:00 2001 From: Rohan S <3526930+brosahay@users.noreply.github.com> Date: Sat, 11 Jan 2025 06:42:30 +0530 Subject: [PATCH] Adds support for VFAT on Android 11 and above (#33) * restyle the mount script * Adds support of VFAT or MSDOS on Android 11+ * Adds fixes in the unmount routine * fix styling * reverting changes --- scripts/mount_ext4.sh | 10 ++++++++-- scripts/remount_vfat.sh | 34 +++++++++++++++++++++++++++------- scripts/unmount.sh | 1 + 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/scripts/mount_ext4.sh b/scripts/mount_ext4.sh index 9c9dbe3..5283d3b 100644 --- a/scripts/mount_ext4.sh +++ b/scripts/mount_ext4.sh @@ -12,7 +12,10 @@ if [ "$(readlink /proc/self/ns/mnt)" != "$(readlink /proc/1/ns/mnt)" ]; then fi mkdir -p -v /mnt/my_drive -mount -t ext4 -o nosuid,nodev,noexec,noatime "$1" /mnt/my_drive +mount \ + -t ext4 \ + -o nosuid,nodev,noexec,noatime \ + "$1" /mnt/my_drive mkdir -p -v /mnt/my_drive/the_binding chmod -R 777 /mnt/my_drive @@ -23,6 +26,9 @@ chown -R sdcard_rw:sdcard_rw /mnt/my_drive setenforce 0 mkdir -p -v /mnt/runtime/write/emulated/0/the_binding -mount -t sdcardfs -o nosuid,nodev,noexec,noatime,gid=9997 /mnt/my_drive/the_binding /mnt/runtime/write/emulated/0/the_binding +mount \ + -t sdcardfs \ + -o nosuid,nodev,noexec,noatime,gid=9997 \ + /mnt/my_drive/the_binding /mnt/runtime/write/emulated/0/the_binding # TODO: reduce permissions via chmod & sdcardfs mask diff --git a/scripts/remount_vfat.sh b/scripts/remount_vfat.sh index 4e84386..1bf5b40 100644 --- a/scripts/remount_vfat.sh +++ b/scripts/remount_vfat.sh @@ -28,18 +28,38 @@ if [ ! -d "$mounted_drive_path" ]; then fi fs_type=$(stat -f -c %T "$mounted_drive_path") -if [ "$fs_type" != "msdos" ]; then - echo "detected filesystem type was not 'msdos', found $fs_type" +if [ "$fs_type" != "msdos" && "$fs_type" != "vfat"]; then + echo "detected filesystem type was not 'msdos' or 'vfat', found $fs_type" exit 1 fi +android_version=$(getprop ro.build.version.release) + drive_binding_dir="$mounted_drive_path/the_binding" -internal_binding_dir="/mnt/runtime/write/emulated/0/the_binding" +if [ $android_version -gt 10 ]; then + # for Android 11+ + internal_binding_dir="/mnt/pass_through/0/emulated/0/the_binding" +else + # for Android 10 and below + internal_binding_dir="/mnt/runtime/write/emulated/0/the_binding" +fi +# create mount points and binding directory mkdir -p -v "$drive_binding_dir" mkdir -p -v "$internal_binding_dir" + +if [ $android_version -gt 10 ]; then mount \ --t sdcardfs \ --o nosuid,nodev,noexec,noatime,gid=9997 \ -"$drive_binding_dir" "$internal_binding_dir" + "$drive_binding_dir" "$internal_binding_dir" +else +mount \ + -t sdcardfs \ + -o nosuid,nodev,noexec,noatime,gid=9997 \ + "$drive_binding_dir" "$internal_binding_dir" +fi + +# broadcast the mounted directory to media scanner +am broadcast \ + -a android.intent.action.MEDIA_SCANNER_SCAN_FILE \ + -d file:///storage/emulated/0/the_binding/ -echo "vfat drive remounted succesfully" \ No newline at end of file +echo "vfat drive remounted succesfully" diff --git a/scripts/unmount.sh b/scripts/unmount.sh index de60fb6..1acc267 100644 --- a/scripts/unmount.sh +++ b/scripts/unmount.sh @@ -11,5 +11,6 @@ if [ "$(readlink /proc/self/ns/mnt)" != "$(readlink /proc/1/ns/mnt)" ]; then exit 1 fi +umount -v /mnt/pass_through/0/emulated/0/the_binding umount -v /mnt/runtime/write/emulated/0/the_binding umount -v /mnt/my_drive