summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib9p/srv.c18
-rw-r--r--lib9p/tests/testclient-sess.c7
-rw-r--r--lib9p/tests/testclient-sess.explog6
3 files changed, 14 insertions, 17 deletions
diff --git a/lib9p/srv.c b/lib9p/srv.c
index df53940..ea8b932 100644
--- a/lib9p/srv.c
+++ b/lib9p/srv.c
@@ -556,10 +556,13 @@ static inline struct _srv_fidinfo *srv_util_fidsave(struct _lib9p_srv_req *ctx,
if (overwrite) {
struct srv_pathinfo *old_pathinfo = pathmap_load(&ctx->parent_sess->paths, fidinfo->path);
assert(old_pathinfo);
- if (srv_util_pathisdir(old_pathinfo))
- LO_CALL(fidinfo->dir.io, iofree);
- else
- LO_CALL(fidinfo->file.io, iofree);
+ if (srv_util_pathisdir(old_pathinfo)) {
+ if (!LO_IS_NULL(fidinfo->dir.io))
+ LO_CALL(fidinfo->dir.io, iofree);
+ } else {
+ if (!LO_IS_NULL(fidinfo->file.io))
+ LO_CALL(fidinfo->file.io, iofree);
+ }
srv_util_pathfree(ctx, fidinfo->path);
} else {
lib9p_error(&ctx->ctx.basectx,
@@ -819,13 +822,6 @@ static void handle_Twalk(struct _lib9p_srv_req *ctx,
pathinfo = new_pathinfo;
}
if (resp->nwqid == req->nwname) {
- if (req->newfid == req->fid) {
- if (srv_util_pathisdir(pathinfo))
- LO_CALL(fidinfo->dir.io, iofree);
- else
- LO_CALL(fidinfo->file.io, iofree);
- fidinfo->flags = 0;
- }
if (!srv_util_fidsave(ctx, req->newfid, pathinfo, req->newfid == req->fid))
srv_util_pathfree(ctx, LO_CALL(pathinfo->file, qid).path);
} else {
diff --git a/lib9p/tests/testclient-sess.c b/lib9p/tests/testclient-sess.c
index d03327b..54b8722 100644
--- a/lib9p/tests/testclient-sess.c
+++ b/lib9p/tests/testclient-sess.c
@@ -102,11 +102,12 @@ int main(int argc, char *argv[]) {
ctx.version = LIB9P_VER_9P2000;
send9p(Tattach, .tag=0, .fid=0, .afid=LIB9P_FID_NOFID, .uname=lib9p_str("nobody"), .aname=lib9p_str(""));
recv9p(); /* Rattach */
- wname[0] = lib9p_str("shutdown"); send9p(Twalk, .tag=0, .fid=0, .newfid=1, .nwname=1, .wname=wname);
+ /* check the newfid==fid case */
+ wname[0] = lib9p_str("shutdown"); send9p(Twalk, .tag=0, .fid=0, .newfid=0, .nwname=1, .wname=wname);
recv9p(); /* Rwalk */
- send9p(Topen, .tag=0, .fid=1, .mode=LIB9P_O_MODE_WRITE);
+ send9p(Topen, .tag=0, .fid=0, .mode=LIB9P_O_MODE_WRITE);
recv9p(); /* Ropen */
- send9p(Twrite, .tag=0, .fid=1, .offset=0, .count=2, .data="1\n");
+ send9p(Twrite, .tag=0, .fid=0, .offset=0, .count=2, .data="1\n");
recv9p(); /* Rwrite */
return 0;
}
diff --git a/lib9p/tests/testclient-sess.explog b/lib9p/tests/testclient-sess.explog
index 71f6244..4932553 100644
--- a/lib9p/tests/testclient-sess.explog
+++ b/lib9p/tests/testclient-sess.explog
@@ -20,9 +20,9 @@
< Rversion { tag=0 max_msg_size=4120 version="9P2000" }
> Tattach { tag=0 fid=0 afid=NOFID uname="nobody" aname="" n_uid=0 }
< Rattach { tag=0 qid={ type=(DIR) vers=1 path=5 } }
-> Twalk { tag=0 fid=0 newfid=1 nwname=1 wname=["shutdown" ] }
+> Twalk { tag=0 fid=0 newfid=0 nwname=1 wname=["shutdown" ] }
< Rwalk { tag=0 nwqid=1 wqid=[{ type=(0) vers=1 path=4 } ] }
-> Topen { tag=0 fid=1 mode=(MODE_WRITE) }
+> Topen { tag=0 fid=0 mode=(MODE_WRITE) }
< Ropen { tag=0 qid={ type=(0) vers=1 path=4 } iounit=0 }
-> Twrite { tag=0 fid=1 offset=0 count=2 data="1\n" }
+> Twrite { tag=0 fid=0 offset=0 count=2 data="1\n" }
< Rwrite { tag=0 count=2 }