Professional Web Applications Themes

How to determine the partition for a file - Linux / Unix Administration

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

  1. #1

    Default How to determine the partition for a file

    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

    Markus.Elfring@web.de Guest

  2. #2

    Default Re: How to determine the partition for a file

    de wrote: 

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

  3. #3

    Default Re: How to determine the partition for a file

    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".

    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!
    Pascal Guest

  4. #4

    Default Re: How to determine the partition for a file

    Pascal Bourguignon wrote: 
    >
    > 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".[/ref]

    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.

    Doug Guest

Similar Threads

  1. determine file name of doent
    By bts2500@yahoo.com in forum Adobe Acrobat SDK
    Replies: 0
    Last Post: August 18th, 05:14 PM
  2. how to remotely determine size of a swf file?
    By miconian in forum Macromedia Flash Ad Development
    Replies: 0
    Last Post: April 1st, 02:59 AM
  3. Best way to determine if file exists
    By Jason Wolfe in forum Macromedia Director Basics
    Replies: 1
    Last Post: February 16th, 03:04 PM
  4. Determine File Transfer Rate
    By Jay in forum AIX
    Replies: 9
    Last Post: December 4th, 01:51 PM
  5. how to determine if link is directory or file?
    By bart plessers in forum ASP
    Replies: 5
    Last Post: July 27th, 11:47 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139