|
Home > Archive > Unix Programming > July 2005 > How to determine the partition for a file
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
How to determine the partition for a file
|
|
| Markus.Elfring@web.de 2005-07-29, 8:08 am |
| 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?
Regards,
Markus
| |
|
|
| Pascal Bourguignon 2005-07-29, 6: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!
| |
| Doug Freyburger 2005-07-29, 6:01 pm |
| Pascal Bourguignon wrote:
> Markus.Elfring@web.de writes:
>
>
> 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".
File system vs partition is the part that interested me.
The logical volume layer means multiple partitions can
be in the same filesystem. "df $FILE" give the filesystem
as the mount point directory and also the device file that
filesystem lives in. It it's a regular device you're done
because that device file is the partition. If it's a
logical volume then you need to figure out what blocks
the inode resides in, then which device in the volume
group those blocks currently reside on. The method
depends on exactly which LVM is in use.
|
|
|
|
|