wok-next annotate busybox/stuff/busybox-1.12.0-zmodules.u @ rev 1299

Up busybox (1.12.0) with built in module-init-tools
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Aug 21 20:11:27 2008 +0000 (2008-08-21)
parents
children ce72aad145d4
rev   line source
pascal@1299 1 --- busybox-1.12.0/modutils/depmod.c
pascal@1299 2 +++ busybox-1.12.0/modutils/depmod.c
pascal@1299 3 @@ -53,27 +53,14 @@ static int FAST_FUNC fileAction(const ch
pascal@1299 4 size_t len = sb->st_size;
pascal@1299 5 void *the_module;
pascal@1299 6 char *ptr;
pascal@1299 7 - int fd;
pascal@1299 8 char *depends, *deps;
pascal@1299 9 dep_lst_t *this;
pascal@1299 10 + extern void *xalloc_load_module(const char filename[], size_t *len);
pascal@1299 11
pascal@1299 12 if (strrstr(fname, ".ko") == NULL) /* not a module */
pascal@1299 13 goto skip;
pascal@1299 14
pascal@1299 15 -/*XXX: FIXME: does not handle compressed modules!
pascal@1299 16 - * There should be a function that looks at the extension and sets up
pascal@1299 17 - * open_transformer for us.
pascal@1299 18 - */
pascal@1299 19 - fd = xopen(fname, O_RDONLY);
pascal@1299 20 - the_module = mmap(NULL, len, PROT_READ, MAP_SHARED
pascal@1299 21 -#if defined MAP_POPULATE
pascal@1299 22 - |MAP_POPULATE
pascal@1299 23 -#endif
pascal@1299 24 - , fd, 0);
pascal@1299 25 - close(fd);
pascal@1299 26 - if (the_module == MAP_FAILED)
pascal@1299 27 - bb_perror_msg_and_die("mmap");
pascal@1299 28 -
pascal@1299 29 + the_module = xalloc_load_module(fname, &len);
pascal@1299 30 this = xzalloc(sizeof(dep_lst_t));
pascal@1299 31 this->name = xstrdup(fname);
pascal@1299 32 this->next = G.lst;
pascal@1299 33 @@ -104,7 +91,7 @@ static int FAST_FUNC fileAction(const ch
pascal@1299 34 pos = (ptr - (char*)the_module);
pascal@1299 35 } while (1);
pascal@1299 36 }
pascal@1299 37 - munmap(the_module, sb->st_size);
pascal@1299 38 + free(the_module);
pascal@1299 39 skip:
pascal@1299 40 return TRUE;
pascal@1299 41 }
pascal@1299 42
pascal@1299 43 --- busybox-1.12.0/modutils/insmod.c
pascal@1299 44 +++ busybox-1.12.0/modutils/insmod.c
pascal@1299 45 @@ -59,6 +59,7 @@
pascal@1299 46 */
pascal@1299 47
pascal@1299 48 #include "libbb.h"
pascal@1299 49 +#include "unarchive.h"
pascal@1299 50 #include <libgen.h>
pascal@1299 51 #include <sys/utsname.h>
pascal@1299 52
pascal@1299 53 @@ -4212,6 +4213,45 @@ static const char *moderror(int err)
pascal@1299 54 }
pascal@1299 55 }
pascal@1299 56
pascal@1299 57 +void *xalloc_load_module(const char filename[], size_t *len);
pascal@1299 58 +void *xalloc_load_module(const char filename[], size_t *len)
pascal@1299 59 +{
pascal@1299 60 + int fd, max;
pascal@1299 61 + unsigned char head[16];
pascal@1299 62 + void *map;
pascal@1299 63 + size_t l;
pascal@1299 64 +
pascal@1299 65 + max = 8 * 1024;
pascal@1299 66 + fd = open(filename, O_RDONLY);
pascal@1299 67 + if (fd < 0) return NULL;
pascal@1299 68 + xread(fd,head,sizeof(head));
pascal@1299 69 + lseek(fd,0L,SEEK_SET);
pascal@1299 70 + if (head[0] == 0x1f && head[1] == 0x8b) { /* gzip */
pascal@1299 71 + open_transformer(fd, unpack_gz_stream, "gunzip");
pascal@1299 72 + }
pascal@1299 73 + else if (head[0] == 'B' && head[1] == 'Z' &&
pascal@1299 74 + head[2] == 'h' && isdigit(head[3])) { /* bzip2 */
pascal@1299 75 + open_transformer(fd, unpack_bz2_stream, "bunzip2");
pascal@1299 76 + }
pascal@1299 77 + else if (head[1] != 'E' || head[2] != 'L' || head[3] != 'F') {
pascal@1299 78 + open_transformer(fd, unpack_lzma_stream, "unlzma");
pascal@1299 79 + if (* (unsigned *) (head + 9) == 0)
pascal@1299 80 + max = 1 + head[5] + (head[6]<<8)
pascal@1299 81 + + (head[7]<<16) + (head[8]<<24);
pascal@1299 82 + }
pascal@1299 83 + l = 0;
pascal@1299 84 + map = xmalloc(max);
pascal@1299 85 + while (1) {
pascal@1299 86 + l += full_read(fd, l + (char *) map, max - l);
pascal@1299 87 + if (l != max) break;
pascal@1299 88 + max <<= 1;
pascal@1299 89 + map = xrealloc(map, max);
pascal@1299 90 + }
pascal@1299 91 + if (len)
pascal@1299 92 + *len = l;
pascal@1299 93 + return xrealloc(map, l);
pascal@1299 94 +}
pascal@1299 95 +
pascal@1299 96 #if !ENABLE_FEATURE_2_4_MODULES
pascal@1299 97 int insmod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
pascal@1299 98 int insmod_main(int argc UNUSED_PARAM, char **argv)
pascal@1299 99 @@ -4264,8 +4304,7 @@ static int insmod_ng_main(int argc UNUSE
pascal@1299 100 xread(fd, map, len);
pascal@1299 101 }
pascal@1299 102 #else
pascal@1299 103 - len = MAXINT(ssize_t);
pascal@1299 104 - map = xmalloc_open_read_close(filename, &len);
pascal@1299 105 + map = xalloc_load_module(filename, &len);
pascal@1299 106 #endif
pascal@1299 107
pascal@1299 108 if (init_module(map, len, options) != 0)
pascal@1299 109
pascal@1299 110 --- busybox-1.12.0/modutils/modprobe.c
pascal@1299 111 +++ busybox-1.12.0/modutils/modprobe.c
pascal@1299 112 @@ -396,6 +396,29 @@ static int include_conf_file2(struct inc
pascal@1299 113 return include_conf_file(conf, oldname);
pascal@1299 114 }
pascal@1299 115
pascal@1299 116 +static int ext_size(char *end USE_FEATURE_2_6_MODULES(, int k_version))
pascal@1299 117 +{
pascal@1299 118 + int ext;
pascal@1299 119 + char *next;
pascal@1299 120 +
pascal@1299 121 + ext = 0;
pascal@1299 122 + if (end[-2] == '.' && end[-1] == 'g' && end[0] == 'z')
pascal@1299 123 + ext = 3;
pascal@1299 124 + if (end[-3] == '.' && end[-2] == 'b' && end[-1] == 'z' && end[0] == '2')
pascal@1299 125 + ext = 4;
pascal@1299 126 + next = end - ext;
pascal@1299 127 +#if ENABLE_FEATURE_2_6_MODULES
pascal@1299 128 + if (ENABLE_FEATURE_2_6_MODULES
pascal@1299 129 + && (k_version > 4) && (next[-2] == '.')
pascal@1299 130 + && (next[-1] == 'k') && (next[0] == 'o'))
pascal@1299 131 + ext += 3;
pascal@1299 132 + else
pascal@1299 133 +#endif
pascal@1299 134 + if ((next[-1] == '.') && (next[0] == 'o'))
pascal@1299 135 + ext += 2;
pascal@1299 136 + return ext;
pascal@1299 137 +}
pascal@1299 138 +
pascal@1299 139 /*
pascal@1299 140 * This function builds a list of dependency rules from /lib/modules/`uname -r`/modules.dep.
pascal@1299 141 * It then fills every modules and aliases with their default options, found by parsing
pascal@1299 142 @@ -464,12 +487,7 @@ static struct dep_t *build_dep(void)
pascal@1299 143 if (!modpath)
pascal@1299 144 modpath = line_buffer; /* module with no path */
pascal@1299 145 /* find the end of the module name in the file name */
pascal@1299 146 - if (ENABLE_FEATURE_2_6_MODULES &&
pascal@1299 147 - (k_version > 4) && (col[-3] == '.') &&
pascal@1299 148 - (col[-2] == 'k') && (col[-1] == 'o'))
pascal@1299 149 - dot = col - 3;
pascal@1299 150 - else if ((col[-2] == '.') && (col[-1] == 'o'))
pascal@1299 151 - dot = col - 2;
pascal@1299 152 + dot = col - ext_size(col - 1 USE_FEATURE_2_6_MODULES(, k_version));
pascal@1299 153
pascal@1299 154 mod = xstrndup(mods, dot - mods);
pascal@1299 155
pascal@1299 156 @@ -522,12 +540,7 @@ static struct dep_t *build_dep(void)
pascal@1299 157 deps = skip_whitespace(deps);
pascal@1299 158
pascal@1299 159 /* find the end of the module name in the file name */
pascal@1299 160 - if (ENABLE_FEATURE_2_6_MODULES
pascal@1299 161 - && (k_version > 4) && (next[-2] == '.')
pascal@1299 162 - && (next[-1] == 'k') && (next[0] == 'o'))
pascal@1299 163 - ext = 3;
pascal@1299 164 - else if ((next[-1] == '.') && (next[0] == 'o'))
pascal@1299 165 - ext = 2;
pascal@1299 166 + ext = ext_size(next USE_FEATURE_2_6_MODULES(, k_version));
pascal@1299 167
pascal@1299 168 /* Cope with blank lines */
pascal@1299 169 if ((next - deps - ext + 1) <= 0)