diff mbox series

[1/3] btrfs-progs: rescue: Add create-control-device subcommand

Message ID 052b7f70aee959f0c724b3d0524a727b5e1f102d.1604013169.git.dxu@dxuuu.xyz (mailing list archive)
State New, archived
Headers show
Series btrfs-progs: rescue: Add create-control-device subcommand | expand

Commit Message

Daniel Xu Oct. 29, 2020, 11:17 p.m. UTC
This commit adds a new `btrfs rescue create-control-device` subcommand
that creats /dev/btrfs-control. This is helpful on systems that may not
have `mknod` installed.

Link: https://github.com/kdave/btrfs-progs/issues/223
Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>
---
 cmds/rescue.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

Comments

Daniel Xu Nov. 11, 2020, 1:33 a.m. UTC | #1
On Thu, Oct 29, 2020, at 4:17 PM, Daniel Xu wrote:
> This commit adds a new `btrfs rescue create-control-device` subcommand
> that creats /dev/btrfs-control. This is helpful on systems that may not
> have `mknod` installed.
> 
> Link: https://github.com/kdave/btrfs-progs/issues/223
> Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>
> ---
>  cmds/rescue.c | 35 +++++++++++++++++++++++++++++++++++
>  1 file changed, 35 insertions(+)
> 
[...]

Ping
diff mbox series

Patch

diff --git a/cmds/rescue.c b/cmds/rescue.c
index 100d25f3..e6972fb7 100644
--- a/cmds/rescue.c
+++ b/cmds/rescue.c
@@ -18,6 +18,12 @@ 
 
 #include "kerncompat.h"
 
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/sysmacros.h>
+#include <fcntl.h>
+#include <unistd.h>
+
 #include <getopt.h>
 #include "kernel-shared/ctree.h"
 #include "kernel-shared/volumes.h"
@@ -264,6 +270,34 @@  out:
 }
 static DEFINE_SIMPLE_COMMAND(rescue_fix_device_size, "fix-device-size");
 
+static const char * const cmd_rescue_create_control_device_usage[] = {
+	"btrfs rescue create-control-device",
+	"Create /dev/btrfs-control (see 'CONTROL DEVICE' in btrfs(5))",
+	NULL
+};
+
+static int cmd_rescue_create_control_device(const struct cmd_struct *cmd,
+					    int argc, char **argv)
+{
+	dev_t device;
+	int ret;
+
+	if (check_argc_exact(argc, 1))
+		return 1;
+
+	device = makedev(10, 234);
+
+	ret = mknod("/dev/btrfs-control", S_IFCHR | S_IRUSR | S_IWUSR, device);
+	if (ret) {
+		error("could not create /dev/btrfs-control: %m");
+		return 1;
+	}
+
+	return 0;
+
+}
+static DEFINE_SIMPLE_COMMAND(rescue_create_control_device, "create-control-device");
+
 static const char rescue_cmd_group_info[] =
 "toolbox for specific rescue operations";
 
@@ -273,6 +307,7 @@  static const struct cmd_group rescue_cmd_group = {
 		&cmd_struct_rescue_super_recover,
 		&cmd_struct_rescue_zero_log,
 		&cmd_struct_rescue_fix_device_size,
+		&cmd_struct_rescue_create_control_device,
 		NULL
 	}
 };