diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-04-19 12:53:51 -0600 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-04-19 12:53:51 -0600 |
commit | 59e1fc370371c8da876d6c2ce68794bb7f89e525 (patch) | |
tree | 8037e1493bfebe72cb6023f5eccb62cff0c63349 /lib9p/srv_include | |
parent | 0cf05b66f94bfe02ecca37a4cbafba25b27c32ae (diff) | |
parent | 7f34046f5b27617b70c1d55f479c2a1abb8b8d8a (diff) |
Merge branch 'lukeshu/9p-tidy'
Diffstat (limited to 'lib9p/srv_include')
-rw-r--r-- | lib9p/srv_include/lib9p/srv.h | 109 |
1 files changed, 78 insertions, 31 deletions
diff --git a/lib9p/srv_include/lib9p/srv.h b/lib9p/srv_include/lib9p/srv.h index 9b3256b..c72aff5 100644 --- a/lib9p/srv_include/lib9p/srv.h +++ b/lib9p/srv_include/lib9p/srv.h @@ -19,9 +19,11 @@ /* context ********************************************************************/ -struct lib9p_srv_authinfo { - lib9p_nuid_t uid; - struct lib9p_s uname; +struct lib9p_srv_userid { + struct lib9p_s name; +#if CONFIG_9P_ENABLE_9P2000_u || CONFIG_9P_ENABLE_9P2000_L + lib9p_nuid_t num; +#endif BEGIN_PRIVATE(LIB9P_SRV_H); unsigned int refcount; @@ -37,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; @@ -45,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); }; @@ -66,14 +69,55 @@ 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 { + struct lib9p_qid qid; + struct lib9p_s name; +}; + 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. +/* 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. */ @@ -101,19 +145,21 @@ lo_interface lib9p_srv_dio; \ /* non-"opened" generic I/O *****************************************/ \ \ - LO_FUNC(struct lib9p_stat , stat , struct lib9p_srv_ctx *) \ + /** Strings returned from stat() must remain valid until free(). */ \ + 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 ***************************************/ \ \ - 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 ***************************************************/ \ \ @@ -131,35 +177,36 @@ 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, \ 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) \ - 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 ****************************************************/ |