File Operations
sys_open / sys_openat
Open a file or device.(openat only) Directory file descriptor for relative paths, or AT_FDCWD for current directory.
Address of null-terminated path string.
File access mode and flags:
O_RDONLY(0): Read-onlyO_WRONLY(1): Write-onlyO_RDWR(2): Read-writeO_CREAT(0x40): Create if doesn’t existO_EXCL(0x80): Fail if exists (with O_CREAT)O_TRUNC(0x200): Truncate to 0 lengthO_APPEND(0x400): Append modeO_NONBLOCK(0x800): Non-blocking I/OO_DIRECTORY(0x10000): Fail if not directoryO_CLOEXEC(0x80000): Close on exec
Permissions for newly created file (masked by umask). Only used with O_CREAT.
Returns file descriptor number on success, negative errno on error.
ENOENT(-2): File doesn’t exist (and O_CREAT not set)EEXIST(-17): File exists (with O_CREAT | O_EXCL)EACCES(-13): Permission deniedEISDIR(-21): Path is directory (cannot open for writing)ENOTDIR(-20): Component in path is not directoryEMFILE(-24): Too many open filesENAMETOOLONG(-36): Path too longEFAULT(-14): Bad address
sys_close
Close a file descriptor.File descriptor to close.
Returns 0 on success, negative errno on error.
EBADF(-9): Invalid file descriptor
sys_read
Read from a file descriptor.File descriptor to read from.
Address of buffer to store read data.
Maximum number of bytes to read.
Returns number of bytes read (may be less than size), 0 on EOF, or negative errno on error.
EBADF(-9): Invalid file descriptor or not open for readingEFAULT(-14): Invalid buffer addressEINTR(-4): Interrupted by signalEIO(-5): I/O errorEISDIR(-21): fd refers to directory
sys_write
Write to a file descriptor.File descriptor to write to.
Address of buffer containing data to write.
Number of bytes to write.
Returns number of bytes written (may be less than size), or negative errno on error.
EBADF(-9): Invalid file descriptor or not open for writingEFAULT(-14): Invalid buffer addressEFBIG(-27): File too largeENOSPC(-28): No space left on deviceEPIPE(-32): Broken pipe
sys_lseek
Reposition file offset.File descriptor.
Offset in bytes.
Reference point:
SEEK_SET(0): Offset from beginning of fileSEEK_CUR(1): Offset from current positionSEEK_END(2): Offset from end of file
Returns new file offset on success, negative errno on error.
EBADF(-9): Invalid file descriptorEINVAL(-22): Invalid whenceESPIPE(-29): fd is pipe or socket
sys_readv / sys_writev
Read/write data into/from multiple buffers.File descriptor.
Address of array of iovec structures.
Number of iovec structures.
Returns total bytes read/written, or negative errno on error.
sys_pread / sys_pwrite
Read/write at specified offset without changing file position.File descriptor.
Buffer address.
Number of bytes to read/write.
Offset in file.
Returns bytes read/written, or negative errno on error.
File Metadata
sys_stat / sys_fstat / sys_lstat
Get file status.Address of null-terminated path string.
(fstat) File descriptor.
(fstatat) Directory fd for relative paths.
Address to store stat structure.
(fstatat) AT_SYMLINK_NOFOLLOW to not follow symlinks.
Returns 0 on success, negative errno on error.
stat: Get status of file at pathlstat: Like stat but doesn’t follow symbolic linksfstat: Get status of open file descriptorfstatat: stat with directory fd support
ENOENT(-2): File doesn’t existEACCES(-13): Permission deniedEBADF(-9): Invalid file descriptor (fstat)EFAULT(-14): Bad address
Directory Operations
sys_mkdir / sys_mkdirat
Create a directory.(mkdirat) Directory fd for relative paths.
Address of null-terminated path string.
Directory permissions (masked by umask).
Returns 0 on success, negative errno on error.
EEXIST(-17): Directory already existsENOENT(-2): Parent directory doesn’t existEACCES(-13): Permission deniedENOSPC(-28): No space on device
sys_rmdir
Remove an empty directory.Address of null-terminated path string.
Returns 0 on success, negative errno on error.
ENOENT(-2): Directory doesn’t existENOTEMPTY(-39): Directory not emptyENOTDIR(-20): Path is not a directoryEACCES(-13): Permission deniedEBUSY(-16): Directory in use
sys_getdents / sys_getdents64
Read directory entries.File descriptor of open directory.
Buffer to store directory entries.
Size of buffer in bytes.
Returns bytes read on success, 0 at end of directory, or negative errno on error.
File System Operations
sys_mount
Mount a filesystem.Address of device or filesystem source path.
Address of mount point path.
Address of filesystem type string.
Mount flags:
MS_READONLY(0x1): Mount read-onlyMS_NOSUID(0x2): Ignore suid/sgid bitsMS_NODEV(0x4): Disallow device filesMS_NOEXEC(0x8): Disallow program execution
Filesystem-specific options.
Returns 0 on success, negative errno on error.
EPERM(-1): Permission deniedENOENT(-2): Mount point doesn’t existENOTDIR(-20): Target not a directoryEBUSY(-16): Target in use
sys_umount2
Unmount a filesystem.Address of mount point path.
Unmount flags (MNT_FORCE, MNT_DETACH, etc.).
Returns 0 on success, negative errno on error.
Link Operations
sys_link / sys_linkat
Create a hard link.Existing file path.
New link path.
Returns 0 on success, negative errno on error.
sys_unlink / sys_unlinkat
Remove a file or link.Path to file to remove.
(unlinkat) AT_REMOVEDIR to remove directory.
Returns 0 on success, negative errno on error.
sys_symlink / sys_symlinkat
Create a symbolic link.Target path (can be relative or absolute).
Symbolic link path to create.
Returns 0 on success, negative errno on error.
sys_readlink / sys_readlinkat
Read symbolic link target.Symbolic link path.
Buffer for target path.
Buffer size.
Returns number of bytes placed in buffer, or negative errno on error.