Unix Programming - Finding mountpoints

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > July 2005 > Finding mountpoints





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Finding mountpoints
A. Melinte

2005-07-25, 6:07 pm

Hello,

I need to find where a device is mounted. For example, the flash device
/dev/cf0 contains a filesystem on it, which is mounted somewhere, say
/mnt/cf0.

Is there a C call I can use? Preferably POSIX one.

Regards
a.


Thorn

2005-07-25, 6:07 pm

On Mon, 25 Jul 2005 11:43:22 -0400, A. Melinte Cried: Read These Runes!:
> Hello,
>
> I need to find where a device is mounted. For example, the flash device
> /dev/cf0 contains a filesystem on it, which is mounted somewhere, say
> /mnt/cf0.


Have you tried "mount"?

Thorn
--
Without ice cream life and fame are meaningless.
Michael B Allen

2005-07-25, 6:07 pm

On Mon, 25 Jul 2005 11:43:22 -0400, A. Melinte wrote:

> Hello,
>
> I need to find where a device is mounted. For example, the flash device
> /dev/cf0 contains a filesystem on it, which is mounted somewhere, say
> /mnt/cf0.
>
> Is there a C call I can use? Preferably POSIX one.


Not POSIX. There probably is a C call but I don't know how portable it
would be. However I believe on most systems typing 'mount' will produce a
list of currently mounted filesystesm. So one thing you could do is run
the 'mount' command in a pty (might want to run through a script like
mount | awk '{ print $1 " " $3 }' to reorder the output if it differs
from system to system). Or you could use system(3) but I prefer to use a
pty for this sort of thing so that you don't have to redirect to a file
and read it back separately.

Mike

Henry Townsend

2005-07-25, 6:07 pm

Michael B Allen wrote:
> On Mon, 25 Jul 2005 11:43:22 -0400, A. Melinte wrote:
>
>
>
>
> Not POSIX. There probably is a C call but I don't know how portable it
> would be. However I believe on most systems typing 'mount' will produce a
> list of currently mounted filesystesm. So one thing you could do is run
> the 'mount' command in a pty (might want to run through a script like
> mount | awk '{ print $1 " " $3 }' to reorder the output if it differs
> from system to system). Or you could use system(3) but I prefer to use a
> pty for this sort of thing so that you don't have to redirect to a file
> and read it back separately.


Boy, isn't that what popen() is for?

--
Henry Townsend
Andrew Gabriel

2005-07-25, 6:07 pm

In article <dc31ar$4an$1@engnntp1.cig.mot.com>,
"A. Melinte" <nospam@nospam.com> writes:
> Hello,
>
> I need to find where a device is mounted. For example, the flash device
> /dev/cf0 contains a filesystem on it, which is mounted somewhere, say
> /mnt/cf0.
>
> Is there a C call I can use? Preferably POSIX one.


Yes, getmntent(), but it's not POSIX.

--
Andrew Gabriel
Antti Nykänen

2005-07-25, 6:07 pm

On 2005-07-25, Andrew Gabriel <andrew@a17> wrote:
> Yes, getmntent(), but it's not POSIX.


And getmntinfo(3) on BSD.

--
Antti Nykänen
http://aon.iki.fi
Michael B Allen

2005-07-26, 7:59 am

On Mon, 25 Jul 2005 14:44:44 -0400, Henry Townsend wrote:

>
> Boy, isn't that what popen() is for?


Ah, yes. In this case that would work fine. I think I mentally blocked
the popen(3) option because it's so ugly. Not that running a program in a
pty is beautiful but at least with a pty you can

o use select(2),
o interact if necessary,
o send Ctrl-C if the program is hung,
o get return codes in a shell by checking the $? builtin variable,
o you don't have to go through an intermediate shell,
o and you don't have to worry about the program behaving oddly
because it's not connected to a real terminal.

Mike

A. Melinte

2005-07-26, 7:59 am


"Antti Nykänen" <aon@iki.fi.invalid> wrote in message
news:slrndeajfn.o92.aon@ecx.no-ip.org...
> On 2005-07-25, Andrew Gabriel <andrew@a17> wrote:
>
> And getmntinfo(3) on BSD.


Thanks, getmntent() seems to do the job. I noted though that members of
struct mntent are named differently, depending on platform, not very
portable. But does the job

Regards
a.



Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com