From c2ee36c75f5acc701e4e8bedc86fa4e76b4cc36e Mon Sep 17 00:00:00 2001 From: Sohei Koyama Date: Thu, 3 Oct 2024 11:24:37 +0900 Subject: [PATCH] fix root stat --- finchfsd/fs_server.c | 28 +++++++++++++++++++++++----- tests/finchfs_test.cc | 8 ++++++++ 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/finchfsd/fs_server.c b/finchfsd/fs_server.c index f3b4030..3cb5af6 100644 --- a/finchfsd/fs_server.c +++ b/finchfsd/fs_server.c @@ -468,7 +468,8 @@ fs_rpc_inode_stat_recv(void *arg, const void *header, size_t header_length, p += sizeof(open); path = (char *)p; - log_debug("fs_rpc_inode_stat_recv() called path=%s", path); + log_debug("fs_rpc_inode_stat_recv() called path=%s open=%d", path, + open); iov_req_t *user_data = malloc(sizeof(iov_req_t) + sizeof(ucp_dt_iov_t) * 2); @@ -503,9 +504,9 @@ fs_rpc_inode_stat_recv(void *arg, const void *header, size_t header_length, entry_t *parent = get_parent_and_filename(base, name, path, &ctx); if (parent == NULL) { - log_debug( - "fs_rpc_inode_stat_recv() path=%s does not exist", - path); + log_debug("fs_rpc_inode_stat_recv() path=%s " + "does not exist", + path); *(int *)(user_data->iov[0].buffer) = FINCH_ENOENT; } else { entry_t key = { @@ -513,7 +514,24 @@ fs_rpc_inode_stat_recv(void *arg, const void *header, size_t header_length, }; entry_t *ent = RB_FIND(entrytree, &parent->entries, &key); - if (ent == NULL) { + if (strcmp(name, "") == 0) { + ent = base == 0 ? &ctx.root : (entry_t *)base; + st->chunk_size = ent->chunk_size; + st->i_ino = ent->i_ino; + st->mode = ent->mode; + st->mtime = ent->mtime; + st->ctime = ent->ctime; + st->size = ent->size; + memcpy(&st->eid, &ent, sizeof(ent)); + *(int *)(user_data->iov[0].buffer) = FINCH_OK; + if (open) { + ent->ref_count++; + } + if (((open >> 1) & O_RDWR) || + ((open >> 1) & O_WRONLY)) { + ent->ref_w_count++; + } + } else if (ent == NULL) { log_debug("fs_rpc_inode_stat_recv() path=%s " "does not exist", path); diff --git a/tests/finchfs_test.cc b/tests/finchfs_test.cc index 5324fe5..0291be7 100644 --- a/tests/finchfs_test.cc +++ b/tests/finchfs_test.cc @@ -1033,6 +1033,14 @@ TEST(FinchfsTest, Mmap1) EXPECT_EQ(finchfs_term(), 0); } +TEST(FinchfsTest, Root) +{ + EXPECT_EQ(finchfs_init(NULL), 0); + struct stat st; + EXPECT_EQ(finchfs_stat("/", &st), 0); + EXPECT_EQ(finchfs_term(), 0); +} + static int path_to_target_hash(const char *path, int div) {