From 5c4004ff3bd66306e03579f6ee350b3517aa4ea9 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Thu, 17 Apr 2025 02:49:53 -0600 Subject: lib9p: Check that we compile for the whole the matrix of "enable"-toggles --- lib9p/srv_include/lib9p/srv.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib9p/srv_include') diff --git a/lib9p/srv_include/lib9p/srv.h b/lib9p/srv_include/lib9p/srv.h index 9b3256b..e9d2e91 100644 --- a/lib9p/srv_include/lib9p/srv.h +++ b/lib9p/srv_include/lib9p/srv.h @@ -20,7 +20,9 @@ /* context ********************************************************************/ struct lib9p_srv_authinfo { +#if CONFIG_9P_ENABLE_9P2000_u || CONFIG_9P_ENABLE_9P2000_L lib9p_nuid_t uid; +#endif struct lib9p_s uname; BEGIN_PRIVATE(LIB9P_SRV_H); -- cgit v1.2.3-2-g168b From 3ae25b0b620ba0f71e5c91f0c28873be1ba68497 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Thu, 17 Apr 2025 02:49:53 -0600 Subject: lib9p_srv: Rename ->authinfo->{uname,uid} to ->userid->{name,num} --- lib9p/srv_include/lib9p/srv.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib9p/srv_include') diff --git a/lib9p/srv_include/lib9p/srv.h b/lib9p/srv_include/lib9p/srv.h index e9d2e91..026075e 100644 --- a/lib9p/srv_include/lib9p/srv.h +++ b/lib9p/srv_include/lib9p/srv.h @@ -19,11 +19,11 @@ /* context ********************************************************************/ -struct lib9p_srv_authinfo { +struct lib9p_srv_userid { + struct lib9p_s name; #if CONFIG_9P_ENABLE_9P2000_u || CONFIG_9P_ENABLE_9P2000_L - lib9p_nuid_t uid; + lib9p_nuid_t num; #endif - struct lib9p_s uname; BEGIN_PRIVATE(LIB9P_SRV_H); unsigned int refcount; @@ -39,7 +39,7 @@ CR_CHAN_DECLARE(_lib9p_srv_flush_ch, enum _lib9p_srv_flush_result); struct lib9p_srv_ctx { struct lib9p_ctx basectx; - struct lib9p_srv_authinfo *authinfo; + struct lib9p_srv_userid *user; BEGIN_PRIVATE(LIB9P_SRV_H); struct _lib9p_srv_sess *parent_sess; -- cgit v1.2.3-2-g168b From b44e1813b9a39827ebe5b8ade6dd68713925c58b Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Thu, 17 Apr 2025 12:42:05 -0600 Subject: lib9p_srv: Document more thoughts about improving stat() --- lib9p/srv_include/lib9p/srv.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lib9p/srv_include') diff --git a/lib9p/srv_include/lib9p/srv.h b/lib9p/srv_include/lib9p/srv.h index 026075e..82d4502 100644 --- a/lib9p/srv_include/lib9p/srv.h +++ b/lib9p/srv_include/lib9p/srv.h @@ -75,7 +75,10 @@ lo_interface lib9p_srv_dio; /* FIXME: I don't like that the pointers returned by stat() and * pread() have to remain live after they return. Perhaps a - * `respond()`-callback? But that just reads as gross in C. + * `respond()`-callback? But that just reads as gross in C. Also, + * because stat is used by srv.c internally for things other than + * Tstat, a `respond()`-callback makes less sense for stat() than it + * does for read(). * * FIXME: It would be nice if pread() could return more than 1 iovec. */ -- cgit v1.2.3-2-g168b From 740bffed4da51c4d46a1295baabe3bd249cf9138 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Thu, 17 Apr 2025 12:42:25 -0600 Subject: lib9p_srv: Set Twrite->byte_offset to zero if append-only --- lib9p/srv_include/lib9p/srv.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib9p/srv_include') diff --git a/lib9p/srv_include/lib9p/srv.h b/lib9p/srv_include/lib9p/srv.h index 82d4502..5b44e79 100644 --- a/lib9p/srv_include/lib9p/srv.h +++ b/lib9p/srv_include/lib9p/srv.h @@ -136,6 +136,10 @@ LO_INTERFACE(lib9p_srv_file); uint32_t byte_count, \ uint64_t byte_offset, \ struct iovec *ret) \ + /** \ + * If the file was append-only when fopen()ed, then byte_offset will \ + * always be 0. \ + */ \ LO_FUNC(uint32_t , pwrite , struct lib9p_srv_ctx *, \ void *buf, \ uint32_t byte_count, \ -- cgit v1.2.3-2-g168b From 539004128822db8c2289544271019d8fd2038c41 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Fri, 18 Apr 2025 11:12:50 -0600 Subject: lib9p_srv: Send response from the handle_T* functions, not the outer worker --- lib9p/srv_include/lib9p/srv.h | 1 + 1 file changed, 1 insertion(+) (limited to 'lib9p/srv_include') diff --git a/lib9p/srv_include/lib9p/srv.h b/lib9p/srv_include/lib9p/srv.h index 5b44e79..cc73634 100644 --- a/lib9p/srv_include/lib9p/srv.h +++ b/lib9p/srv_include/lib9p/srv.h @@ -47,6 +47,7 @@ struct lib9p_srv_ctx { uint8_t *net_bytes; _lib9p_srv_flush_ch_t flush_ch; bool flush_acknowledged; + bool responded; END_PRIVATE(LIB9P_SRV_H); }; -- cgit v1.2.3-2-g168b From 0a700d5e8e5feec3fc07316924a00b2b7cab6050 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Thu, 17 Apr 2025 03:17:44 -0600 Subject: lib9p_srv: Think harder about the stat() and dcreate() APIs --- lib9p/srv_include/lib9p/srv.h | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'lib9p/srv_include') diff --git a/lib9p/srv_include/lib9p/srv.h b/lib9p/srv_include/lib9p/srv.h index cc73634..0ef674a 100644 --- a/lib9p/srv_include/lib9p/srv.h +++ b/lib9p/srv_include/lib9p/srv.h @@ -74,12 +74,9 @@ void lib9p_srv_acknowledge_flush(struct lib9p_srv_ctx *ctx); lo_interface lib9p_srv_fio; lo_interface lib9p_srv_dio; -/* FIXME: I don't like that the pointers returned by stat() and - * pread() have to remain live after they return. Perhaps a - * `respond()`-callback? But that just reads as gross in C. Also, - * because stat is used by srv.c internally for things other than - * Tstat, a `respond()`-callback makes less sense for stat() than it - * does for read(). +/* FIXME: I don't like that the pointer returned by pread() has to + * remain live after it returns. Perhaps a `respond()`-callback? But + * that just reads as gross in C. * * FIXME: It would be nice if pread() could return more than 1 iovec. */ @@ -107,6 +104,7 @@ lo_interface lib9p_srv_dio; \ /* non-"opened" generic I/O *****************************************/ \ \ + /** Strings returned from stat() must remain valid until free(). */ \ LO_FUNC(struct lib9p_stat , stat , struct lib9p_srv_ctx *) \ LO_FUNC(void , wstat , struct lib9p_srv_ctx *, \ struct lib9p_stat new) \ @@ -114,12 +112,13 @@ lo_interface lib9p_srv_dio; \ /* non-"opened" directory I/O ***************************************/ \ \ - LO_FUNC(lo_interface lib9p_srv_file, dwalk , struct lib9p_srv_ctx *, \ - struct lib9p_s childname) \ - LO_FUNC(lo_interface lib9p_srv_file, dcreate, struct lib9p_srv_ctx *, \ - struct lib9p_s childname, \ - lib9p_dm_t perm, \ - lib9p_o_t flags) \ + LO_FUNC(lo_interface lib9p_srv_file, dwalk , struct lib9p_srv_ctx *, \ + struct lib9p_s childname) \ + LO_FUNC(lo_interface lib9p_srv_file, dcreate, struct lib9p_srv_ctx *, \ + struct lib9p_s childname, \ + struct lib9p_srv_userid *user, \ + struct lib9p_srv_userid *group, \ + lib9p_dm_t perm) \ \ /* open() for I/O ***************************************************/ \ \ @@ -163,13 +162,14 @@ LO_INTERFACE(lib9p_srv_fio); /* starting at this object -> */ size_t obj_offset) LO_INTERFACE(lib9p_srv_dio); -#define LIB9P_SRV_NOTDIR(TYP, NAM) \ - static lo_interface lib9p_srv_file NAM##_dwalk (TYP *, struct lib9p_srv_ctx *, struct lib9p_s) { assert_notreached("not a directory"); } \ - static lo_interface lib9p_srv_file NAM##_dcreate(TYP *, struct lib9p_srv_ctx *, struct lib9p_s, lib9p_dm_t, lib9p_o_t) { assert_notreached("not a directory"); } \ - static lo_interface lib9p_srv_dio NAM##_dopen (TYP *, struct lib9p_srv_ctx *) { assert_notreached("not a directory"); } +#define LIB9P_SRV_NOTDIR(TYP, NAM) \ + static lo_interface lib9p_srv_file NAM##_dwalk (TYP *, struct lib9p_srv_ctx *, struct lib9p_s) { assert_notreached("not a directory"); } \ + static lo_interface lib9p_srv_file NAM##_dcreate(TYP *, struct lib9p_srv_ctx *, struct lib9p_s, \ + struct lib9p_srv_userid *, struct lib9p_srv_userid *, lib9p_dm_t) { assert_notreached("not a directory"); } \ + static lo_interface lib9p_srv_dio NAM##_dopen (TYP *, struct lib9p_srv_ctx *) { assert_notreached("not a directory"); } #define LIB9P_SRV_NOTFILE(TYP, NAM) \ - static lo_interface lib9p_srv_fio NAM##_fopen (TYP *, struct lib9p_srv_ctx *, bool, bool, bool) { assert_notreached("not a file"); } + static lo_interface lib9p_srv_fio NAM##_fopen (TYP *, struct lib9p_srv_ctx *, bool, bool, bool) { assert_notreached("not a file"); } /* main server entrypoints ****************************************************/ -- cgit v1.2.3-2-g168b From d81b0e1036aedb127c4033a187b671deaaca54c4 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Sat, 19 Apr 2025 11:04:27 -0600 Subject: lib9p_srv: Rethink the dio interface --- lib9p/srv_include/lib9p/srv.h | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'lib9p/srv_include') diff --git a/lib9p/srv_include/lib9p/srv.h b/lib9p/srv_include/lib9p/srv.h index 0ef674a..1c534e9 100644 --- a/lib9p/srv_include/lib9p/srv.h +++ b/lib9p/srv_include/lib9p/srv.h @@ -71,6 +71,11 @@ void lib9p_srv_acknowledge_flush(struct lib9p_srv_ctx *ctx); /* interface definitions ******************************************************/ +struct lib9p_srv_dirent { + struct lib9p_qid qid; + struct lib9p_s name; +}; + lo_interface lib9p_srv_fio; lo_interface lib9p_srv_dio; @@ -146,20 +151,16 @@ LO_INTERFACE(lib9p_srv_file); uint64_t byte_offset) LO_INTERFACE(lib9p_srv_fio); -/* FIXME: The dio interface just feels clunky. I'm not in a rush to - * change it because util9p_static_dir is already implemented and I - * don't anticipate the sbc-harness needing another dio - * implementation. But if I wanted lib9p to be used outside of - * sbc-harness, this is one of the first things that I'd want to - * change. - */ #define lib9p_srv_dio_LO_IFACE \ LO_FUNC(struct lib9p_qid , qid ) \ LO_FUNC(void , iofree ) \ - LO_FUNC(size_t /* <- obj cnt */ , dread , struct lib9p_srv_ctx *, \ - uint8_t *buf, \ - /* num bytes -> */ uint32_t byte_count, \ - /* starting at this object -> */ size_t obj_offset) + /** \ + * Return the idx-th dirent. idx will always be either 0 or \ + * prev_idx+1. A dirrent with an empty name signals EOF. The string + * must remain valid until the next dread() call or iofree(). \ + */ \ + LO_FUNC(struct lib9p_srv_dirent , dread , struct lib9p_srv_ctx *, \ + size_t idx) LO_INTERFACE(lib9p_srv_dio); #define LIB9P_SRV_NOTDIR(TYP, NAM) \ -- cgit v1.2.3-2-g168b From 09cac1d04e106b70ad4afde3b24df6d294d191b1 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Sat, 19 Apr 2025 09:14:20 -0600 Subject: lib9p_srv: Separate the stat API from the network format --- lib9p/srv_include/lib9p/srv.h | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) (limited to 'lib9p/srv_include') diff --git a/lib9p/srv_include/lib9p/srv.h b/lib9p/srv_include/lib9p/srv.h index 1c534e9..c72aff5 100644 --- a/lib9p/srv_include/lib9p/srv.h +++ b/lib9p/srv_include/lib9p/srv.h @@ -69,6 +69,42 @@ bool lib9p_srv_flush_requested(struct lib9p_srv_ctx *ctx); */ void lib9p_srv_acknowledge_flush(struct lib9p_srv_ctx *ctx); +/* version-independent stat ***************************************************/ + +struct lib9p_srv_stat { + struct lib9p_qid qid; + lib9p_dm_t mode; + uint32_t atime_sec; /* BUG: u32 seconds means a 2106 problem */ +#if CONFIG_9P_ENABLE_9P2000_L + uint32_t atime_nsec; +#endif + uint32_t mtime_sec; /* BUG: u32 seconds means a 2106 problem */ +#if CONFIG_9P_ENABLE_9P2000_L + uint32_t mtime_nsec; + uint32_t ctime_sec; /* BUG: u32 seconds means a 2106 problem */ + uint32_t ctime_nsec; + uint32_t btime_sec; /* BUG: u32 seconds means a 2106 problem */ + uint32_t btime_nsec; +#endif + uint64_t size; + struct lib9p_s name; + struct lib9p_srv_userid owner_uid; + struct lib9p_srv_userid owner_gid; + struct lib9p_srv_userid last_modifier_uid; +#if CONFIG_9P_ENABLE_9P2000_u + struct lib9p_s extension; +#endif +}; + +static inline void lib9p_srv_stat_assert(struct lib9p_srv_stat stat) { + assert( ((bool)(stat.mode & LIB9P_DM_DIR )) == ((bool)(stat.qid.type & LIB9P_QT_DIR )) ); + assert( ((bool)(stat.mode & LIB9P_DM_APPEND)) == ((bool)(stat.qid.type & LIB9P_QT_APPEND)) ); + assert( ((bool)(stat.mode & LIB9P_DM_EXCL )) == ((bool)(stat.qid.type & LIB9P_QT_EXCL )) ); + assert( ((bool)(stat.mode & LIB9P_DM_AUTH )) == ((bool)(stat.qid.type & LIB9P_QT_AUTH )) ); + assert( ((bool)(stat.mode & LIB9P_DM_TMP )) == ((bool)(stat.qid.type & LIB9P_QT_TMP )) ); + assert( (stat.size == 0) || !(stat.mode & LIB9P_DM_DIR) ); +} + /* interface definitions ******************************************************/ struct lib9p_srv_dirent { @@ -110,9 +146,9 @@ lo_interface lib9p_srv_dio; /* non-"opened" generic I/O *****************************************/ \ \ /** Strings returned from stat() must remain valid until free(). */ \ - LO_FUNC(struct lib9p_stat , stat , struct lib9p_srv_ctx *) \ + LO_FUNC(struct lib9p_srv_stat , stat , struct lib9p_srv_ctx *) \ LO_FUNC(void , wstat , struct lib9p_srv_ctx *, \ - struct lib9p_stat new) \ + struct lib9p_srv_stat) \ LO_FUNC(void , remove , struct lib9p_srv_ctx *) \ \ /* non-"opened" directory I/O ***************************************/ \ -- cgit v1.2.3-2-g168b