Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

File and Directory Operations

open and openat

Supported functionality of open in SCML:

access_mode =
    O_RDONLY |
    O_WRONLY |
    O_RDWR;
creation_flags =
    O_CLOEXEC |
    O_DIRECTORY |
    O_EXCL |
    O_NOCTTY |
    O_NOFOLLOW |
    O_TRUNC;
status_flags =
    O_APPEND |
    O_ASYNC |
    O_DIRECT |
    O_LARGEFILE |
    O_NOATIME |
    O_NONBLOCK |
    O_SYNC;

// Open an existing file
open(
    path,
    flags = <access_mode> | <creation_flags> | <status_flags>,
);
openat(
    dirfd,
    path,
    flags = <access_mode> | <creation_flags> | <status_flags>,
);

// Create a new file
open(
    path,
    flags = O_CREAT | <access_mode> | <creation_flags> | <status_flags>,
    mode
);
openat(
    dirfd,
    path,
    flags = O_CREAT | <access_mode> | <creation_flags> | <status_flags>,
    mode
);

// Status flags that are meaningful with O_PATH
opath_valid_flags = O_CLOEXEC | O_DIRECTORY | O_NOFOLLOW;
// All other flags are ignored with O_PATH
opath_ignored_flags = O_CREAT | <creation_flags> | <status_flags>;
// Obtain a file descriptor to indicate a location in FS
open(
    path,
    flags = O_PATH | <opath_valid_flags> | <opath_ignored_flags>
);
openat(
    dirfd,
    path,
    flags = O_PATH | <opath_valid_flags> | <opath_ignored_flags>
);

// Create an unnamed file
// open(path, flags = O_TMPFILE | <creation_flags> | <status_flags>)

Silently-ignored flags:

  • O_NOCTTY
  • O_DSYNC
  • O_SYNC
  • O_LARGEFILE
  • O_NOATIME
  • O_NOCTTY

Partially-supported flags:

  • O_PATH

未支援的旗標:

  • O_TMPFILE

Supported and unsupported functionality of openat are the same as open. The SCML rules are omitted for brevity.

For more information, see the man page.

renameat2

SCML 支援的功能:

// Rename a file, moving it between directories if required.
renameat2(olddirfd, oldpath, newdirfd, newpath, 0);

未支援的旗標:

  • RENAME_EXCHANGE
  • RENAME_NOREPLACE
  • RENAME_WHITEOUT

For more information, see the man page.

lseek

SCML 支援的功能:

// Set file offset
lseek(
    fd, offset,
    whence = SEEK_SET | SEEK_CUR | SEEK_END
);

未支援的旗標:

  • SEEK_DATA
  • SEEK_HOLE

For more information, see the man page.

newfstatat

SCML 支援的功能:

// Retrieve file status by file descriptor
newfstatat(
    dirfd, path, statbuf,
    flags = AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW
);

Silently-ignored flags:

  • AT_NO_AUTOMOUNT

For more information, see the man page.

preadv2 and pwritev2

SCML 支援的功能:

// Read data from multiple buffers
preadv2(fd, iov, iovcnt, offset, flags = 0);

// Write data to multiple buffers
pwritev2(fd, iov, iovcnt, offset, flags = 0);

Silently-ignored flags:

  • RWF_DSYNC
  • RWF_HIPRI
  • RWF_SYNC
  • RWF_NOWAIT

未支援的旗標:

  • RWF_APPEND
  • RWF_NOAPPEND
  • RWF_ATOMIC

For more information, see the man page.

faccessat2

SCML 支援的功能:

// Check user's permissions for a file
faccessat2(
    dirfd, path, mode,
    flags = AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW
);

Silently-ignored flags:

  • AT_EACCESS

For more information, see the man page.

statx

SCML 支援的功能:

statx_flags = AT_EMPTY_PATH | AT_NO_AUTOMOUNT | AT_STATX_FORCE_SYNC |
              AT_STATX_DONT_SYNC | AT_STATX_SYNC_AS_STAT | AT_SYMLINK_NOFOLLOW;
statx_mask = STATX_TYPE | STATX_MODE | STATX_NLINK | STATX_UID | STATX_GID |
             STATX_ATIME | STATX_MTIME | STATX_CTIME | STATX_INO | STATX_SIZE |
             STATX_BLOCKS | STATX_BASIC_STATS | STATX_BTIME | STATX_ALL |
             STATX_MNT_ID | STATX_DIOALIGN | STATX_MNT_ID_UNIQUE | STATX_SUBVOL |
             STATX_WRITE_ATOMIC | STATX_DIO_READ_ALIGN;

// Get file status (extended)
statx(
    dirfd, pathname,
    flags = <statx_flags>,
    mask = <statx_mask>,
    statxbuf
);

Silently-ignored flags:

  • AT_NO_AUTOMOUNT
  • AT_STATX_FORCE_SYNC
  • AT_STATX_DONT_SYNC

Silently-ignored masks:

  • STATX_DIOALIGN
  • STATX_MNT_ID_UNIQUE
  • STATX_SUBVOL
  • STATX_WRITE_ATOMIC
  • STATX_DIO_READ_ALIGN

For more information, see the man page.

fallocate

SCML 支援的功能:

// Allocate disk space within the range specified
fallocate(fd, mode = FALLOC_FL_KEEP_SIZE, offset, size);

// Deallocate space (create a hole) while keeping the file size unchanged
fallocate(fd, mode = FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, offset, size);

未支援的模式:

  • FALLOC_FL_UNSHARE_RANGE
  • FALLOC_FL_COLLAPSE_RANGE
  • FALLOC_FL_ZERO_RANGE
  • FALLOC_FL_INSERT_RANGE

For more information, see the man page.

utimensat

SCML 支援的功能:

// Change file timestamps with nanosecond precision
utimensat(dirfd, path, times, flags = AT_SYMLINK_NOFOLLOW);

未支援的旗標:

  • AT_EMPTY_PATH

For more information, see the man page.