Accessing mount points

Accessing mount points

Post by Larry Ble » Sat, 09 Nov 1991 06:32:49



Hello.  I have a minor programming problem that some of you may have the answer
to.  I have written a program to monitor the free disk space on a group
of file systems that the user specifies and report on significant drops,
etc.  I read up on the getmnt system call and am using the information
returned in it.  My intention is that the user would specify the mount
point of the file system to be monitored.  As it turns out, if you pass
getmnt anything underneath the mount point you still get the info for
the whole file system.  For instance, if /usr is mouonted on its own
partition and you getmnt on /usr/share info on /usr is returned.

This is fine behaviour, but consider the case of a separate partition
called, say, /scratch.  This gets monitored properly.  If /scratch is
now umounted the underlying directory /scratch is revealed, and the next
call to getmnt returns info on / instead of telling me that /scratch is
no longer mounted.  This shows up as a huge drop in space on /scratch!

I could code around it if something would tell me if the file system I
pass to getmnt is actually a mount point or not.  If it ever stops being
a mount point then I flag the file system as being unmounted until it
comes back on line (is mounted again).  Thus there are no spurious
reports of drops in disk space and the correct condition is detected.

Does anyone have a suggestion on how to go about getting this
information?  Or perhaps even a better way of detecting this condition
and handling it?  Thanks.
I'm running Ultrix 4.2 on a DECstation 5000-200.

Larry Bleau
Physics Dept
University of Maryland

301-405-6180 or -6048

P.S. I haven't yet tried umount-ing a remote file system to see if I
handle that case properly; that should be interesting.

 
 
 

Accessing mount points

Post by der Mou » Mon, 11 Nov 1991 19:04:49



> I have written a program to monitor the free disk space on a group of
> file systems that the user specifies and report on significant drops,
> etc.  [...getmnt syscall to get the info...]
> This is fine behaviour, but consider the case of a separate partition
> called, say, /scratch.  This gets monitored properly.  If /scratch is
> now umounted the underlying directory /scratch is revealed, and the
> next call to getmnt returns info on / instead of telling me that
> /scratch is no longer mounted.  This shows up as a huge drop in space
> on /scratch!
> I could code around it if something would tell me if the file system
> I pass to getmnt is actually a mount point or not.

Well, it's not *quite* what you want, but you can stat() the given
directory; if the (st_dev,st_ino) pair ever changes, it is very likely
that a mount or unmount has taken place that causes the path to refer
to a different filesystem.  (Be careful to check for errors from
stat(); in some circumstances you may start getting ENOENTs.)

Of course, there is a race condition - you have to assume that nothing
happens between the stat() and the getmnt().  You can reduce this by
doing another stat() immediately afterward, but I don't think it can
ever be completely eliminated without help from the kernel.

                                        der Mouse

                        old: mcgill-vision!mouse


 
 
 

Accessing mount points

Post by Don Lew » Sat, 16 Nov 1991 17:29:04



>Hello.  I have a minor programming problem that some of you may have the answer
>to.  I have written a program to monitor the free disk space on a group
>of file systems that the user specifies and report on significant drops,
>etc.  I read up on the getmnt system call and am using the information
>returned in it.  My intention is that the user would specify the mount
>point of the file system to be monitored.  As it turns out, if you pass
>getmnt anything underneath the mount point you still get the info for
>the whole file system.  For instance, if /usr is mouonted on its own
>partition and you getmnt on /usr/share info on /usr is returned.

>This is fine behaviour, but consider the case of a separate partition
>called, say, /scratch.  This gets monitored properly.  If /scratch is
>now umounted the underlying directory /scratch is revealed, and the next
>call to getmnt returns info on / instead of telling me that /scratch is
>no longer mounted.  This shows up as a huge drop in space on /scratch!

Try doing a stat() on /scratch and /scratch/.. (or / -- whatever name
with the last component removed, you might have to be careful if your
mount point is a symlink).  If the st_dev fields of the stat structures
differ, you must be at a mount point.  If they are the same, then you
are not at a mount point.
--
Don "Truck" Lewis              Phone: +1 916 265-3211   Silicon Systems
Internet: (under contruction)  FAX:   +1 916 265-2931   138 New Mohawk Road
UUCP: {uunet,tektronix!gvgpsa.gvg.tek.com}!ssigv!lewis  Nevada City, CA  95959
 
 
 

1. Accessing mount point directory

I seem to recall a thread on accessing the mount point directory of an
nfs mounted filesystem that cannot be umounted (/var, for example).
This was in January or February.  I cannot locate this thread on
groups.google.com and do not remember if it was this newsgroup. Anyone
have any info on this?

Thanks in advance.

2. Q: time quota for child process

3. tunnel point to point vs physical point to point

4. Linux on a Mac vs. x86 Linux

5. Limiting access to mount points?

6. Expanding Disk Space without re-partitioning!

7. Acess Point to Access Point?

8. CA Unicenter

9. mount: mount point /media/cdrom0 does not exist

10. mounting several partitions on the same mount point

11. mount doesn't recognize mount points

12. mount: dev fd0 not a mount point

13. mount gives error: mount point doesn't exist!