0

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.

0

I would expect that using /dev/mmcblk1p3 in two different ways at once, on the one hand mounted using kernel buffers, on the other hand via g_mass_storage using its buffers is going to cause trouble as soon as the buffers get out of sync. "Doesn't delete files" is probably only the tip of the iceberg; in general whoever writes back the block last wins, leading to inconsistent state, and whether you will see changes made in the one system as changes in the other systems will depend on the current buffering state.

So: Don't do that. Either mount, or use as g_mass_storage, but not both. If you want to share files between two computers, use something different (e.g. a network filesystem).

  • "use something different", isn't really an option. I have to use USB cable. My Android phone can and does do this... I did discover basically the same thing 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. – DMacAttack Jul 17 '18 at 14:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.