Sample Header Ad - 728x90

What happens when Android mounts a microsd card?

3 votes
0 answers
1259 views
I've got a 256 GB microsd card which only works with my phone if its file system is FAT32. The issue I have with this, is that FAT32 only supports files up to 4 GiB, which is a bit low by today's standards. I am able to successfully mount an exFAT partition using a FUSE driver, which I found here: https://forum.xda-developers.com/showpost.php?p=79685842&postcount=9 I did not install that zip; instead, I simply extracted the mount.exfat binary and called it from a superuser shell. The actual issue I'm having, is that if I mount anything using that method, the Android OS doesn't "register" that as a microsd card. So apps can read and write data to the mountpoint as if it was a plain directory, but it is not recognized as an actual external storage device. I'm trying to figure out what exactly does Android do when you tap the "Mount SD card" entry in Storage settings, and how can that be replicated outside of the Settings app. If a FAT32 card is mounted automatically by Android, here's what the mount points look like:
$ mount | grep 5D03
/dev/block/vold/public:179,65 on /mnt/media_rw/5D03-6C2D type vfat (rw,dirsync,nosuid,nodev,noexec,noatime,uid=1023,gid=1023,fmask=0007,dmask=0007,allow_utime=0020,codepage=437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro)
/mnt/media_rw/5D03-6C2D on /mnt/runtime/default/5D03-6C2D type sdcardfs (rw,nosuid,nodev,noexec,noatime,fsuid=1023,fsgid=1023,gid=1015,mask=6)
/mnt/media_rw/5D03-6C2D on /storage/5D03-6C2D type sdcardfs (rw,nosuid,nodev,noexec,noatime,fsuid=1023,fsgid=1023,gid=1015,mask=6)
/mnt/media_rw/5D03-6C2D on /mnt/runtime/read/5D03-6C2D type sdcardfs (rw,nosuid,nodev,noexec,noatime,fsuid=1023,fsgid=1023,gid=9997,mask=18)
/mnt/media_rw/5D03-6C2D on /mnt/runtime/write/5D03-6C2D type sdcardfs (rw,nosuid,nodev,noexec,noatime,fsuid=1023,fsgid=1023,gid=9997,mask=18)
Forgetting about exFAT or other file systems for a moment, I first tried to replicate that using the same FAT32 partition which was mountable natively by Android. I unmounted the SD card from settings, which resulted in the above command not outputting anything anymore, and proceeded to mount the partition in much the same way as described by the mount output seen above. From a su -mm shell, I first created the necessary mount points with mkdir, then replicated all the entries with mount, like mount -o rw -o nosuid -o nodev [...] -t vfat /dev/block/vold/public:179,65 /mnt/media_rw/5D03-6C2D. When finished, the output from mount | grep 5D03 was almost exactly the same as if it was the Android OS doing the mounting (checked with diff: the single difference was the lack of the dirsync option, as mount complained about not recognizing that option, all other lines were exactly the same). But that still did not make the Android OS acknowledge that a SD card was indeed mounted. From this, I gather that Android does some extra step when mounting an SD card. For example, if the card is mounted natively by Android, file manager apps will show the SD card's capacity and free space, and will allow to easily browse its contents. But if I mounted the very same SD card manually, as described above, the same file manager would only offer to browse internal storage. The SD card could still be accessed if I navigated to the mount point directory (/mnt/media_rw/5D03-6C2D) so it was properly mounted and working, just not recognized by Android. So I guess this lengthy question really boils down to this simple one: How can one mount devices in Android OS and have the mount points recognized as real external storage devices?
Asked by combinedfleet (31 rep)
Jun 14, 2019, 11:03 AM