Lucas De Marchi | 8f788d5 | 2011-11-25 01:22:56 -0200 | [diff] [blame] | 1 | /* |
| 2 | * libkmod - interface to kernel module operations |
| 3 | * |
| 4 | * Copyright (C) 2011 ProFUSION embedded systems |
Lucas De Marchi | 8f788d5 | 2011-11-25 01:22:56 -0200 | [diff] [blame] | 5 | * |
| 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Lesser General Public |
| 8 | * License as published by the Free Software Foundation version 2.1. |
| 9 | * |
| 10 | * This library is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU Lesser General Public |
| 16 | * License along with this library; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
Lucas De Marchi | 7636e72 | 2011-12-01 17:56:03 -0200 | [diff] [blame] | 20 | #include <assert.h> |
Lucas De Marchi | 8f788d5 | 2011-11-25 01:22:56 -0200 | [diff] [blame] | 21 | #include <stdio.h> |
| 22 | #include <stdlib.h> |
| 23 | #include <stddef.h> |
| 24 | #include <stdarg.h> |
| 25 | #include <unistd.h> |
| 26 | #include <errno.h> |
| 27 | #include <string.h> |
| 28 | #include <ctype.h> |
| 29 | #include <inttypes.h> |
Gustavo Sverzut Barbieri | f12ae3c | 2011-12-04 12:40:00 -0200 | [diff] [blame] | 30 | #include <limits.h> |
| 31 | #include <dirent.h> |
Lucas De Marchi | 8f788d5 | 2011-11-25 01:22:56 -0200 | [diff] [blame] | 32 | #include <sys/stat.h> |
| 33 | #include <sys/types.h> |
| 34 | #include <sys/mman.h> |
| 35 | #include <string.h> |
| 36 | |
| 37 | #include "libkmod.h" |
| 38 | #include "libkmod-private.h" |
| 39 | |
| 40 | /** |
| 41 | * kmod_module: |
| 42 | * |
| 43 | * Opaque object representing a module. |
| 44 | */ |
| 45 | struct kmod_module { |
| 46 | struct kmod_ctx *ctx; |
Gustavo Sverzut Barbieri | f1fb6f8 | 2011-12-08 04:44:03 -0200 | [diff] [blame^] | 47 | char *path; |
Lucas De Marchi | 7636e72 | 2011-12-01 17:56:03 -0200 | [diff] [blame] | 48 | struct kmod_list *dep; |
Gustavo Sverzut Barbieri | 8d3f3ef | 2011-12-02 21:10:24 -0200 | [diff] [blame] | 49 | int refcount; |
Lucas De Marchi | 7636e72 | 2011-12-01 17:56:03 -0200 | [diff] [blame] | 50 | struct { |
| 51 | bool dep : 1; |
| 52 | } init; |
Lucas De Marchi | d753b8c | 2011-12-05 18:14:51 -0200 | [diff] [blame] | 53 | char name[]; |
Lucas De Marchi | 8f788d5 | 2011-11-25 01:22:56 -0200 | [diff] [blame] | 54 | }; |
| 55 | |
Lucas De Marchi | 6c343b1 | 2011-12-06 09:01:01 -0200 | [diff] [blame] | 56 | static inline char *modname_normalize(char *modname, char buf[NAME_MAX], |
| 57 | size_t *len) |
Lucas De Marchi | 8f788d5 | 2011-11-25 01:22:56 -0200 | [diff] [blame] | 58 | { |
Lucas De Marchi | 8f788d5 | 2011-11-25 01:22:56 -0200 | [diff] [blame] | 59 | char *c; |
Lucas De Marchi | d753b8c | 2011-12-05 18:14:51 -0200 | [diff] [blame] | 60 | size_t s; |
Lucas De Marchi | 8f788d5 | 2011-11-25 01:22:56 -0200 | [diff] [blame] | 61 | |
Lucas De Marchi | d753b8c | 2011-12-05 18:14:51 -0200 | [diff] [blame] | 62 | if (buf) { |
| 63 | buf[NAME_MAX] = '\0'; |
| 64 | modname = strncpy(buf, modname, NAME_MAX - 1); |
Lucas De Marchi | 8f788d5 | 2011-11-25 01:22:56 -0200 | [diff] [blame] | 65 | } |
| 66 | |
Lucas De Marchi | d753b8c | 2011-12-05 18:14:51 -0200 | [diff] [blame] | 67 | for (c = modname, s = 0; *c != '\0' && *c != '.'; c++) { |
| 68 | if (*c == '-') |
| 69 | *c = '_'; |
| 70 | s++; |
| 71 | } |
| 72 | |
| 73 | if (len) |
| 74 | *len = s; |
| 75 | |
Lucas De Marchi | 8f788d5 | 2011-11-25 01:22:56 -0200 | [diff] [blame] | 76 | *c = '\0'; |
Lucas De Marchi | d753b8c | 2011-12-05 18:14:51 -0200 | [diff] [blame] | 77 | |
Lucas De Marchi | 8f788d5 | 2011-11-25 01:22:56 -0200 | [diff] [blame] | 78 | return modname; |
| 79 | } |
| 80 | |
Lucas De Marchi | 6c343b1 | 2011-12-06 09:01:01 -0200 | [diff] [blame] | 81 | static char *path_to_modname(const char *path, char buf[NAME_MAX], size_t *len) |
| 82 | { |
| 83 | char *modname; |
| 84 | |
| 85 | modname = basename(path); |
| 86 | if (modname == NULL || modname[0] == '\0') |
| 87 | return NULL; |
| 88 | |
| 89 | return modname_normalize(modname, buf, len); |
| 90 | } |
| 91 | |
Lucas De Marchi | 671d489 | 2011-12-05 20:23:05 -0200 | [diff] [blame] | 92 | int kmod_module_parse_depline(struct kmod_module *mod, char *line) |
Lucas De Marchi | 7636e72 | 2011-12-01 17:56:03 -0200 | [diff] [blame] | 93 | { |
| 94 | struct kmod_ctx *ctx = mod->ctx; |
| 95 | struct kmod_list *list = NULL; |
| 96 | char *p, *saveptr; |
| 97 | int err, n = 0; |
| 98 | |
| 99 | assert(!mod->init.dep && mod->dep == NULL); |
| 100 | mod->init.dep = true; |
| 101 | |
| 102 | p = strchr(line, ':'); |
| 103 | if (p == NULL) |
| 104 | return 0; |
| 105 | |
Lucas De Marchi | 671d489 | 2011-12-05 20:23:05 -0200 | [diff] [blame] | 106 | *p = '\0'; |
| 107 | if (mod->path == NULL) |
| 108 | mod->path = strdup(line); |
| 109 | |
Lucas De Marchi | 7636e72 | 2011-12-01 17:56:03 -0200 | [diff] [blame] | 110 | p++; |
| 111 | |
| 112 | for (p = strtok_r(p, " \t", &saveptr); p != NULL; |
| 113 | p = strtok_r(NULL, " \t", &saveptr)) { |
Lucas De Marchi | d753b8c | 2011-12-05 18:14:51 -0200 | [diff] [blame] | 114 | const char *modname = path_to_modname(p, NULL, NULL); |
Lucas De Marchi | 1fc1c9a | 2011-12-02 10:00:03 -0200 | [diff] [blame] | 115 | struct kmod_module *depmod; |
Lucas De Marchi | 7636e72 | 2011-12-01 17:56:03 -0200 | [diff] [blame] | 116 | |
Lucas De Marchi | 1fc1c9a | 2011-12-02 10:00:03 -0200 | [diff] [blame] | 117 | err = kmod_module_new_from_name(ctx, modname, &depmod); |
Lucas De Marchi | 7636e72 | 2011-12-01 17:56:03 -0200 | [diff] [blame] | 118 | if (err < 0) { |
| 119 | ERR(ctx, "ctx=%p modname=%s error=%s\n", |
| 120 | ctx, modname, strerror(-err)); |
| 121 | goto fail; |
| 122 | } |
| 123 | |
| 124 | DBG(ctx, "add dep: %s\n", modname); |
| 125 | |
Lucas De Marchi | 1fc1c9a | 2011-12-02 10:00:03 -0200 | [diff] [blame] | 126 | list = kmod_list_append(list, depmod); |
Lucas De Marchi | 7636e72 | 2011-12-01 17:56:03 -0200 | [diff] [blame] | 127 | n++; |
| 128 | } |
| 129 | |
| 130 | DBG(ctx, "%d dependencies for %s\n", n, mod->name); |
| 131 | |
| 132 | mod->dep = list; |
| 133 | return n; |
| 134 | |
| 135 | fail: |
| 136 | kmod_module_unref_list(list); |
| 137 | mod->init.dep = false; |
| 138 | return err; |
| 139 | } |
| 140 | |
Lucas De Marchi | 8f788d5 | 2011-11-25 01:22:56 -0200 | [diff] [blame] | 141 | KMOD_EXPORT int kmod_module_new_from_name(struct kmod_ctx *ctx, |
| 142 | const char *name, |
| 143 | struct kmod_module **mod) |
| 144 | { |
| 145 | struct kmod_module *m; |
Lucas De Marchi | d753b8c | 2011-12-05 18:14:51 -0200 | [diff] [blame] | 146 | size_t namelen; |
Lucas De Marchi | 4f2bb7c | 2011-12-06 02:46:22 -0200 | [diff] [blame] | 147 | char name_norm[NAME_MAX]; |
Lucas De Marchi | 8f788d5 | 2011-11-25 01:22:56 -0200 | [diff] [blame] | 148 | |
| 149 | if (ctx == NULL || name == NULL) |
| 150 | return -ENOENT; |
| 151 | |
Lucas De Marchi | 6c343b1 | 2011-12-06 09:01:01 -0200 | [diff] [blame] | 152 | modname_normalize((char *)name, name_norm, &namelen); |
Lucas De Marchi | d753b8c | 2011-12-05 18:14:51 -0200 | [diff] [blame] | 153 | |
Lucas De Marchi | fd186ae | 2011-12-06 03:38:37 -0200 | [diff] [blame] | 154 | m = kmod_pool_get_module(ctx, name_norm); |
| 155 | if (m != NULL) { |
| 156 | *mod = kmod_module_ref(m); |
| 157 | return 0; |
| 158 | } |
| 159 | |
Lucas De Marchi | 4f2bb7c | 2011-12-06 02:46:22 -0200 | [diff] [blame] | 160 | m = calloc(1, sizeof(*m) + namelen + 1); |
Lucas De Marchi | 8f788d5 | 2011-11-25 01:22:56 -0200 | [diff] [blame] | 161 | if (m == NULL) { |
| 162 | free(m); |
| 163 | return -ENOMEM; |
| 164 | } |
| 165 | |
| 166 | m->ctx = kmod_ref(ctx); |
Lucas De Marchi | 4f2bb7c | 2011-12-06 02:46:22 -0200 | [diff] [blame] | 167 | memcpy(m->name, name_norm, namelen + 1); |
Gustavo Sverzut Barbieri | 87ca03b | 2011-12-04 12:34:02 -0200 | [diff] [blame] | 168 | m->refcount = 1; |
Lucas De Marchi | 8f788d5 | 2011-11-25 01:22:56 -0200 | [diff] [blame] | 169 | |
Lucas De Marchi | fd186ae | 2011-12-06 03:38:37 -0200 | [diff] [blame] | 170 | kmod_pool_add_module(ctx, m); |
| 171 | |
Lucas De Marchi | 8f788d5 | 2011-11-25 01:22:56 -0200 | [diff] [blame] | 172 | *mod = m; |
| 173 | |
| 174 | return 0; |
| 175 | } |
| 176 | |
| 177 | KMOD_EXPORT int kmod_module_new_from_path(struct kmod_ctx *ctx, |
| 178 | const char *path, |
| 179 | struct kmod_module **mod) |
| 180 | { |
| 181 | struct kmod_module *m; |
| 182 | int err; |
| 183 | struct stat st; |
Lucas De Marchi | d753b8c | 2011-12-05 18:14:51 -0200 | [diff] [blame] | 184 | char name[NAME_MAX]; |
Lucas De Marchi | 71e975c | 2011-12-07 13:53:53 -0200 | [diff] [blame] | 185 | char *abspath; |
Lucas De Marchi | d753b8c | 2011-12-05 18:14:51 -0200 | [diff] [blame] | 186 | size_t namelen; |
Lucas De Marchi | 8f788d5 | 2011-11-25 01:22:56 -0200 | [diff] [blame] | 187 | |
| 188 | if (ctx == NULL || path == NULL) |
| 189 | return -ENOENT; |
| 190 | |
Lucas De Marchi | 71e975c | 2011-12-07 13:53:53 -0200 | [diff] [blame] | 191 | abspath = path_make_absolute_cwd(path); |
| 192 | if (abspath == NULL) |
| 193 | return -ENOMEM; |
| 194 | |
| 195 | err = stat(abspath, &st); |
| 196 | if (err < 0) { |
| 197 | free(abspath); |
Lucas De Marchi | 8f788d5 | 2011-11-25 01:22:56 -0200 | [diff] [blame] | 198 | return -errno; |
Lucas De Marchi | 71e975c | 2011-12-07 13:53:53 -0200 | [diff] [blame] | 199 | } |
Lucas De Marchi | 8f788d5 | 2011-11-25 01:22:56 -0200 | [diff] [blame] | 200 | |
Lucas De Marchi | d753b8c | 2011-12-05 18:14:51 -0200 | [diff] [blame] | 201 | path_to_modname(path, name, &namelen); |
| 202 | |
Lucas De Marchi | fd186ae | 2011-12-06 03:38:37 -0200 | [diff] [blame] | 203 | m = kmod_pool_get_module(ctx, name); |
| 204 | if (m != NULL) { |
Lucas De Marchi | 6bd0b8d | 2011-12-07 14:08:01 -0200 | [diff] [blame] | 205 | if (m->path == NULL) |
| 206 | m->path = abspath; |
| 207 | else if (streq(m->path, abspath)) |
| 208 | free(abspath); |
| 209 | else { |
| 210 | ERR(ctx, "kmod_module '%s' already exists with different path\n", |
| 211 | name); |
| 212 | free(abspath); |
| 213 | return -EEXIST; |
| 214 | } |
| 215 | |
Lucas De Marchi | fd186ae | 2011-12-06 03:38:37 -0200 | [diff] [blame] | 216 | *mod = kmod_module_ref(m); |
| 217 | return 0; |
| 218 | } |
| 219 | |
Lucas De Marchi | d753b8c | 2011-12-05 18:14:51 -0200 | [diff] [blame] | 220 | m = calloc(1, sizeof(*m) + namelen + 1); |
| 221 | if (m == NULL) |
| 222 | return -errno; |
| 223 | |
Lucas De Marchi | 8f788d5 | 2011-11-25 01:22:56 -0200 | [diff] [blame] | 224 | m->ctx = kmod_ref(ctx); |
Lucas De Marchi | d753b8c | 2011-12-05 18:14:51 -0200 | [diff] [blame] | 225 | memcpy(m->name, name, namelen); |
Lucas De Marchi | 71e975c | 2011-12-07 13:53:53 -0200 | [diff] [blame] | 226 | m->path = abspath; |
Gustavo Sverzut Barbieri | 87ca03b | 2011-12-04 12:34:02 -0200 | [diff] [blame] | 227 | m->refcount = 1; |
Lucas De Marchi | 8f788d5 | 2011-11-25 01:22:56 -0200 | [diff] [blame] | 228 | |
Lucas De Marchi | fd186ae | 2011-12-06 03:38:37 -0200 | [diff] [blame] | 229 | kmod_pool_add_module(ctx, m); |
| 230 | |
Lucas De Marchi | 8f788d5 | 2011-11-25 01:22:56 -0200 | [diff] [blame] | 231 | *mod = m; |
| 232 | |
| 233 | return 0; |
| 234 | } |
| 235 | |
| 236 | KMOD_EXPORT struct kmod_module *kmod_module_unref(struct kmod_module *mod) |
| 237 | { |
| 238 | if (mod == NULL) |
| 239 | return NULL; |
| 240 | |
| 241 | if (--mod->refcount > 0) |
| 242 | return mod; |
| 243 | |
| 244 | DBG(mod->ctx, "kmod_module %p released\n", mod); |
| 245 | |
Lucas De Marchi | 7636e72 | 2011-12-01 17:56:03 -0200 | [diff] [blame] | 246 | kmod_module_unref_list(mod->dep); |
Lucas De Marchi | 8f788d5 | 2011-11-25 01:22:56 -0200 | [diff] [blame] | 247 | kmod_unref(mod->ctx); |
Gustavo Sverzut Barbieri | f1fb6f8 | 2011-12-08 04:44:03 -0200 | [diff] [blame^] | 248 | free(mod->path); |
Lucas De Marchi | 8f788d5 | 2011-11-25 01:22:56 -0200 | [diff] [blame] | 249 | free(mod); |
| 250 | return NULL; |
| 251 | } |
| 252 | |
| 253 | KMOD_EXPORT struct kmod_module *kmod_module_ref(struct kmod_module *mod) |
| 254 | { |
| 255 | if (mod == NULL) |
| 256 | return NULL; |
| 257 | |
| 258 | mod->refcount++; |
| 259 | |
| 260 | return mod; |
| 261 | } |
| 262 | |
Lucas De Marchi | b14dcfd | 2011-11-30 20:29:51 -0200 | [diff] [blame] | 263 | #define CHECK_ERR_AND_FINISH(_err, _label_err, _list, label_finish) \ |
| 264 | do { \ |
| 265 | if ((_err) < 0) \ |
| 266 | goto _label_err; \ |
| 267 | if (*(_list) != NULL) \ |
| 268 | goto finish; \ |
| 269 | } while (0) |
| 270 | |
Lucas De Marchi | 7f3eb0c | 2011-11-30 19:03:41 -0200 | [diff] [blame] | 271 | KMOD_EXPORT int kmod_module_new_from_lookup(struct kmod_ctx *ctx, |
| 272 | const char *alias, |
| 273 | struct kmod_list **list) |
| 274 | { |
Lucas De Marchi | 7f3eb0c | 2011-11-30 19:03:41 -0200 | [diff] [blame] | 275 | int err; |
| 276 | |
| 277 | if (ctx == NULL || alias == NULL) |
| 278 | return -ENOENT; |
| 279 | |
Lucas De Marchi | 7f3eb0c | 2011-11-30 19:03:41 -0200 | [diff] [blame] | 280 | if (list == NULL || *list != NULL) { |
| 281 | ERR(ctx, "An empty list is needed to create lookup\n"); |
| 282 | return -ENOSYS; |
| 283 | } |
| 284 | |
Lucas De Marchi | b14dcfd | 2011-11-30 20:29:51 -0200 | [diff] [blame] | 285 | /* Aliases from config file override all the others */ |
Lucas De Marchi | 7f3eb0c | 2011-11-30 19:03:41 -0200 | [diff] [blame] | 286 | err = kmod_lookup_alias_from_config(ctx, alias, list); |
Lucas De Marchi | b14dcfd | 2011-11-30 20:29:51 -0200 | [diff] [blame] | 287 | CHECK_ERR_AND_FINISH(err, fail, list, finish); |
Lucas De Marchi | 7f3eb0c | 2011-11-30 19:03:41 -0200 | [diff] [blame] | 288 | |
Lucas De Marchi | 64700e4 | 2011-12-01 15:57:53 -0200 | [diff] [blame] | 289 | err = kmod_lookup_alias_from_moddep_file(ctx, alias, list); |
| 290 | CHECK_ERR_AND_FINISH(err, fail, list, finish); |
| 291 | |
Lucas De Marchi | 9ba6f57 | 2011-11-30 20:31:45 -0200 | [diff] [blame] | 292 | err = kmod_lookup_alias_from_symbols_file(ctx, alias, list); |
| 293 | CHECK_ERR_AND_FINISH(err, fail, list, finish); |
Lucas De Marchi | b14dcfd | 2011-11-30 20:29:51 -0200 | [diff] [blame] | 294 | |
Lucas De Marchi | 49e61ca | 2011-12-01 16:27:04 -0200 | [diff] [blame] | 295 | err = kmod_lookup_alias_from_aliases_file(ctx, alias, list); |
| 296 | CHECK_ERR_AND_FINISH(err, fail, list, finish); |
| 297 | |
Lucas De Marchi | b14dcfd | 2011-11-30 20:29:51 -0200 | [diff] [blame] | 298 | finish: |
Lucas De Marchi | 7f3eb0c | 2011-11-30 19:03:41 -0200 | [diff] [blame] | 299 | |
| 300 | return err; |
Lucas De Marchi | b14dcfd | 2011-11-30 20:29:51 -0200 | [diff] [blame] | 301 | fail: |
| 302 | kmod_module_unref_list(*list); |
| 303 | *list = NULL; |
Lucas De Marchi | 84f4220 | 2011-12-02 10:03:34 -0200 | [diff] [blame] | 304 | return err; |
Lucas De Marchi | 7f3eb0c | 2011-11-30 19:03:41 -0200 | [diff] [blame] | 305 | } |
Lucas De Marchi | b14dcfd | 2011-11-30 20:29:51 -0200 | [diff] [blame] | 306 | #undef CHECK_ERR_AND_FINISH |
| 307 | |
Lucas De Marchi | 7f3eb0c | 2011-11-30 19:03:41 -0200 | [diff] [blame] | 308 | |
| 309 | KMOD_EXPORT int kmod_module_unref_list(struct kmod_list *list) |
| 310 | { |
| 311 | for (; list != NULL; list = kmod_list_remove(list)) |
| 312 | kmod_module_unref(list->data); |
| 313 | |
| 314 | return 0; |
| 315 | } |
| 316 | |
Lucas De Marchi | f1cd799 | 2011-12-05 19:40:45 -0200 | [diff] [blame] | 317 | KMOD_EXPORT struct kmod_list *kmod_module_get_dependencies(const struct kmod_module *mod) |
Lucas De Marchi | 0835fc3 | 2011-12-01 20:06:08 -0200 | [diff] [blame] | 318 | { |
Lucas De Marchi | f1cd799 | 2011-12-05 19:40:45 -0200 | [diff] [blame] | 319 | struct kmod_list *l, *l_new, *list_new = NULL; |
| 320 | |
| 321 | if (mod == NULL) |
| 322 | return NULL; |
| 323 | |
Lucas De Marchi | 671d489 | 2011-12-05 20:23:05 -0200 | [diff] [blame] | 324 | if (!mod->init.dep) { |
| 325 | /* lazy init */ |
| 326 | char *line = kmod_search_moddep(mod->ctx, mod->name); |
| 327 | |
| 328 | if (line == NULL) |
| 329 | return NULL; |
| 330 | |
| 331 | kmod_module_parse_depline((struct kmod_module *)mod, line); |
| 332 | free(line); |
| 333 | |
| 334 | if (!mod->init.dep) |
| 335 | return NULL; |
| 336 | } |
Lucas De Marchi | f1cd799 | 2011-12-05 19:40:45 -0200 | [diff] [blame] | 337 | |
| 338 | kmod_list_foreach(l, mod->dep) { |
| 339 | l_new = kmod_list_append(list_new, kmod_module_ref(l->data)); |
| 340 | if (l_new == NULL) { |
| 341 | kmod_module_unref(l->data); |
| 342 | goto fail; |
| 343 | } |
| 344 | |
| 345 | list_new = l_new; |
| 346 | } |
| 347 | |
| 348 | return list_new; |
| 349 | |
| 350 | fail: |
| 351 | ERR(mod->ctx, "out of memory\n"); |
| 352 | kmod_module_unref_list(list_new); |
| 353 | return NULL; |
Lucas De Marchi | 0835fc3 | 2011-12-01 20:06:08 -0200 | [diff] [blame] | 354 | } |
| 355 | |
Gustavo Sverzut Barbieri | ad4d1ae | 2011-12-04 13:14:11 -0200 | [diff] [blame] | 356 | KMOD_EXPORT struct kmod_module *kmod_module_get_module(const struct kmod_list *entry) |
Lucas De Marchi | 6e869df | 2011-11-30 19:01:01 -0200 | [diff] [blame] | 357 | { |
Gustavo Sverzut Barbieri | ad4d1ae | 2011-12-04 13:14:11 -0200 | [diff] [blame] | 358 | if (entry == NULL) |
| 359 | return NULL; |
| 360 | return kmod_module_ref(entry->data); |
Lucas De Marchi | 6e869df | 2011-11-30 19:01:01 -0200 | [diff] [blame] | 361 | } |
| 362 | |
Gustavo Sverzut Barbieri | 69f9dd4 | 2011-12-04 14:02:30 -0200 | [diff] [blame] | 363 | KMOD_EXPORT long kmod_module_get_size(const struct kmod_module *mod) |
| 364 | { |
| 365 | // FIXME TODO: this should be available from /sys/module/foo |
| 366 | FILE *fp; |
| 367 | char line[4096]; |
| 368 | int lineno = 0; |
| 369 | long size = -ENOENT; |
| 370 | |
| 371 | if (mod == NULL) |
| 372 | return -ENOENT; |
| 373 | |
| 374 | fp = fopen("/proc/modules", "r"); |
| 375 | if (fp == NULL) { |
| 376 | int err = -errno; |
| 377 | ERR(mod->ctx, |
| 378 | "could not open /proc/modules: %s\n", strerror(errno)); |
| 379 | return err; |
| 380 | } |
| 381 | |
| 382 | while (fgets(line, sizeof(line), fp)) { |
| 383 | char *saveptr, *endptr, *tok = strtok_r(line, " \t", &saveptr); |
| 384 | long value; |
| 385 | |
| 386 | lineno++; |
Lucas De Marchi | 877e80c | 2011-12-07 02:26:31 -0200 | [diff] [blame] | 387 | if (tok == NULL || !streq(tok, mod->name)) |
Gustavo Sverzut Barbieri | 69f9dd4 | 2011-12-04 14:02:30 -0200 | [diff] [blame] | 388 | continue; |
| 389 | |
| 390 | tok = strtok_r(NULL, " \t", &saveptr); |
| 391 | if (tok == NULL) { |
| 392 | ERR(mod->ctx, |
| 393 | "invalid line format at /proc/modules:%d\n", lineno); |
| 394 | break; |
| 395 | } |
| 396 | |
| 397 | value = strtol(tok, &endptr, 10); |
| 398 | if (endptr == tok || *endptr != '\0') { |
| 399 | ERR(mod->ctx, |
| 400 | "invalid line format at /proc/modules:%d\n", lineno); |
| 401 | break; |
| 402 | } |
| 403 | |
| 404 | size = value; |
| 405 | break; |
| 406 | } |
| 407 | fclose(fp); |
| 408 | return size; |
| 409 | } |
| 410 | |
Gustavo Sverzut Barbieri | 1ce08a5 | 2011-12-02 20:24:07 -0200 | [diff] [blame] | 411 | KMOD_EXPORT const char *kmod_module_get_name(const struct kmod_module *mod) |
Lucas De Marchi | 6e869df | 2011-11-30 19:01:01 -0200 | [diff] [blame] | 412 | { |
Lucas De Marchi | 6e869df | 2011-11-30 19:01:01 -0200 | [diff] [blame] | 413 | return mod->name; |
| 414 | } |
| 415 | |
Lucas De Marchi | c5e7b1f | 2011-12-05 20:28:13 -0200 | [diff] [blame] | 416 | /* |
| 417 | * Relative paths are relative to dirname. Absolute paths are only used when |
| 418 | * user created kmod_module by giving a path |
| 419 | */ |
Gustavo Sverzut Barbieri | 1ce08a5 | 2011-12-02 20:24:07 -0200 | [diff] [blame] | 420 | KMOD_EXPORT const char *kmod_module_get_path(const struct kmod_module *mod) |
Lucas De Marchi | 6e869df | 2011-11-30 19:01:01 -0200 | [diff] [blame] | 421 | { |
Lucas De Marchi | e005fac | 2011-12-08 10:42:34 -0200 | [diff] [blame] | 422 | char *line; |
Lucas De Marchi | c5e7b1f | 2011-12-05 20:28:13 -0200 | [diff] [blame] | 423 | |
Lucas De Marchi | e005fac | 2011-12-08 10:42:34 -0200 | [diff] [blame] | 424 | DBG(mod->ctx, "name='%s' path='%s'", mod->name, mod->path); |
Lucas De Marchi | c5e7b1f | 2011-12-05 20:28:13 -0200 | [diff] [blame] | 425 | |
Lucas De Marchi | e005fac | 2011-12-08 10:42:34 -0200 | [diff] [blame] | 426 | if (mod->path != NULL) |
| 427 | return mod->path; |
| 428 | if (mod->init.dep) |
| 429 | return NULL; |
Lucas De Marchi | c5e7b1f | 2011-12-05 20:28:13 -0200 | [diff] [blame] | 430 | |
Lucas De Marchi | e005fac | 2011-12-08 10:42:34 -0200 | [diff] [blame] | 431 | /* lazy init */ |
| 432 | line = kmod_search_moddep(mod->ctx, mod->name); |
| 433 | if (line == NULL) |
| 434 | return NULL; |
| 435 | |
| 436 | kmod_module_parse_depline((struct kmod_module *) mod, line); |
| 437 | free(line); |
Lucas De Marchi | c5e7b1f | 2011-12-05 20:28:13 -0200 | [diff] [blame] | 438 | |
Lucas De Marchi | 6e869df | 2011-11-30 19:01:01 -0200 | [diff] [blame] | 439 | return mod->path; |
| 440 | } |
| 441 | |
| 442 | |
Lucas De Marchi | 8f788d5 | 2011-11-25 01:22:56 -0200 | [diff] [blame] | 443 | extern long delete_module(const char *name, unsigned int flags); |
| 444 | |
| 445 | KMOD_EXPORT int kmod_module_remove_module(struct kmod_module *mod, |
| 446 | unsigned int flags) |
| 447 | { |
| 448 | int err; |
Lucas De Marchi | 8f788d5 | 2011-11-25 01:22:56 -0200 | [diff] [blame] | 449 | |
| 450 | if (mod == NULL) |
| 451 | return -ENOENT; |
| 452 | |
| 453 | /* Filter out other flags */ |
| 454 | flags &= (KMOD_REMOVE_FORCE | KMOD_REMOVE_NOWAIT); |
| 455 | |
Lucas De Marchi | d753b8c | 2011-12-05 18:14:51 -0200 | [diff] [blame] | 456 | err = delete_module(mod->name, flags); |
Lucas De Marchi | 8f788d5 | 2011-11-25 01:22:56 -0200 | [diff] [blame] | 457 | if (err != 0) { |
Lucas De Marchi | d753b8c | 2011-12-05 18:14:51 -0200 | [diff] [blame] | 458 | ERR(mod->ctx, "Removing '%s': %s\n", mod->name, |
Lucas De Marchi | 8f788d5 | 2011-11-25 01:22:56 -0200 | [diff] [blame] | 459 | strerror(-err)); |
| 460 | return err; |
| 461 | } |
| 462 | |
| 463 | return 0; |
| 464 | } |
| 465 | |
| 466 | extern long init_module(void *mem, unsigned long len, const char *args); |
| 467 | |
| 468 | KMOD_EXPORT int kmod_module_insert_module(struct kmod_module *mod, |
| 469 | unsigned int flags) |
| 470 | { |
| 471 | int err; |
| 472 | void *mmaped_file; |
| 473 | struct stat st; |
| 474 | int fd; |
| 475 | const char *args = ""; |
| 476 | |
| 477 | if (mod == NULL) |
| 478 | return -ENOENT; |
| 479 | |
| 480 | if (mod->path == NULL) { |
Lucas De Marchi | 1b2e26a | 2011-11-25 01:28:39 -0200 | [diff] [blame] | 481 | ERR(mod->ctx, "Not supported to load a module by name yet\n"); |
Lucas De Marchi | 8f788d5 | 2011-11-25 01:22:56 -0200 | [diff] [blame] | 482 | return -ENOSYS; |
| 483 | } |
| 484 | |
| 485 | if (flags != 0) |
Lucas De Marchi | 1b2e26a | 2011-11-25 01:28:39 -0200 | [diff] [blame] | 486 | INFO(mod->ctx, "Flags are not implemented yet\n"); |
Lucas De Marchi | 8f788d5 | 2011-11-25 01:22:56 -0200 | [diff] [blame] | 487 | |
| 488 | if ((fd = open(mod->path, O_RDONLY)) < 0) { |
| 489 | err = -errno; |
| 490 | return err; |
| 491 | } |
| 492 | |
Lucas De Marchi | b418a82 | 2011-12-01 23:13:27 -0200 | [diff] [blame] | 493 | fstat(fd, &st); |
Lucas De Marchi | 8f788d5 | 2011-11-25 01:22:56 -0200 | [diff] [blame] | 494 | |
| 495 | if ((mmaped_file = mmap(0, st.st_size, PROT_READ, |
| 496 | MAP_PRIVATE, fd, 0)) == MAP_FAILED) { |
| 497 | close(fd); |
| 498 | return -errno; |
| 499 | } |
| 500 | |
| 501 | err = init_module(mmaped_file, st.st_size, args); |
| 502 | if (err < 0) |
Lucas De Marchi | 1b2e26a | 2011-11-25 01:28:39 -0200 | [diff] [blame] | 503 | ERR(mod->ctx, "Failed to insert module '%s'\n", mod->path); |
Lucas De Marchi | 8f788d5 | 2011-11-25 01:22:56 -0200 | [diff] [blame] | 504 | |
| 505 | munmap(mmaped_file, st.st_size); |
| 506 | close(fd); |
| 507 | |
| 508 | return err; |
| 509 | } |
Gustavo Sverzut Barbieri | f12ae3c | 2011-12-04 12:40:00 -0200 | [diff] [blame] | 510 | |
| 511 | KMOD_EXPORT const char *kmod_module_initstate_str(enum kmod_module_initstate state) |
| 512 | { |
| 513 | switch (state) { |
| 514 | case KMOD_MODULE_BUILTIN: |
| 515 | return "builtin"; |
| 516 | case KMOD_MODULE_LIVE: |
| 517 | return "live"; |
| 518 | case KMOD_MODULE_COMING: |
| 519 | return "coming"; |
| 520 | case KMOD_MODULE_GOING: |
| 521 | return "going"; |
| 522 | default: |
| 523 | return NULL; |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | KMOD_EXPORT int kmod_module_get_initstate(const struct kmod_module *mod) |
| 528 | { |
| 529 | char path[PATH_MAX], buf[32]; |
| 530 | int fd, err, pathlen; |
| 531 | |
| 532 | pathlen = snprintf(path, sizeof(path), |
| 533 | "/sys/module/%s/initstate", mod->name); |
| 534 | fd = open(path, O_RDONLY); |
| 535 | if (fd < 0) { |
| 536 | err = -errno; |
| 537 | |
| 538 | if (pathlen > (int)sizeof("/initstate") - 1) { |
| 539 | struct stat st; |
| 540 | path[pathlen - (sizeof("/initstate") - 1)] = '\0'; |
| 541 | if (stat(path, &st) == 0 && S_ISDIR(st.st_mode)) |
| 542 | return KMOD_MODULE_BUILTIN; |
| 543 | } |
| 544 | |
| 545 | ERR(mod->ctx, "could not open '%s': %s\n", |
| 546 | path, strerror(-err)); |
| 547 | return err; |
| 548 | } |
| 549 | |
| 550 | err = read_str_safe(fd, buf, sizeof(buf)); |
| 551 | close(fd); |
| 552 | if (err < 0) { |
| 553 | ERR(mod->ctx, "could not read from '%s': %s\n", |
| 554 | path, strerror(-err)); |
| 555 | return err; |
| 556 | } |
| 557 | |
Lucas De Marchi | 877e80c | 2011-12-07 02:26:31 -0200 | [diff] [blame] | 558 | if (streq(buf, "live\n")) |
Gustavo Sverzut Barbieri | f12ae3c | 2011-12-04 12:40:00 -0200 | [diff] [blame] | 559 | return KMOD_MODULE_LIVE; |
Lucas De Marchi | 877e80c | 2011-12-07 02:26:31 -0200 | [diff] [blame] | 560 | else if (streq(buf, "coming\n")) |
Gustavo Sverzut Barbieri | f12ae3c | 2011-12-04 12:40:00 -0200 | [diff] [blame] | 561 | return KMOD_MODULE_COMING; |
Lucas De Marchi | 877e80c | 2011-12-07 02:26:31 -0200 | [diff] [blame] | 562 | else if (streq(buf, "going\n")) |
Gustavo Sverzut Barbieri | f12ae3c | 2011-12-04 12:40:00 -0200 | [diff] [blame] | 563 | return KMOD_MODULE_GOING; |
| 564 | |
| 565 | ERR(mod->ctx, "unknown %s: '%s'\n", path, buf); |
| 566 | return -EINVAL; |
| 567 | } |
| 568 | |
| 569 | KMOD_EXPORT int kmod_module_get_refcnt(const struct kmod_module *mod) |
| 570 | { |
| 571 | char path[PATH_MAX]; |
| 572 | long refcnt; |
| 573 | int fd, err; |
| 574 | |
| 575 | snprintf(path, sizeof(path), "/sys/module/%s/refcnt", mod->name); |
| 576 | fd = open(path, O_RDONLY); |
| 577 | if (fd < 0) { |
| 578 | err = -errno; |
| 579 | ERR(mod->ctx, "could not open '%s': %s\n", |
| 580 | path, strerror(errno)); |
| 581 | return err; |
| 582 | } |
| 583 | |
| 584 | err = read_str_long(fd, &refcnt, 10); |
| 585 | close(fd); |
| 586 | if (err < 0) { |
| 587 | ERR(mod->ctx, "could not read integer from '%s': '%s'\n", |
| 588 | path, strerror(-err)); |
| 589 | return err; |
| 590 | } |
| 591 | |
| 592 | return (int)refcnt; |
| 593 | } |
| 594 | |
| 595 | KMOD_EXPORT struct kmod_list *kmod_module_get_holders(const struct kmod_module *mod) |
| 596 | { |
| 597 | char dname[PATH_MAX]; |
| 598 | struct kmod_list *list = NULL; |
| 599 | DIR *d; |
Gustavo Sverzut Barbieri | f12ae3c | 2011-12-04 12:40:00 -0200 | [diff] [blame] | 600 | |
| 601 | if (mod == NULL) |
| 602 | return NULL; |
| 603 | snprintf(dname, sizeof(dname), "/sys/module/%s/holders", mod->name); |
| 604 | |
| 605 | d = opendir(dname); |
| 606 | if (d == NULL) { |
| 607 | ERR(mod->ctx, "could not open '%s': %s\n", |
Lucas De Marchi | 53886dd | 2011-12-05 13:24:23 -0200 | [diff] [blame] | 608 | dname, strerror(errno)); |
Gustavo Sverzut Barbieri | f12ae3c | 2011-12-04 12:40:00 -0200 | [diff] [blame] | 609 | return NULL; |
| 610 | } |
| 611 | |
Lucas De Marchi | 53886dd | 2011-12-05 13:24:23 -0200 | [diff] [blame] | 612 | for (;;) { |
| 613 | struct dirent de, *entp; |
Gustavo Sverzut Barbieri | f12ae3c | 2011-12-04 12:40:00 -0200 | [diff] [blame] | 614 | struct kmod_module *holder; |
Lucas De Marchi | 53886dd | 2011-12-05 13:24:23 -0200 | [diff] [blame] | 615 | struct kmod_list *l; |
Gustavo Sverzut Barbieri | f12ae3c | 2011-12-04 12:40:00 -0200 | [diff] [blame] | 616 | int err; |
| 617 | |
Lucas De Marchi | 53886dd | 2011-12-05 13:24:23 -0200 | [diff] [blame] | 618 | err = readdir_r(d, &de, &entp); |
| 619 | if (err != 0) { |
| 620 | ERR(mod->ctx, "could not iterate for module '%s': %s\n", |
| 621 | mod->name, strerror(-err)); |
| 622 | goto fail; |
| 623 | } |
| 624 | |
| 625 | if (entp == NULL) |
| 626 | break; |
| 627 | |
| 628 | if (de.d_name[0] == '.') { |
| 629 | if (de.d_name[1] == '\0' || |
| 630 | (de.d_name[1] == '.' && de.d_name[2] == '\0')) |
Gustavo Sverzut Barbieri | f12ae3c | 2011-12-04 12:40:00 -0200 | [diff] [blame] | 631 | continue; |
| 632 | } |
| 633 | |
Lucas De Marchi | 53886dd | 2011-12-05 13:24:23 -0200 | [diff] [blame] | 634 | err = kmod_module_new_from_name(mod->ctx, de.d_name, &holder); |
Gustavo Sverzut Barbieri | f12ae3c | 2011-12-04 12:40:00 -0200 | [diff] [blame] | 635 | if (err < 0) { |
| 636 | ERR(mod->ctx, "could not create module for '%s': %s\n", |
Lucas De Marchi | 53886dd | 2011-12-05 13:24:23 -0200 | [diff] [blame] | 637 | de.d_name, strerror(-err)); |
| 638 | goto fail; |
Gustavo Sverzut Barbieri | f12ae3c | 2011-12-04 12:40:00 -0200 | [diff] [blame] | 639 | } |
| 640 | |
Lucas De Marchi | 53886dd | 2011-12-05 13:24:23 -0200 | [diff] [blame] | 641 | l = kmod_list_append(list, holder); |
| 642 | if (l != NULL) { |
| 643 | list = l; |
| 644 | } else { |
Gustavo Sverzut Barbieri | f12ae3c | 2011-12-04 12:40:00 -0200 | [diff] [blame] | 645 | ERR(mod->ctx, "out of memory\n"); |
| 646 | kmod_module_unref(holder); |
Lucas De Marchi | 53886dd | 2011-12-05 13:24:23 -0200 | [diff] [blame] | 647 | goto fail; |
Gustavo Sverzut Barbieri | f12ae3c | 2011-12-04 12:40:00 -0200 | [diff] [blame] | 648 | } |
| 649 | } |
| 650 | |
| 651 | closedir(d); |
| 652 | return list; |
Lucas De Marchi | 53886dd | 2011-12-05 13:24:23 -0200 | [diff] [blame] | 653 | |
| 654 | fail: |
| 655 | closedir(d); |
| 656 | kmod_module_unref_list(list); |
| 657 | return NULL; |
Gustavo Sverzut Barbieri | f12ae3c | 2011-12-04 12:40:00 -0200 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | struct kmod_module_section { |
| 661 | unsigned long address; |
| 662 | char name[]; |
| 663 | }; |
| 664 | |
| 665 | static void kmod_module_section_free(struct kmod_module_section *section) |
| 666 | { |
| 667 | free(section); |
| 668 | } |
| 669 | |
| 670 | KMOD_EXPORT struct kmod_list *kmod_module_get_sections(const struct kmod_module *mod) |
| 671 | { |
| 672 | char dname[PATH_MAX]; |
| 673 | struct kmod_list *list = NULL; |
| 674 | DIR *d; |
| 675 | int dfd; |
Gustavo Sverzut Barbieri | f12ae3c | 2011-12-04 12:40:00 -0200 | [diff] [blame] | 676 | |
| 677 | if (mod == NULL) |
| 678 | return NULL; |
| 679 | snprintf(dname, sizeof(dname), "/sys/module/%s/sections", mod->name); |
| 680 | |
| 681 | d = opendir(dname); |
| 682 | if (d == NULL) { |
| 683 | ERR(mod->ctx, "could not open '%s': %s\n", |
| 684 | dname, strerror(errno)); |
| 685 | return NULL; |
| 686 | } |
| 687 | |
| 688 | dfd = dirfd(d); |
Lucas De Marchi | 40923bd | 2011-12-05 13:40:16 -0200 | [diff] [blame] | 689 | |
| 690 | for (;;) { |
| 691 | struct dirent de, *entp; |
Gustavo Sverzut Barbieri | f12ae3c | 2011-12-04 12:40:00 -0200 | [diff] [blame] | 692 | struct kmod_module_section *section; |
Lucas De Marchi | 40923bd | 2011-12-05 13:40:16 -0200 | [diff] [blame] | 693 | struct kmod_list *l; |
Gustavo Sverzut Barbieri | f12ae3c | 2011-12-04 12:40:00 -0200 | [diff] [blame] | 694 | unsigned long address; |
| 695 | size_t namesz; |
| 696 | int fd, err; |
| 697 | |
Lucas De Marchi | 40923bd | 2011-12-05 13:40:16 -0200 | [diff] [blame] | 698 | err = readdir_r(d, &de, &entp); |
| 699 | if (err != 0) { |
| 700 | ERR(mod->ctx, "could not iterate for module '%s': %s\n", |
| 701 | mod->name, strerror(-err)); |
| 702 | goto fail; |
| 703 | } |
| 704 | |
| 705 | if (de.d_name[0] == '.') { |
| 706 | if (de.d_name[1] == '\0' || |
| 707 | (de.d_name[1] == '.' && de.d_name[2] == '\0')) |
Gustavo Sverzut Barbieri | f12ae3c | 2011-12-04 12:40:00 -0200 | [diff] [blame] | 708 | continue; |
| 709 | } |
| 710 | |
Lucas De Marchi | 40923bd | 2011-12-05 13:40:16 -0200 | [diff] [blame] | 711 | fd = openat(dfd, de.d_name, O_RDONLY); |
Gustavo Sverzut Barbieri | f12ae3c | 2011-12-04 12:40:00 -0200 | [diff] [blame] | 712 | if (fd < 0) { |
Lucas De Marchi | 40923bd | 2011-12-05 13:40:16 -0200 | [diff] [blame] | 713 | ERR(mod->ctx, "could not open '%s/%s': %m\n", |
| 714 | dname, de.d_name); |
| 715 | goto fail; |
Gustavo Sverzut Barbieri | f12ae3c | 2011-12-04 12:40:00 -0200 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | err = read_str_ulong(fd, &address, 16); |
Lucas De Marchi | 40923bd | 2011-12-05 13:40:16 -0200 | [diff] [blame] | 719 | close(fd); |
| 720 | |
Gustavo Sverzut Barbieri | f12ae3c | 2011-12-04 12:40:00 -0200 | [diff] [blame] | 721 | if (err < 0) { |
Lucas De Marchi | 40923bd | 2011-12-05 13:40:16 -0200 | [diff] [blame] | 722 | ERR(mod->ctx, "could not read long from '%s/%s': %m\n", |
| 723 | dname, de.d_name); |
| 724 | goto fail; |
Gustavo Sverzut Barbieri | f12ae3c | 2011-12-04 12:40:00 -0200 | [diff] [blame] | 725 | } |
| 726 | |
Lucas De Marchi | 40923bd | 2011-12-05 13:40:16 -0200 | [diff] [blame] | 727 | namesz = strlen(de.d_name) + 1; |
| 728 | section = malloc(sizeof(*section) + namesz); |
Gustavo Sverzut Barbieri | f12ae3c | 2011-12-04 12:40:00 -0200 | [diff] [blame] | 729 | |
Lucas De Marchi | 40923bd | 2011-12-05 13:40:16 -0200 | [diff] [blame] | 730 | if (section == NULL) { |
| 731 | ERR(mod->ctx, "out of memory\n"); |
| 732 | goto fail; |
| 733 | } |
| 734 | |
| 735 | section->address = address; |
| 736 | memcpy(section->name, de.d_name, namesz); |
| 737 | |
| 738 | l = kmod_list_append(list, section); |
| 739 | if (l != NULL) { |
| 740 | list = l; |
| 741 | } else { |
Gustavo Sverzut Barbieri | f12ae3c | 2011-12-04 12:40:00 -0200 | [diff] [blame] | 742 | ERR(mod->ctx, "out of memory\n"); |
| 743 | free(section); |
Lucas De Marchi | 40923bd | 2011-12-05 13:40:16 -0200 | [diff] [blame] | 744 | goto fail; |
Gustavo Sverzut Barbieri | f12ae3c | 2011-12-04 12:40:00 -0200 | [diff] [blame] | 745 | } |
Gustavo Sverzut Barbieri | f12ae3c | 2011-12-04 12:40:00 -0200 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | closedir(d); |
| 749 | return list; |
Lucas De Marchi | 40923bd | 2011-12-05 13:40:16 -0200 | [diff] [blame] | 750 | |
| 751 | fail: |
| 752 | closedir(d); |
| 753 | kmod_module_unref_list(list); |
| 754 | return NULL; |
Gustavo Sverzut Barbieri | f12ae3c | 2011-12-04 12:40:00 -0200 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | KMOD_EXPORT const char *kmod_module_section_get_name(const struct kmod_list *entry) |
| 758 | { |
| 759 | struct kmod_module_section *section; |
| 760 | if (entry == NULL) |
| 761 | return NULL; |
| 762 | section = entry->data; |
| 763 | return section->name; |
| 764 | } |
| 765 | |
| 766 | KMOD_EXPORT unsigned long kmod_module_section_get_address(const struct kmod_list *entry) |
| 767 | { |
| 768 | struct kmod_module_section *section; |
| 769 | if (entry == NULL) |
| 770 | return (unsigned long)-1; |
| 771 | section = entry->data; |
| 772 | return section->address; |
| 773 | } |
| 774 | |
| 775 | KMOD_EXPORT void kmod_module_section_free_list(struct kmod_list *list) |
| 776 | { |
| 777 | while (list) { |
| 778 | kmod_module_section_free(list->data); |
| 779 | list = kmod_list_remove(list); |
| 780 | } |
| 781 | } |