File Functions

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

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

Description

File Attribute Functions

arcapix.fs.gpfs.clib.file.get_fileset_name(gpfs_file_t 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_storage_pool(gpfs_file_t 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_snapshot_name(gpfs_file_t 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_replication(gpfs_file_t 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_status_strings(int status)

Convert a status integer to a list of flag strings.

Parameters

status (int) – status as returned from get_replication()

Return type

list of str

arcapix.fs.gpfs.clib.file.get_winattrs(pathname)

Returns windows attributes of the file.

Use get_winattrs_strings() 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(unsigned int attrs)

Convert winattrs integer to a list of flag strings.

Parameters

attrs (int) – value as returned from get_winattrs()

Return type

list of str

arcapix.fs.gpfs.clib.file.set_winattrs(pathname, unsigned int attrs)

Set windows attributes on a file.

Parameters
  • pathname (str) – path to file to set win attrs for

  • flags (int) – attribute flags to apply

Flags is a combination of: WA_ARCHIVE, WA_COMPRESSED, WA_ENCRYPTED, WA_HIDDEN, WA_NOT_CONTENT_INDEXED, WA_READONLY, WA_REPARSE_POINT, WA_SPARSE_FILE, WA_SYSTEM, WA_TEMPORARY, WA_HAS_STREAMS

Any other WA_* flag (e.g. WA_OFFLINE) will be ignored. If no supported flags are passed, the result will be WA_NORMAL.

Note

Setting winattrs may update file change time (ctime).

arcapix.fs.gpfs.clib.file.get_creation_time(pathname)

Returns creation time of the file.

Parameters

pathname (str) – path to file to get creation time for

Return type

float

arcapix.fs.gpfs.clib.file.set_creation_time(pathname, creation_time)

Set the creation time of a file.

Parameters
  • pathname (str) – path to file to set creation time for

  • creation_time (float) – creation time

Note

Using this method to set creation time may update file change time (ctime). To ensure ctime isn’t updated, use set_times() instead.

Misc Functions

arcapix.fs.gpfs.clib.file.prealloc(gpfs_file_t fileDesc, gpfs_off64_t start, gpfs_off64_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.set_times(fd, atime=None, mtime=None, ctime=None, creation_time=None, follow=True)

Sets file access time, modified time, change time, and/or creation time.

Parameters
  • fd (int) – file descriptor for an open file to set times for

  • atime (int) – set access time

  • mtime (int) – set modification time

  • ctime (int) – set change time

  • creation_time (int) – set creation time

  • follow (bool) – whether to follow symlinks (default=True)

Important

follow=False isn’t supported on GPFS <= 4.1.0

Any timestamps which are not specified will remain unchanged. Unlike touch, changing a file’s atime doesn’t affect its ctime.

Warning

Changing file timestamps may interfere with the operation of other software, such as backup tools

arcapix.fs.gpfs.clib.file.set_times_path(pathname, atime=None, mtime=None, ctime=None, creation_time=None, follow=True)

Sets file access time, modified time, change time, and/or creation time.

Parameters
  • pathname (str) – path of the file to set times for

  • atime (int) – set access time

  • mtime (int) – set modification time

  • ctime (int) – set change time

  • creation_time (int) – set creation time

  • follow (bool) – whether to follow symlinks (default=True)

Important

follow=False isn’t supported on GPFS <= 4.1.0

Any timestamps which are not specified will remain unchanged. Unlike touch, changing a file’s atime doesn’t affect its ctime.

Warning

Changing file timestamps may interfere with the operation of other software, such as backup tools

Examples

Lookup attributes of a file

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

>>> from arcapix.fs.gpfs.clib.file import get_winattrs, WA_OFFLINE
>>>
>>> print(bool(get_winattrs('/mmfs1/test.txt') & WA_OFFLINE))
False

Set windows attributes

>>> from arcapix.fs.gpfs.clib.file import set_winattrs, WA_ARCHIVE, WA_HIDDEN
>>>
>>> set_winattrs('/mmfs1/test.txt', WA_ARCHIVE|WA_HIDDEN)