I've made a MP3 player for the Pi using a 16x2 LCD display and 5 buttons; what I would like to do next is to add the ability to automount any USB flash inserted and then tell my program (all written in C btw) so it can add any music on the flash to it's linked list / playlist. As I won't be changing anything on the flash, I'd just want to mount it ro mode (plus to avoid any corruption when the flash is removed)
/etc/udev/rules.d , create a file named like usb-ro.rules, with the following content.
KERNEL=="sd*", SUBSYSTEMS=="usb", MODE="0555"
This will mount all USB devices as read-only.
If you have something mounted on USB, unmount it all and issue command
sudo /etc/init.d/udev restart
I think to get RW access you need to unmount it while plugged in then remount it with
mount. I am sure you can add that into your program to do this via the interface and calling bash command directly as
If you want to be able to "automount" any kind of USB device on any port with FAT32/NTFS/EXT it will require a bit more work.
You can simplify the
/dev/sd location by always mounting any USB device to the same device namespace location by using udev again..(restart required also)
This will yield (pure example with multiple partitions)
ls -l /dev/Playlist* lrwxrwxrwx 1 root root 3 2014-02-23 12:36 /dev/Playlist -> sdc lrwxrwxrwx 1 root root 12 2014-02-23 12:36 /dev/Playlist0 -> bsg/14:0:0:0 lrwxrwxrwx 1 root root 4 2014-02-23 12:36 /dev/Playlist1 -> sdc1 lrwxrwxrwx 1 root root 3 2014-02-23 12:36 /dev/Playlist3 -> sg3
You can then install
autofs which will detect the filesytem and mount it where you need.
apt-get install autofs
In the masterfile add this
/media/ /etc/auto.ext-usb --timeout=10,defaults,user,exec,uid=1000
/etc/auto.ext-usb and add this (this will auto mount any 1st partition)
Playlist -fstype=auto :/dev/Playlist1
You still need to check if a USB was plugged in or not with your software.
And if there is something to mount its as simple as command