[PATCH 10/14] Extend debugfs stat command to take an optional file name

Valerie Aurora val at versity.com
Thu Feb 27 06:16:19 PST 2025


Stat used to only show the root inode, now it shows either the current
working directory or the optional filename argument.

Signed-off-by: Valerie Aurora <val at versity.com>
---
 cli/debugfs.c | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/cli/debugfs.c b/cli/debugfs.c
index 9d3bd5d..ce9b1b4 100644
--- a/cli/debugfs.c
+++ b/cli/debugfs.c
@@ -157,13 +157,36 @@ static void cmd_readdir(struct debugfs_context *ctx, int argc, char **argv)
 
 static void cmd_stat(struct debugfs_context *ctx, int argc, char **argv)
 {
+	struct ngnfs_dir_handle hdl;
 	struct ngnfs_inode ninode;
+	u64 ino = ctx->cwd_ino;
+	char *name;
 	int ret;
 
-	ret = ngnfs_inode_read_copy(ctx->nfi, NGNFS_ROOT_INO, &ninode, sizeof(ninode));
+	if (argc > 2) {
+		printf("usage: stat [filename]\n");
+		return;
+	}
+
+	if (argc == 2) {
+		name = argv[1];
+		ret = ngnfs_dir_get_handle(ctx->nfi, ctx->cwd_ino, name, strlen(name), &hdl);
+		if (ret < 0) {
+			if (ret == -ENAMETOOLONG)
+				printf("stat: %s name too long\n", name);
+			else if (ret == -ENOENT)
+				printf("stat: %s does not exist\n", name);
+			else
+				log("stat error: "ENOF"\n", ENOA(-ret));
+			return;
+		}
+		ino = hdl.ino;
+	}
+
+	ret = ngnfs_inode_read_copy(ctx->nfi, ino, &ninode, sizeof(ninode));
 
 	if (ret < 0) {
-		log("stat error: %d", ret);
+		log("inode read error: %d", ret);
 	} else if (ret < sizeof(ninode)) {
 		log("returned inode buffer size %d too small, wanted at least %zu",
 		    ret, sizeof(ninode));
-- 
2.48.1




More information about the ngnfs-devel mailing list