Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/modutils/modutils.c
- Timestamp:
- Dec 20, 2016, 4:07:32 PM (7 years ago)
- Location:
- branches/3.3
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3/mindi-busybox/modutils/modutils.c
r3232 r3621 17 17 #endif 18 18 19 static module_entry *helper_get_module(module_db *db, const char *module, int create) 20 { 21 char modname[MODULE_NAME_LEN]; 22 struct module_entry *e; 23 unsigned i, hash; 24 25 filename2modname(module, modname); 26 27 hash = 0; 28 for (i = 0; modname[i]; i++) 29 hash = ((hash << 5) + hash) + modname[i]; 30 hash %= MODULE_HASH_SIZE; 31 32 for (e = db->buckets[hash]; e; e = e->next) 33 if (strcmp(e->modname, modname) == 0) 34 return e; 35 if (!create) 36 return NULL; 37 38 e = xzalloc(sizeof(*e)); 39 e->modname = xstrdup(modname); 40 e->next = db->buckets[hash]; 41 db->buckets[hash] = e; 42 IF_DEPMOD(e->dnext = e->dprev = e;) 43 44 return e; 45 } 46 module_entry* FAST_FUNC moddb_get(module_db *db, const char *module) 47 { 48 return helper_get_module(db, module, 0); 49 } 50 module_entry* FAST_FUNC moddb_get_or_create(module_db *db, const char *module) 51 { 52 return helper_get_module(db, module, 1); 53 } 54 55 void FAST_FUNC moddb_free(module_db *db) 56 { 57 module_entry *e, *n; 58 unsigned i; 59 60 for (i = 0; i < MODULE_HASH_SIZE; i++) { 61 for (e = db->buckets[i]; e; e = n) { 62 n = e->next; 63 free(e->name); 64 free(e->modname); 65 free(e); 66 } 67 } 68 } 69 19 70 void FAST_FUNC replace(char *s, char what, char with) 20 71 { … … 48 99 char* FAST_FUNC filename2modname(const char *filename, char *modname) 49 100 { 101 char local_modname[MODULE_NAME_LEN]; 50 102 int i; 51 c har *from;103 const char *from; 52 104 53 105 if (filename == NULL) 54 106 return NULL; 55 107 if (modname == NULL) 56 modname = xmalloc(MODULE_NAME_LEN); 57 from = bb_get_last_path_component_nostrip(filename); 108 modname = local_modname; 109 // Disabled since otherwise "modprobe dir/name" would work 110 // as if it is "modprobe name". It is unclear why 111 // 'basenamization' was here in the first place. 112 //from = bb_get_last_path_component_nostrip(filename); 113 from = filename; 58 114 for (i = 0; i < (MODULE_NAME_LEN-1) && from[i] != '\0' && from[i] != '.'; i++) 59 115 modname[i] = (from[i] == '-') ? '_' : from[i]; 60 116 modname[i] = '\0'; 117 118 if (modname == local_modname) 119 return xstrdup(modname); 61 120 62 121 return modname; … … 183 242 } 184 243 244 /* Note: not suitable for delete_module() errnos. 245 * For them, probably only EWOULDBLOCK needs explaining: 246 * "Other modules depend on us". So far we don't do such 247 * translation and don't use moderror() for removal errors. 248 */ 185 249 const char* FAST_FUNC moderror(int err) 186 250 {
Note:
See TracChangeset
for help on using the changeset viewer.