per-user udev rules subset

gibboris at gmail.com gibboris at gmail.com
Wed Oct 14 05:57:59 PDT 2009


Hello,

On Wed, Oct 14, 2009 at 10:39:42AM +0200, Stef Bon wrote:
> Hello Raph,
> 
> I'm sorry to say, but your email is too technical (complicated) for me.
> I'll go through your answer checking what you mean:
I'm really sorry, I was to quick to write, and wrote as if you wanted to
understand the attached code (I shouldn't do that)

> 
> gibboris at gmail.com wrote:
> > Hi Stef,
> > From what I uinderstand, udev is to low-level.
> >   
> Too low-level. For what??
A userspace daemon could link against libudev for hotplug event, and
listen to /proc/mount modifications (like the MountMonitor of DKD) but
the DKD "layer" provides much more information (eg, disk vs partition, ...)
Moreover it provides this information publicly through a bus, it seems to me
to be the "way to go"

> > My 1st goal is to get all devices (known and unknown) automounted.
> >   
> Automounted, ok. With automounter then or....?
I always think as "known devices" vs "unknown devices"
with "known devices" being known at system wide.
IMnHO it's unavoidable that known devices get their own entry in the fstab,
at system wide. Configured with users option and a common mountpath
(/mnt, /media, ...)
If I buy a new usbstick, mmccard, ... I create an entry (root needed).
(A gui (gnome, kde, ...) can ask for root password the first time
and add a corresponding entry in the fstab)
Thereafter, me (-o user,uid) or anyone (-o users) can use this device.

I wan't to handle the "any/unknown device" case separatly, I speak about that below

I didn't use autofs, be if I was only interested in automounting, I would do :
# auto.master
/mnt/<user>        /home/<user>/.autofs/auto.misc           --timeout=5 --ghost
# /home/<user>/.autofs/auto.misc
mp3-stick  -fstype=vfat,uid=1002,gid=100   UUID="0467-FFC1"

But it's automounting only (anyway I should have started by studying this kind of
solution), and per-user "exclusive" (if a system identical /etc/auto.misc included on top of
auto.master is overwriten by following lines, a device can't be common/shared/...)



> > Then, to let a user spawn any action for any block device event
> > (added, removed, mounted, unmounted)
> Spawn any action?? Explain. I'm dutch , my english is ok, but I do not 
> understand this.
I should have said "trigger" as in :
"block device events trigger user actions"
or in other words : hotplug and mount event can be "post-hooked"


> > 1) I have set all the rules for my known hardware in the fstab
> > so users have the right to mount it.
> >   
> What rules?? How do they look like? Fstab is a file where all the system 
> related mountcommands are listed... not per user/session info.


> > 2) Here the devkit-disks-trigger (attachment) plays the role of ivman,
> > nothing root happens : each user can set a configuration file and launch
> > devkit-disks-trigger dbus listener at session startup so devices can be
> > automounted (and eg, a terminal spawn in the mountpoint).
> >   
> Can you explain ivman, I've heard of this, it's a sort of automounter, 
> but explain please.
> Futher which mountpoint? How does this work according to you. Can you 
> make a drawing to give an overview?
> 
> > 3) Then for the unknown devices, I will use the udev rule (I saw somewhere in the
> > /usr/share/udev) which create a mount point (the mount point dir name
> > can be numbered or can be the label of the partition, ...).
> > It system-wide but then the users can also be warned about a new device mounted
> > by devkit-disks-trigger as in 2).
> >
> > In my case, I don't really mind about mountpoint path, I just want the ability
> > for a user to go there quickly so I want to have the freedom to launch the terminal
> > in the mountpoint, set a variable, create a symlink, do a rsync, ...
> >
> > I'm quite sure you may find it useful with a config like :
> > [my_device]
> > IdLabel=mypictures
> > # choice 1 : it's configured in fstab to let a user mount it
> > DeviceAdded=mount %device_file my stuff like I want
> >   
> No, if working with a dynamic construction, you do not have to write 
> lines in fstab first. It must be possible
> to put in an USB device in any computer without having to write anything 
> to fstab!
If we speak about "any" device, then it's hal, or DKD with polkit, or udev.
The easy way : udev with this script [1].
Otherwise, it's devicekit-disks which should do something similar after
having ask to polkit if it's possible.

> > DeviceMountPaths=/mnt/pictures #or /home/user/media/mypictures
> > DeviceMounted=mirage /mnt/pictures
> >   
> No,this way there is only one mountpath: my idea is that in the 
> configuration is should be possible to use a per user mountpath
DKD handle several mountpaths (char **), so does my code (comma separated) :
if one of specified path matches one the mountpath of the newly mounted device
(which I recall, can be mounted by automounter, user, root, udev, ...)
The the value of DeviceMounted is execvp()
("mirage" is simple image viewer, I should have said that).
The action may have been :
ln -sf /mnt/pictures ~/.fuse/bind/Pictures

> > # choice 2 : the mount part is done by root, or udev
> > # so we only do stuff at post-mount time
> > DeviceMounted=mirage %device_mount_paths
This simple entry trigger the image viewer each time a device is mounted.

> Please note that not everybody has the same skills as you when 
> answering... make your emails a little bit readable.
I'm really sorry about my failure to make my previous email clear and the
reason is precisely my lack of skill.

> BTW: my fuse module to create a virtual network- and device map in the 
> user's homedirectory:
> http://linux.bononline.nl/linux/fuse-workspace/
> 
> I use the automounter for Linux to mount network devices. I'm not so far 
> that my construction also deals with USB devices, but again, to let this
> work ok on a multi user system, per-user device-disk rules are necessary.
> To explain the idea: with the fuse-module it's possible to bind/mirror 
> any file/directory on your computer in a subdirectory of your homedirectory.
> So it's possible to mirror an USB device mounted at /media/USBstick to 
> for example $HOME/Workspace/Devices/USBstick.
I remember having searched for a non-root bind -o, if it's possible with fuse-workspace,
then the following theory should work :
- plug happens
- udev calls this script [1]
- DKD is warned that plug happens (but not about mount)
- DKD --monitor knows about mount, with my code it can trigger an event like :
[catch-all mount rule]
DeviceMounted=ln -sf %device_mount_paths ~/.fuse/bind/<something_variable_to_define>
- the fuse-workspace daemon was already loaded, the bind is done
My only problem with this is that I don't want my "known" mp3 player being given a generic
name (or even it's LABEL) but being given specific mount path and access.
So I need to find out how to make udev nicely ignore fstab configured device but that's another
story.

[1] http://en.gentoo-wiki.com/wiki/Autofs#Write_the_mount.2Funmount_scripts_2

> 
> For the system the device is mounted at /media/USBstick, but for the 
> users the path where it's mirrored/binded should be exported
> to the graphical environment, making for example Dolphin show this 
> device and open in the directory $HOME/Workspace/Devices/USBstick.
> So per-user rules!! (or per-session....)
My previous workaround relied upon incron to monitor /media with per-user .incrontab
with a set of udev rules (specific + a catch-all)

I wish I was more understandable this time.
Have a nice day.

Raph


More information about the devkit-devel mailing list