How to prevent file corruption in SD card during unmount?
1
vote
0
answers
154
views
I have a custom device running Android 8.1. I am mimicking a partition of the internal flash storage to be used as a removable storage.
At boot *vold* mounts the storage and creates the mount points.
From an android app, I am able to use storage manager APIs to access the storage and perform operations such as mount, unmount, etc.
Problem is, occasionally, I am getting file corruptions on the SD card when unmounting. I am saying '***on unmounting***' because I see the files corrupted when the same partition is enumerated to computer as USB mass storage after unmounting.
I do make sure the files written to the card are 'flushed' and later a 'sync' is done on the shell as an extra precaution before unmounting the volume using the android storage manager APIs
Storage is available in android app at
/storage/D80A-0F16
.
/dev/block/vold/public:179,27 on /mnt/media_rw/D80A-0F16 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/D80A-0F16 on /mnt/runtime/default/D80A-0F16 type sdcardfs (rw,nosuid,nodev,noexec,noatime,fsuid=1023,fsgid=1023,gid=1015,mask=6) /mnt/media_rw/D80A-0F16 on /storage/D80A-0F16 type sdcardfs (rw,nosuid,nodev,noexec,noatime,fsuid=1023,fsgid=1023,gid=1015,mask=6) /mnt/media_rw/D80A-0F16 on /mnt/runtime/read/D80A-0F16 type sdcardfs (rw,nosuid,nodev,noexec,noatime,fsuid=1023,fsgid=1023,gid=9997,mask=18) /mnt/media_rw/D80A-0F16 on /mnt/runtime/write/D80A-0F16 type sdcardfs (rw,nosuid,nodev,noexec,noatime,fsuid=1023,fsgid=1023,gid=9997,mask=18)---------------------------------------------------- Can anyone think of a scenario I might be missing here which causes the file corruption? **Edit:** Another observation I have is, if I restart the device the filesystem seem to not get corrupt, which makes me think that for some reason the files are not getting synced to disk correctly when unmounted? What can I do to make sure the files are getting synced to disk when unmounted?
Asked by CyA
(11 rep)
May 6, 2020, 03:27 PM
Last activity: May 9, 2020, 04:54 AM
Last activity: May 9, 2020, 04:54 AM