mdev doesn't remove devices

Bernhard Fischer rep.nop at aon.at
Wed Aug 23 08:54:35 UTC 2006


On Wed, Aug 09, 2006 at 03:48:23PM +0100, Chris Steel wrote:
>I've built a rootfs with uclibc 0.9.28 and busybox 1.2.1 and set up mdev rather than udev. I've noticed that when I plug in a USB stick all the expected devices are created in /dev, but when I unplug the stick none of the devices get removed from /dev. This seems to be down to mdev checking if each new entry in /sys has a dev component containing the major and minor device numbers, and only creating a device if it can get the device numbers. This works fine for creating the devices, but when it comes to removing them, the dev component has been removed from /sys before the hotplug event arrives, so nothing ever gets removed.
>
>The attached patch stops mdev checking for device numbers (which it doesn't need to delete a device) on remove events, and this makes mdev work like I was expecting. It'll try to delete a lot of devices which is hasn't created but I think that this is OK as they non existant devices all have weird names like 4-1:1-0 which are unlikely to duplicate the name of an existing legitimate device.
>
>Is this a valid fix, or have I just broken mdev in some way that I don't appreciate?
>
> 		
>---------------------------------
> All new Yahoo! Mail "The new Interface is stunning in its simplicity and ease of use." - PC Magazine
Content-Description: 1320694326-mdev_remove.patch
>diff -urN busybox-1.2.1-clean/util-linux/mdev.c busybox-1.2.1/util-linux/mdev.c
>--- busybox-1.2.1-clean/util-linux/mdev.c	2006-06-30 23:42:13.000000000 +0100
>+++ busybox-1.2.1/util-linux/mdev.c	2006-08-09 15:22:06.000000000 +0100
>@@ -40,18 +40,20 @@
> 	 * because sscanf() will stop at the first nondigit, which \n is.  We
> 	 * also depend on path having writeable space after it. */
> 
>-	strcat(path, "/dev");
>-	fd = open(path, O_RDONLY);
>-	len = read(fd, temp + 1, 64);
>-	*temp++ = 0;
>-	close(fd);
>-	if (len < 1) return;
>-
>+	if (!delete)
>+	{
>+		strcat(path, "/dev");

Didn't look, but would it be benefical to remove the constraint that
path is pre-allocated and use concat_path_file() here?

Also, it looks like the initialization of *command above should be moved
to below this "if (!delete)" clause -- potentially saves space.

Furthermore, why is umask(0) further down not placed into the "if
(!delete)" clause as this seems to be the only place where it would be
needed?

Did someone already look at mdev with size in mind? Just curious as i
didn't look at it (yet)..

Bernhard
>+		fd = open(path, O_RDONLY);
>+		if (fd < 0) return;
>+		len = read(fd, temp + 1, 64);
>+		*temp++ = 0;
>+		close(fd);
>+		if (len < 1) return;
>+	}
> 	/* Determine device name, type, major and minor */
> 
> 	device_name = strrchr(path, '/') + 1;
> 	type = path[5]=='c' ? S_IFCHR : S_IFBLK;
>-	if (sscanf(temp, "%d:%d", &major, &minor) != 2) return;
> 
> 	/* If we have a config file, look up permissions for this device */
> 
>@@ -167,6 +169,8 @@
> 
> 	umask(0);
> 	if (!delete) {
>+		if (sscanf(temp, "%d:%d", &major, &minor) != 2) return;
>+
> 		if (mknod(device_name, mode | type, makedev(major, minor)) && errno != EEXIST)
> 			bb_perror_msg_and_die("mknod %s failed", device_name);
> 



More information about the busybox mailing list