Skip to content

Commit

Permalink
fix root stat
Browse files Browse the repository at this point in the history
  • Loading branch information
KoyamaSohei committed Oct 3, 2024
1 parent c1b3fe0 commit c2ee36c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
28 changes: 23 additions & 5 deletions finchfsd/fs_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -503,17 +504,34 @@ 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 = {
.name = name,
};
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);
Expand Down
8 changes: 8 additions & 0 deletions tests/finchfs_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit c2ee36c

Please sign in to comment.