Skip to contentSkip to conversation

Finding sysfs mount point

DISCUSSION Ian Pilcher 4 participants 4 messages Apr 28, 2005 – May 4, 2005

lore
Share & tools
lore
#0 lore raw

I'm trying to write a script (invoked via a PROGRAM key) to find the interface number of a USB serial port. (See my post in the "udev: rules using multiple sysfs directories" thread for the reason why.)

To do this I need to look as sysfs. What's the best way to figure out where it's mounted?

Also, is it safe to rely on the contents of DEVPATH to find a symbolic link to the device?

Thanks!

Signature · 15 lines
====================================
Ian Pilcher                                        [email protected]
====================================



-------------------------------------------------------
SF.Net email is sponsored by: Tell us your software development plans!
Take this survey and enter to win a one-year sub to SourceForge.net
Plus IDC's 2005 look-ahead and a copy of this survey
Click here to start!  http://www.idcswdc.com/cgi-bin/survey?id5hix
_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
#1 lore raw
Quoted 6 lines · Ian Pilcher

I'm trying to write a script (invoked via a PROGRAM key) to find the interface number of a USB serial port. (See my post in the "udev: rules using multiple sysfs directories" thread for the reason why.)

To do this I need to look as sysfs. What's the best way to figure out where it's mounted?

cat /proc/mounts | grep sysfs | cut -f 2 -d " "

works for me. I think there's a glibc function to retrieve this too.

Quoted 2 lines

Also, is it safe to rely on the contents of DEVPATH to find a symbolic link to the device?

Yes, that's what it is there for :)

thanks,

greg k-h

-------------------------------------------------------
SF.Net email is sponsored by: Tell us your software development plans! Take this survey and enter to win a one-year sub to SourceForge.net Plus IDC's 2005 look-ahead and a copy of this survey
Click here to start! http://www.idcswdc.com/cgi-bin/survey?id5hix
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#2 lore raw
In reply to Ian Pilcher
Quoted 1 line · Greg KH

cat /proc/mounts | grep sysfs | cut -f 2 -d " "

if sysfs is mounted several times, this results in a non useful value for scripting. what about

cat /proc/mounts | grep -m 1 sysfs | cut -f 2 -d " "

to get the first available mountpoint?

cheers

Christian

-------------------------------------------------------
SF.Net email is sponsored by: Tell us your software development plans! Take this survey and enter to win a one-year sub to SourceForge.net Plus IDC's 2005 look-ahead and a copy of this survey
Click here to start! http://www.idcswdc.com/cgi-bin/survey?id5hix
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#3 lore raw
In reply to Ian Pilcher

Christian Borntr?ger [Fri, Apr 29, 2005 at 09:09:47AM +0200]:

Quoted 9 lines · Greg KH
Quoted 1 line

cat /proc/mounts | grep sysfs | cut -f 2 -d " "

if sysfs is mounted several times, this results in a non useful value for scripting. what about

cat /proc/mounts | grep -m 1 sysfs | cut -f 2 -d " "

to get the first available mountpoint?

None of those expamples is reliable, when other paths contain 'sysfs'.

Simply use awk for it, it's build for such things:

awk '$3 ~ /sysfs/ { print $2; exit }' /proc/mounts

This will catch wrong sysfs mounts and also display only the first match.

Nico

Signature · 3 lines
Keep it simple & stupid, use what's available.
Please use pgp encryption: 8D0E 27A4 is my id.
http://nico.schotteli.us | http://linux.schottelius.org