You are not logged in.

#1 2008-12-11 19:26:18

Mashi
Member
Registered: 2007-02-19
Posts: 38

Introducing PyMount, a python based automount daemon

I wrote a python program to perform automounting of removable drives. It's not perfect yet, but I hope that when it's finished it will provide a more pleasant automounting experience.

Motivation
I have had some problems with current automounting implementations.. The inability to specify mount options, the complicated config files required, the fact that they do not handle the directories that they create nicely, and also that some of them only work alongside a DE.  I observed that /etc/fstab can contain sufficient information to solve all these problems, so the way that PyMount works is it mounts drives according to their entry in /etc/fstab.

How it works
Creates a listener using hal/dbus. When a device is connected, it scans /etc/fstab for an entry corresponding to the UUID of the drive. If found, it mounts the drive (using the mount command) according to the fstab entry. When a device is disconnected, it unmounts it.

If you specify a UID or GID in the fstab mount options, the created folder will be chowned to match those values.

Current Limitations
* Devices must have an fstab entry. Support for automounting devices without an fstab entry is of course possible in the future.
* Your fstab entry must specify the drive by UUID.
* No "nice" behaviour for when mount / unmount fails (usually unmount fails because there are open file handles to the disconnected drive).
* Probably won't work as a daemon right now, unless you want to jerry rig it yourself. I've started work on a corresponsing /etc/rc.d script so it shouldn't be too hard.
* Probably others...

The Code
here: http://privatepaste.com/f4qTdaDK5k
To use it:
* Create an fstab entry for one of your removable drives.
* As root, run: "python pymount.py" (tested with python 2.6)
* Add / Remove the device, see what happens.

Providing Feedback
I'd like to hear any problems, suggestions, or feature requests. I'd especially like to hear if you think this is a good idea and what it would take for PyMount to replace your existing automounter. The main problem that I see right now is how to handle failure. Since this is a command line daemon, no notification can be given to the user if something goes wrong. They expect that their drive has mounted / unmounted, when in fact it has not. The main issue is when a device is removed and some program still has an open file handle to it. Unmount will fail and the mount folder is left in limbo. The XFCE automounter leaves it as it is and when next the device is connected creates another folder with a trailing underscore. This is annoying but I'm not exactly sure what to do.

Update:
The situation with open files on non-present drives is as follows:
* If a process has a handle to a file on a non-present drive, it is possible to get the file descriptor via /proc/{PID}/fd.
* File descriptors are integers which are relative to their parent process, so a file handle cannot be easily closed from another process.
* Assuming there is a way, the remaining question is how dangerous it to the other process to forcibly close the handle, as opposed to leaving it open and letting that process encouter an access error.

Last edited by Mashi (2008-12-11 20:09:53)

Offline

#2 2008-12-11 20:15:50

bavardage
Member
Registered: 2008-02-17
Posts: 160

Re: Introducing PyMount, a python based automount daemon

Suggestion - use libnotify (through pynotify) to notify the user if something goes awry.

Offline

Board footer

Powered by FluxBB