detecting drives for windows and linux

Alex Martelli aleaxit at yahoo.com
Tue Mar 28 04:38:38 CEST 2006


Florian Diesch <diesch at spamfence.net> wrote:
   ...
> >> are and want to do it anyway?) Linux puts the whole file system 
> >> (including mounted iPods, ISOs and NTFS drives) in one hierarchy.
> >
> > Yes, but you may still want to distinguish (because, for example, hard
> > linking doesn't work across filesystems, and mv is not atomic then).
> 
> Why not use os.stat?

Each os.stat call gives you information about one file (or directory);
it may be simpler and faster to get the information "in bulk" once and
for all.

> > Running a df command is a good simple way to find out what drives are
> > mounted to what mountpoints -- the mount command is an alternative, but
> > its output may be slightly harder to parse than df's.
> 
> Executing df may be expensive if it needs to read some slow file systems.

That's what the -n flag is for, if you're worried about that (although I
believe it may not be available on all systems) -- executing mount is
the alternative (just putting up with some parsing difficulties
depending, e.g., on what automounters may be doing).

> Reading /etc/mtab is not difficult and much faster

$ cat /etc/mtab
cat: /etc/mtab: No such file or directory

Oops!  BSD systems don't have /etc/mtab... so, if you choose to get your
info by reading it, you've just needlessly destroyed your program's
compatibility with a large portion of the Unix-y universe.  popen a
mount or df, and information will be easier to extract portably.


Alex



More information about the Python-list mailing list