File Functions

File functions provide methods to determine attributes and manipulate files in a GPFS Filesystem.

CLib’s File Functions provide faster operation than the equivalent ArcaPix GPFS Python API’s File(). methods.


Stat Functions

Stat functions offer an alternative to the POSIX stat(1) functions and provide additional GPFS-relevant properties not available to POSIX stat(1).

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.


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

File Attribute Functions

XAttr Functions

ACL Functions

Misc Functions


Lookup attributes of a file

>>> from arcapix.fs.gpfs.clib import get_fileset_name, get_storage_pool
>>> with open('/mmfs1/test.txt', 'r') as f:
...    print get_fileset_name(f.fileno())
>>> with open('/mmfs1/test.txt', 'r') as f:
...    print get_storage_pool(f.fileno())

Lookup windows attributes

>>> from arcapix.fs.gpfs.clib import get_winattrs, get_winattrs_strings
>>> print get_winattrs('/mmfs1/test.txt')
>>> # convert integer flag to a list of strings
... print get_winattrs_strings(1)

Check if a file is Offline

>>> # Note - unlike mmlsattr this approach doesn't trigger a recall
>>> from arcapix.fs.gpfs.clib import get_winattrs, WA_OFFLINE
>>> print bool(get_winattrs('/mmfs1/test.txt') & WA_OFFLINE)

Copy ACLs from one file to another

>>> from arcapix.fs.gpfs.clib.file import copy_acl
>>> copy_acl('/mmfs1/test01.txt', '/mmfs1/test02.txt')

Comparison to POSIX stat

>>> from arcapix.fs.gpfs.clib.file 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)

Lookup extended attributes

>>> from arcapix.fs.gpfs.clib.file import get_all_xattrs
>>> with open('/mmfs1/test.txt', 'r') as f:
...     print get_all_xattrs(f.fileno())
{'': 'bar'}

Check free space on a filesystem

>>> from arcapix.fs.gpfs.clib.files import statfs
>>> result = statfs('/mmfs1')
>>> # free space in KB
... result.f_bfree * result.f_bsize / 1024
>>> # percent free space in blocks
... 100 * result.f_bfree / result.f_blocks
>>> # used inodes
... result.f_files - result.f_ffree