I'm having a strange problem with g_mass_storage gadget where deleted files from the PC are not 'actually' being deleted, which causes further problems when indexing.
Here is the procedure:
- mount the partition for the linux device:
$ mount /dev/mmcblk1p3 /mnt/data
- start the g_mass_storage gadget:
$ modprobe g_mass_storage file=/dev/mmcblk1p3 removable=y
- write a file to the mounted partition on the linux device:
$ echo "hello world" > /mnt/data/hello.txt
- plug in the USB OTG --> PC
- open the mounted file on your pc to verify the text
- delete the hello.txt from your pc (shift - delete)
- remove the usb from the PC
- wait until the usb storage is available again
(on my target the state can be viewed in /sys/class/udc/ci_hdrc.0/state )
- observe the file system no longer contains the hello.txt file (it doesn't)
$ ls /mnt/data/
- stat the file
$ stat hello.txt
File: hello.txt
Size: 12 Blocks: 8 IO Block: 4096 regular file
Device: b303h/45827d Inode: 58 Links: 1
Access: (0755/-rwxr-xr-x) Uid: (0/root) Gid: (0/root)
Access: 2022-08-21 05:57:00.000000000
Modify: 2022-08-21 05:57:00.000000000
Change: 2022-08-21 05:57:00.000000000
- cat the 'invisible file'
$ cat hello.txt
hello world
Whats going on? If I attempt to edit the invisible file it will work ONCE and the file system will then become read-only. for which the fix is to re-mount the file system.
How do I allow the PC host to delete files permanently?
EDIT:
I did discover basically that the file systems are out of sync, which IMO is silly, as what else is the point of the mass storage device if its only accessible from the PC host. Just use a USB Thumbdrive then....
I was able to hack something together that unmounts/mounts the target's file system depending on the USB connection, however in the future I'll be updating the logic to force the user to activate the USB connection.