aboutsummaryrefslogtreecommitdiff
blob: 35057b619adbb2ec836fca65a5fe5bcded2c9829 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
diff --git a/util-linux/mdStart.c b/util-linux/mdStart.c
--- util-linux/mdStart.c	1969-12-31 18:00:00.000000000 -0600
+++ util-linux/mdStart.c	2017-01-01 18:25:14.582737879 -0600
@@ -0,0 +1,76 @@
+/*
+ * Linux 2.6(+) RAID Autostarter
+ *
+ * Copyright (C) 2005 by Tim Yamin <plasmaroo@gentoo.org> <plasm@roo.me.uk>
+ * Copyright (C) 2012 by Sebastian Pipping <sebastian@pipping.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+//config:config MDSTART
+//config:	bool "mdstart"
+//config:	default n
+//config:	help
+//config:	  Allows you to autostart /dev/md devices if using an initramfs to
+//config:	  boot.
+
+//applet:IF_MDSTART(APPLET(mdstart, BB_DIR_SBIN, BB_SUID_DROP))
+
+//kbuild:lib-$(CONFIG_MDSTART) += mdStart.o
+
+//usage:#define mdstart_trivial_usage
+//usage:	"[PARTITION] MD-NODE [[PARTITION] MD-NODE ...]"
+//usage:
+//usage:#define mdstart_full_usage "\n\n"
+//usage:	"Run the RAID_AUTORUN ioctl on the given MD number"
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <linux/major.h>
+#include <linux/raid/md_u.h>
+
+extern int
+mdstart_main(int argc, char *argv[])
+{
+	int i, fd, part = 0, retval = 0;
+
+	if(argc < 2)
+	{
+		bb_show_usage();
+	}
+
+	for(i = 1; i < argc; i++)
+	{
+		if(sscanf(argv[i], "%d", &part) == 1)
+			continue;
+
+		fd = open(argv[i], 0, 0);
+		if (fd >= 0)
+		{
+			ioctl(fd, RAID_AUTORUN, part);
+			close(fd);
+		} else
+		{
+			printf("Error: Failed to open %s!\n", argv[i]);
+			retval=1;
+		}
+
+		part = 0;
+	}
+
+	return retval;
+}