[PATCH 09/15] Extend debugfs stat command to take an optional file name
Valerie Aurora
val at versity.com
Wed Mar 12 07:33:48 PDT 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 | 26 +++++++++++++++++++++++---
1 file changed, 23 insertions(+), 3 deletions(-)
diff --git a/cli/debugfs.c b/cli/debugfs.c
index 8bc1dc4..c24b9e4 100644
--- a/cli/debugfs.c
+++ b/cli/debugfs.c
@@ -164,14 +164,34 @@ 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_inode_ino_gen root_ig = INIT_NGNFS_ROOT_IG;
+ struct ngnfs_inode_ino_gen ig = ctx->cwd_ig;
+ struct ngnfs_dir_lookup_entry lent;
struct ngnfs_inode ninode;
+ char *name;
int ret;
- ret = ngnfs_inode_read_copy(ctx->nfi, &root_ig, &ninode, sizeof(ninode));
+ if (argc > 2) {
+ printf("usage: stat [filename]\n");
+ return;
+ }
+
+ if (argc == 2) {
+ name = argv[1];
+ ret = ngnfs_dir_lookup(ctx->nfi, &ctx->cwd_ig, name, strlen(name), &lent);
+ if (ret < 0) {
+ if (ret == -ENOENT)
+ printf("stat: %s does not exist\n", name);
+ else
+ log("stat error: "ENOF"\n", ENOA(-ret));
+ return;
+ }
+ ig = lent.ig;
+ }
+
+ ret = ngnfs_inode_read_copy(ctx->nfi, &ig, &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