From ed5d5723196e47290beda01cc4785cfe5cbc5266 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Fri, 6 Jun 2025 16:24:06 -0600 Subject: sbc_harness: config.h: Remove duplicate --- cmd/sbc_harness/config/config.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'cmd') diff --git a/cmd/sbc_harness/config/config.h b/cmd/sbc_harness/config/config.h index ca23462..7a91001 100644 --- a/cmd/sbc_harness/config/config.h +++ b/cmd/sbc_harness/config/config.h @@ -49,8 +49,6 @@ #define CONFIG_9P_SRV_DEBUG 1 /* bool */ -#define CONFIG_9P_SRV_MAX_MSG_SIZE ((4*1024)+24) - /** * This max-msg-size is sized so that a Twrite message can return * 8KiB of data. -- cgit v1.2.3-2-g168b From 8a9fc1704dcf3ec117a3bf37fd70a44a43873659 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Thu, 29 May 2025 23:39:12 -0400 Subject: lib9p: Use errnums internally --- cmd/sbc_harness/fs_harness_flash_bin.c | 10 +++++----- cmd/sbc_harness/fs_harness_uptime_txt.c | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'cmd') diff --git a/cmd/sbc_harness/fs_harness_flash_bin.c b/cmd/sbc_harness/fs_harness_flash_bin.c index 8bd144e..0a7364a 100644 --- a/cmd/sbc_harness/fs_harness_flash_bin.c +++ b/cmd/sbc_harness/fs_harness_flash_bin.c @@ -170,13 +170,13 @@ static void flash_file_wstat(struct flash_file *self, struct lib9p_srv_ctx *ctx, assert(self); assert(ctx); - lib9p_error(&ctx->basectx, LIB9P_ERRNO_L_EROFS, "read-only part of filesystem"); + lib9p_error(&ctx->basectx, E_POSIX_EROFS, "read-only part of filesystem"); } static void flash_file_remove(struct flash_file *self, struct lib9p_srv_ctx *ctx) { assert(self); assert(ctx); - lib9p_error(&ctx->basectx, LIB9P_ERRNO_L_EROFS, "read-only part of filesystem"); + lib9p_error(&ctx->basectx, E_POSIX_EROFS, "read-only part of filesystem"); } LIB9P_SRV_NOTDIR(struct flash_file, flash_file); @@ -230,7 +230,7 @@ static void flash_file_pread(struct flash_file *self, struct lib9p_srv_ctx *ctx, if (byte_offset > DATA_SIZE) { lib9p_error(&ctx->basectx, - LIB9P_ERRNO_L_EINVAL, "offset is past the chip size"); + E_POSIX_EINVAL, "offset is past the chip size"); return; } @@ -276,14 +276,14 @@ static uint32_t flash_file_pwrite(struct flash_file *self, struct lib9p_srv_ctx if (byte_offset > DATA_HSIZE) { lib9p_error(&ctx->basectx, - LIB9P_ERRNO_L_EINVAL, "offset is past half the chip size"); + E_POSIX_EINVAL, "offset is past half the chip size"); return 0; } if (byte_count == 0) return 0; if (byte_offset == DATA_HSIZE) { lib9p_error(&ctx->basectx, - LIB9P_ERRNO_L_EINVAL, "offset is at half the chip size"); + E_POSIX_EINVAL, "offset is at half the chip size"); return 0; } diff --git a/cmd/sbc_harness/fs_harness_uptime_txt.c b/cmd/sbc_harness/fs_harness_uptime_txt.c index 23ac9d4..848c34f 100644 --- a/cmd/sbc_harness/fs_harness_uptime_txt.c +++ b/cmd/sbc_harness/fs_harness_uptime_txt.c @@ -69,13 +69,13 @@ static void uptime_file_wstat(struct uptime_file *self, struct lib9p_srv_ctx *ct assert(self); assert(ctx); - lib9p_error(&ctx->basectx, LIB9P_ERRNO_L_EROFS, "read-only part of filesystem"); + lib9p_error(&ctx->basectx, E_POSIX_EROFS, "read-only part of filesystem"); } static void uptime_file_remove(struct uptime_file *self, struct lib9p_srv_ctx *ctx) { assert(self); assert(ctx); - lib9p_error(&ctx->basectx, LIB9P_ERRNO_L_EROFS, "read-only part of filesystem"); + lib9p_error(&ctx->basectx, E_POSIX_EROFS, "read-only part of filesystem"); } LIB9P_SRV_NOTDIR(struct uptime_file, uptime_file); @@ -124,7 +124,7 @@ static void uptime_fio_pread(struct uptime_fio *self, struct lib9p_srv_ctx *ctx, if (byte_offset > (uint64_t)self->buf_len) { lib9p_error(&ctx->basectx, - LIB9P_ERRNO_L_EINVAL, "offset is past end-of-file length"); + E_POSIX_EINVAL, "offset is past end-of-file length"); return; } @@ -145,6 +145,6 @@ static uint32_t uptime_fio_pwrite(struct uptime_fio *self, struct lib9p_srv_ctx assert(self); assert(ctx); - lib9p_error(&ctx->basectx, LIB9P_ERRNO_L_EROFS, "read-only part of filesystem"); + lib9p_error(&ctx->basectx, E_POSIX_EROFS, "read-only part of filesystem"); return 0; } -- cgit v1.2.3-2-g168b From 945756b1b050bdf09d1119854cc5b22ad15efacd Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Thu, 29 May 2025 22:25:02 -0400 Subject: lib9p_core: Switch to use error.h --- cmd/sbc_harness/config/config.h | 3 +-- cmd/sbc_harness/fs_harness_flash_bin.c | 13 +++++-------- cmd/sbc_harness/fs_harness_uptime_txt.c | 9 ++++----- 3 files changed, 10 insertions(+), 15 deletions(-) (limited to 'cmd') diff --git a/cmd/sbc_harness/config/config.h b/cmd/sbc_harness/config/config.h index 7a91001..61745e5 100644 --- a/cmd/sbc_harness/config/config.h +++ b/cmd/sbc_harness/config/config.h @@ -37,8 +37,6 @@ /* 9P *************************************************************************/ -#define CONFIG_9P_MAX_ERR_SIZE 128 /* 128 is what Plan 9 4e uses */ - #define CONFIG_9P_ENABLE_9P2000 1 /* bool */ #define CONFIG_9P_ENABLE_9P2000_u 1 /* bool */ #define CONFIG_9P_ENABLE_9P2000_e 0 /* bool */ @@ -67,6 +65,7 @@ * (8*1024)+160 in 2e and 3e. */ #define CONFIG_9P_SRV_MAX_MSG_SIZE ((4*1024)+24) +#define CONFIG_9P_SRV_MAX_ERR_SIZE 128 /* 128 is what Plan 9 4e uses */ /** * Maximum host-data-structure size. A message may be larger in * unmarshaled-host-structures than marshaled-net-bytes due to (1) diff --git a/cmd/sbc_harness/fs_harness_flash_bin.c b/cmd/sbc_harness/fs_harness_flash_bin.c index 0a7364a..d3f90b9 100644 --- a/cmd/sbc_harness/fs_harness_flash_bin.c +++ b/cmd/sbc_harness/fs_harness_flash_bin.c @@ -170,13 +170,13 @@ static void flash_file_wstat(struct flash_file *self, struct lib9p_srv_ctx *ctx, assert(self); assert(ctx); - lib9p_error(&ctx->basectx, E_POSIX_EROFS, "read-only part of filesystem"); + lib9p_error(ctx, E_POSIX_EROFS, "read-only part of filesystem"); } static void flash_file_remove(struct flash_file *self, struct lib9p_srv_ctx *ctx) { assert(self); assert(ctx); - lib9p_error(&ctx->basectx, E_POSIX_EROFS, "read-only part of filesystem"); + lib9p_error(ctx, E_POSIX_EROFS, "read-only part of filesystem"); } LIB9P_SRV_NOTDIR(struct flash_file, flash_file); @@ -229,8 +229,7 @@ static void flash_file_pread(struct flash_file *self, struct lib9p_srv_ctx *ctx, assert(ret); if (byte_offset > DATA_SIZE) { - lib9p_error(&ctx->basectx, - E_POSIX_EINVAL, "offset is past the chip size"); + lib9p_error(ctx, E_POSIX_EINVAL, "offset is past the chip size"); return; } @@ -275,15 +274,13 @@ static uint32_t flash_file_pwrite(struct flash_file *self, struct lib9p_srv_ctx assert(ctx); if (byte_offset > DATA_HSIZE) { - lib9p_error(&ctx->basectx, - E_POSIX_EINVAL, "offset is past half the chip size"); + lib9p_error(ctx, E_POSIX_EINVAL, "offset is past half the chip size"); return 0; } if (byte_count == 0) return 0; if (byte_offset == DATA_HSIZE) { - lib9p_error(&ctx->basectx, - E_POSIX_EINVAL, "offset is at half the chip size"); + lib9p_error(ctx, E_POSIX_EINVAL, "offset is at half the chip size"); return 0; } diff --git a/cmd/sbc_harness/fs_harness_uptime_txt.c b/cmd/sbc_harness/fs_harness_uptime_txt.c index 848c34f..2533558 100644 --- a/cmd/sbc_harness/fs_harness_uptime_txt.c +++ b/cmd/sbc_harness/fs_harness_uptime_txt.c @@ -69,13 +69,13 @@ static void uptime_file_wstat(struct uptime_file *self, struct lib9p_srv_ctx *ct assert(self); assert(ctx); - lib9p_error(&ctx->basectx, E_POSIX_EROFS, "read-only part of filesystem"); + lib9p_error(ctx, E_POSIX_EROFS, "read-only part of filesystem"); } static void uptime_file_remove(struct uptime_file *self, struct lib9p_srv_ctx *ctx) { assert(self); assert(ctx); - lib9p_error(&ctx->basectx, E_POSIX_EROFS, "read-only part of filesystem"); + lib9p_error(ctx, E_POSIX_EROFS, "read-only part of filesystem"); } LIB9P_SRV_NOTDIR(struct uptime_file, uptime_file); @@ -123,8 +123,7 @@ static void uptime_fio_pread(struct uptime_fio *self, struct lib9p_srv_ctx *ctx, } if (byte_offset > (uint64_t)self->buf_len) { - lib9p_error(&ctx->basectx, - E_POSIX_EINVAL, "offset is past end-of-file length"); + lib9p_error(ctx, E_POSIX_EINVAL, "offset is past end-of-file length"); return; } @@ -145,6 +144,6 @@ static uint32_t uptime_fio_pwrite(struct uptime_fio *self, struct lib9p_srv_ctx assert(self); assert(ctx); - lib9p_error(&ctx->basectx, E_POSIX_EROFS, "read-only part of filesystem"); + lib9p_error(ctx, E_POSIX_EROFS, "read-only part of filesystem"); return 0; } -- cgit v1.2.3-2-g168b From 7b0f4d3ac1a64f4015148e89eeeeedf0a617cbc5 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Thu, 29 May 2025 22:25:02 -0400 Subject: lib9p_srv: Change the public API to use error.h --- cmd/sbc_harness/fs_harness_flash_bin.c | 66 ++++++++++++++------------------- cmd/sbc_harness/fs_harness_uptime_txt.c | 43 ++++++++++----------- cmd/sbc_harness/main.c | 4 +- 3 files changed, 49 insertions(+), 64 deletions(-) (limited to 'cmd') diff --git a/cmd/sbc_harness/fs_harness_flash_bin.c b/cmd/sbc_harness/fs_harness_flash_bin.c index d3f90b9..ea60447 100644 --- a/cmd/sbc_harness/fs_harness_flash_bin.c +++ b/cmd/sbc_harness/fs_harness_flash_bin.c @@ -148,11 +148,11 @@ static struct lib9p_qid flash_file_qid(struct flash_file *self) { }; } -static struct lib9p_srv_stat flash_file_stat(struct flash_file *self, struct lib9p_srv_ctx *ctx) { +static lib9p_srv_stat_or_error flash_file_stat(struct flash_file *self, struct lib9p_srv_ctx *ctx) { assert(self); assert(ctx); - return (struct lib9p_srv_stat){ + return ERROR_NEW_VAL(lib9p_srv_stat, ((struct lib9p_srv_stat){ .qid = flash_file_qid(self), .mode = LIB9P_DM_EXCL|0666, .atime_sec = UTIL9P_ATIME, @@ -163,25 +163,25 @@ static struct lib9p_srv_stat flash_file_stat(struct flash_file *self, struct lib .owner_gid = { .name = lib9p_str("root"), .num = 0 }, .last_modifier_uid = { .name = lib9p_str("root"), .num = 0 }, .extension = lib9p_str(NULL), - }; + })); } -static void flash_file_wstat(struct flash_file *self, struct lib9p_srv_ctx *ctx, +static error flash_file_wstat(struct flash_file *self, struct lib9p_srv_ctx *ctx, struct lib9p_srv_stat) { assert(self); assert(ctx); - lib9p_error(ctx, E_POSIX_EROFS, "read-only part of filesystem"); + return error_new(E_POSIX_EROFS, "read-only part of filesystem"); } -static void flash_file_remove(struct flash_file *self, struct lib9p_srv_ctx *ctx) { +static error flash_file_remove(struct flash_file *self, struct lib9p_srv_ctx *ctx) { assert(self); assert(ctx); - lib9p_error(ctx, E_POSIX_EROFS, "read-only part of filesystem"); + return error_new(E_POSIX_EROFS, "read-only part of filesystem"); } LIB9P_SRV_NOTDIR(struct flash_file, flash_file); -static lo_interface lib9p_srv_fio flash_file_fopen(struct flash_file *self, struct lib9p_srv_ctx *ctx, +static lib9p_srv_fio_or_error flash_file_fopen(struct flash_file *self, struct lib9p_srv_ctx *ctx, bool rd, bool wr, bool trunc) { assert(self); assert(ctx); @@ -201,7 +201,7 @@ static lo_interface lib9p_srv_fio flash_file_fopen(struct flash_file *self, stru self->wbuf.ok = false; } - return LO_BOX(lib9p_srv_fio, self); + return ERROR_NEW_VAL(lib9p_srv_fio, LO_BOX(lib9p_srv_fio, self)); } /* srv_fio ********************************************************************/ @@ -221,17 +221,13 @@ static void flash_file_iofree(struct flash_file *self) { ab_flash_finalize(self->wbuf.dat); } -static void flash_file_pread(struct flash_file *self, struct lib9p_srv_ctx *ctx, - uint32_t byte_count, uint64_t byte_offset, - struct iovec *ret) { +static iovec_or_error flash_file_pread(struct flash_file *self, struct lib9p_srv_ctx *ctx, + uint32_t byte_count, uint64_t byte_offset) { assert(self); assert(ctx); - assert(ret); - if (byte_offset > DATA_SIZE) { - lib9p_error(ctx, E_POSIX_EINVAL, "offset is past the chip size"); - return; - } + if (byte_offset > DATA_SIZE) + return ERROR_NEW_ERR(iovec, error_new(E_POSIX_EINVAL, "offset is past the chip size")); /* Assume that somewhere down the line the iovec we return * will be passed to DMA. We don't want the DMA engine to hit @@ -240,12 +236,10 @@ static void flash_file_pread(struct flash_file *self, struct lib9p_srv_ctx *ctx, * data to a buffer in (fast) RAM first. It's lame that the * DMA engine can only have a DREQ on one side of the channel. */ - if (byte_offset == DATA_SIZE) { - *ret = (struct iovec){ + if (byte_offset == DATA_SIZE) + return ERROR_NEW_VAL(iovec, ((struct iovec){ .iov_len = 0, - }; - return; - } + })); size_t sector_base = LM_ROUND_DOWN(byte_offset, FLASH_SECTOR_SIZE); if (byte_offset + byte_count > sector_base + FLASH_SECTOR_SIZE) byte_count = (sector_base + FLASH_SECTOR_SIZE) - byte_offset; @@ -257,32 +251,28 @@ static void flash_file_pread(struct flash_file *self, struct lib9p_srv_ctx *ctx, memcpy(self->rbuf.dat, DATA_START+sector_base, FLASH_SECTOR_SIZE); } - *ret = (struct iovec){ + return ERROR_NEW_VAL(iovec, ((struct iovec){ .iov_base = &self->rbuf.dat[byte_offset-sector_base], .iov_len = byte_count, - }; + })); } /* TODO: Short/corrupt writes are dangerous. This should either (1) * check a checksum, (2) use uf2 instead of verbatim data, or (3) use * ihex instead of verbatim data. */ -static uint32_t flash_file_pwrite(struct flash_file *self, struct lib9p_srv_ctx *ctx, - void *buf, - uint32_t byte_count, - uint64_t byte_offset) { +static uint32_t_or_error flash_file_pwrite(struct flash_file *self, struct lib9p_srv_ctx *ctx, + void *buf, + uint32_t byte_count, + uint64_t byte_offset) { assert(self); assert(ctx); - if (byte_offset > DATA_HSIZE) { - lib9p_error(ctx, E_POSIX_EINVAL, "offset is past half the chip size"); - return 0; - } + if (byte_offset > DATA_HSIZE) + return ERROR_NEW_ERR(uint32_t, error_new(E_POSIX_EINVAL, "offset is past half the chip size")); if (byte_count == 0) - return 0; - if (byte_offset == DATA_HSIZE) { - lib9p_error(ctx, E_POSIX_EINVAL, "offset is at half the chip size"); - return 0; - } + return ERROR_NEW_VAL(uint32_t, 0); + if (byte_offset == DATA_HSIZE) + return ERROR_NEW_ERR(uint32_t, error_new(E_POSIX_EINVAL, "offset is at half the chip size")); size_t sector_base = LM_ROUND_DOWN(byte_offset, FLASH_SECTOR_SIZE); if (byte_offset + byte_count > sector_base + FLASH_SECTOR_SIZE) @@ -300,5 +290,5 @@ static uint32_t flash_file_pwrite(struct flash_file *self, struct lib9p_srv_ctx memcpy(&self->wbuf.dat[byte_offset-sector_base], buf, byte_count); self->written = true; - return byte_count; + return ERROR_NEW_VAL(uint32_t, byte_count); } diff --git a/cmd/sbc_harness/fs_harness_uptime_txt.c b/cmd/sbc_harness/fs_harness_uptime_txt.c index 2533558..021a8bd 100644 --- a/cmd/sbc_harness/fs_harness_uptime_txt.c +++ b/cmd/sbc_harness/fs_harness_uptime_txt.c @@ -37,7 +37,7 @@ static struct lib9p_qid uptime_file_qid(struct uptime_file *self) { }; } -static struct lib9p_srv_stat uptime_file_stat(struct uptime_file *self, struct lib9p_srv_ctx *ctx) { +static lib9p_srv_stat_or_error uptime_file_stat(struct uptime_file *self, struct lib9p_srv_ctx *ctx) { assert(self); assert(ctx); @@ -51,7 +51,7 @@ static struct lib9p_srv_stat uptime_file_stat(struct uptime_file *self, struct l size++; size += 3; - return (struct lib9p_srv_stat){ + return ERROR_NEW_VAL(lib9p_srv_stat, ((struct lib9p_srv_stat){ .qid = uptime_file_qid(self), .mode = 0444, .atime_sec = UTIL9P_ATIME, @@ -62,26 +62,26 @@ static struct lib9p_srv_stat uptime_file_stat(struct uptime_file *self, struct l .owner_gid = { .name = lib9p_str("root"), .num = 0 }, .last_modifier_uid = { .name = lib9p_str("root"), .num = 0 }, .extension = lib9p_str(NULL), - }; + })); } -static void uptime_file_wstat(struct uptime_file *self, struct lib9p_srv_ctx *ctx, - struct lib9p_srv_stat) { +static error uptime_file_wstat(struct uptime_file *self, struct lib9p_srv_ctx *ctx, + struct lib9p_srv_stat) { assert(self); assert(ctx); - lib9p_error(ctx, E_POSIX_EROFS, "read-only part of filesystem"); + return error_new(E_POSIX_EROFS, "read-only part of filesystem"); } -static void uptime_file_remove(struct uptime_file *self, struct lib9p_srv_ctx *ctx) { +static error uptime_file_remove(struct uptime_file *self, struct lib9p_srv_ctx *ctx) { assert(self); assert(ctx); - lib9p_error(ctx, E_POSIX_EROFS, "read-only part of filesystem"); + return error_new(E_POSIX_EROFS, "read-only part of filesystem"); } LIB9P_SRV_NOTDIR(struct uptime_file, uptime_file); -static lo_interface lib9p_srv_fio uptime_file_fopen(struct uptime_file *self, struct lib9p_srv_ctx *ctx, - bool LM_UNUSED(rd), bool LM_UNUSED(wr), bool LM_UNUSED(trunc)) { +static lib9p_srv_fio_or_error uptime_file_fopen(struct uptime_file *self, struct lib9p_srv_ctx *ctx, + bool LM_UNUSED(rd), bool LM_UNUSED(wr), bool LM_UNUSED(trunc)) { assert(self); assert(ctx); @@ -89,7 +89,7 @@ static lo_interface lib9p_srv_fio uptime_file_fopen(struct uptime_file *self, st ret->parent = self; ret->buf_len = 0; - return LO_BOX(lib9p_srv_fio, ret); + return ERROR_NEW_VAL(lib9p_srv_fio, LO_BOX(lib9p_srv_fio, ret)); } /* srv_fio ********************************************************************/ @@ -110,40 +110,35 @@ static struct lib9p_qid uptime_fio_qid(struct uptime_fio *self) { return uptime_file_qid(self->parent); } -static void uptime_fio_pread(struct uptime_fio *self, struct lib9p_srv_ctx *ctx, - uint32_t byte_count, uint64_t byte_offset, - struct iovec *ret) { +static iovec_or_error uptime_fio_pread(struct uptime_fio *self, struct lib9p_srv_ctx *ctx, + uint32_t byte_count, uint64_t byte_offset) { assert(self); assert(ctx); - assert(ret); if (byte_offset == 0 || self->buf_len == 0) { uint64_t now = LO_CALL(bootclock, get_time_ns); self->buf_len = fmt_snprint(self->buf, sizeof(self->buf), now, "ns\n"); } - if (byte_offset > (uint64_t)self->buf_len) { - lib9p_error(ctx, E_POSIX_EINVAL, "offset is past end-of-file length"); - return; - } + if (byte_offset > (uint64_t)self->buf_len) + return ERROR_NEW_ERR(iovec, error_new(E_POSIX_EINVAL, "offset is past end-of-file length")); size_t beg_off = (size_t)byte_offset; size_t end_off = beg_off + (size_t)byte_count; if (end_off > self->buf_len) end_off = self->buf_len; - *ret = (struct iovec){ + return ERROR_NEW_VAL(iovec, ((struct iovec){ .iov_base = &self->buf[beg_off], .iov_len = end_off-beg_off, - }; + })); } -static uint32_t uptime_fio_pwrite(struct uptime_fio *self, struct lib9p_srv_ctx *ctx, +static uint32_t_or_error uptime_fio_pwrite(struct uptime_fio *self, struct lib9p_srv_ctx *ctx, void *LM_UNUSED(buf), uint32_t LM_UNUSED(byte_count), uint64_t LM_UNUSED(byte_offset)) { assert(self); assert(ctx); - lib9p_error(ctx, E_POSIX_EROFS, "read-only part of filesystem"); - return 0; + return ERROR_NEW_ERR(uint32_t, error_new(E_POSIX_EROFS, "read-only part of filesystem")); } diff --git a/cmd/sbc_harness/main.c b/cmd/sbc_harness/main.c index d32b775..82519ae 100644 --- a/cmd/sbc_harness/main.c +++ b/cmd/sbc_harness/main.c @@ -114,8 +114,8 @@ static struct lib9p_srv_file root = ), ); -static lo_interface lib9p_srv_file get_root(struct lib9p_srv_ctx *LM_UNUSED(ctx), struct lib9p_s LM_UNUSED(treename)) { - return root; +static lib9p_srv_file_or_error get_root(struct lib9p_srv_ctx *LM_UNUSED(ctx), struct lib9p_s LM_UNUSED(treename)) { + return ERROR_NEW_VAL(lib9p_srv_file, root); } /* Code ***********************************************************************/ -- cgit v1.2.3-2-g168b