How to determine the partition for a file
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > How to determine the partition for a file




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    How to determine the partition for a file  
Markus.Elfring@web.de


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-29-05 01:08 PM

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






[ Post a follow-up to this message ]



    Re: How to determine the partition for a file  
Grumble


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-29-05 11:01 PM

Markus.Elfring@web.de wrote:
> Which programming interfaces and tools can show to which partition a
> file belongs to?

Could 'df FILE' provide some information?
http://www.gnu.org/software/fileutils/fileutils.html





[ Post a follow-up to this message ]



    Re: How to determine the partition for a file  
Pascal Bourguignon


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
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 ]



    Re: How to determine the partition for a file  
Doug Freyburger


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-29-05 11: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.






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 09:54 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register