[PATCH 14/23] Add the cd command to debugfs
Valerie Aurora
val at versity.com
Fri Apr 4 11:45:30 PDT 2025
Allow changing the current working directory in debugfs.
Signed-off-by: Valerie Aurora <val at versity.com>
---
cli/debugfs.c | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/cli/debugfs.c b/cli/debugfs.c
index 17ccd0f..f2f12ba 100644
--- a/cli/debugfs.c
+++ b/cli/debugfs.c
@@ -1,7 +1,9 @@
/* SPDX-License-Identifier: GPL-2.0 */
+#include <dirent.h>
#include <signal.h>
#include <unistd.h>
+#include <sys/stat.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -55,6 +57,33 @@ static void print_err(char *cmd, int err)
log("%s unexpected error: "ENOF, cmd, ENOA(-err));
}
+static void cmd_cd(struct debugfs_context *ctx, int argc, char **argv)
+{
+ struct ngnfs_dir_lookup_entry lent;
+ char *name;
+ int ret;
+
+ if (argc != 2) {
+ printf("usage: cd <directory name>\n");
+ return;
+ }
+
+ name = argv[1];
+
+ ret = ngnfs_dir_lookup(ctx->nfi, &ctx->cwd_ig, name, strlen(name), &lent);
+ if (ret < 0) {
+ print_err("cd", ret);
+ return;
+ }
+
+ if (lent.dtype != DT_DIR) {
+ printf("cd: not a directory: %s", name);
+ return;
+ }
+
+ ctx->cwd_ig = lent.ig;
+}
+
static void cmd_create(struct debugfs_context *ctx, int argc, char **argv)
{
int ret;
@@ -249,6 +278,7 @@ static struct command {
char *name;
void (*func)(struct debugfs_context *ctx, int argc, char **argv);
} commands[] = {
+ { "cd", cmd_cd, },
{ "create", cmd_create, },
{ "lookup", cmd_lookup, },
{ "mkfs", cmd_mkfs, },
--
2.48.1
More information about the ngnfs-devel
mailing list