07-29-05 11:01 PM
Markus.Elfring@web.de writes:
> Which programming interfaces and tools can show to which partition a
> file belongs to?
> How do you get from the file name to the corresponding partition name
> and mount point?
Use stat(2) (or fstat or lstat). The file is identified with st_dev
and st_ino. st_dev, the device number actually identifies the file
system, what you call a "partition".
There's no more portable API. The rest will have to be done with
implementation specific stuff. On linux, you can get the list of the
mount points from /proc/mounts. You can also read /etc/mtab, and
further use stat on the mount points you find to identify the file,
host or device on which the file system is stored. Indeed, some file
systems are not stored in a "partition", but in a file or on a remote
host.
Use: strace /bin/df file # or ptrace or whatever is provided on your OS.
to see what system calls are used by df to do the job.
--
__Pascal Bourguignon__ http://www.informatimago.com/
I need a new toy.
Tail of black dog keeps good time.
Pounce! Good dog! Good dog!
[ Post a follow-up to this message ]
|