1 diff -Naur busybox.orig/util-linux/Config.in busybox/util-linux/Config.in
2 --- busybox.orig/util-linux/Config.in 2008-03-22 09:11:36 +0000
3 +++ busybox/util-linux/Config.in 2008-03-22 15:25:22 +0000
6 For more information, please see docs/mdev.txt
8 +config FEATURE_MDEV_RENAME_REGEXP
9 + bool "Support regular expressions substitutions when renaming device"
11 + depends on FEATURE_MDEV_RENAME
13 + Add support for regular expressions substitutions when renaming device.
15 config FEATURE_MDEV_EXEC
16 bool "Support command execution at device addition/removal"
18 diff -Naur busybox.orig/util-linux/mdev.c busybox/util-linux/mdev.c
19 --- busybox.orig/util-linux/mdev.c 2008-03-17 18:23:37 +0000
20 +++ busybox/util-linux/mdev.c 2008-03-22 19:15:10 +0000
23 #define MAX_SYSFS_DEPTH 3 /* prevent infinite loops in /sys symlinks */
25 +#if ENABLE_FEATURE_MDEV_RENAME_REGEXP
26 +static char *strsubst(const char *s, const char *str, regmatch_t *vals)
28 + char *buf = xzalloc(PATH_MAX), *p = buf;
32 + int n = vals[i].rm_eo-vals[i].rm_so;
33 + strncpy(p, str+vals[i].rm_so, n);
44 /* mknod in /dev based on a path like "/sys/block/hda/hda1" */
45 static void make_device(char *path, int delete)
49 while ((vline = line = xmalloc_getline(fp)) != NULL) {
51 +#if ENABLE_FEATURE_MDEV_RENAME_REGEXP
55 /* A pristine copy for command execution. */
59 /* Regex to match this device */
61 +#if !ENABLE_FEATURE_MDEV_RENAME_REGEXP
67 xregcomp(&match, val, REG_EXTENDED);
68 +#if ENABLE_FEATURE_MDEV_RENAME_REGEXP
69 + result = regexec(&match, device_name, 10, off, 0);
71 result = regexec(&match, device_name, 1, &off, 0);
75 /* If not this device, skip rest of line */
76 +#if ENABLE_FEATURE_MDEV_RENAME_REGEXP
77 + if (result || off[0].rm_so || off[0].rm_eo != strlen(device_name))
79 if (result || off.rm_so || off.rm_eo != strlen(device_name))
83 } else if (field == 1) {
90 +#if ENABLE_FEATURE_MDEV_RENAME_REGEXP
91 + // substitute %1..9 with off[1..9], if any
92 + alias = strsubst(val + 1, device_name, off);
94 alias = xstrdup(val + 1);
103 temp = strrchr(alias, '/');
104 +#if ENABLE_FEATURE_MDEV_RENAME_REGEXP
105 + // directory given ->
106 + if (temp && temp[1] == '\0') {
108 + bb_make_directory(alias, 0755, FILEUTILS_RECUR);
109 + // compose device new location
110 + dest = concat_path_file(alias, device_name);
111 + // filename given ->
114 + dest = xstrdup(alias);
115 + // create parent directories
116 + bb_make_directory(dirname(alias), 0755, FILEUTILS_RECUR);
121 /* given a file name, so rename it */
123 dest = concat_path_file(alias, device_name);
128 rename(device_name, dest); // TODO: xrename?
129 symlink(dest, device_name);