Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Getting a list of removable devices (and their partitions)
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware
View previous topic :: View next topic  
Author Message
tobr
Guru
Guru


Joined: 29 May 2006
Posts: 330

PostPosted: Sat Sep 20, 2008 2:41 pm    Post subject: Getting a list of removable devices (and their partitions) Reply with quote

Hello.

I have a computer on which I run VDR (to watch TV etc.). I use fvwm as window manager because it's lightweight and highly configurable. Therefore I miss the automount capabilities of Gnome/KDE. I'd like to mount USB sticks and similiar devices with autofs but the problem is that this needs a config file and one can't know everything about the USB devices in advance. So I'd like to let udev execute a script whenever a removable device is plugged in, which creates a config file for autofs with the current removable devices and signal the daemon a SIGHUP to reread the file.

The problem is now to get a list of mountable partitions on the removable devices. Google yielded only something which uses HAL, which I'd like to avoid. So is there another way using as little extra programs as possible (I'd like to keep the system simple and small)?
_________________
Please add [SOLVED] to your message title if your problem is solved.

Death to all blobs!
Back to top
View user's profile Send private message
ZeuZ_NG
Guru
Guru


Joined: 10 Sep 2008
Posts: 453
Location: Near /dev/urandom | /dev/null

PostPosted: Sat Sep 20, 2008 2:52 pm    Post subject: Reply with quote

My guess is that you could make a pact with dmesg to check whether it has been plugged, and where the inode for the device was created on /dev, later you'll need to daemonize it, or add your user to root group (wich can be dangerous, so the first option is adviced), to be able to mount depending on the data extracted from dmesg output.
By the way, have you tried thunar? I think it's a default for xfce4 and serves your needs..
Well, continuing with that, to automat the process, you could do a for counting from 0 to the maximum ammount of USB ports that your PC has.

Then something like:
ls /mountpoint | grep $NUMBER | wc -l
would give you something for an if to jump from device mountpoint to device mountpoint.
I'm thinking on a ´bash-ee´way of doing it, perhaps this gives you some ideas.
_________________
| Intel Core i7 920. | Intel DX58SO Extreme. |
| 8gb DDR3 1666mHz | 1TB 7200 RPM WD HDD.|
Unix´s guru view of sex:
unzip ; strip ; touch ; grep ; finger ; \
mount ; fsck ; more ; yes ; umount ; sleep.
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 54821
Location: 56N 3W

PostPosted: Sat Sep 20, 2008 2:54 pm    Post subject: Reply with quote

tobr,

I think udev can do all of this. I don't use the automount so my knowledge there is a bit sketchy.

The first step is to write some udev rules to create /dev entries for your devices and their partitions.
I have
Code:
SUBSYSTEM=="block", GROUP="disk"
SYSFS{product}=="DatawriteVoyager",             SYSFS{manufacturer}=="Pendrive",        SYSFS{serial}=="173426667658"   NAME="pendrive"
SYSFS{product}=="HP PhotoSmart 318 Camera",     SYSFS{manufacturer}=="Hewlett-Packard",                                 NAME="camera%n"

Note that /dev/pendrive is not partitioned (its like a big floppy) and /dev/camera is, so the %n provides /dev nodes camera1, camera2 and so on, as you would expect for a partitioned device.
udev can also run helper scripts, so these helper scripts could do your mounting for you but thats where my detailed knowledge runs out
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
tobr
Guru
Guru


Joined: 29 May 2006
Posts: 330

PostPosted: Sat Sep 20, 2008 3:08 pm    Post subject: Reply with quote

First thanks for the thoughts!

ZeuZ_NG wrote:
My guess is that you could make a pact with dmesg to check whether it has been plugged, and where the inode for the device was created on /dev, later you'll need to daemonize it, or add your user to root group (wich can be dangerous, so the first option is adviced), to be able to mount depending on the data extracted from dmesg output.

That's a bit too dodgy for my taste.

Quote:
By the way, have you tried thunar? I think it's a default for xfce4 and serves your needs..

I'd like to be able to browse these sticks from VDR with a remote control. I'd like to avoid file managers because of that.

NeddySeagoon wrote:
I think udev can do all of this. I don't use the automount so my knowledge there is a bit sketchy.

The first step is to write some udev rules to create /dev entries for your devices and their partitions.

The problem is that I don't want to write rules for the USB sticks. Perhaps I will get a stick from a friend with his photos on it and I want to browse them or whatever. I don't know in advance which hardware will be connected. It is correct that udev can run a skript whenever a device is created. I could then add the device to the list of removable devices in the config file. But I also need to remove it when the device is unplugged. Can udev do that, too?
_________________
Please add [SOLVED] to your message title if your problem is solved.

Death to all blobs!
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 54821
Location: 56N 3W

PostPosted: Sat Sep 20, 2008 3:47 pm    Post subject: Reply with quote

tobr,

udev gets events from the kernel when a device is added or removed.
The default rules act on both events, adding and removing entries from /dev

This suggests that you could handle theremove event yourself if you wanted to.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
a.b.
Apprentice
Apprentice


Joined: 23 Mar 2008
Posts: 218
Location: Anus Mundi, Germany

PostPosted: Sat Sep 20, 2008 3:54 pm    Post subject: Reply with quote

Ivman does the job for me without much configuration:
http://gentoo-wiki.com/HOWTO_ivman
Back to top
View user's profile Send private message
ZeuZ_NG
Guru
Guru


Joined: 10 Sep 2008
Posts: 453
Location: Near /dev/urandom | /dev/null

PostPosted: Sat Sep 20, 2008 5:16 pm    Post subject: Reply with quote

a.b. wrote:
Ivman does the job for me without much configuration:
http://gentoo-wiki.com/HOWTO_ivman


Didn't knew that project, still it says it requires HAL in order to work, wich he said he didn't want if possible.

After some reading, I'd go for modifing the udev rules too.
_________________
| Intel Core i7 920. | Intel DX58SO Extreme. |
| 8gb DDR3 1666mHz | 1TB 7200 RPM WD HDD.|
Unix´s guru view of sex:
unzip ; strip ; touch ; grep ; finger ; \
mount ; fsck ; more ; yes ; umount ; sleep.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum