svn commit: trunk/busybox: docs util-linux

vapier at busybox.net vapier at busybox.net
Fri Feb 1 06:53:52 UTC 2008


Author: vapier
Date: 2008-01-31 22:53:50 -0800 (Thu, 31 Jan 2008)
New Revision: 20927

Log:
add support for renaming/relocating device nodes

Modified:
   trunk/busybox/docs/mdev.txt
   trunk/busybox/util-linux/Config.in
   trunk/busybox/util-linux/mdev.c


Changeset:
Modified: trunk/busybox/docs/mdev.txt
===================================================================
--- trunk/busybox/docs/mdev.txt	2008-02-01 01:41:57 UTC (rev 20926)
+++ trunk/busybox/docs/mdev.txt	2008-02-01 06:53:50 UTC (rev 20927)
@@ -53,6 +53,15 @@
 create your own total match like so:
 	.* 1:1 777
 
+You can rename/relocate device nodes by using the next optional field.
+	<device regex> <uid>:<gid> <octal permissions> [>path]
+So if you want to place the device node into a subdirectory, make sure the path
+has a trailing /.  If you want to rename the device node, just place the name.
+	hda 0:3 660 >drives/
+This will relocate "hda" into the drives/ subdirectory.
+	hdb 0:3 660 >cdrom
+This will rename "hdb" to "cdrom".
+
 If you also enable support for executing your own commands, then the file has
 the format:
 	<device regex> <uid>:<gid> <octal permissions> [<@|$|*> <command>]

Modified: trunk/busybox/util-linux/Config.in
===================================================================
--- trunk/busybox/util-linux/Config.in	2008-02-01 01:41:57 UTC (rev 20926)
+++ trunk/busybox/util-linux/Config.in	2008-02-01 06:53:50 UTC (rev 20927)
@@ -301,6 +301,15 @@
 
 	  For more information, please see docs/mdev.txt
 
+config FEATURE_MDEV_RENAME
+	bool "Support subdirs/symlinks"
+	default n
+	depends on FEATURE_MDEV_CONF
+	help
+	  Add support for renaming devices and creating symlinks.
+
+	  For more information, please see docs/mdev.txt
+
 config FEATURE_MDEV_EXEC
 	bool "Support command execution at device addition/removal"
 	default n

Modified: trunk/busybox/util-linux/mdev.c
===================================================================
--- trunk/busybox/util-linux/mdev.c	2008-02-01 01:41:57 UTC (rev 20926)
+++ trunk/busybox/util-linux/mdev.c	2008-02-01 06:53:50 UTC (rev 20927)
@@ -31,7 +31,11 @@
 	gid_t gid = 0;
 	char *temp = path + strlen(path);
 	char *command = NULL;
+	char *alias = NULL;
 
+	/* Force the configuration file settings exactly. */
+	umask(0);
+
 	/* Try to read major/minor string.  Note that the kernel puts \n after
 	 * the data, so we don't need to worry about null terminating the string
 	 * because sscanf() will stop at the first nondigit, which \n is.  We
@@ -70,7 +74,7 @@
 			++lineno;
 
 			/* Three fields: regex, uid:gid, mode */
-			for (field = 0; field < (3 + ENABLE_FEATURE_MDEV_EXEC); ++field) {
+			for (field = 0; field < (3 + ENABLE_FEATURE_MDEV_RENAME + ENABLE_FEATURE_MDEV_EXEC); ++field) {
 
 				/* Find a non-empty field */
 				char *val;
@@ -131,8 +135,17 @@
 					/* Mode device permissions */
 					mode = strtoul(val, NULL, 8);
 
-				} else if (ENABLE_FEATURE_MDEV_EXEC && field == 3) {
+				} else if (ENABLE_FEATURE_MDEV_RENAME && field == 3) {
 
+					if (*val != '>')
+						++field;
+					else
+						alias = xstrdup(val + 1);
+
+				}
+
+				if (ENABLE_FEATURE_MDEV_EXEC && field == 3 + ENABLE_FEATURE_MDEV_RENAME) {
+
 					/* Optional command to run */
 					const char *s = "@$*";
 					const char *s2 = strchr(s, *val);
@@ -167,20 +180,45 @@
  end_parse:	/* nothing */ ;
 	}
 
-	umask(0);
 	if (!delete) {
 		if (sscanf(temp, "%d:%d", &major, &minor) != 2)
 			return;
+
+		if (ENABLE_FEATURE_MDEV_RENAME)
+			unlink(device_name);
+
 		if (mknod(device_name, mode | type, makedev(major, minor)) && errno != EEXIST)
 			bb_perror_msg_and_die("mknod %s", device_name);
 
 		if (major == root_major && minor == root_minor)
 			symlink(device_name, "root");
 
-		if (ENABLE_FEATURE_MDEV_CONF)
+		if (ENABLE_FEATURE_MDEV_CONF) {
 			chown(device_name, uid, gid);
+
+			if (ENABLE_FEATURE_MDEV_RENAME && alias) {
+				char *dest;
+
+				temp = strrchr(alias, '/');
+				if (temp) {
+					if (temp[1] != '\0')
+						/* given a file name, so rename it */
+						*temp = '\0';
+					bb_make_directory(alias, 0755, FILEUTILS_RECUR);
+					dest = concat_path_file(alias, device_name);
+				} else
+					dest = alias;
+
+				rename(device_name, dest);
+				symlink(dest, device_name);
+
+				if (alias != dest)
+					free(alias);
+				free(dest);
+			}
+		}
 	}
-	if (command) {
+	if (ENABLE_FEATURE_MDEV_EXEC && command) {
 		/* setenv will leak memory, so use putenv */
 		char *s = xasprintf("MDEV=%s", device_name);
 		putenv(s);



More information about the busybox-cvs mailing list