Skip to content

Commit

Permalink
Filesystem: retire fs_status enum in favor of standard error codes
Browse files Browse the repository at this point in the history
Having filesystem-specific error codes requires conversion between
filesystem codes and POSIX standard codes every time a filesystem-
related error is reported to userspace. For the 9P filesystem, in
some cases a double conversion (from a standard code to a
filesystem code and then back to a standard code) may need to be
done.
This change removes the fs_status enum that declares the filesystem
error codes, and uses standard POSIX codes to report filesystem
errors; this allows eliminating the above conversions. Standard
error codes are defined in the new kernel/errno.h header file; in
order to prevent this file from being included from userspace code,
the kernel directory is being removed from the include paths in
the relevant Makefiles; this required some adjustments to other
header files so that they can be included by both kernel and non-
kernel code.
For the 9P filesystem, the p9_create() callback function is being
modified so that EOPNOTSUPP is returned instead or EINVAL if the
user program tries to open a file with the O_TMPFILE flag (#2051).
  • Loading branch information
francescolavra committed Aug 26, 2024
1 parent 5409d51 commit 721d2b9
Show file tree
Hide file tree
Showing 49 changed files with 776 additions and 911 deletions.
8 changes: 4 additions & 4 deletions klib/shmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ sysreturn memfd_create(const char *name, unsigned int flags)
filesystem fs = shmem.fs;
fsfile fsf;
filesystem_lock(fs);
fs_status fss = filesystem_creat_unnamed(fs, &fsf);
if (fss == FS_STATUS_OK) {
int fss = filesystem_creat_unnamed(fs, &fsf);
if (fss == 0) {
if (!(flags & MFD_ALLOW_SEALING))
fss = fs->set_seals(fs, fsf, F_SEAL_SEAL);
} else {
fsf = 0;
}
sysreturn rv;
if (fss == FS_STATUS_OK)
if (fss == 0)
rv = unix_file_new(fs, fs->root, FDESC_TYPE_REGULAR, O_RDWR | O_TMPFILE, fsf);
else
rv = sysreturn_from_fs_status(fss);
rv = fss;
filesystem_unlock(fs);
if ((rv < 0) && fsf)
fsfile_release(fsf);
Expand Down
2 changes: 1 addition & 1 deletion klib/syslog.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ closure_function(4, 1, void, syslog_file_write_complete,
syslog_file_rotate();
} else {
/* Delete old logs instead of rotating. */
if (fsfile_truncate(syslog.fsf, 0) == FS_STATUS_OK) {
if (fsfile_truncate(syslog.fsf, 0) == 0) {
syslog.file_offset = 0;
} else {
fsfile_release(syslog.fsf);
Expand Down
39 changes: 20 additions & 19 deletions klib/tmpfs.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <errno.h>
#include <kernel.h>
#include <pagecache.h>
#include <fs.h>
Expand All @@ -12,7 +13,7 @@ typedef struct tmpfs_file {
closure_struct(thunk, free);
} *tmpfs_file;

static fs_status tmpfs_get_fsfile(filesystem fs, tuple n, fsfile *f)
static int tmpfs_get_fsfile(filesystem fs, tuple n, fsfile *f)
{
return fs_get_fsfile(((tmpfs)fs)->files, n, f);
}
Expand Down Expand Up @@ -67,8 +68,8 @@ closure_func_basic(pagecache_node_reserve, status, tmpfsfile_reserve,
{
tmpfs_file fsf = struct_from_field(closure_self(), tmpfs_file, reserve);
if (fsfile_get_length(&fsf->f) < q.end) {
fs_status fss = filesystem_truncate(fsf->f.fs, &fsf->f, q.end);
if (fss != FS_STATUS_OK) {
int fss = filesystem_truncate(fsf->f.fs, &fsf->f, q.end);
if (fss != 0) {
status s = timm("result", "failed to update file length");
return timm_append(s, "fsstatus", "%d", fss);
}
Expand Down Expand Up @@ -119,21 +120,21 @@ static s64 tmpfsfile_get_blocks(fsfile f)
return (pages << ((tmpfs)f->fs)->page_order) >> SECTOR_OFFSET;
}

static fs_status tmpfs_create(filesystem fs, tuple parent, string name, tuple md, fsfile *f)
static int tmpfs_create(filesystem fs, tuple parent, string name, tuple md, fsfile *f)
{
tmpfs tmpfs = (struct tmpfs *)fs;
tmpfs_file fsf;
fs_status fss;
int fss;
if (!md || is_regular(md)) {
heap h = fs->h;
fsf = allocate(h, sizeof(*fsf));
if (fsf == INVALID_ADDRESS)
return FS_STATUS_NOMEM;
return -ENOMEM;
fss = fsfile_init(fs, &fsf->f, md,
init_closure_func(&fsf->reserve, pagecache_node_reserve,
tmpfsfile_reserve),
init_closure_func(&fsf->free, thunk, tmpfsfile_free));
if (fss != FS_STATUS_OK) {
if (fss != 0) {
deallocate(h, fsf, sizeof(*fsf));
return fss;
}
Expand All @@ -146,50 +147,50 @@ static fs_status tmpfs_create(filesystem fs, tuple parent, string name, tuple md
fsfile_reserve(&fsf->f);
} else {
fsf = INVALID_ADDRESS;
fss = FS_STATUS_OK;
fss = 0;
}
if (md)
table_set(tmpfs->files, md, fsf);
return fss;
}

static fs_status tmpfs_unlink(filesystem fs, tuple parent, string name, tuple md,
static int tmpfs_unlink(filesystem fs, tuple parent, string name, tuple md,
boolean *destruct_md)
{
fs_unlink(((tmpfs)fs)->files, md);
*destruct_md = true;
return FS_STATUS_OK;
return 0;
}

static fs_status tmpfs_rename(filesystem fs, tuple old_parent, string old_name, tuple old_md,
static int tmpfs_rename(filesystem fs, tuple old_parent, string old_name, tuple old_md,
tuple new_parent, string new_name, tuple new_md, boolean exchange,
boolean *destruct_md)
{
fs_status s = fs_check_rename(old_parent, old_md, new_parent, new_md, exchange);
if ((s == FS_STATUS_OK) && !exchange && new_md) {
int s = fs_check_rename(old_parent, old_md, new_parent, new_md, exchange);
if ((s == 0) && !exchange && new_md) {
fs_unlink(((tmpfs)fs)->files, new_md);
*destruct_md = true;
}
return s;
}

static fs_status tmpfs_truncate(filesystem fs, fsfile f, u64 len)
static int tmpfs_truncate(filesystem fs, fsfile f, u64 len)
{
return FS_STATUS_OK;
return 0;
}

static fs_status tmpfs_set_seals(filesystem fs, fsfile f, u64 seals)
static int tmpfs_set_seals(filesystem fs, fsfile f, u64 seals)
{
tmpfs_file fsf = (tmpfs_file)f;
fsf->seals = seals;
return FS_STATUS_OK;
return 0;
}

static fs_status tmpfs_get_seals(filesystem fs, fsfile f, u64 *seals)
static int tmpfs_get_seals(filesystem fs, fsfile f, u64 *seals)
{
tmpfs_file fsf = (tmpfs_file)f;
*seals = fsf->seals;
return FS_STATUS_OK;
return 0;
}

static u64 tmpfs_freeblocks(filesystem fs)
Expand Down
17 changes: 8 additions & 9 deletions klib/unveil.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ static sysreturn unveil(const char *path, const char *permissions)
tuple n;
process_get_cwd(current->p, &cwd_fs, &cwd);
fs = cwd_fs;
if (filesystem_get_node(&fs, cwd, path_ss, false, false, false, false, &n, 0) == FS_STATUS_OK) {
if (filesystem_get_node(&fs, cwd, path_ss, false, false, false, false, &n, 0) == 0) {
if (is_dir(n)) {
rv = unveil_set_dir_perms(fs, n, perms);
} else {
Expand All @@ -200,8 +200,7 @@ static sysreturn unveil(const char *path, const char *permissions)
} else {
parent_path = ss(".");
}
if (filesystem_get_node(&fs, cwd, parent_path, false, false, false, false, &n, 0) ==
FS_STATUS_OK) {
if (filesystem_get_node(&fs, cwd, parent_path, false, false, false, false, &n, 0) == 0) {
sstring dir_entry;
if (dir_separator) {
dir_entry.ptr = dir_separator + 1;
Expand Down Expand Up @@ -254,10 +253,10 @@ static sysreturn unveil_check_path_internal(filesystem fs, inode cwd, sstring pa
u64 perms)
{
tuple n;
fs_status fss = filesystem_get_node(&fs, cwd, path, nofollow,
int fss = filesystem_get_node(&fs, cwd, path, nofollow,
false, false, false, &n, 0);
u64 unveil_perms = 0;
if (fss == FS_STATUS_OK) {
if (fss == 0) {
do {
unveil_perms = unveil_get_perms(fs, n);
if ((unveil_perms & UNVEIL_PERMS_VALID) || (n == filesystem_getroot(fs))) {
Expand All @@ -267,7 +266,7 @@ static sysreturn unveil_check_path_internal(filesystem fs, inode cwd, sstring pa
inode ino = fs->get_inode(fs, n);
filesystem_put_node(fs, n);
fss = filesystem_get_node(&fs, ino, ss(".."), true, false, false, false, &n, 0);
} while (fss == FS_STATUS_OK);
} while (fss == 0);
} else {
/* Nonexistent path: look for the parent directory. */
char *dir_separator = path_find_last_delim(path);
Expand All @@ -283,7 +282,7 @@ static sysreturn unveil_check_path_internal(filesystem fs, inode cwd, sstring pa
parent_path = ss(".");
}
fss = filesystem_get_node(&fs, cwd, parent_path, false, false, false, false, &n, 0);
if (fss == FS_STATUS_OK) {
if (fss == 0) {
unveil_dir dir = unveil_find_dir(fs, n);
if (dir && dir->dir_entries) {
sstring dir_entry;
Expand Down Expand Up @@ -511,8 +510,8 @@ static boolean unveil_unlinkat(u64 arg0, u64 arg1, u64 arg2, u64 arg3, u64 arg4,
return false;
filesystem fs = cwd_fs;
tuple n;
fs_status fss = filesystem_get_node(&fs, cwd, path_ss, true, false, false, false, &n, 0);
if (fss == FS_STATUS_OK) {
int fss = filesystem_get_node(&fs, cwd, path_ss, true, false, false, false, &n, 0);
if (fss == 0) {
struct unveil_dir d = {
.fs = fs,
.ino = fs->get_inode(fs, n),
Expand Down
9 changes: 0 additions & 9 deletions platform/pc/boot/stage2.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,6 @@ void console_write(const char *s, bytes count)
}
}

void klog_write(const char *s, bytes count)
{
}

heap heap_dma(void)
{
return general;
}

closure_function(1, 1, void, stage2_bios_read,
u64, offset,
storage_req req)
Expand Down
3 changes: 0 additions & 3 deletions src/aarch64/kernel_machine.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,6 @@ static inline void wait_for_interrupt(void)
#define cmdline_consume(o, h) (void)(h)
#define boot_params_apply(t)

/* locking constructs */
#include <mutex.h>

/* device mmio region access */
#define MK_MMIO_READ(BITS, ISUFFIX, RPREFIX) \
static inline u##BITS mmio_read_##BITS(u64 addr) \
Expand Down
9 changes: 0 additions & 9 deletions src/boot/uefi.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ void console_write(const char *s, bytes count)
uefi_system_table->con_out->output_string(uefi_system_table->con_out, buf);
}

void klog_write(const char *s, bytes count)
{
}

void print_frame_trace_from_here(void)
{
}
Expand Down Expand Up @@ -100,11 +96,6 @@ void halt_with_code(u8 code, sstring format, ...)
while(1); /* to honor "noreturn" attribute */
}

heap heap_dma(void)
{
return &general;
}

static u64 uefi_alloc(heap h, bytes b)
{
void *buf;
Expand Down
Loading

0 comments on commit 721d2b9

Please sign in to comment.