[BusyBox] Another modprobe patch

Mike Castle dalgoda at ix.netcom.com
Thu Aug 12 06:21:17 UTC 2004


It turns out the insmod does not need full path to work.  So, to make our
lives easier, get rid of mod_strcmp and essentially use $(basename
/path/to/module/foo.o .o).

This simplifies logic by having the code that strips the extention in only
one place.  It also reduced the size of the .o file by 628 bytes, and
memory usage by 15k, on my modules.dep which is 111k in size.

I see one minor difference between busybox's modprobe and the real one:

If two modules are given to modprobe, the second one should be discarded.
With busyboxes, it's added as an argument to the last insmod.

Example:

thune:/usr/lib/busybox# bin/busybox modprobe -nv bar foo
insmod    firmware_class 
insmod    usbcore 
insmod    bluez 
insmod    bfusb foo 
thune:/usr/lib/busybox#  modprobe -nv bar foo
/sbin/insmod /lib/modules/2.4.25-mmx/kernel/lib/firmware_class.o
/sbin/insmod /lib/modules/2.4.25-mmx/kernel/drivers/usb/usbcore.o
/sbin/insmod /lib/modules/2.4.25-mmx/kernel/net/bluetooth/bluez.o
/sbin/insmod /lib/modules/2.4.25-mmx/kernel/drivers/bluetooth/bfusb.o


Anyway, the patch:

--- modprobe.c?rev=1.37	2004-08-11 22:59:17.000000000 -0700
+++ modprobe.c	2004-08-11 23:02:58.000000000 -0700
@@ -159,11 +159,11 @@
 
 		if ( !continuation_line ) {
 			char *col = strchr ( buffer, ':' );
+			char *dot = col;
 
 			if ( col ) {
 				char *mods;
 				char *mod;
-				int ext = 0;
 
 				*col = 0;
 				mods = strrchr ( buffer, '/' );
@@ -176,13 +176,13 @@
 #if defined(CONFIG_FEATURE_2_6_MODULES)
 				if ((k_version > 4) && ( *(col-3) == '.' ) &&
 						( *(col-2) == 'k' ) && ( *(col-1) == 'o' ))
-					ext = 3;
+					dot = col - 3;
 				else
 #endif
 					if (( *(col-2) == '.' ) && ( *(col-1) == 'o' ))
-						ext = 2;
+						dot = col - 2;
 
-				mod = bb_xstrndup ( buffer, col - buffer );
+				mod = bb_xstrndup ( mods, dot - mods );
 
 				if ( !current ) {
 					first = current = (struct dep_t *) xmalloc ( sizeof ( struct dep_t ));
@@ -357,29 +357,6 @@
 	return first;
 }
 
-/* check if /lib/modules/bar/foo.ko belongs to module foo */
-/* return 1 = found, 0 = not found                        */
-static int mod_strcmp ( const char *mod_path, const char *mod_name )
-{
-	/* last path component */
-	const char *last_comp = strrchr (mod_path, '/'); 
-	const char *mod_ext = ".o";
-
-#if defined(CONFIG_FEATURE_2_6_MODULES)
-	if ( k_version > 4 )
-		mod_ext = ".ko";
-#endif
-
-	last_comp = last_comp ? last_comp + 1 : mod_path;
-
-	return (strncmp(last_comp,
-					 mod_name,
-					 strlen(mod_name)) == 0 ) &&
-		   ((strcmp(last_comp + strlen (mod_name), mod_ext) == 0) || last_comp[strlen(mod_name)] == 0) &&
-		   (strcmp(mod_path + strlen(mod_path) -
-					strlen(mod_ext), mod_ext) == 0);
-}
-
 /* return 1 = loaded, 0 = not loaded, -1 = can't tell */
 static int already_loaded (const char *name)
 {
@@ -396,7 +373,7 @@
 		p = strchr (buffer, ' ');
 		if (p) {
 			*p = 0;
-			if (mod_strcmp (name, buffer)) {
+			if (strcmp (name, buffer) == 0) {
 				close (fd);
 				return 1;
 			}
@@ -450,23 +427,10 @@
 	struct mod_list_t *find;
 	struct dep_t *dt;
 	char *opt = 0;
-	int lm;
-
-	// remove .o extension
-	lm = bb_strlen ( mod );
-
-#if defined(CONFIG_FEATURE_2_6_MODULES)
-	if ((k_version > 4) && ( mod [lm-3] == '.' ) &&
-			( mod [lm-2] == 'k' ) && ( mod [lm-1] == 'o' ))
-		mod [lm-3] = 0;
-	else
-#endif
-		if (( mod [lm-2] == '.' ) && ( mod [lm-1] == 'o' ))
-			mod [lm-2] = 0;
 
 	// check dependencies
 	for ( dt = depend; dt; dt = dt-> m_next ) {
-		if ( mod_strcmp ( dt-> m_module, mod )) {
+		if ( strcmp ( dt-> m_module, mod ) == 0) {
 			mod = dt-> m_module;
 			opt = dt-> m_options;
 			break;
@@ -597,8 +561,6 @@
 
 }
 
-
-
 extern int modprobe_main(int argc, char** argv)
 {
 	int	opt;


-- 
     Mike Castle      dalgoda at ix.netcom.com      www.netcom.com/~dalgoda/
    We are all of us living in the shadow of Manhattan.  -- Watchmen
fatal ("You are in a maze of twisty compiler features, all different"); -- gcc



More information about the busybox mailing list