[BusyBox] A busybox developper can help me to patch?

Henrion Benjamin bh at udev.org
Fri Mar 7 20:32:03 UTC 2003


Hello,

I'm not a C developper, I don't know C at all, but I'm using busybox to
make a wireless router supporting aodv/ipv6.

I'm using the latest unstable version, because I need the ipv6 support,
which is not included in the stable version.

I need to gzip the modules of the kernel (ipv6.o and hostap.o, they
are heavy in space), so as to win 100Ko to fit on the 1MB flash I've.

I've tried to cut and paste the patch posted on the ml of April2002, but
it seems that the code has changed in some places. I've never done
nothing in C, so can somebody patch (take a look at the differences, in
some places, it's just a simple cut/paste) it for me?

I enclose the patches that were already posted on the ml, you just need
the older cvs files to see what have changed...

Can you help me?

-- 
Benjamin Henrion <bh at udev.org>
http://bh.udev.org
-------------- next part --------------
--- insmod.orig.c	Thu Apr 11 21:59:21 2002
+++ insmod.c	Sat Apr 27 15:24:56 2002
@@ -623,6 +623,7 @@
 static int flag_autoclean = 0;
 static int flag_verbose = 0;
 static int flag_export = 1;
+static int flag_gunzip = 0;
 
 
 /*======================================================================*/
@@ -3203,6 +3204,11 @@
 				ELFW(ST_INFO) (STB_LOCAL, ELFW(ST_TYPE) (sym->info));
 }
 
+void delete_unziped_module(char *name)
+{
+	if (unlink(name) < 0)
+		fprintf(stderr, "Couldnt remove %s", name);
+}
 
 
 extern int insmod_main( int argc, char **argv)
@@ -3218,6 +3224,7 @@
 	struct obj_file *f;
 	struct stat st;
 	char m_name[FILENAME_MAX + 1] = "\0";
+	char m_ext[6];
 	int exit_status = EXIT_FAILURE;
 	int m_has_modinfo;
 #ifdef BB_FEATURE_INSMOD_VERSION_CHECKING
@@ -3228,8 +3235,11 @@
 #endif
 
 	/* Parse any options */
-	while ((opt = getopt(argc, argv, "fkvxLo:")) > 0) {
+	while ((opt = getopt(argc, argv, "zfkvxLo:")) > 0) {
 		switch (opt) {
+			case 'z':           /* gunzip module */
+				flag_gunzip = 1;
+				break;
 			case 'f':			/* force loading */
 				flag_force_load = 1;
 				break;
@@ -3267,15 +3277,25 @@
 		tmp = argv[optind];
 	}
 	len = strlen(tmp);
-
-	if (len > 2 && tmp[len - 2] == '.' && tmp[len - 1] == 'o')
-		len -= 2;
+	
+	if (flag_gunzip)
+	{
+		strcpy(m_ext, ".o.gz");
+		if (len > 5 && tmp[len - 5] == '.' && tmp[len - 4] == 'o' && tmp[len - 3] == '.' && tmp[len - 2] == 'g' && tmp[len - 1] == 'z')
+			len -= 5;
+	}
+	else
+	{
+		strcpy(m_ext, ".o");
+		if (len > 2 && tmp[len - 2] == '.' && tmp[len - 1] == 'o')
+			len -= 2;
+	}
 	memcpy(m_fullName, tmp, len);
 	m_fullName[len]='\0';
 	if (*m_name == '\0') {
 		strcpy(m_name, m_fullName);
 	}
-	strcat(m_fullName, ".o");
+	strcat(m_fullName, m_ext);
 
 	/* Get a filedesc for the module.  Check we we have a complete path */
 	if (stat(argv[optind], &st) < 0 || !S_ISREG(st.st_mode) ||
@@ -3323,11 +3343,52 @@
 	} else 
 		safe_strncpy(m_filename, argv[optind], sizeof(m_filename));
 
+	if (flag_gunzip)
+	{
+		FILE *fp_unziped;
+		int my_len;
+		char m_filename_unziped[FILENAME_MAX + 1] = "\0";	
+		
+		strcpy(m_filename_unziped, m_filename);
+		my_len = strlen(m_filename_unziped);
+		m_filename_unziped[my_len - 3] = '\0';
+		
+		if ((fp_unziped = fopen (m_filename_unziped, "w")) == NULL)
+		{
+			perror(m_filename_unziped);
+			return EXIT_FAILURE;
+		}
+		
+		if (unzip(fp, fp_unziped) != 0)
+		{
+			fclose(fp);
+			fclose(fp_unziped);
+			error_msg("unable to gunzip %s", m_filename_unziped);
+			delete_unziped_module(m_filename_unziped);
+			return EXIT_FAILURE;
+		}
+		
+		fclose(fp);
+		fclose(fp_unziped);
+
+		strcpy(m_filename, m_filename_unziped);
+		
+		if ((fp = fopen (m_filename, "r")) == NULL)
+		{
+			perror(m_filename);
+			return EXIT_FAILURE;
+		}
+	}
+	
 	printf("Using %s\n", m_filename);
 
 	if ((f = obj_load(fp, LOADBITS)) == NULL)
+	{
+		if (flag_gunzip)
+			delete_unziped_module(m_filename);
 		perror_msg_and_die("Could not load the module");
-
+	}
+	
 	if (get_modinfo_value(f, "kernel_version") == NULL)
 		m_has_modinfo = 0;
 	else
@@ -3479,5 +3540,7 @@
 
 out:
 	fclose(fp);
+	if (flag_gunzip)
+		delete_unziped_module(m_filename);
 	return(exit_status);
 }
-------------- next part --------------
--- modprobe.orig.c	Wed Apr 24 15:49:03 2002
+++ modprobe.c	Sat Apr 27 16:35:24 2002
@@ -18,6 +18,7 @@
 #include "busybox.h"
 
 static char cmd[128];
+static int unzip_module = 0;
 
 #define BB_FEATURE_MODPROBE_DEPEND
 
@@ -188,8 +189,16 @@
 	}
 	if ( loadit ) {
 		char lcmd [128];
+
+		if (unzip_module) {
+			int my_len;
+			
+			my_len=strlen(mod);
+			if (mod[my_len - 2] == '.' && mod[my_len - 1] == 'o')
+				mod[my_len - 2] = '\0';
+		}
 		
-		sprintf ( lcmd, "insmod -k %s 2>/dev/null", mod );
+		sprintf ( lcmd, "insmod -k %s %s 2>/dev/null",unzip_module ? "-z" : "" , mod);
 		system ( lcmd );	
 	}
 }	
@@ -204,8 +213,11 @@
 	int	show_only = 0, quiet = 0, remove_opt = 0, do_syslog = 0, verbose = 0;
 	char	*load_type = NULL, *config = NULL;
 
-	while ((ch = getopt(argc, argv, "acdklnqrst:vVC:")) != -1)
+	while ((ch = getopt(argc, argv, "zacdklnqrst:vVC:")) != -1)
 		switch(ch) {
+		case 'z':
+			unzip_module = 1;
+			break;
 		case 'a':
 			loadall++;
 			break;
@@ -280,10 +292,11 @@
 		exit(EXIT_FAILURE);
 	}
 
-	sprintf(cmd, "insmod %s %s %s",
+	sprintf(cmd, "insmod %s %s %s %s",
 			do_syslog ? "-s" : "",
 			quiet ? "-q" : "",
-			autoclean ? "-k" : "");
+			autoclean ? "-k" : "",
+			unzip_module ? "-z" : "");
 
 #ifdef BB_FEATURE_MODPROBE_DEPEND
 	check_dep ( argv [optind], 0 );
-------------- next part --------------
--- usage.orig.h	Fri Apr 26 03:06:23 2002
+++ usage.h	Sat Apr 27 15:34:59 2002
@@ -815,6 +815,7 @@
 	"\t-k\tMake module autoclean-able.\n" \
 	"\t-v\tverbose output\n"  \
 	"\t-L\tLock to prevent simultaneous loads of a module\n" \
+	"\t-z\tsupport for gzip'ed modules\n"\
 	"\t-x\tdo not export externs"
 
 #define kill_trivial_usage \
@@ -1110,7 +1111,10 @@
 #define modprobe_trivial_usage \
 	"[FILE ...]"
 #define modprobe_full_usage \
-	"Used for hight level module loading and unloading."
+	"Used for hight level module loading and unloading.\n\n"\
+	"Options:\n"\
+	"\t-z\tSupport for gzip'ed modules\n"
+	
 #define modprobe_example_usage \
 	"$ modprobe cdrom\n" 


More information about the busybox mailing list