From: Sascha Hauer <s.hauer@pengutronix.de>
To: BAREBOX <barebox@lists.infradead.org>
Subject: [PATCH 02/10] commands: add mknod command
Date: Thu, 27 Nov 2025 10:19:24 +0100 [thread overview]
Message-ID: <20251127-devfs-v1-2-4aff12818757@pengutronix.de> (raw)
In-Reply-To: <20251127-devfs-v1-0-4aff12818757@pengutronix.de>
Add a mknod command. This is intended for testing/debugging purposes as
normally device special nodes are created automatically in devfs.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
commands/Kconfig | 4 ++++
commands/Makefile | 1 +
commands/mknod.c | 43 +++++++++++++++++++++++++++++++++++++++++++
3 files changed, 48 insertions(+)
diff --git a/commands/Kconfig b/commands/Kconfig
index c7c03a65477b4f083c256dc55053aab8c8ad2741..6b8e19533dc07b54c41326b84adabb1553bc415d 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -1144,6 +1144,10 @@ config CMD_MKDIR
Options:
-p make parent directories as needed
+config CMD_MKNOD
+ tristate
+ prompt "mknod"
+
config CMD_PWD
tristate
default y
diff --git a/commands/Makefile b/commands/Makefile
index 8fffac8fd4428d275f86c5ad9898fed96c5b18ac..356957cab56bd97f80dbac67a3e17c333d4be45c 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -34,6 +34,7 @@ obj-$(CONFIG_CMD_CD) += cd.o
obj-$(CONFIG_CMD_PWD) += pwd.o
obj-$(CONFIG_CMD_MKDIR) += mkdir.o
obj-$(CONFIG_CMD_RMDIR) += rmdir.o
+obj-$(CONFIG_CMD_MKNOD) += mknod.o
obj-$(CONFIG_CMD_CP) += cp.o
obj-$(CONFIG_CMD_RM) += rm.o
obj-$(CONFIG_CMD_CAT) += cat.o
diff --git a/commands/mknod.c b/commands/mknod.c
new file mode 100644
index 0000000000000000000000000000000000000000..e99078995f995f54ba1d06587fc3d27e09f79e3b
--- /dev/null
+++ b/commands/mknod.c
@@ -0,0 +1,43 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <command.h>
+#include <fs.h>
+
+static int do_mknod(int argc, char *argv[])
+{
+ const char *filename, *cdevname;
+ umode_t mode;
+
+ if (argc < 4)
+ return COMMAND_ERROR_USAGE;
+
+ filename = argv[1];
+ if (!strcmp(argv[2], "b"))
+ mode = S_IFBLK;
+ else if (!strcmp(argv[2], "c"))
+ mode = S_IFCHR;
+ else
+ return COMMAND_ERROR_USAGE;
+
+ cdevname = argv[3];
+
+ return mknod(filename, mode, cdevname);
+}
+
+BAREBOX_CMD_HELP_START(mknod)
+BAREBOX_CMD_HELP_TEXT("make a device special node.")
+BAREBOX_CMD_HELP_TEXT("")
+BAREBOX_CMD_HELP_TEXT("usage: mknod <name> c|b <cdevname>")
+BAREBOX_CMD_HELP_TEXT("")
+BAREBOX_CMD_HELP_TEXT("Create a device special node named <name> directing")
+BAREBOX_CMD_HELP_TEXT("to cdev <cdevname>. This can either be a block (b) or")
+BAREBOX_CMD_HELP_TEXT("character (c) device.")
+BAREBOX_CMD_HELP_END
+
+BAREBOX_CMD_START(mknod)
+ .cmd = do_mknod,
+ BAREBOX_CMD_DESC("make device nodes")
+ BAREBOX_CMD_OPTS("NAME TYPE CDEVNAME")
+ BAREBOX_CMD_GROUP(CMD_GRP_FILE)
+ BAREBOX_CMD_HELP(cmd_mknod_help)
+BAREBOX_CMD_END
--
2.47.3
next prev parent reply other threads:[~2025-11-27 9:20 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-27 9:19 [PATCH 00/10] fs: Use device special nodes for devfs Sascha Hauer
2025-11-27 9:19 ` [PATCH 01/10] fs: implement mknod Sascha Hauer
2025-11-27 9:19 ` Sascha Hauer [this message]
2025-11-27 9:19 ` [PATCH 03/10] fs: ramfs: add device file support Sascha Hauer
2025-11-27 9:19 ` [PATCH 04/10] cdev: add cdev_size() helper Sascha Hauer
2025-11-27 9:19 ` [PATCH 05/10] fs: fix st_size for device files Sascha Hauer
2025-11-27 9:19 ` [PATCH 06/10] fs: retire devfs as filesystem Sascha Hauer
2025-11-27 9:19 ` [PATCH 07/10] fs: include cdevname in struct stat Sascha Hauer
2025-11-27 9:19 ` [PATCH 08/10] fs: stat_print: get cdevname from stat Sascha Hauer
2025-11-27 9:19 ` [PATCH 09/10] fs: replace cdev links with aliases Sascha Hauer
2025-11-27 9:19 ` [PATCH 10/10] ls: use ~0 for FILE_SIZE_STREAM Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251127-devfs-v1-2-4aff12818757@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox