cligen/statx

Search:
Group by:

The idea of this module is to allow callers to pretend their system has the Linux statx call & Statx type even if it does not. Callers simply program to the "superset" using Statx and statx and i just works. We simulate/translate ordinary Stat results when necessary.

Types

Statx {.importc: "struct statx", header: "<sys/stat.h>", final, pure.} = object
  stx_mask*: uint32          ## Mask of bits indicating filled fields
  stx_blksize*: uint32       ## Block size for filesystem I/O
  stx_attributes*: uint64    ## Extra file attribute indicators
  stx_nlink*: uint32         ## Number of hard links
  stx_uid*: uint32           ## User ID of owner
  stx_gid*: uint32           ## Group ID of owner
  stx_mode*: uint16          ## File type and mode
  stx_ino*: uint64           ## Inode number
  stx_size*: uint64          ## Total size in bytes
  stx_blocks*: uint64        ## Number of 512B blocks allocated
  stx_attributes_mask*: uint64 ## Mask showing supported by stx_attributes
  stx_atime*: StatxTs        ## Last access
  stx_btime*: StatxTs        ## Birth/Creation
  stx_ctime*: StatxTs        ## Last status change
  stx_mtime*: StatxTs        ## Last modification
  stx_rdev_major*: uint32    ## Major ID if file is a device
  stx_rdev_minor*: uint32    ## Minor ID if file is a device
  stx_dev_major*: uint32     ## Major ID of dev of FS where file resides
  stx_dev_minor*: uint32     ## Minor ID of dev of FS where file resides
struct statx
StatxTs {.importc: "struct statx_timestamp", header: "<sys/stat.h>", final, pure.} = object
  tv_sec*: int64
  tv_nsec*: int32

Lets

AT_STATX_DONT_SYNC {.inject.} = locAT_STATX_DONT_SYNC
AT_STATX_FORCE_SYNC {.inject.} = locAT_STATX_FORCE_SYNC
AT_STATX_SYNC_AS_STAT {.inject.} = locAT_STATX_SYNC_AS_STAT
AT_STATX_SYNC_TYPE {.inject.} = locAT_STATX_SYNC_TYPE
STATX_ALL {.inject.} = locSTATX_ALL
STATX_ATIME {.inject.} = locSTATX_ATIME
STATX_ATTR_APPEND {.inject.} = locSTATX_ATTR_APPEND
STATX_ATTR_AUTOMOUNT {.inject.} = locSTATX_ATTR_AUTOMOUNT
STATX_ATTR_COMPRESSED {.inject.} = locSTATX_ATTR_COMPRESSED
STATX_ATTR_ENCRYPTED {.inject.} = locSTATX_ATTR_ENCRYPTED
STATX_ATTR_IMMUTABLE {.inject.} = locSTATX_ATTR_IMMUTABLE
STATX_ATTR_NODUMP {.inject.} = locSTATX_ATTR_NODUMP
STATX_BASIC_STATS {.inject.} = locSTATX_BASIC_STATS
STATX_BLOCKS {.inject.} = locSTATX_BLOCKS
STATX_BTIME {.inject.} = locSTATX_BTIME
STATX_CTIME {.inject.} = locSTATX_CTIME
STATX_GID {.inject.} = locSTATX_GID
STATX_INO {.inject.} = locSTATX_INO
STATX_MODE {.inject.} = locSTATX_MODE
STATX_MTIME {.inject.} = locSTATX_MTIME
STATX_SIZE {.inject.} = locSTATX_SIZE
STATX_TYPE {.inject.} = locSTATX_TYPE
STATX_UID {.inject.} = locSTATX_UID

Consts

haveStatx = true

Procs

proc `<`(x, y: StatxTs): bool {.inline, ...raises: [], tags: [], forbids: [].}
proc `<=`(x, y: StatxTs): bool {.inline, ...raises: [], tags: [], forbids: [].}
proc doStat(dfd: cint; path: string; nmAt: int; st: var Statx;
            Deref, quiet: bool): bool {.inline, ...raises: [IOError],
                                        tags: [WriteIOEffect], forbids: [].}
A helper proc to effect either lstatx or if Deref then statxat OR if that fails fall back to lstatxat. quite=true suppresses errors.
proc fileTime(path: string; kind: char; missing = int64(0); dir = 1): int64 {.
    ...raises: [], tags: [], forbids: [].}
Return file time stamp ([bamcv]) in nanoseconds since the Unix epoch.
proc fileTime(st: Statx; kind: char; dir = 1): int64 {.inline, ...raises: [],
    tags: [], forbids: [].}
Return file time stamp ([bamcv]) in nanoseconds since the Unix epoch.
proc fstat(fd: cint; stx: var Statx): cint {.inline, ...raises: [], tags: [],
    forbids: [].}
proc fstatat(dirfd: cint; path: cstring; stx: var Statx; flags: cint): cint {.
    inline, ...raises: [], tags: [], forbids: [].}
Always fstatat but take/return Statx w/simulated e.g. stx_btime.
proc fstatx(fd: cint; stx: var Statx; flags = (0x00001000 or statxFlags);
            mask = statxMask): cint {.inline, ...raises: [], tags: [], forbids: [].}
A Linux statx wrapper with a call signature more like regular fstat.
proc getBirthTimeNsec(path: string): int64 {....raises: [], tags: [], forbids: [].}
proc getBirthTimeNsec(stx`gensym52: Statx): int64 {.inline, ...raises: [],
    tags: [], forbids: [].}
proc getCreationTimeNsec(stx`gensym51: Statx): int64 {.inline, ...raises: [],
    tags: [], forbids: [].}
proc getLastAccTimeNsec(stx`gensym49: Statx): int64 {.inline, ...raises: [],
    tags: [], forbids: [].}
proc getLastModTimeNsec(stx`gensym50: Statx): int64 {.inline, ...raises: [],
    tags: [], forbids: [].}
proc lstat(path: cstring; stx: var Statx): cint {.inline, ...raises: [], tags: [],
    forbids: [].}
proc lstatx(path: cstring; stx: var Statx;
            flags = (statxFlags or AT_SYMLINK_NOFOLLOW); mask = statxMask): cint {.
    inline, ...raises: [], tags: [], forbids: [].}
A Linux statx wrapper with a call signature more like regular lstat.
proc lstatxat(dirfd: cint; path: cstring; stx: var Statx; flags: cint): cint {.
    ...raises: [], tags: [], forbids: [].}
proc st_atim(st: Statx): Timespec {.inline, ...raises: [], tags: [], forbids: [].}
proc st_blksize(st: Statx): Blksize {.inline, ...raises: [], tags: [], forbids: [].}
proc st_blocks(st: Statx): Blkcnt {.inline, ...raises: [], tags: [], forbids: [].}
proc st_btim(st: Statx): Timespec {.inline, ...raises: [], tags: [], forbids: [].}
proc st_ctim(st: Statx): Timespec {.inline, ...raises: [], tags: [], forbids: [].}
proc st_dev(st: Statx): Dev {.inline, ...raises: [], tags: [], forbids: [].}
proc st_gid(st: Statx): Gid {.inline, ...raises: [], tags: [], forbids: [].}
proc st_ino(st: Statx): Ino {.inline, ...raises: [], tags: [], forbids: [].}
proc st_major(dno: Dev): uint32 {.inline, ...raises: [], tags: [], forbids: [].}
proc st_minor(dno: Dev): uint32 {.inline, ...raises: [], tags: [], forbids: [].}
proc st_mode(st: Statx): Mode {.inline, ...raises: [], tags: [], forbids: [].}
proc st_mtim(st: Statx): Timespec {.inline, ...raises: [], tags: [], forbids: [].}
proc st_rmaj(st: Statx): Dev {.inline, ...raises: [], tags: [], forbids: [].}
proc st_rmin(st: Statx): Dev {.inline, ...raises: [], tags: [], forbids: [].}
proc st_size(st: Statx): Off {.inline, ...raises: [], tags: [], forbids: [].}
proc st_uid(st: Statx): Uid {.inline, ...raises: [], tags: [], forbids: [].}
proc st_vtim(st: Statx): Timespec {.inline, ...raises: [], tags: [], forbids: [].}
proc stat(path: cstring; stx: var Statx): cint {.inline, ...raises: [], tags: [],
    forbids: [].}
proc statx(dirfd: cint; path: cstring; flags: cint; mask: cint; stx: ptr Statx): cint {.
    importc: "statx", header: "<sys/stat.h>", ...raises: [], tags: [], forbids: [].}
proc statx(dirfd: cint; path: cstring; flags: cint; stx: var Statx;
           mask = statxMask): cint {.inline, ...raises: [], tags: [], forbids: [].}
A statx that looks more like fstatat w/a final parameter ignored when simulated.
proc statx(dirfd: cint; path: cstring; stx: var Statx; flags: cint;
           mask = statxMask): cint {.inline, ...raises: [], tags: [], forbids: [].}
A statx that looks more like fstatat with an ignorable final parameter
proc statx(path: cstring; stx: var Statx; flags = statxFlags; mask = statxMask): cint {.
    inline, ...raises: [], tags: [], forbids: [].}
A Linux statx wrapper with a call signature more like regular stat.
proc statxat(dirfd: cint; path: cstring; stx: var Statx; flags: cint): cint {.
    ...raises: [], tags: [], forbids: [].}
proc toInt64(t: StatxTs): int64 {.inline, ...raises: [], tags: [], forbids: [].}
64-bits represents +-292 years from 1970 exactly & conveniently.
proc toStatxTs(t: int64): StatxTs {.inline, ...raises: [], tags: [], forbids: [].}
proc toStatxTs(ts: Timespec): StatxTs {.inline, ...raises: [], tags: [],
                                        forbids: [].}
proc toTimespec(ts: StatxTs): Timespec {.inline, ...raises: [], tags: [],
    forbids: [].}