I'm developing an application which at some point needs to write in a USB drive unit. The application gets executed with non-superuser permissions and I've thought the best way to write on the drive would be to have it mounted with the flush option as soon as the drive gets inserted, this way, theoretically I don't need to do any umount operation, with this udev rule:
ACTION="add", KERNEL="sd*[0-9]", SUBSYSTEMS="usb", RUN+="/bin/sh mymountscript.sh '%E{DEVNAME}'"
The mount script tries to invoke the command this way:
mount -o --flush $1 /media/my-user/my-usb-unit
But I get this mount error:
mount: wrong fs type, bad option, bad superblock on /dev/sdb1,
missing codepage or helper program, or other error
What it's curious about it is that I get this error only when trying to mount it through the udev rule, if I invoke mymountscript.sh
myself the unit gets properly mounted in the point.
Apart from a solution for this issue, I would like to know if it's risky to do it this way (I understand it is because I don't umount the drive after the file is written). If I go the other way, I would need the application script (which gets executed on behalf of the user) to be able to mount/umount the unit himself. For this, I would need to save the device name somewhere when it gets inserted and also to grant mount permissions to the application.
The OS is Xubuntu 16.04.
mymountscript.sh /dev/sdb1
./dev/sdb1
itself. It's not a problem with the parameter actually, themount
command does it well when no--flush
option is specified.