aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2005-12-13 08:21:33 +0000
committerRob Landley <rob@landley.net>2005-12-13 08:21:33 +0000
commit70f7ef7be385f782e57106df523f1c5e16fbdc47 (patch)
treee560de3934ac70ae03dd77695450cff91bdfce0b
parent3858bf18d5d3b6a858ca46acb6c8628715520d1c (diff)
downloadbusybox-w32-70f7ef7be385f782e57106df523f1c5e16fbdc47.tar.gz
busybox-w32-70f7ef7be385f782e57106df523f1c5e16fbdc47.tar.bz2
busybox-w32-70f7ef7be385f782e57106df523f1c5e16fbdc47.zip
Nothing to see here. Move along.
Not buying it, eh? I know I said new features before 1.1, but, well... (I was weak!) The config file and hotplug modes aren't implemented yet. Might take a stab at those tomorrow. (I _should_ go back to focusing on the bug triage list.)
-rw-r--r--include/applets.h3
-rw-r--r--include/usage.h26
-rw-r--r--util-linux/Config.in30
-rw-r--r--util-linux/Makefile.in2
-rw-r--r--util-linux/mdev.c121
5 files changed, 180 insertions, 2 deletions
diff --git a/include/applets.h b/include/applets.h
index 79d18207e..47376c624 100644
--- a/include/applets.h
+++ b/include/applets.h
@@ -414,6 +414,9 @@
414#ifdef CONFIG_MD5SUM 414#ifdef CONFIG_MD5SUM
415 APPLET(md5sum, md5sum_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) 415 APPLET(md5sum, md5sum_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
416#endif 416#endif
417#ifdef CONFIG_MDEV
418 APPLET(mdev, mdev_main, _BB_DIR_SBIN, _BB_SUID_NEVER)
419#endif
417#ifdef CONFIG_MESG 420#ifdef CONFIG_MESG
418 APPLET(mesg, mesg_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) 421 APPLET(mesg, mesg_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
419#endif 422#endif
diff --git a/include/usage.h b/include/usage.h
index e595bd9d9..12c45b45f 100644
--- a/include/usage.h
+++ b/include/usage.h
@@ -1841,6 +1841,26 @@
1841 "busybox: OK\n" \ 1841 "busybox: OK\n" \
1842 "^D\n" 1842 "^D\n"
1843 1843
1844#define mdev_trivial_usage \
1845 "[-s]"
1846#define mdev_full_usage \
1847 "\ts\tScan /sys and populate /dev during system boot\n\n" \
1848 "Called with no options (via hotplug) it uses environment variables\n" \
1849 "to determine which device to add/remove."
1850#ifdef CONFIG_FEATURE_MDEV_CONFIG
1851#define mdev_notes_usage \
1852 "The mdev config file contains lines that look like:\n" \
1853 " hd[a-z][0-9]* 0:3 660\n\n" \
1854 "That's device name (with regex match), uid:gid, and permissions.\n\n" \
1855 "Optionally, that can be followed (on the same line) by an asterisk\n" \
1856 "and a command line to run after creating the corresponding device(s),\n"\
1857 "ala:\n\n" \
1858 " hdc root:cdrom 660 *ln -s hdc cdrom\n\n" \
1859 "Config file parsing stops on the first matching line. If no config\n"\
1860 "entry is matched, devices are created with default 0:0 660. (Make\n"\
1861 "the last line match .* to override this.)\n\n"
1862#endif
1863
1844#define mesg_trivial_usage \ 1864#define mesg_trivial_usage \
1845 "[y|n]" 1865 "[y|n]"
1846#define mesg_full_usage \ 1866#define mesg_full_usage \
@@ -2822,10 +2842,12 @@
2822 "\t-a\tStart swapping on all swap devices" 2842 "\t-a\tStart swapping on all swap devices"
2823 2843
2824#define switch_root_trivial_usage \ 2844#define switch_root_trivial_usage \
2825 "NEW_ROOT NEW_INIT [ARGUMENTS_TO_INIT]" 2845 "[-c /dev/console] NEW_ROOT NEW_INIT [ARGUMENTS_TO_INIT]"
2826#define switch_root_full_usage \ 2846#define switch_root_full_usage \
2827 "Use from PID 1 under initramfs to free initramfs, chroot to NEW_ROOT,\n" \ 2847 "Use from PID 1 under initramfs to free initramfs, chroot to NEW_ROOT,\n" \
2828 "and exec NEW_INIT.\n" 2848 "and exec NEW_INIT.\n\n" \
2849 "Options:\n" \
2850 "\t-c\tRedirect console to device on new root"
2829 2851
2830#define sync_trivial_usage \ 2852#define sync_trivial_usage \
2831 "" 2853 ""
diff --git a/util-linux/Config.in b/util-linux/Config.in
index fe71dac2c..5ab54e038 100644
--- a/util-linux/Config.in
+++ b/util-linux/Config.in
@@ -245,6 +245,36 @@ config CONFIG_LOSETUP
245 file or block device, and to query the status of a loop device. This 245 file or block device, and to query the status of a loop device. This
246 version does not currently support enabling data encryption. 246 version does not currently support enabling data encryption.
247 247
248config CONFIG_MDEV
249 bool "mdev"
250 default n
251 help
252 mdev is a mini-udev implementation: call it with -s to populate
253 /dev from /sys, then "echo /sbin/mdev > /sys/kernel/hotplug" to
254 have it handle hotplug events afterwards. Device names are taken
255 from sysfs.
256
257config CONFIG_FEATURE_MDEV_CONFIG
258 bool " Support /etc/mdev.conf"
259 default n
260 depends on CONFIG_MDEV
261 help
262 The mdev config file contains lines that look like:
263
264 hd[a-z][0-9]* 0:3 660
265
266 That's device name (with regex match), uid:gid, and permissions.
267
268 Optionally, that can be followed (on the same line) by an asterisk
269 and a command line to run after creating the corresponding device(s),
270 ala:
271
272 hdc root:cdrom 660 *ln -s hdc cdrom
273
274 Config file parsing stops on the first matching line. If no config
275 entry is matched, devices are created with default 0:0 660. (Make
276 the last line match .* to override this.)
277
248config CONFIG_MKSWAP 278config CONFIG_MKSWAP
249 bool "mkswap" 279 bool "mkswap"
250 default n 280 default n
diff --git a/util-linux/Makefile.in b/util-linux/Makefile.in
index f6fdba96a..782870cdb 100644
--- a/util-linux/Makefile.in
+++ b/util-linux/Makefile.in
@@ -24,12 +24,14 @@ UTILLINUX-$(CONFIG_HWCLOCK) +=hwclock.o
24UTILLINUX-$(CONFIG_IPCRM) +=ipcrm.o 24UTILLINUX-$(CONFIG_IPCRM) +=ipcrm.o
25UTILLINUX-$(CONFIG_IPCS) +=ipcs.o 25UTILLINUX-$(CONFIG_IPCS) +=ipcs.o
26UTILLINUX-$(CONFIG_LOSETUP) +=losetup.o 26UTILLINUX-$(CONFIG_LOSETUP) +=losetup.o
27UTILLINUX-$(CONFIG_MDEV) +=mdev.o
27UTILLINUX-$(CONFIG_MKFS_MINIX) +=mkfs_minix.o 28UTILLINUX-$(CONFIG_MKFS_MINIX) +=mkfs_minix.o
28UTILLINUX-$(CONFIG_MKSWAP) +=mkswap.o 29UTILLINUX-$(CONFIG_MKSWAP) +=mkswap.o
29UTILLINUX-$(CONFIG_MORE) +=more.o 30UTILLINUX-$(CONFIG_MORE) +=more.o
30UTILLINUX-$(CONFIG_MOUNT) +=mount.o 31UTILLINUX-$(CONFIG_MOUNT) +=mount.o
31UTILLINUX-$(CONFIG_FEATURE_MOUNT_NFS) +=nfsmount.o 32UTILLINUX-$(CONFIG_FEATURE_MOUNT_NFS) +=nfsmount.o
32UTILLINUX-$(CONFIG_PIVOT_ROOT) +=pivot_root.o 33UTILLINUX-$(CONFIG_PIVOT_ROOT) +=pivot_root.o
34UTILLINUX-$(CONFIG_SWITCH_ROOT) +=switch_root.o
33UTILLINUX-$(CONFIG_RDATE) +=rdate.o 35UTILLINUX-$(CONFIG_RDATE) +=rdate.o
34UTILLINUX-$(CONFIG_READPROFILE) +=readprofile.o 36UTILLINUX-$(CONFIG_READPROFILE) +=readprofile.o
35UTILLINUX-$(CONFIG_SWAPONOFF) +=swaponoff.o 37UTILLINUX-$(CONFIG_SWAPONOFF) +=swaponoff.o
diff --git a/util-linux/mdev.c b/util-linux/mdev.c
new file mode 100644
index 000000000..49904d17a
--- /dev/null
+++ b/util-linux/mdev.c
@@ -0,0 +1,121 @@
1/* vi:set ts=4:
2 *
3 * mdev - Mini udev for busybox
4 *
5 * Copyright 2005 Rob Landley <rob@landley.net>
6 * Copyright 2005 Frank Sorenson <frank@tuxrocks.com>
7 *
8 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
9 */
10
11#include <dirent.h>
12#include <errno.h>
13#include <fcntl.h>
14#include <stdio.h>
15#include <string.h>
16#include <sys/stat.h>
17#include <sys/types.h>
18#include <unistd.h>
19
20#define DEV_PATH "/dev"
21#define DEV_MODE 0660
22
23#include <busybox.h>
24
25/* mknod in /dev based on a path like "/sys/block/hda/hda1" */
26void make_device(char *path)
27{
28 char *device_name, *s;
29 int major,minor,type,len,fd;
30
31 RESERVE_CONFIG_BUFFER(temp,PATH_MAX);
32
33 /* Try to read major/minor string */
34
35 snprintf(temp, PATH_MAX, "%s/dev", path);
36 fd = open(temp, O_RDONLY);
37 len = read(fd, temp, PATH_MAX-1);
38 if (len<1) goto end;
39 temp[len] = 0;
40 close(fd);
41
42 /* Determine device name, type, major and minor */
43
44 device_name = strrchr(path, '/') + 1;
45 type = strncmp(path+5, "block/" ,6) ? S_IFCHR : S_IFBLK;
46 major = minor = 0;
47 for(s = temp; *s; s++) {
48 if(*s == ':') {
49 major = minor;
50 minor = 0;
51 } else {
52 minor *= 10;
53 minor += (*s) - '0';
54 }
55 }
56
57/* Open config file here, look up permissions */
58
59 sprintf(temp, "%s/%s", DEV_PATH, device_name);
60 if(mknod(temp, DEV_MODE | type, makedev(major, minor)) && errno != EEXIST)
61 bb_perror_msg_and_die("mknod %s failed", temp);
62
63/* Perform shellout here */
64
65end:
66 RELEASE_CONFIG_BUFFER(temp);
67}
68
69/* Recursive search of /sys/block or /sys/class. path must be a writeable
70 * buffer of size PATH_MAX containing the directory string to start at. */
71
72void find_dev(char *path)
73{
74 DIR *dir;
75 int len=strlen(path);
76
77 if(!(dir = opendir(path)))
78 bb_perror_msg_and_die("No %s",path);
79
80 for(;;) {
81 struct dirent *entry = readdir(dir);
82
83 if(!entry) break;
84
85 /* Skip "." and ".." (also skips hidden files, which is ok) */
86
87 if (entry->d_name[0]=='.') continue;
88
89 if (entry->d_type == DT_DIR) {
90 snprintf(path+len, PATH_MAX-len, "/%s", entry->d_name);
91 find_dev(path);
92 path[len] = 0;
93 }
94
95 /* If there's a dev entry, mknod it */
96
97 if (strcmp(entry->d_name, "dev")) make_device(path);
98 }
99
100 closedir(dir);
101}
102
103int mdev_main(int argc, char *argv[])
104{
105 if (argc > 1) {
106 if(argc == 2 && !strcmp(argv[1],"-s")) {
107 RESERVE_CONFIG_BUFFER(temp,PATH_MAX);
108 strcpy(temp,"/sys/block");
109 find_dev(temp);
110 strcpy(temp,"/sys/class");
111 find_dev(temp);
112 if(ENABLE_FEATURE_CLEAN_UP)
113 RELEASE_CONFIG_BUFFER(temp);
114 return 0;
115 } else bb_show_usage();
116 }
117
118/* hotplug support goes here */
119
120 return 0;
121}