summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib9p/srv.c7
-rw-r--r--lib9p/srv_include/lib9p/srv.h4
-rw-r--r--lib9p/tests/test_server/fs_shutdown.c7
-rwxr-xr-xlib9p/tests/testclient-p9p2
-rw-r--r--lib9p/tests/testclient-p9p.explog4
-rw-r--r--lib9p/tests/testclient-sess.explog4
6 files changed, 19 insertions, 9 deletions
diff --git a/lib9p/srv.c b/lib9p/srv.c
index 9dcf605..9adaefa 100644
--- a/lib9p/srv.c
+++ b/lib9p/srv.c
@@ -92,6 +92,7 @@ struct srv_pathinfo {
#define FIDFLAG_OPEN_R (1<<0)
#define FIDFLAG_OPEN_W (1<<1)
#define FIDFLAG_RCLOSE (1<<2)
+#define FIDFLAG_APPEND (1<<3)
#define FIDFLAG_OPEN (FIDFLAG_OPEN_R|FIDFLAG_OPEN_W)
struct srv_fidinfo {
@@ -1046,8 +1047,10 @@ static void handle_Topen(struct srv_req *ctx,
LIB9P_ERRNO_L_EEXIST, "exclusive file is already opened");
goto topen_return;
}
- if (stat.file_mode & LIB9P_DM_APPEND)
+ if (stat.file_mode & LIB9P_DM_APPEND) {
+ fidflags |= FIDFLAG_APPEND;
reqmode = reqmode & ~LIB9P_O_TRUNC;
+ }
uint8_t perm_bits = 0;
bool rd = false, wr = false;
switch (reqmode & LIB9P_O_MODE_MASK) {
@@ -1216,6 +1219,8 @@ static void handle_Twrite(struct srv_req *ctx,
LIB9P_ERRNO_L_EINVAL, "FID not open for writing");
return;
}
+ if (fidinfo->flags & FIDFLAG_APPEND)
+ req->offset = 0;
/* Do it. */
ctx->user = srv_userid_incref(fidinfo->user);
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, \
diff --git a/lib9p/tests/test_server/fs_shutdown.c b/lib9p/tests/test_server/fs_shutdown.c
index e7375ef..af2a989 100644
--- a/lib9p/tests/test_server/fs_shutdown.c
+++ b/lib9p/tests/test_server/fs_shutdown.c
@@ -24,7 +24,7 @@ static void shutdown_file_free(struct shutdown_file *self) {
static struct lib9p_qid shutdown_file_qid(struct shutdown_file *self) {
assert(self);
return (struct lib9p_qid){
- .type = LIB9P_QT_FILE,
+ .type = LIB9P_QT_FILE | LIB9P_QT_APPEND,
.vers = 1,
.path = self->pathnum,
};
@@ -37,7 +37,7 @@ static struct lib9p_stat shutdown_file_stat(struct shutdown_file *self, struct l
.kern_type = 0,
.kern_dev = 0,
.file_qid = shutdown_file_qid(self),
- .file_mode = 0222,
+ .file_mode = 0222 | LIB9P_DM_APPEND,
.file_atime = UTIL9P_ATIME,
.file_mtime = UTIL9P_MTIME,
.file_size = 0,
@@ -91,10 +91,11 @@ static uint32_t shutdown_fio_iounit(struct shutdown_fio *self) {
return 0;
}
-static uint32_t shutdown_fio_pwrite(struct shutdown_fio *self, struct lib9p_srv_ctx *ctx, void *buf, uint32_t byte_count, uint64_t LM_UNUSED(offset)) {
+static uint32_t shutdown_fio_pwrite(struct shutdown_fio *self, struct lib9p_srv_ctx *ctx, void *buf, uint32_t byte_count, uint64_t offset) {
assert(self);
assert(ctx);
assert(buf);
+ assert(offset == 0);
if (byte_count == 0)
return 0;
for (size_t i = 0; i < self->parent->nlisteners; i++)
diff --git a/lib9p/tests/testclient-p9p b/lib9p/tests/testclient-p9p
index 9c9f9f2..09ce746 100755
--- a/lib9p/tests/testclient-p9p
+++ b/lib9p/tests/testclient-p9p
@@ -30,7 +30,7 @@ expect_lines \
'--r--r--r-- M 0 root root 6 Oct 7 2024 flush-silent' \
'--r--r--r-- M 0 root root 6 Oct 7 2024 flush-slowread' \
'--r--r--r-- M 0 root root 6 Oct 7 2024 flush-slowsilent' \
- '---w--w--w- M 0 root root 0 Oct 7 2024 shutdown' \
+ 'a--w--w--w- M 0 root root 0 Oct 7 2024 shutdown' \
'--r--r--r-- M 0 root root 9 Oct 7 2024 whoami'
out=$("${client[@]}" ls -l 'Documentation/')
diff --git a/lib9p/tests/testclient-p9p.explog b/lib9p/tests/testclient-p9p.explog
index 7f3953d..8216297 100644
--- a/lib9p/tests/testclient-p9p.explog
+++ b/lib9p/tests/testclient-p9p.explog
@@ -97,9 +97,9 @@
> Tattach { tag=0 fid=0 afid=NOFID uname="nobody" aname="" n_uid=0 }
< Rattach { tag=0 qid={ type=(DIR) vers=1 path=1 } }
> Twalk { tag=0 fid=0 newfid=1 nwname=1 wname=[ "shutdown" ] }
-< Rwalk { tag=0 nwqid=1 wqid=[ { type=(0) vers=1 path=5 } ] }
+< Rwalk { tag=0 nwqid=1 wqid=[ { type=(APPEND) vers=1 path=5 } ] }
> Topen { tag=0 fid=1 mode=(TRUNC|MODE_WRITE) }
-< Ropen { tag=0 qid={ type=(0) vers=1 path=5 } iounit=0 }
+< Ropen { tag=0 qid={ type=(APPEND) vers=1 path=5 } iounit=0 }
> Twrite { tag=0 fid=1 offset=0 count=2 data="1\n" }
< Rwrite { tag=0 count=2 }
> Tclunk { tag=0 fid=1 }
diff --git a/lib9p/tests/testclient-sess.explog b/lib9p/tests/testclient-sess.explog
index 74a2cd7..f686045 100644
--- a/lib9p/tests/testclient-sess.explog
+++ b/lib9p/tests/testclient-sess.explog
@@ -149,8 +149,8 @@
> Tattach { tag=0 fid=0 afid=NOFID uname="nobody" aname="" n_uid=0 }
< Rattach { tag=0 qid={ type=(DIR) vers=1 path=1 } }
> Twalk { tag=0 fid=0 newfid=0 nwname=1 wname=[ "shutdown" ] }
-< Rwalk { tag=0 nwqid=1 wqid=[ { type=(0) vers=1 path=5 } ] }
+< Rwalk { tag=0 nwqid=1 wqid=[ { type=(APPEND) vers=1 path=5 } ] }
> Topen { tag=0 fid=0 mode=(MODE_WRITE) }
-< Ropen { tag=0 qid={ type=(0) vers=1 path=5 } iounit=0 }
+< Ropen { tag=0 qid={ type=(APPEND) vers=1 path=5 } iounit=0 }
> Twrite { tag=0 fid=0 offset=0 count=2 data="1\n" }
< Rwrite { tag=0 count=2 }