From 52291b2c755704acde718dae3a2d3eed418e1a7c Mon Sep 17 00:00:00 2001 From: Zach Brown Date: Wed, 25 Jan 2017 11:17:30 -0800 Subject: [PATCH] Update format for readdir_pos We now track each parent dir's next readdir pos and the readdir pos of each dirent. Signed-off-by: Zach Brown --- utils/src/format.h | 3 +++ utils/src/mkfs.c | 3 ++- utils/src/print.c | 8 +++++--- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/utils/src/format.h b/utils/src/format.h index 28125b6c..f2480fc3 100644 --- a/utils/src/format.h +++ b/utils/src/format.h @@ -380,6 +380,7 @@ struct scoutfs_inode { __le64 blocks; __le64 link_counter; __le64 data_version; + __le64 next_readdir_pos; __le32 nlink; __le32 uid; __le32 gid; @@ -403,6 +404,7 @@ struct scoutfs_inode { struct scoutfs_dirent { __le64 ino; __le64 counter; + __le64 readdir_pos; __u8 type; __u8 name[0]; } __packed; @@ -435,6 +437,7 @@ struct scoutfs_dirent { #define SCOUTFS_DIRENT_OFF_BITS 31 #define SCOUTFS_DIRENT_OFF_MASK ((1U << SCOUTFS_DIRENT_OFF_BITS) - 1) /* getdents returns next pos with an entry, no entry at (f_pos)~0 */ +#define SCOUTFS_DIRENT_FIRST_POS 2 #define SCOUTFS_DIRENT_LAST_POS (INT_MAX - 1) enum { diff --git a/utils/src/mkfs.c b/utils/src/mkfs.c index db310b14..57174c9f 100644 --- a/utils/src/mkfs.c +++ b/utils/src/mkfs.c @@ -180,7 +180,8 @@ static int write_new_fs(char *path, int fd) *ikey = root_ikey; - inode->nlink = cpu_to_le32(2); + inode->next_readdir_pos = cpu_to_le64(2); + inode->nlink = cpu_to_le32(SCOUTFS_DIRENT_FIRST_POS); inode->mode = cpu_to_le32(0755 | 0040000); inode->atime.sec = cpu_to_le64(tv.tv_sec); inode->atime.nsec = cpu_to_le32(tv.tv_usec * 1000); diff --git a/utils/src/print.c b/utils/src/print.c index 7c5b1321..30749431 100644 --- a/utils/src/print.c +++ b/utils/src/print.c @@ -85,7 +85,7 @@ static void print_inode(void *key, int key_len, void *val, int val_len) printf(" inode: ino %llu size %llu blocks %llu lctr %llu nlink %u\n" " uid %u gid %u mode 0%o rdev 0x%x\n" - " salt 0x%x data_version %llu\n" + " salt 0x%x next_readdir_pos %llu data_version %llu\n" " atime %llu.%08u ctime %llu.%08u\n" " mtime %llu.%08u\n", be64_to_cpu(ikey->ino), @@ -94,6 +94,7 @@ static void print_inode(void *key, int key_len, void *val, int val_len) le32_to_cpu(inode->nlink), le32_to_cpu(inode->uid), le32_to_cpu(inode->gid), le32_to_cpu(inode->mode), le32_to_cpu(inode->rdev), le32_to_cpu(inode->salt), + le64_to_cpu(inode->next_readdir_pos), le64_to_cpu(inode->data_version), le64_to_cpu(inode->atime.sec), le32_to_cpu(inode->atime.nsec), @@ -149,9 +150,10 @@ static void print_dirent(void *key, int key_len, void *val, int val_len) unsigned int name_len = key_len - sizeof(*dkey); u8 *name = global_printable_name(dkey->name, name_len); - printf(" dirent: dir ino %llu type %u targ ino %llu\n" + printf(" dirent: dir ino %llu type %u rdpos %llu targ ino %llu\n" " name %s\n", - be64_to_cpu(dkey->ino), dent->type, le64_to_cpu(dent->ino), + be64_to_cpu(dkey->ino), dent->type, + le64_to_cpu(dent->readdir_pos), le64_to_cpu(dent->ino), name); }