Oups, sorry.. Just corrected, attached patch modified in consequence.

Size benchmark (Intel, defconfig):

Busybox before :
  text    data     bss     dec     hex filename
567869    3008   46992  617869   96d8d busybox

Busybox  patched :
  text    data     bss     dec     hex filename
567821    3008   46992  617821   96d5d busybox
diff -Nru busybox-1.4.1_original/util-linux/mdev.c busybox-1.4.1_modified/util-linux/mdev.c
--- busybox-1.4.1_original/util-linux/mdev.c	2007-01-24 22:34:51.000000000 +0100
+++ busybox-1.4.1_modified/util-linux/mdev.c	2007-06-11 16:26:15.874496968 +0200
@@ -14,6 +13,8 @@
 
 #define DEV_PATH	"/dev"
 
+#define MAX_DEPTH	3
+
 struct mdev_globals
 {
 	int root_major, root_minor;
@@ -194,41 +195,45 @@
 	if (delete) unlink(device_name);
 }
 
-/* Recursive search of /sys/block or /sys/class.  path must be a writeable
- * buffer of size PATH_MAX containing the directory string to start at. */
-
-static void find_dev(char *path)
+/* File action callback.
+ * 
+ */
+static int faction(const char *fileName, 
+			struct stat *statbuf, 
+			void* userData, int depth)
 {
-	DIR *dir;
-	size_t len = strlen(path);
-	struct dirent *entry;
-
-	dir = opendir(path);
-	if (dir == NULL)
-		return;
-
-	while ((entry = readdir(dir)) != NULL) {
-		struct stat st;
-
-		/* Skip "." and ".." (also skips hidden files, which is ok) */
-
-		if (entry->d_name[0] == '.')
-			continue;
-
-		// uClibc doesn't fill out entry->d_type reliably. so we use lstat().
+	char *pt;
+	
+	/* Remove path from fileName */
+	pt = strrchr(fileName,'/');
+	
+	if(!pt || strcmp(pt, DEV_PATH))
+		return FALSE;
+		
+	make_device(xasprintf("%.*s",pt-fileName,fileName), 0);
 
-		snprintf(path+len, PATH_MAX-len, "/%s", entry->d_name);
-		if (!lstat(path, &st) && S_ISDIR(st.st_mode)) find_dev(path);
-		path[len] = 0;
-
-		/* If there's a dev entry, mknod it */
-
-		if (!strcmp(entry->d_name, "dev")) make_device(path, 0);
-	}
+	return TRUE;	
+}
 
-	closedir(dir);
+/* Directory callback.
+ * Should return SKIP to stop traversal.
+ */
+static int daction(const char *fileName, 
+			struct stat *statbuf, 
+			void* userData, int depth)
+{
+	/* Maximum depth */ 
+	if(depth>=MAX_DEPTH)
+		return SKIP;
+		
+	return TRUE;
 }
 
+/* Recursive search of /sys/block or /sys/class.  
+ * The recursive depth is limited to avoid 
+ * inifinite loop (circular symlinks)
+ * (see udevstart.c)
+ */
 int mdev_main(int argc, char *argv[])
 {
 	char *action;
@@ -245,10 +250,20 @@
 		xstat("/", &st);
 		bbg.root_major = major(st.st_dev);
 		bbg.root_minor = minor(st.st_dev);
-		strcpy(temp,"/sys/block");
-		find_dev(temp);
-		strcpy(temp,"/sys/class");
-		find_dev(temp);
+		recursive_action("/sys/block", 
+				TRUE, TRUE,	/* Recurse, follow links */
+				FALSE,		/* no depth first */
+				faction, 	/* file action callback */
+				daction, 	/* dir action callback */
+				NULL, 0);
+
+		recursive_action("/sys/class", 
+				TRUE, TRUE,  	/* Recurse, follow links */
+				FALSE,		/* no depth first */
+				faction, 	/* file action callback */
+				daction, 	/* dir action callback */
+				NULL, 0);
+
 
 	/* Hotplug */
 
_______________________________________________
busybox mailing list
[email protected]
http://busybox.net/cgi-bin/mailman/listinfo/busybox

Reply via email to