Re: detecting drives for windows and linux



aleaxit@xxxxxxxxx (Alex Martelli) wrote:

Florian Diesch <diesch@xxxxxxxxxxxxx> 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.

Depends on what you want to do. Offen you need informations like file size,
permissions or owner in any case.


For things like creating hardlinks it may be the best to just try it and
catch the exception.


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) --

GNU df doesn't have it.
Some of the various version of df at Solaris don't have it too. And they
have at least two different output formats.


executing mount
is the alternative (just putting up with some parsing difficulties
depending, e.g., on what automounters may be doing).

I would prefer mount as ir is cheaper than df

Reading /etc/mtab is not difficult and much faster

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

Ok, wasn't that clever. On Solaris it's /etc/mntab, I don't have any BSD around

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.

On the other hand I know of at least two boxes (no, not mine) where
ordinary users don't have permission to exec mount.





Florian
--
Emacs doesn't crash! It contains very little C, so there's very
little reason to have it crash. [Pascal Bourguignon in gnu.emacs.help]
.



Relevant Pages

  • [BUG]: Crash with CONFIG_FAIR_CGROUP_SCHED=y
    ... If we skip the 'mount' command, there is no crash. ... mounting just the cpu or just the ns subsystem does not ... Kernel 2.6.24-rc1 on an x86_64 ...
    (Linux-Kernel)
  • Re: Mount and read a solaris disk in Linux
    ... > I have a Solaris disk that I need to mount and read on a linux box. ... When you mount a filesystem, nothing should be written to it ...
    (comp.os.linux.misc)
  • Unable to mount Iriver T60
    ... I have been trying to connect an Iriver T60 mp3 player to an Ultra 80 ... running Solaris 9 but i am not able to mount the device. ...
    (comp.unix.solaris)
  • mounting windows snapview volume to Solaris server
    ... Window LUN to a Solaris server - tryed mounting as -F pcfs filesystem but no ... Want to mount the snapshot to a Solaris host for backup. ... AIG Europe Limited is an appointed representative of New Hampshire Insurance Company and of Landmark Insurance Company Limited, both of which are authorised and regulated by the UK Financial Services Authority. ...
    (SunManagers)
  • Solaris 7 mounts / and /usr read-only
    ... This happened on a solaris 7 machine before and the ultimate solution was to ... upgrade to solaris8. ... The system starts to boot, appears to load a video driver (I base this on ... mount -o rw,remount /usr ...
    (comp.unix.solaris)