PDA

View Full Version : Linux: Getting the underlying device from a mount point


KenD00
7th September 2007, 03:25
I'm a linux n00b and try to do the following from c / c++ code:
I have a path where a device is mounted, e.g. /media/cdrom and need to get the underlying device, e.g. /dev/hdb. Calling mount and parsing its output doesn't count ;). I've looked at the source of mount but its way too much work to understand how it works. Is there a sort of API call to get this type of information that works across (almost) all linux distros?

:rolleyes:

xc3ll
11th September 2007, 08:47
you could try dmesg. it should work. dmesg is available on all linux distros that i've ever used.

KenD00
12th September 2007, 22:14
Thanks, but isn't dmesg a binary program like mount too? I don't want to execute an external program to get that information. For now i am parsing /proc/mounts to get the desired information, but is there an easier way?

:rolleyes:

akupenguin
14th September 2007, 00:51
getmntent()

KenD00
14th September 2007, 06:12
Thanks, thats exactly what i was looking for.

:rolleyes: