The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
sys_fs.c File Reference
#include "syscall_internal.h"
#include "syscall.h"
#include "fd_table.h"
#include "kernel/vfs/stat.h"
#include "kernel/vfs/permission.h"
#include "kernel/process/process.h"
#include "kernel/vfs/dirent.h"
#include "kernel/vfs/vfs.h"
#include "kernel/time/clock.h"
#include "common/memory.h"
#include "common/string.h"

Macros

#define ACCESS_MODE_BITS   7
#define UTIME_NOW   ((1l << 30) - 1)
#define UTIME_OMIT   ((1l << 30) - 2)
#define DIRENT_RECORD_MAX   ((KDIRENT_HEADER + EXT2_NAME_MAX + 3) & ~3u)

Functions

int32_t resolve_user_path (const char *user_path, char *resolved, uint32_t size)
 copy a path string in from user memory and resolve it against the current process's cwd.
int32_t resolve_user_path_at (int32_t dirfd, const char *user_path, char *resolved, uint32_t size, bool follow)
 as resolve_user_path, with a relative path taken in the directory open as dirfd (AT_FDCWD: the working directory).
int32_t set_new_owner (const char *path, uint32_t mode)
 give a file the caller has just created its mode (taken through the umask) and the caller's effective user and group as owner.
syscall_ret_t sys_stat (struct registers *regs)
 SYS_stat: get file metadata.
syscall_ret_t sys_fstatat (struct registers *regs)
 SYS_fstatat: stat a path relative to a directory.
syscall_ret_t sys_rename (struct registers *regs)
 SYS_rename: rename a file or directory.
syscall_ret_t sys_renameat (struct registers *regs)
 SYS_renameat: rename, each path relative to its own directory.
syscall_ret_t sys_access (struct registers *regs)
 SYS_access: check that a file exists and may be accessed.
syscall_ret_t sys_faccessat (struct registers *regs)
 SYS_faccessat: access, relative to a directory.
syscall_ret_t sys_mkdir (struct registers *regs)
 SYS_mkdir: create a directory.
syscall_ret_t sys_mkdirat (struct registers *regs)
 SYS_mkdirat: mkdir relative to a directory.
syscall_ret_t sys_unlink (struct registers *regs)
 SYS_unlink: remove a file.
syscall_ret_t sys_rmdir (struct registers *regs)
 SYS_rmdir: remove a directory.
syscall_ret_t sys_unlinkat (struct registers *regs)
 SYS_unlinkat: remove a file or (AT_REMOVEDIR) a directory, relative to a directory.
syscall_ret_t sys_symlinkat (struct registers *regs)
 SYS_symlinkat: make a symbolic link.
syscall_ret_t sys_readlinkat (struct registers *regs)
 SYS_readlinkat: read the target of a symbolic link.
syscall_ret_t sys_linkat (struct registers *regs)
 SYS_linkat: give a file one more name (a hard link).
syscall_ret_t sys_mknodat (struct registers *regs)
 SYS_mknodat: make a named pipe, a device node or an empty file.
syscall_ret_t sys_utimensat (struct registers *regs)
 SYS_utimensat: set a file's access and modification times.
syscall_ret_t sys_getdents (struct registers *regs)
 SYS_getdents: read directory entries.

Macro Definition Documentation

◆ ACCESS_MODE_BITS

#define ACCESS_MODE_BITS   7

◆ UTIME_NOW

#define UTIME_NOW   ((1l << 30) - 1)

◆ UTIME_OMIT

#define UTIME_OMIT   ((1l << 30) - 2)

◆ DIRENT_RECORD_MAX

#define DIRENT_RECORD_MAX   ((KDIRENT_HEADER + EXT2_NAME_MAX + 3) & ~3u)

Function Documentation

◆ resolve_user_path()

int32_t resolve_user_path ( const char * user_path,
char * resolved,
uint32_t size )

copy a path string in from user memory and resolve it against the current process's cwd.

Parameters
user_paththe user's path pointer.
resolvedreceives the absolute path.
sizesize of resolved.
Returns
0, or a negative errno (EFAULT for a bad pointer, EINVAL for a path too long or unresolvable).

◆ resolve_user_path_at()

int32_t resolve_user_path_at ( int32_t dirfd,
const char * user_path,
char * resolved,
uint32_t size,
bool follow )

as resolve_user_path, with a relative path taken in the directory open as dirfd (AT_FDCWD: the working directory).

the symbolic links along the path are replaced by their targets.

Parameters
followalso the last name, when it is a link (stat, open); not for the calls that act on the name itself (unlink, rename, lstat).
Returns
0, or -EFAULT, -ENAMETOOLONG, -ENOENT (an empty path), -EBADF, -ENOTDIR (dirfd is no directory), or -ELOOP.

◆ set_new_owner()

int32_t set_new_owner ( const char * path,
uint32_t mode )

give a file the caller has just created its mode (taken through the umask) and the caller's effective user and group as owner.

Parameters
paththe new file's absolute path.
modethe permission bits asked for.
Returns
0, or a negative errno.

◆ sys_stat()

syscall_ret_t sys_stat ( struct registers * regs)

SYS_stat: get file metadata.

args: path, struct stat pointer (kernel/vfs/stat.h). returns 0 on success, negative errno on failure.

◆ sys_fstatat()

syscall_ret_t sys_fstatat ( struct registers * regs)

SYS_fstatat: stat a path relative to a directory.

args: dirfd, path, struct stat pointer, flags (AT_SYMLINK_NOFOLLOW).

◆ sys_rename()

syscall_ret_t sys_rename ( struct registers * regs)

SYS_rename: rename a file or directory.

args: old path, new path (same filesystem). returns 0 on success, negative errno on failure (EXDEV across mounts).

◆ sys_renameat()

syscall_ret_t sys_renameat ( struct registers * regs)

SYS_renameat: rename, each path relative to its own directory.

args: old dirfd, old path, new dirfd, new path.

◆ sys_access()

syscall_ret_t sys_access ( struct registers * regs)

SYS_access: check that a file exists and may be accessed.

args: path, mode (F_OK, or R_OK | W_OK | X_OK). returns 0, or a negative errno (ENOENT, EACCES).

◆ sys_faccessat()

syscall_ret_t sys_faccessat ( struct registers * regs)

SYS_faccessat: access, relative to a directory.

args: dirfd, path, mode, flags (AT_EACCESS).

◆ sys_mkdir()

syscall_ret_t sys_mkdir ( struct registers * regs)

SYS_mkdir: create a directory.

args: path, mode. returns 0 on success, negative errno on failure.

◆ sys_mkdirat()

syscall_ret_t sys_mkdirat ( struct registers * regs)

SYS_mkdirat: mkdir relative to a directory.

args: dirfd, path, mode.

◆ sys_unlink()

syscall_ret_t sys_unlink ( struct registers * regs)

SYS_unlink: remove a file.

args: path. returns 0 on success, negative errno on failure.

◆ sys_rmdir()

syscall_ret_t sys_rmdir ( struct registers * regs)

SYS_rmdir: remove a directory.

args: path. returns 0 on success, negative errno on failure.

◆ sys_unlinkat()

syscall_ret_t sys_unlinkat ( struct registers * regs)

SYS_unlinkat: remove a file or (AT_REMOVEDIR) a directory, relative to a directory.

args: dirfd, path, flags.

◆ sys_symlinkat()

syscall_ret_t sys_symlinkat ( struct registers * regs)

SYS_symlinkat: make a symbolic link.

args: target (the path the link points at; it need not exist), dirfd, path of the new link. the link belongs to the caller's effective user and group. returns 0, or a negative errno (EEXIST, ENOENT, EACCES, ENAMETOOLONG).

◆ sys_readlinkat()

syscall_ret_t sys_readlinkat ( struct registers * regs)

SYS_readlinkat: read the target of a symbolic link.

args: dirfd, path, buffer, buffer size. returns the bytes put in the buffer (no NUL; a longer target is cut), or a negative errno (EINVAL: not a link).

◆ sys_linkat()

syscall_ret_t sys_linkat ( struct registers * regs)

SYS_linkat: give a file one more name (a hard link).

args: old dirfd, old path, new dirfd, new path, flags (AT_SYMLINK_FOLLOW: link to what a symbolic link points at, not the link itself). returns 0, or a negative errno (EXDEV across mounts, EPERM for a directory, EEXIST, EMLINK).

◆ sys_mknodat()

syscall_ret_t sys_mknodat ( struct registers * regs)

SYS_mknodat: make a named pipe, a device node or an empty file.

args: dirfd, path, mode (S_IFIFO, S_IFCHR, S_IFBLK or S_IFREG, with the permission bits, taken through the umask), the device number. a device node needs root. it opens with ENXIO: the devices are in /dev. returns 0, or a negative errno (EEXIST, EPERM, EINVAL, EACCES).

◆ sys_utimensat()

syscall_ret_t sys_utimensat ( struct registers * regs)

SYS_utimensat: set a file's access and modification times.

args: dirfd, path (NULL: the file open as dirfd, which is futimens), times (two timespecs, access then modification; NULL: both now), flags (AT_SYMLINK_NOFOLLOW). a tv_nsec of UTIME_NOW takes the time now; UTIME_OMIT keeps the time. returns 0, or a negative errno (EPERM, EACCES, EINVAL, ENOENT, EBADF).

◆ sys_getdents()

syscall_ret_t sys_getdents ( struct registers * regs)

SYS_getdents: read directory entries.

args: EBX = fd of an open directory, ECX = buffer, EDX = buffer size. fills the buffer with as many whole records (kernel/vfs/dirent.h) as fit. returns the bytes written, 0 at the end of the directory, or a negative errno (EINVAL if the buffer cannot hold the next record, ENOTDIR if fd is not a directory).