summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/sbc_harness/config/config.h3
-rw-r--r--cmd/sbc_harness/fs_harness_flash_bin.c69
-rw-r--r--cmd/sbc_harness/fs_harness_uptime_txt.c44
-rw-r--r--cmd/sbc_harness/main.c4
4 files changed, 50 insertions, 70 deletions
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 8bd144e..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->basectx, LIB9P_ERRNO_L_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->basectx, LIB9P_ERRNO_L_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,18 +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->basectx,
- LIB9P_ERRNO_L_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
@@ -241,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;
@@ -258,34 +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->basectx,
- LIB9P_ERRNO_L_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->basectx,
- LIB9P_ERRNO_L_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)
@@ -303,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 23ac9d4..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->basectx, LIB9P_ERRNO_L_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->basectx, LIB9P_ERRNO_L_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,41 +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->basectx,
- LIB9P_ERRNO_L_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->basectx, LIB9P_ERRNO_L_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 ***********************************************************************/