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 are also provided which offer an alternative to the POSIX stat(1) function and provide additional GPFS-relevant properties not available to POSIX stat(1).

Description

arcapix.fs.gpfs.clib.file.copy_acl(source, dest)

Copy ACL from one file to another.

Parameters:
  • source (str) – path to file from which ACL should be copied
  • dest (str) – path to file to which copied ACL should be applied
arcapix.fs.gpfs.clib.file.fstat(const char *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 for st_mtime and st_atime.

Parameters:pathname (str) – Path to a file in a GPFS Filesystem
arcapix.fs.gpfs.clib.file.get_fileset_name(int fileDesc)

Get the name of the fileset a file belongs to.

Parameters:fileDesc (int) – descriptor of an open file
arcapix.fs.gpfs.clib.file.get_replication(int fileDesc)

Get file replication factors.

Parameters:fileDesc (int) – descriptor of an open file
Returns:dict of replication values and status code. Use get_status_strings() to convert status code to list of strings.
Return type:dict
arcapix.fs.gpfs.clib.file.get_snapshot_name(int fileDesc)

Get the name of the snapshot the file belongs to.

Parameters:fileDesc (int) – descriptor of an open file
arcapix.fs.gpfs.clib.file.get_status_strings(int status)

Convert a status integer to a list of flag strings.

Parameters:status (int) – status as returned from :py:func`get_replication`
Return type:list of str
arcapix.fs.gpfs.clib.file.get_storage_pool(int fileDesc)

Get the name of the storage pool the file belongs to.

Parameters:fileDesc (int) – descriptor of an open file
arcapix.fs.gpfs.clib.file.get_winattrs(const char *pathname)

Returns windows attributes of the file.

Use get_winattrs_string() to convert returned integer to a list of strings.

Parameters:pathname (str) – path to file to get win attrs for
Return type:int
arcapix.fs.gpfs.clib.file.get_winattrs_strings(int attrs)

Convert winattrs integer to a list of flag strings.

Parameters:attrs (int) – value as returned from :py:func`get_winattrs`
Return type:list of str
arcapix.fs.gpfs.clib.file.getacl(char *source)

Get a file’s acls.

Parameters:source (str) – path to a file to get acls from.
Returns:opaque_acl object holding the file’s acls
arcapix.fs.gpfs.clib.file.prealloc(int fileDesc, off_t start, off_t bytes)

Pre-allocates disk storage for a GPFS file.

Parameters:
  • fileDesc (int) – descriptor of an open file to preallocated
  • start (int) – offset in files to start allocating from
  • bytes (int) – number of bytes to allocate
arcapix.fs.gpfs.clib.file.putacl(char *dest, opaque_acl acls)

Set a file’s acls.

Parameters:
  • dest (str) – path to file whose acls should be changed.
  • acls (opaque_acl) – opaque_acl object with acls to set. This should be an object returned from a getacl() call
arcapix.fs.gpfs.clib.file.stat(const char *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

Examples

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())
'root'
>>>
>>> with open('/mmfs1/test.txt', 'r') as f:
...    print get_storage_pool(f.fileno())
'sata1'

Lookup windows attributes

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

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)
    False

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)