|
ginnOS
The reference: libc, the libraries and the kernel
|
#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. | |
| #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) |
copy a path string in from user memory and resolve it against the current process's cwd.
| user_path | the user's path pointer. |
| resolved | receives the absolute path. |
| size | size of resolved. |
| 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.
| follow | also the last name, when it is a link (stat, open); not for the calls that act on the name itself (unlink, rename, lstat). |
give a file the caller has just created its mode (taken through the umask) and the caller's effective user and group as owner.
| path | the new file's absolute path. |
| mode | the permission bits asked for. |
| 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.
| 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).
| 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).
| 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.
| 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).
| syscall_ret_t sys_faccessat | ( | struct registers * | regs | ) |
SYS_faccessat: access, relative to a directory.
args: dirfd, path, mode, flags (AT_EACCESS).
| syscall_ret_t sys_mkdir | ( | struct registers * | regs | ) |
SYS_mkdir: create a directory.
args: path, mode. returns 0 on success, negative errno on failure.
| syscall_ret_t sys_mkdirat | ( | struct registers * | regs | ) |
SYS_mkdirat: mkdir relative to a directory.
args: dirfd, path, mode.
| syscall_ret_t sys_unlink | ( | struct registers * | regs | ) |
SYS_unlink: remove a file.
args: path. returns 0 on success, negative errno on failure.
| syscall_ret_t sys_rmdir | ( | struct registers * | regs | ) |
SYS_rmdir: remove a directory.
args: path. returns 0 on success, negative errno on failure.
| 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.
| 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).
| 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).
| 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).
| 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).
| 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).
| 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).