Ifile Functions
The ifile
module provides methods for opening and reading Filesystem objects by inode number.
These methods could be used to make backups of a Filesystem or iterate selective areas of the Filesystem.
Note
These objects require root permission to create
Description
direntx struct
The direntx
struct returned by ireaddir()
has the following fields
d_type # Type (int) - can be converted with 'get_type_string'
d_ino # File inode number (int)
d_gen # Generation number for the inode (int)
d_flags # Flags (int) - can be converted with 'get_flags_strings'
d_name # File name (str)
- arcapix.fs.gpfs.clib.ifile.get_flags_strings(unsigned int flags)
Get strings for direntx flags integer.
Used to convert the
d_flags
value ofdirentx
as returned byireaddir`()
- Returns
One or more of (JUNCTION, IJUNCTION, ORPHAN, CLONE, NONE)
- Return type
list of str
- arcapix.fs.gpfs.clib.ifile.get_type_string(int type)
Get the type string for a direntx type integer.
Used to convert the
d_type
value ofdirentx
as returned byireaddir`()
- Returns
One of (REG, DIR, LNK, DEL, FIFO, CHR, BLK, SOCK, OTHER)
- Return type
- arcapix.fs.gpfs.clib.ifile.iclose(ifile file)
Close an ifile object.
- Parameters
file –
ifile
to close
- class arcapix.fs.gpfs.clib.ifile.ifile
The ifile object acts as a wrapper for the
gpfs_ifile_t
pointer.
- arcapix.fs.gpfs.clib.ifile.iopen(fssnap_handle fssnap, gpfs_ino64_t ino, int flags=0)
Open an ifile object for the given inode.
- Parameters
fsnap (fssnap_handle) – fssnap handle identifying a filesystem or snapshot
ino (int) – Inode number of the file object to open
flags (int) – flags indicating open mode (default=0, readonly)
- Returns
an open ifile object
- Return type
- arcapix.fs.gpfs.clib.ifile.iread(ifile file, int buffersize, gpfs_off64_t offset=0)
Read bytes from an open ifile.
- arcapix.fs.gpfs.clib.ifile.ireaddir(ifile idir)
Read entries from a directory.
This method can be used to iterate over the file objects in a directory.
>>> for ent in iter(lambda: ireaddir(idir), None): ... # do stuff
- Parameters
idir –
ifile
to read from. This should correspond to a directory.- Returns
a directory entry representing a file in the directory
- Return type
direntx
- arcapix.fs.gpfs.clib.ifile.ireadlink(fssnap_handle fssnap, gpfs_ino64_t ino)
Get the target of a Symlink by inode number.
- Parameters
fssnap (fssnap_handle) – Filesystem of snapshot to look in
ino (int) – inode number of the symlink to read
- Return type
Examples
Print a list of objects in a directory
>>> from arcapix.fs.gpfs.clib.fssnap import get_fssnaphandle_by_name
>>> from arcapix.fs.gpfs.clib.ifile import iopen, ireaddir, ireadlink, iclose, DE_LNK
>>>
>>> # Create handle
... fs = get_fssnaphandle_by_name('mmfs1')
>>>
>>> # Open directory; inode 3 = fs root directory
... d = iopen(fs, 3)
>>>
>>> # iterate over contents
... for f in iter(lambda: ireaddir(d), None):
... # if symlink, print target
... if f.d_type == DE_LNK:
... print("%s\t%s -> %s" % (f.d_ino, f.d_name, ireadlink(fs, f.d_ino)))
... else:
... print("%s\t%s" % (f.d_ino, f.d_name))
3 .
3 ..
39173 link -> /mmfs1/test
16134 test
18177 data
18176 .policytmp
>>> # close idir
... iclose(d)