Trickiness while trying to implement an automounter ...
So, I'm busy using inotify to implement a kind of automounter for linux. Essentially it watches /dev for the creation of any 'files' matching a pattern (e.g. 'sd*'). when such a file appears, it creates a new mount point (e.g. /mnt/myautomount/volume0) and simulates an automount subprocess on that mount point, i.e. whenever files are accessed in that mount point, the created device is mounted on that mount point, and then once every second, the process tries to unmount it. Once successfully unmounted, the subprocess watches for further file access in the mount point, and repeats the process. The main process also picks up when the device s removed (e.g. /dev/sda1 goes away) and kills the appropriate subprocess.
So in theory this seems all hunky dory, except that the sub process catches the file access attempt after it has happened, and mounts the device post facto. Meaning an ls in the mount point reveals an empty directory, and I must change up and back down again to get 'into' the mounted file system.
So I've thought of two solutions here
a) use automount proper as a sub process, using the executable as map function, to determine the mount point name. To do this I need some way of accessing the table of mount point/device pairs in my main process from another program, i.e. shared memory. I've never done this before, so some pointers to good docs on using shared mem in linux would be of great help
b) I need to somehow detect and hook into the file access of the mount point directory and complete the mount before the access is complete, which is I think how automount does it. I've googled, I've sworn, I've looked at code from things like submount, I've perused the kernel filesystem code briefly, I've cried... Any suggestions on how one might go about this are most welcome...
Oh, and before anyone jumps down my throat and screams 'DON'T REINVENT THE WHEEL', this is as much an academic exercise as it is practical. Yes I know about HAL, and ivman, etc... just want to try my hand at something similar...