I'm on a cubie board (a single-board computer, like a Raspberry Pi) running a Debian derivative called cubian
Linux Cubian 3.4.79-sun4i #1 PREEMPT Wed Feb 25 08:50:31 UTC 2015 armv7l GNU/Linux
USB drives are automatically mounted to a subdirectory of /media via
I'm trying to manage this as a kiosk (user has no access to a windowing system, etc) so I need to respond to situations programmatically. Recently during testing, my code threw an error indicating that there was more than one directory in /media. I ssh'd in, and, indeed, there were two directories there. I said to myself "yeah, but one is just the stale remainder of a not-properly-unmounted drive, so the directory will be empty [I had seen that case before], and I just need to add code to check for that".
To my surprise, the directory was not empty, and not only was I able to get a listing, I was able to open and read the contents of a file. This question describes a similar situation.
I assume this is some sort of cache that I'm accessing. Is there a way that I can programmatically detect this situation?
I'm not worried about cleaning up the directories as much as I am knowing which one actually corresponds to a physically mounted drive.
Also, unfortunately, I don't know how to reproduce this--I tried killing udevil and mounting it manually with
mount and then pulling it out, and the files disappeared.
If there were a reliable way to reproduce it, I could test some things (like seeing if a
touch command fails but doesn't hang, maybe?), so that would also be a helpful answer.