[PATCH 10/15] Add the cd command to debugfs
Valerie Aurora
val at versity.com
Wed Mar 12 07:33:49 PDT 2025
Allow changing the current working directory in debugfs.
Signed-off-by: Valerie Aurora <val at versity.com>
---
cli/debugfs.c | 33 +++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/cli/debugfs.c b/cli/debugfs.c
index c24b9e4..0c0914c 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>
@@ -35,6 +37,36 @@ struct debugfs_context {
#define LINE_SIZE (PATH_MAX * 5)
#define MAX_ARGC ((LINE_SIZE + 1) / 2)
+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) {
+ if (ret == -ENOENT)
+ printf("lookup: %s does not exist\n", name);
+ else
+ log("lookup error: "ENOF"\n", ENOA(-ret));
+ return;
+ }
+
+ if (lent.dtype != DT_DIR) {
+ printf("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;
@@ -233,6 +265,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