Stat Functions
Stat functions offer an alternative to the POSIX stat(1)
functions
and provide additional PixStor-relevant properties not available to POSIX stat(1).
Description
stat_result struct
The stat_result
struct returned by stat()
, fstat()
, statlite()
, and lstatlite()
has the following fields
st_dev # device id
st_ino # inode number
st_mode # access mode
st_nlink # number of hard links
st_uid # user ID of owner
st_gid # group ID of owner
st_rdev # device type (if inode device)
st_size # total size, in bytes
st_blksize # blocksize for filesystem I/O
st_blocks # number of blocks allocated
st_atime # time of last access
st_mtime # time of last modification
st_ctime # time of last change
All fields are of type int.
statfs_result struct
The statfs_result
struct returned by statfs()
has the following fields
f_type # type of file system
f_bsize # optimal transfer block size
f_blocks # total data blocks in file system
f_bfree # free blocks in fs
f_bavail # free blocks available to unprivileged user
f_files # total file nodes in file system
f_ffree # free file nodes in fs
f_namelen # maximum length of filenames
All fields are of type int.
Note
The value of the f_bfree
field may not be accurate.
For a more accurate reading of free space on the filesystem, see the mmdf
command
- arcapix.fs.gpfs.clib.stat.fstat(pathname)
Look up file properties just like unix
stat
.Looks up file properties for files in the GPFS filesystem specifically. Looking up file outside of the GPFS filesystem will cause an error to be raised.
An alternative to gpfs
stat()
, which may not provide exact values forst_mtime
andst_atime
.- Parameters
pathname (str) – Path to a file in a GPFS Filesystem
- arcapix.fs.gpfs.clib.stat.lstatlite(pathname, unsigned int litemask=SL_NONE)
Returns stat information with specified accuracy
Like
statlite()
but doesn’t follow symlinks- Parameters
Lite mask is some combination of:
SL_NONE
,SL_SIZE
,SL_BLKSIZE
,SL_BLOCKS
,SL_ATIME
,SL_MTIME
,SL_CTIME
,SL_EXACT
- arcapix.fs.gpfs.clib.stat.stat(pathname)
Look up file properties just like unix
stat
.Looks up file properties for files in the GPFS filesystem specifically. Looking up file outside of the GPFS filesystem will cause an error to be raised
- Parameters
pathname (str) – Path to a file in a GPFS Filesystem
- arcapix.fs.gpfs.clib.stat.statfs(pathname)
Get information about the file system.
Note
requires root permission
- Parameters
pathname (str) – Path to any file in a GPFS Filesystem
- arcapix.fs.gpfs.clib.stat.statlite(pathname, unsigned int litemask=SL_NONE)
Returns stat information with specified accuracy
- Parameters
Lite mask is some combination of:
SL_NONE
,SL_SIZE
,SL_BLKSIZE
,SL_BLOCKS
,SL_ATIME
,SL_MTIME
,SL_CTIME
,SL_EXACT
Examples
Comparison to POSIX stat
>>> from arcapix.fs.gpfs.clib.stat import stat as gpfs_stat
>>> from os import stat
>>>
>>> gpfs_stat('/mmfs1/test1')
stat_result(st_mode=33279, st_ino=26368, st_dev=61334, st_rdev=0, st_nlink=2, st_uid=0, st_gid=0,
st_size=1394, st_blocks=256, st_blksize=4194304, st_atime=1464784803, st_mtime=1456850352, st_ctime=1461061390)
>>>
>>> stat('/mmfs1/test1')
posix.stat_result(st_mode=33279, st_ino=26368, st_dev=29L, st_nlink=2, st_uid=0, st_gid=0,
st_size=1394, st_atime=1464784803, st_mtime=1456850352, st_ctime=1461061390)
Check free space on a filesystem
>>> from arcapix.fs.gpfs.clib.stat import statfs
>>>
>>> result = statfs('/mmfs1')
>>>
>>> # free space in KB
... result.f_bfree * result.f_bsize / 1024
24719360
>>> # percent free space in blocks
... 100 * result.f_bfree / result.f_blocks
94
>>> # used inodes
... result.f_files - result.f_ffree
8342L