diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-10-10 10:26:28 -0600 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-10-10 10:26:28 -0600 |
commit | db92bd35807305e6daec5ec40bd67cbc43fe88ee (patch) | |
tree | 8458933923545c87632e953a1c10a215efa78a0c /lib9p/include | |
parent | bb5afed7a0eeaf361be1e29b3a3ab8ace2865b39 (diff) |
lib9p: Implemnt Topen, add permission checks in Twalk
Diffstat (limited to 'lib9p/include')
-rw-r--r-- | lib9p/include/lib9p/9p.generated.h | 30 | ||||
-rw-r--r-- | lib9p/include/lib9p/9p.h | 6 | ||||
-rw-r--r-- | lib9p/include/lib9p/srv.h | 37 |
3 files changed, 36 insertions, 37 deletions
diff --git a/lib9p/include/lib9p/9p.generated.h b/lib9p/include/lib9p/9p.generated.h index 6248ec7..584960c 100644 --- a/lib9p/include/lib9p/9p.generated.h +++ b/lib9p/include/lib9p/9p.generated.h @@ -80,7 +80,7 @@ typedef uint32_t lib9p_dm_t; #define LIB9P_DM_OTHER_W ((lib9p_dm_t)(1<<1)) #define LIB9P_DM_OTHER_X ((lib9p_dm_t)(1<<0)) -#define LIB9P_DM_PERM ((lib9p_dm_t)(0777)) +#define LIB9P_DM_PERM_MASK ((lib9p_dm_t)(0777)) typedef uint8_t lib9p_qt_t; @@ -125,19 +125,21 @@ struct lib9p_stat { typedef uint8_t lib9p_o_t; -/* unused ((lib9p_o_t)(1<<7)) */ -#define LIB9P_O_RCLOSE ((lib9p_o_t)(1<<6)) -/* unused ((lib9p_o_t)(1<<5)) */ -#define LIB9P_O_TRUNC ((lib9p_o_t)(1<<4)) -/* unused ((lib9p_o_t)(1<<3)) */ -/* unused ((lib9p_o_t)(1<<2)) */ -#define LIB9P_O_rwx_1 ((lib9p_o_t)(1<<1)) -#define LIB9P_O_rwx_0 ((lib9p_o_t)(1<<0)) - -#define LIB9P_O_READ ((lib9p_o_t)(0)) -#define LIB9P_O_WRITE ((lib9p_o_t)(1)) -#define LIB9P_O_RDWR ((lib9p_o_t)(2)) -#define LIB9P_O_EXEC ((lib9p_o_t)(3)) +/* unused ((lib9p_o_t)(1<<7)) */ +#define LIB9P_O_RCLOSE ((lib9p_o_t)(1<<6)) +/* unused ((lib9p_o_t)(1<<5)) */ +#define LIB9P_O_TRUNC ((lib9p_o_t)(1<<4)) +/* unused ((lib9p_o_t)(1<<3)) */ +/* unused ((lib9p_o_t)(1<<2)) */ +#define LIB9P_O_mode_1 ((lib9p_o_t)(1<<1)) +#define LIB9P_O_mode_0 ((lib9p_o_t)(1<<0)) + +#define LIB9P_O_READ ((lib9p_o_t)(0)) +#define LIB9P_O_WRITE ((lib9p_o_t)(1)) +#define LIB9P_O_RDWR ((lib9p_o_t)(2)) +#define LIB9P_O_EXEC ((lib9p_o_t)(3)) +#define LIB9P_O_MODE_MASK ((lib9p_o_t)(0b00000011)) +#define LIB9P_O_FLAG_MASK ((lib9p_o_t)(0b11111100)) #endif /* defined(CONFIG_9P_ENABLE_9P2000) || defined(CONFIG_9P_ENABLE_9P2000_e) || defined(CONFIG_9P_ENABLE_9P2000_u) */ /* messages *******************************************************************/ diff --git a/lib9p/include/lib9p/9p.h b/lib9p/include/lib9p/9p.h index 3ad52f1..c3c6a8b 100644 --- a/lib9p/include/lib9p/9p.h +++ b/lib9p/include/lib9p/9p.h @@ -41,6 +41,12 @@ struct lib9p_ctx { char err_msg[CONFIG_9P_MAX_ERR_SIZE]; }; +static void lib9p_ctx_clear_error(struct lib9p_ctx *ctx) { + assert(ctx); + ctx->err_num = 0; + ctx->err_msg[0] = '\0'; +} + static bool lib9p_ctx_has_error(struct lib9p_ctx *ctx) { assert(ctx); return ctx->err_num || ctx->err_msg[0]; diff --git a/lib9p/include/lib9p/srv.h b/lib9p/include/lib9p/srv.h index d79e7db..5df6b1a 100644 --- a/lib9p/include/lib9p/srv.h +++ b/lib9p/include/lib9p/srv.h @@ -35,7 +35,6 @@ static inline int lib9p_srv_acknowledge_flush(struct lib9p_srv_ctx *ctx) { /* vtables you must implement *************************************************/ struct lib9p_srv_file; -struct lib9p_srv_io; struct lib9p_srv_file_vtable { /* all - resource management */ @@ -43,28 +42,26 @@ struct lib9p_srv_file_vtable { void (*free )(struct lib9p_srv_ctx *, struct lib9p_srv_file *); /* all - syscalls */ - struct lib9p_srv_io *(*io )(struct lib9p_srv_ctx *, struct lib9p_srv_file *, + uint32_t (*io )(struct lib9p_srv_ctx *, struct lib9p_srv_file *, lib9p_o_t flags); struct lib9p_stat (*stat )(struct lib9p_srv_ctx *, struct lib9p_srv_file *); void (*wstat )(struct lib9p_srv_ctx *, struct lib9p_srv_file *, struct lib9p_stat new); void (*remove )(struct lib9p_srv_ctx *, struct lib9p_srv_file *); - /* directories */ + /* directories - base */ struct lib9p_srv_file *(*dopen )(struct lib9p_srv_ctx *, struct lib9p_srv_file *, char *childname); struct lib9p_srv_file *(*dcreate)(struct lib9p_srv_ctx *, struct lib9p_srv_file *, char *childname, lib9p_dm_t perm, lib9p_o_t flags); -}; -struct lib9p_srv_io_dir_vtable { + /* directories - once opened */ size_t (*readdir)(struct lib9p_srv_ctx *, struct lib9p_srv_io_dir *, struct lib9p_stat *buf, size_t count, size_t offset); -}; -struct lib9p_srv_io_file_vtable { + /* non-directories - once opened */ uint32_t (*pread )(struct lib9p_srv_ctx *, struct lib9p_srv_io_file *, void *buf, uint32_t count, uint64_t offset); @@ -78,25 +75,19 @@ struct lib9p_srv_io_file_vtable { struct lib9p_srv_file { struct lib9p_srv_file_vtable *vtable; - /* Managed by srv.c */ - struct lib9p_srv_file *_parent_dir; - - /* This is where your implementation data goes. */ - char data[0]; -}; - -struct lib9p_srv_io { - union { - struct lib9p_srv_io_dir_vtable *dir; - struct lib9p_srv_io_file_vtable *file; - } vtable; + /* Managed by srv.c, but should be cloned by ->vtable->clone(). */ + struct lib9p_srv_file *_parent_dir; /* clone this - struct lib9p_srv_file *file; - struct lib9p_qid qid; - uint32_t iounit; + /* Managed by srv.c, and should be initialized to 0 by ->vtable->clone(). */ + /* ref type 1: an entry in fidmap + * ref type 2: ->_parent_dir of another file */ + struct lib9p_srv_file *_refcount; + lib9p_o_t _io_flags; + struct lib9p_qid _io_qid; + uint32_t _io_unit; /* This is where your implementation data goes. */ - char data[0]; + char data[0]; }; /* main server entrypoints ****************************************************/ |