Unix Programming - Mount & search?

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > June 2005 > Mount & search?





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 Mount & search?
A. Melinte

2005-06-23, 6:00 pm

Hi,

I am looking to get the following informations from within a C program:

-which devices/filesystems were mounted and where
-search a mounted filesystem for a given file

Could not find any API call?


Background:
-I am on a LynxOS machine
-the device in cause is a flash-based filesystem
-there might be multiple such flashes mounted
-but only one of them contains the file I am looking for, but exactly where
is not specified
-I need the serial number of that flash (this part of the puzzle is solved)

Regards
a.


Gordon Burditt

2005-06-23, 6:00 pm

>I am looking to get the following informations from within a C program:
>
>-which devices/filesystems were mounted and where


On a UNIX-like system you can parse the output of the "df" or "mount"
commands.

>-search a mounted filesystem for a given file


Functions like ftw() or programs like "find" can let you tree-walk
the whole filesystem looking for the file you want. You need to
know the mount point, or just search the whole filesystem tree.
This can take days on systems like news servers with terabytes of
storage. The same applies to a slow, old system with a gigabyte of
on-line floppies.

You can make your own recursive tree-walk out of opendir() / readdir()
/ closedir() and stat(). This can get ugly if your file tree can
be deeper than the max number of file descriptors you've got.

>Background:
>-I am on a LynxOS machine


I'm not familiar with that. Since you are posting in comp.unix.programmer,
how UNIX/POSIX-like is that?

>-the device in cause is a flash-based filesystem
>-there might be multiple such flashes mounted
>-but only one of them contains the file I am looking for, but exactly where
>is not specified
>-I need the serial number of that flash (this part of the puzzle is solved)


Will:
find / -name 'my.file' -a -print
work, even if it takes way too much time? You could speed it up
if you know the usual mount points for the flashes, or can get them
from "mount" or "df".

Gordon L. Burditt
Pascal Bourguignon

2005-06-23, 6:00 pm

"A. Melinte" <nospam@nospam.com> writes:

> Hi,
>
> I am looking to get the following informations from within a C program:
>
> -which devices/filesystems were mounted and where
> -search a mounted filesystem for a given file
>
> Could not find any API call?


For the first, there's no standard API.
For the second, there's the POSIX fts(3).


> Background:
> -I am on a LynxOS machine


Check the documentation of LynxOS.
I'm not sure the Linux ABI LynxOS provides covers stuff such as /proc.
Actually, even on Linux, /proc is not necessarily always present.

If it is, then there are the pseudo-files /proc/filesystems (which
lists the known filesystem types) and /proc/mounts that lists the
mounts.

Otherwise, if the Linux ABI covers stuff such as system("mount"), then
there's the mount(1) command that can be used to list the mount
points.


> -the device in cause is a flash-based filesystem


I don't see that it matters at all. At least on unix, I don't know
about LynxOS.


> -there might be multiple such flashes mounted
> -but only one of them contains the file I am looking for, but exactly where
> is not specified
> -I need the serial number of that flash (this part of the puzzle is solved)


You're welcome.


--
__Pascal Bourguignon__ http://www.informatimago.com/
Until real software engineering is developed, the next best practice
is to develop with a dynamic system that has extreme late binding in
all aspects. The first system to really do this in an important way
is Lisp. -- Alan Kay
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com