[Tutor] Checking to see whether or not a filesystem is mounted--?
kalle at lysator.liu.se
Sun Aug 8 02:46:08 CEST 2004
> Anyway, enough preamble. I'm wanting to write a small graphical applet
> for mounting and unmounting filesystems with a button-press. Can anyone
> suggest a method for testing whether or not a particular filesystem is
> mounted (so I can inform the user with a message dialog)?
I'd probably try reading the output of `mount`. This consists of one
or more lines, formatted something like
<device> on <mount point> type <fstype> [(<options>)]
If there is a line matching the device you're interested in, the
device is mounted. Otherwise it isn't, obviously.
Symbolic links could make this more difficult, I suppose. E.g. if
/foo is a symlink to /mnt/bar, /foo won't appear in the `mount` output
even if /mnt/bar is mounted. I assume there are other difficulties as
well. Otherwise it wouldn't be any fun, would it?
Program output can be gathered with os.popen and friends or any of
several third-party modules. For this purpose, I think os.popen is
sufficient. Read more about it on
More information about the Tutor