diff options
author | Rob Landley <rob@landley.net> | 2005-12-13 08:21:33 +0000 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2005-12-13 08:21:33 +0000 |
commit | 70f7ef7be385f782e57106df523f1c5e16fbdc47 (patch) | |
tree | e560de3934ac70ae03dd77695450cff91bdfce0b /util-linux | |
parent | 3858bf18d5d3b6a858ca46acb6c8628715520d1c (diff) | |
download | busybox-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.)
Diffstat (limited to 'util-linux')
-rw-r--r-- | util-linux/Config.in | 30 | ||||
-rw-r--r-- | util-linux/Makefile.in | 2 | ||||
-rw-r--r-- | util-linux/mdev.c | 121 |
3 files changed, 153 insertions, 0 deletions
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 | ||
248 | config 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 | |||
257 | config 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 | |||
248 | config CONFIG_MKSWAP | 278 | config 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 | |||
24 | UTILLINUX-$(CONFIG_IPCRM) +=ipcrm.o | 24 | UTILLINUX-$(CONFIG_IPCRM) +=ipcrm.o |
25 | UTILLINUX-$(CONFIG_IPCS) +=ipcs.o | 25 | UTILLINUX-$(CONFIG_IPCS) +=ipcs.o |
26 | UTILLINUX-$(CONFIG_LOSETUP) +=losetup.o | 26 | UTILLINUX-$(CONFIG_LOSETUP) +=losetup.o |
27 | UTILLINUX-$(CONFIG_MDEV) +=mdev.o | ||
27 | UTILLINUX-$(CONFIG_MKFS_MINIX) +=mkfs_minix.o | 28 | UTILLINUX-$(CONFIG_MKFS_MINIX) +=mkfs_minix.o |
28 | UTILLINUX-$(CONFIG_MKSWAP) +=mkswap.o | 29 | UTILLINUX-$(CONFIG_MKSWAP) +=mkswap.o |
29 | UTILLINUX-$(CONFIG_MORE) +=more.o | 30 | UTILLINUX-$(CONFIG_MORE) +=more.o |
30 | UTILLINUX-$(CONFIG_MOUNT) +=mount.o | 31 | UTILLINUX-$(CONFIG_MOUNT) +=mount.o |
31 | UTILLINUX-$(CONFIG_FEATURE_MOUNT_NFS) +=nfsmount.o | 32 | UTILLINUX-$(CONFIG_FEATURE_MOUNT_NFS) +=nfsmount.o |
32 | UTILLINUX-$(CONFIG_PIVOT_ROOT) +=pivot_root.o | 33 | UTILLINUX-$(CONFIG_PIVOT_ROOT) +=pivot_root.o |
34 | UTILLINUX-$(CONFIG_SWITCH_ROOT) +=switch_root.o | ||
33 | UTILLINUX-$(CONFIG_RDATE) +=rdate.o | 35 | UTILLINUX-$(CONFIG_RDATE) +=rdate.o |
34 | UTILLINUX-$(CONFIG_READPROFILE) +=readprofile.o | 36 | UTILLINUX-$(CONFIG_READPROFILE) +=readprofile.o |
35 | UTILLINUX-$(CONFIG_SWAPONOFF) +=swaponoff.o | 37 | UTILLINUX-$(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" */ | ||
26 | void 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 | |||
65 | end: | ||
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 | |||
72 | void 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 | |||
103 | int 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 | } | ||