diff options
Diffstat (limited to 'lib9p_util/static.c')
-rw-r--r-- | lib9p_util/static.c | 80 |
1 files changed, 41 insertions, 39 deletions
diff --git a/lib9p_util/static.c b/lib9p_util/static.c index 6861869..6071e03 100644 --- a/lib9p_util/static.c +++ b/lib9p_util/static.c @@ -9,21 +9,18 @@ #include <util9p/static.h> -LO_IMPLEMENTATION_C(lib9p_srv_file, struct util9p_static_dir, util9p_static_dir, static); -LO_IMPLEMENTATION_C(lib9p_srv_file, struct util9p_static_file, util9p_static_file, static); +LO_IMPLEMENTATION_C(lib9p_srv_file, struct util9p_static_dir, util9p_static_dir); +LO_IMPLEMENTATION_C(lib9p_srv_file, struct util9p_static_file, util9p_static_file); -LO_IMPLEMENTATION_H(lib9p_srv_dio, struct util9p_static_dir, util9p_static_dir); -LO_IMPLEMENTATION_C(lib9p_srv_dio, struct util9p_static_dir, util9p_static_dir, static); - -LO_IMPLEMENTATION_H(lib9p_srv_fio, struct util9p_static_file, util9p_static_file); -LO_IMPLEMENTATION_C(lib9p_srv_fio, struct util9p_static_file, util9p_static_file, static); +LO_IMPLEMENTATION_STATIC(lib9p_srv_dio, struct util9p_static_dir, util9p_static_dio); +LO_IMPLEMENTATION_STATIC(lib9p_srv_fio, struct util9p_static_file, util9p_static_fio); /* dir ************************************************************************/ -static void util9p_static_dir_free(struct util9p_static_dir *self) { +void util9p_static_dir_free(struct util9p_static_dir *self) { assert(self); } -static struct lib9p_qid util9p_static_dir_qid(struct util9p_static_dir *self) { +struct lib9p_qid util9p_static_dir_qid(struct util9p_static_dir *self) { assert(self); return (struct lib9p_qid){ @@ -33,7 +30,7 @@ static struct lib9p_qid util9p_static_dir_qid(struct util9p_static_dir *self) { }; } -static lib9p_srv_stat_or_error util9p_static_dir_stat(struct util9p_static_dir *self, struct lib9p_srv_ctx *ctx) { +lib9p_srv_stat_or_error util9p_static_dir_stat(struct util9p_static_dir *self, struct lib9p_srv_ctx *ctx) { assert(self); assert(ctx); @@ -50,22 +47,22 @@ static lib9p_srv_stat_or_error util9p_static_dir_stat(struct util9p_static_dir * .extension = lib9p_str(NULL), })); } -static error util9p_static_dir_wstat(struct util9p_static_dir *self, struct lib9p_srv_ctx *ctx, +error util9p_static_dir_wstat(struct util9p_static_dir *self, struct lib9p_srv_ctx *ctx, struct lib9p_srv_stat) { assert(self); assert(ctx); return error_new(E_POSIX_EROFS, "read-only part of filesystem"); } -static error util9p_static_dir_remove(struct util9p_static_dir *self, struct lib9p_srv_ctx *ctx) { +error util9p_static_dir_remove(struct util9p_static_dir *self, struct lib9p_srv_ctx *ctx) { assert(self); assert(ctx); return error_new(E_POSIX_EROFS, "read-only part of filesystem"); } -static lib9p_srv_file_or_error util9p_static_dir_dwalk(struct util9p_static_dir *self, struct lib9p_srv_ctx *ctx, - struct lib9p_s childname) { +lib9p_srv_file_or_error util9p_static_dir_dwalk(struct util9p_static_dir *self, struct lib9p_srv_ctx *ctx, + struct lib9p_s childname) { assert(self); assert(ctx); @@ -81,7 +78,7 @@ static lib9p_srv_file_or_error util9p_static_dir_dwalk(struct util9p_static_dir return ERROR_NEW_ERR(lib9p_srv_file, error_new(E_POSIX_ENOENT, "no such file or directory")); } -static lib9p_srv_file_or_error util9p_static_dir_dcreate(struct util9p_static_dir *self, struct lib9p_srv_ctx *ctx, +lib9p_srv_file_or_error util9p_static_dir_dcreate(struct util9p_static_dir *self, struct lib9p_srv_ctx *ctx, struct lib9p_s LM_UNUSED(childname), struct lib9p_srv_userid *LM_UNUSED(user), struct lib9p_srv_userid *LM_UNUSED(group), @@ -92,17 +89,21 @@ static lib9p_srv_file_or_error util9p_static_dir_dcreate(struct util9p_static_di return ERROR_NEW_ERR(lib9p_srv_file, error_new(E_POSIX_EROFS, "read-only part of filesystem")); } -LIB9P_SRV_NOTFILE(struct util9p_static_dir, util9p_static_dir); +LIB9P_SRV_NOTFILE(, struct util9p_static_dir, util9p_static_dir); -static lib9p_srv_dio_or_error util9p_static_dir_dopen(struct util9p_static_dir *self, struct lib9p_srv_ctx *ctx) { +lib9p_srv_dio_or_error util9p_static_dir_dopen(struct util9p_static_dir *self, struct lib9p_srv_ctx *ctx) { assert(self); assert(ctx); return ERROR_NEW_VAL(lib9p_srv_dio, LO_BOX(lib9p_srv_dio, self)); } -static void util9p_static_dir_iofree(struct util9p_static_dir *self) { + +static struct lib9p_qid util9p_static_dio_ioqid(struct util9p_static_dir *self) { + return util9p_static_dir_qid(self); +} +static void util9p_static_dio_iofree(struct util9p_static_dir *self) { assert(self); } -static lib9p_srv_dirent_or_error util9p_static_dir_dread(struct util9p_static_dir *self, struct lib9p_srv_ctx *ctx, size_t idx) { +static lib9p_srv_dirent_or_error util9p_static_dio_dread(struct util9p_static_dir *self, struct lib9p_srv_ctx *ctx, size_t idx) { assert(self); assert(ctx); @@ -123,10 +124,10 @@ static lib9p_srv_dirent_or_error util9p_static_dir_dread(struct util9p_static_di /* file ***********************************************************************/ -static void util9p_static_file_free(struct util9p_static_file *self) { +void util9p_static_file_free(struct util9p_static_file *self) { assert(self); } -static struct lib9p_qid util9p_static_file_qid(struct util9p_static_file *self) { +struct lib9p_qid util9p_static_file_qid(struct util9p_static_file *self) { assert(self); return (struct lib9p_qid){ @@ -148,7 +149,7 @@ static inline size_t util9p_static_file_size(struct util9p_static_file *file) { } -static lib9p_srv_stat_or_error util9p_static_file_stat(struct util9p_static_file *self, struct lib9p_srv_ctx *ctx) { +lib9p_srv_stat_or_error util9p_static_file_stat(struct util9p_static_file *self, struct lib9p_srv_ctx *ctx) { assert(self); assert(ctx); @@ -165,23 +166,23 @@ static lib9p_srv_stat_or_error util9p_static_file_stat(struct util9p_static_file .extension = lib9p_str(NULL), })); } -static error util9p_static_file_wstat(struct util9p_static_file *self, struct lib9p_srv_ctx *ctx, +error util9p_static_file_wstat(struct util9p_static_file *self, struct lib9p_srv_ctx *ctx, struct lib9p_srv_stat) { assert(self); assert(ctx); return error_new(E_POSIX_EROFS, "read-only part of filesystem"); } -static error util9p_static_file_remove(struct util9p_static_file *self, struct lib9p_srv_ctx *ctx) { +error util9p_static_file_remove(struct util9p_static_file *self, struct lib9p_srv_ctx *ctx) { assert(self); assert(ctx); return error_new(E_POSIX_EROFS, "read-only part of filesystem"); } -LIB9P_SRV_NOTDIR(struct util9p_static_file, util9p_static_file); +LIB9P_SRV_NOTDIR(, struct util9p_static_file, util9p_static_file); -static lib9p_srv_fio_or_error util9p_static_file_fopen(struct util9p_static_file *self, struct lib9p_srv_ctx *ctx, +lib9p_srv_fio_or_error util9p_static_file_fopen(struct util9p_static_file *self, struct lib9p_srv_ctx *ctx, bool rd, bool wr, bool trunc) { assert(self); assert(ctx); @@ -190,36 +191,37 @@ static lib9p_srv_fio_or_error util9p_static_file_fopen(struct util9p_static_file assert(!trunc); return ERROR_NEW_VAL(lib9p_srv_fio, LO_BOX(lib9p_srv_fio, self)); } -static void util9p_static_file_iofree(struct util9p_static_file *self) { + +static struct lib9p_qid util9p_static_fio_ioqid(struct util9p_static_file *self) { + return util9p_static_file_qid(self); +} +static void util9p_static_fio_iofree(struct util9p_static_file *self) { assert(self); } -static uint32_t util9p_static_file_iounit(struct util9p_static_file *self) { +static uint32_t util9p_static_fio_iounit(struct util9p_static_file *self) { assert(self); return 0; } -static iovec_or_error util9p_static_file_pread(struct util9p_static_file *self, struct lib9p_srv_ctx *ctx, - uint32_t byte_count, uint64_t byte_offset) { +static error util9p_static_fio_pread(struct util9p_static_file *self, struct lib9p_srv_ctx *ctx, + lo_interface io_writer dst, uint64_t byte_offset, uint32_t byte_count) { assert(self); assert(ctx); size_t data_size = util9p_static_file_size(self); if (byte_offset > (uint64_t)data_size) - return ERROR_NEW_ERR(iovec, error_new(E_POSIX_EINVAL, "offset is past end-of-file length")); + return 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 > data_size) end_off = data_size; - return ERROR_NEW_VAL(iovec, ((struct iovec){ - .iov_base = &self->data_start[beg_off], - .iov_len = end_off-beg_off, - })); + return io_write(dst, &self->data_start[beg_off], end_off-beg_off).err; } -static uint32_t_or_error util9p_static_file_pwrite(struct util9p_static_file *self, struct lib9p_srv_ctx *ctx, - void *LM_UNUSED(buf), - uint32_t LM_UNUSED(byte_count), - uint64_t LM_UNUSED(byte_offset)) { +static uint32_t_or_error util9p_static_fio_pwrite(struct util9p_static_file *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); |