Skip to content

Commit

Permalink
Adds support for VFAT on Android 11 and above (#33)
Browse files Browse the repository at this point in the history
* restyle the mount script

* Adds support of VFAT or MSDOS on Android 11+

* Adds fixes in the unmount routine

* fix styling

* reverting changes
  • Loading branch information
brosahay authored Jan 11, 2025
1 parent fe8a884 commit 0c14203
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
10 changes: 8 additions & 2 deletions scripts/mount_ext4.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
34 changes: 27 additions & 7 deletions scripts/remount_vfat.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
echo "vfat drive remounted succesfully"
1 change: 1 addition & 0 deletions scripts/unmount.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 0c14203

Please sign in to comment.