The stat (and fstat) unix
system calls update a structure (
passed by reference) with information about an
inode.
Standard fields include:
- st_mode
- this includes inode type (directory, plain file, device file, pipe, socket, symbolic link, etc.) and permission bitmask
- st_ino
- inode number of the file
- st_dev
- device number of the device containing the mounted filesystem
- st_nlink
- number of names (hard links) this file has
- st_uid
- owner of the file
- st_gid
- group owner of the file
- st_size
- offset of the last byte in the file (length)
- st_atime
- last time the file was accessed
- st_mtime
- last time the file was modified
- st_ctime
- last time the file was changed (including modifying atime or mtime)
- st_blocks (BSD derived systems only--not POSIX)
- size of the file in 512b blocks
The inode number and device number together are guarenteed to uniquely identify a file. This is the only (portable) way to verify that
two names are hardlinks to the same file.
If (st_blocks * 512 < st_size), then the file is a sparse file and has one or more
holes in it. (I.e., not every section of the file has disk space allocated to it.) This is the only (portable) way to detect holes in a file.