summaryrefslogtreecommitdiff
path: root/cmd/srv9p
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/srv9p')
-rw-r--r--cmd/srv9p/CMakeLists.txt25
-rw-r--r--cmd/srv9p/config/config.h53
-rw-r--r--cmd/srv9p/main.c116
-rw-r--r--cmd/srv9p/static/Documentation/x1
-rw-r--r--cmd/srv9p/static/README.md1
-rw-r--r--cmd/srv9p/static9p.c242
-rw-r--r--cmd/srv9p/static9p.h47
7 files changed, 0 insertions, 485 deletions
diff --git a/cmd/srv9p/CMakeLists.txt b/cmd/srv9p/CMakeLists.txt
deleted file mode 100644
index b747882..0000000
--- a/cmd/srv9p/CMakeLists.txt
+++ /dev/null
@@ -1,25 +0,0 @@
-# cmd/srv9p/CMakeLists.txt - Build script for srv9p test/dev executable
-#
-# Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com>
-# SPDX-License-Identifier: AGPL-3.0-or-later
-
-if (PICO_PLATFORM STREQUAL "host")
-
-add_executable(srv9p
- main.c
- static9p.c
-)
-target_embed_sources(srv9p static.h
- static/README.md
- static/Documentation/x
-)
-target_include_directories(srv9p PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
-target_include_directories(srv9p PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/config)
-target_link_libraries(srv9p
- libcr
- libcr_ipc
- libmisc
- lib9p
-)
-
-endif()
diff --git a/cmd/srv9p/config/config.h b/cmd/srv9p/config/config.h
deleted file mode 100644
index a184e6f..0000000
--- a/cmd/srv9p/config/config.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/* config.h - Compile-time configuration for srv9p
- *
- * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com>
- * SPDX-License-Identifier: AGPL-3.0-or-later
- */
-
-#ifndef _CONFIG_H_
-#define _CONFIG_H_
-
-#define CONFIG_NETIO_NUM_CONNS 8
-
-#define CONFIG_9P_PORT 564
-/**
- * This max-msg-size is sized so that a Twrite message can return
- * 8KiB of data.
- *
- * This is the same as the default in Plan 9 4e's lib9p; it has the
- * comment that "24" is "ample room for Twrite/Rread header
- * (iounit)". In fact, the Twrite header is only 23 bytes
- * ("size[4] Twrite[1] tag[2] fid[4] offset[8] count[4]") and the
- * Rread header is even shorter at 11 bytes ("size[4] Rread[1]
- * tag[2] count[4]"), so "24" appears to be the size of the Twrite
- * header rounded up to a nice round number.
- *
- * In older versions of 9P ("9P1"), the max message size was
- * defined as part of the protocol specification rather than
- * negotiated. In Plan 9 1e it was (8*1024)+128, and was bumped to
- * (8*1024)+160 in 2e and 3e.
- */
-#define CONFIG_9P_MAX_MSG_SIZE ((4*1024)+24)
-/**
- * Maximum host-data-structure size. A message may be larger in
- * unmarshaled-host-structures than marshaled-net-bytes due to (1)
- * struct padding, (2) nul-terminator byes for strings.
- */
-#define CONFIG_9P_MAX_HOSTMSG_SIZE CONFIG_9P_MAX_MSG_SIZE+16
-#define CONFIG_9P_MAX_FIDS 16
-#define CONFIG_9P_MAX_REQS 2
-#define CONFIG_9P_MAX_ERR_SIZE 128 /* 128 is what Plan 9 4e uses */
-#define CONFIG_9P_ENABLE_9P2000_u
-/*#define CONFIG_9P_ENABLE_9P2000_e*/
-
-#define CONFIG_COROUTINE_DEFAULT_STACK_SIZE (32*1024)
-#define CONFIG_COROUTINE_MEASURE_STACK 1 /* bool */
-#define CONFIG_COROUTINE_PROTECT_STACK 1 /* bool */
-#define CONFIG_COROUTINE_DEBUG 0 /* bool */
-#define CONFIG_COROUTINE_VALGRIND 1 /* bool */
-#define CONFIG_COROUTINE_NUM (1 /* usb_common */ +\
- 1 /* usb_keyboard */ +\
- CONFIG_NETIO_NUM_CONNS /* accept+read */ +\
- (CONFIG_9P_MAX_REQS*CONFIG_NETIO_NUM_CONNS) /* work+write */ )
-
-#endif /* _CONFIG_H_ */
diff --git a/cmd/srv9p/main.c b/cmd/srv9p/main.c
deleted file mode 100644
index d30c4f9..0000000
--- a/cmd/srv9p/main.c
+++ /dev/null
@@ -1,116 +0,0 @@
-/* srv9p/main.c - Main entry point for test 9P server
- *
- * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com>
- * SPDX-License-Identifier: AGPL-3.0-or-later
- */
-
-#include <error.h>
-#include <stdio.h>
-
-#include <lib9p/srv.h>
-#include <libcr/coroutine.h>
-#include <libhw/generic/net.h>
-#include <libhw/host_net.h>
-
-#include "static9p.h"
-#include "static.h"
-
-/* configuration **************************************************************/
-
-#include "config.h"
-
-#ifndef CONFIG_NETIO_NUM_CONNS
- #error config.h must define CONFIG_NETIO_NUM_CONNS
-#endif
-
-/* implementation *************************************************************/
-
-#define UNUSED(name) /* name __attribute__((unused)) */
-
-/* file tree ******************************************************************/
-
-#define FILE_COMMON(NAME) { \
- .vtable = &static_file_vtable, \
- \
- .u_name = "root", .u_num = 0, /* owner user */ \
- .g_name = "root", .g_num = 0, /* owner group */ \
- .m_name = "root", .m_num = 0, /* last-modified-by user */ \
- \
- .pathnum = __COUNTER__, \
- .name = NAME, \
- .perm = 0444, \
- .atime = 1728337905, \
- .mtime = 1728337904, \
- }
-
-#define DIR_COMMON(NAME) { \
- .vtable = &static_dir_vtable, \
- \
- .u_name = "root", .u_num = 0, /* owner user */ \
- .g_name = "root", .g_num = 0, /* owner group */ \
- .m_name = "root", .m_num = 0, /* last-modified-by user */ \
- \
- .pathnum = __COUNTER__, \
- .name = NAME, \
- .perm = 0555, \
- .atime = 1728337905, \
- .mtime = 1728337904, \
- }
-
-#define STATIC_FILE(STRNAME, SYMNAME) \
- &((static struct static_file){ \
- ._static_common = FILE_COMMON(STRNAME), \
- .data_start = _binary_static_##SYMNAME##_start, \
- .data_end = _binary_static_##SYMNAME##_end, \
- })
-
-static struct static_dir root = {
- ._static_common = DIR_COMMON(""),
- .members = {
- &((static struct static_dir){
- ._static_common = DIR_COMMON("Documentation"),
- .members = {
- STATIC_FILE("x", Documentation_x),
- NULL
- },
- }),
- STATIC_FILE("README.md", README_md),
- NULL,
- },
-};
-
-static implements_lib9p_srv_file *get_root(struct lib9p_srv_ctx *UNUSED(ctx), char *UNUSED(treename)) {
- return &root;
-}
-
-/* main ***********************************************************************/
-
-static COROUTINE read_cr(void *_srv) {
- struct lib9p_srv *srv = _srv;
- assert(srv);
-
- cr_begin();
-
- struct hostnet_tcp_listener listener;
- hostnet_tcp_listener_init(&listener, 9000);
-
- lib9p_srv_read_cr(srv, &listener);
-
- cr_end();
-}
-
-int main() {
- struct lib9p_srv srv = {
- .rootdir = get_root,
- };
-
- for (int i = 0; i < CONFIG_NETIO_NUM_CONNS; i++)
- if (!coroutine_add(read_cr, &srv))
- error(1, 0, "coroutine_add(read_cr, &srv)");
- for (int i = 0; i < 2*CONFIG_NETIO_NUM_CONNS; i++)
- if (!coroutine_add(lib9p_srv_write_cr, &srv))
- error(1, 0, "coroutine_add(lib9p_srv_write_cr, &srv)");
-
- coroutine_main();
- return 1;
-}
diff --git a/cmd/srv9p/static/Documentation/x b/cmd/srv9p/static/Documentation/x
deleted file mode 100644
index 257cc56..0000000
--- a/cmd/srv9p/static/Documentation/x
+++ /dev/null
@@ -1 +0,0 @@
-foo
diff --git a/cmd/srv9p/static/README.md b/cmd/srv9p/static/README.md
deleted file mode 100644
index af5626b..0000000
--- a/cmd/srv9p/static/README.md
+++ /dev/null
@@ -1 +0,0 @@
-Hello, world!
diff --git a/cmd/srv9p/static9p.c b/cmd/srv9p/static9p.c
deleted file mode 100644
index 3632c26..0000000
--- a/cmd/srv9p/static9p.c
+++ /dev/null
@@ -1,242 +0,0 @@
-/* srv9p/static9p.c - Serve static files over 9P
- *
- * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com>
- * SPDX-License-Identifier: AGPL-3.0-or-later
- */
-
-#include <assert.h>
-
-#include <libmisc/vcall.h>
-
-#include "static9p.h"
-
-#define UNUSED(name) /* name __attribute__((unused)) */
-#define p9_str(cstr) ((struct lib9p_s){ .len = strlen(cstr), .utf8 = cstr })
-#define p9_nulstr ((struct lib9p_s){ .len = 0, .utf8 = NULL })
-
-/* common *********************************************************************/
-
-static implements_lib9p_srv_file *static_common_clone(implements_lib9p_srv_file *_self, struct lib9p_srv_ctx *ctx) {
- _static_common *self = VCALL_SELF(_static_common, implements_lib9p_srv_file, _self);
- assert(self);
- assert(ctx);
-
- return self;
-}
-
-static void static_common_free(implements_lib9p_srv_file *_self, struct lib9p_srv_ctx *ctx) {
- _static_common *self = VCALL_SELF(_static_common, implements_lib9p_srv_file, _self);
- assert(self);
- assert(ctx);
-
- /* do nothing */
-}
-
-static uint32_t static_common_io(implements_lib9p_srv_file *_self, struct lib9p_srv_ctx *ctx, lib9p_o_t UNUSED(flags)) {
- _static_common *self = VCALL_SELF(_static_common, implements_lib9p_srv_file, _self);
- assert(self);
- assert(ctx);
-
- return 0;
-}
-
-static void static_common_wstat(implements_lib9p_srv_file *_self, struct lib9p_srv_ctx *ctx,
- struct lib9p_stat UNUSED(new)) {
- _static_common *self = VCALL_SELF(_static_common, implements_lib9p_srv_file, _self);
- assert(self);
- assert(ctx);
-
- lib9p_error(&ctx->basectx, LINUX_EROFS, "read-only part of filesystem");
-}
-
-static void static_common_remove(implements_lib9p_srv_file *_self, struct lib9p_srv_ctx *ctx) {
- _static_common *self = VCALL_SELF(_static_common, implements_lib9p_srv_file, _self);
- assert(self);
- assert(ctx);
-
- lib9p_error(&ctx->basectx, LINUX_EROFS, "read-only part of filesystem");
-}
-
-/* dir ************************************************************************/
-
-static struct lib9p_stat static_dir_stat(implements_lib9p_srv_file *_self, struct lib9p_srv_ctx *ctx) {
- struct static_dir *self = VCALL_SELF(struct static_dir, implements_lib9p_srv_file, _self);
- assert(self);
- assert(ctx);
-
- return (struct lib9p_stat){
- .kern_type = 0,
- .kern_dev = 0,
- .file_qid = {
- .type = LIB9P_QT_DIR,
- .vers = 1,
- .path = self->pathnum,
- },
- .file_mode = LIB9P_DM_DIR | (self->perm & 0555),
- .file_atime = self->atime,
- .file_mtime = self->mtime,
- .file_size = 0,
- .file_name = p9_str(self->name),
- .file_owner_uid = p9_str(self->u_name),
- .file_owner_gid = p9_str(self->g_name),
- .file_last_modified_uid = p9_str(self->m_name),
- .file_extension = p9_nulstr,
- .file_owner_n_uid = self->u_num,
- .file_owner_n_gid = self->g_num,
- .file_last_modified_n_uid = self->m_num,
- };
-}
-
-static implements_lib9p_srv_file *static_dir_dopen(implements_lib9p_srv_file *_self, struct lib9p_srv_ctx *ctx,
- char *childname) {
- struct static_dir *self = VCALL_SELF(struct static_dir, implements_lib9p_srv_file, _self);
- assert(self);
- assert(ctx);
-
- for (size_t i = 0; self->members[i]; i++) {
- implements_lib9p_srv_file *filep = self->members[i];
- struct lib9p_stat stat = VCALL(filep, stat, ctx);
- if (lib9p_ctx_has_error(&ctx->basectx))
- break;
- lib9p_assert_stat(stat);
- if (strcmp(stat.file_name.utf8, childname) == 0)
- return filep;
- }
- lib9p_error(&ctx->basectx,
- LINUX_ENOENT, "no such file or directory");
- return NULL;
-}
-
-static implements_lib9p_srv_file *static_dir_dcreate(implements_lib9p_srv_file *_self, struct lib9p_srv_ctx *ctx,
- char *UNUSED(childname),
- lib9p_dm_t UNUSED(perm), lib9p_o_t UNUSED(flags)) {
- struct static_dir *self = VCALL_SELF(struct static_dir, implements_lib9p_srv_file, _self);
- assert(self);
- assert(ctx);
-
- lib9p_error(&ctx->basectx, LINUX_EROFS, "read-only part of filesystem");
- return NULL;
-}
-
-static size_t static_dir_dread(implements_lib9p_srv_file *_self, struct lib9p_srv_ctx *ctx,
- uint8_t *buf,
- uint32_t byte_count,
- size_t _obj_offset) {
- struct static_dir *self = VCALL_SELF(struct static_dir, implements_lib9p_srv_file, _self);
- assert(self);
- assert(ctx);
-
- uint32_t byte_offset = 0;
- size_t obj_offset = _obj_offset;
- while (self->members[obj_offset]) {
- implements_lib9p_srv_file *filep = self->members[obj_offset];
- struct lib9p_stat stat = VCALL(filep, stat, ctx);
- if (lib9p_ctx_has_error(&ctx->basectx))
- break;
- lib9p_assert_stat(stat);
- uint32_t nbytes = lib9p_marshal_stat(&ctx->basectx, byte_count-byte_offset, &stat,
- &buf[byte_offset]);
- if (!nbytes) {
- if (obj_offset == _obj_offset)
- lib9p_error(&ctx->basectx,
- LINUX_ERANGE, "stat object does not fit into negotiated max message size");
- break;
- }
- byte_offset += nbytes;
- obj_offset++;
- }
- return obj_offset - _obj_offset;
-}
-
-struct lib9p_srv_file_vtable static_dir_vtable = {
- .clone = static_common_clone,
- .free = static_common_free,
-
- .io = static_common_io,
- .stat = static_dir_stat,
- .wstat = static_common_wstat,
- .remove = static_common_remove,
-
- .dopen = static_dir_dopen,
- .dcreate = static_dir_dcreate,
-
- .dread = static_dir_dread,
-};
-
-/* file ***********************************************************************/
-
-static inline size_t static_file_size(struct static_file *file) {
- assert(file);
-
-#if __unix__
- assert(file->data_start);
-#endif
- if (!file->data_end)
- return file->data_size;
- return (size_t)((uintptr_t)file->data_end - (uintptr_t)file->data_start);
-}
-
-static struct lib9p_stat static_file_stat(implements_lib9p_srv_file *_self, struct lib9p_srv_ctx *ctx) {
- struct static_file *self = VCALL_SELF(struct static_file, implements_lib9p_srv_file, _self);
- assert(self);
- assert(ctx);
-
- return (struct lib9p_stat){
- .kern_type = 0,
- .kern_dev = 0,
- .file_qid = {
- .type = LIB9P_QT_FILE,
- .vers = 1,
- .path = self->pathnum,
- },
- .file_mode = self->perm & 0444,
- .file_atime = self->atime,
- .file_mtime = self->mtime,
- .file_size = (uint64_t)static_file_size(self),
- .file_name = p9_str(self->name),
- .file_owner_uid = p9_str(self->u_name),
- .file_owner_gid = p9_str(self->g_name),
- .file_last_modified_uid = p9_str(self->m_name),
- .file_extension = p9_nulstr,
- .file_owner_n_uid = self->u_num,
- .file_owner_n_gid = self->g_num,
- .file_last_modified_n_uid = self->m_num,
- };
-}
-
-static uint32_t static_file_pread(implements_lib9p_srv_file *_self, struct lib9p_srv_ctx *ctx,
- void *buf,
- uint32_t byte_count,
- uint64_t byte_offset) {
- struct static_file *self = VCALL_SELF(struct static_file, implements_lib9p_srv_file, _self);
- assert(self);
- assert(ctx);
-
- size_t data_size = static_file_size(self);
-
- if (byte_offset > (uint64_t)data_size) {
- lib9p_error(&ctx->basectx,
- LINUX_EINVAL, "offset is past end-of-file length");
- return 0;
- }
-
- 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;
- memcpy(buf, &self->data_start[beg_off], end_off-beg_off);
- return (uint32_t)(end_off-beg_off);
-}
-
-struct lib9p_srv_file_vtable static_file_vtable = {
- .clone = static_common_clone,
- .free = static_common_free,
-
- .io = static_common_io,
- .stat = static_file_stat,
- .wstat = static_common_wstat,
- .remove = static_common_remove,
-
- .pread = static_file_pread,
- .pwrite = NULL,
-};
diff --git a/cmd/srv9p/static9p.h b/cmd/srv9p/static9p.h
deleted file mode 100644
index 7a3d476..0000000
--- a/cmd/srv9p/static9p.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/* srv9p/static9p.h - Serve static files over 9P
- *
- * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com>
- * SPDX-License-Identifier: AGPL-3.0-or-later
- */
-
-#ifndef _SRV9P_STATIC9P_H_
-#define _SRV9P_STATIC9P_H_
-
-#include <lib9p/srv.h>
-
-typedef struct {
- implements_lib9p_srv_file;
-
- char *u_name;
- uint32_t u_num;
- char *g_name;
- uint32_t g_num;
- char *m_name;
- uint32_t m_num;
-
- uint64_t pathnum;
- char *name;
- lib9p_dm_t perm;
- uint32_t atime, mtime;
-} _static_common;
-
-struct static_dir {
- _static_common;
-
- /* NULL-terminated */
- implements_lib9p_srv_file *members[];
-};
-
-
-struct static_file {
- _static_common;
-
- char *data_start; /* must not be NULL */
- char *data_end; /* may be NULL, in which case data_size is used */
- size_t data_size; /* only used if .data_end==NULL */
-};
-
-extern struct lib9p_srv_file_vtable static_dir_vtable;
-extern struct lib9p_srv_file_vtable static_file_vtable;
-
-#endif /* _SRV9P_STATIC9P_H_ */