2 * kmod-depmod - calculate modules.dep using libkmod.
4 * Copyright (C) 2011-2013 ProFUSION embedded systems
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
33 #include <sys/utsname.h>
35 #include <shared/array.h>
36 #include <shared/hash.h>
37 #include <shared/macro.h>
38 #include <shared/util.h>
39 #include <shared/scratchbuf.h>
41 #include <libkmod/libkmod-internal.h>
48 #define DEFAULT_VERBOSE LOG_WARNING
49 static int verbose
= DEFAULT_VERBOSE
;
51 static const char CFG_BUILTIN_KEY
[] = "built-in";
52 static const char CFG_EXTERNAL_KEY
[] = "external";
53 static const char *default_cfg_paths
[] = {
55 SYSCONFDIR
"/depmod.d",
60 static const char cmdopts_s
[] = "aAb:C:E:F:euqrvnP:wmVh";
61 static const struct option cmdopts
[] = {
62 { "all", no_argument
, 0, 'a' },
63 { "quick", no_argument
, 0, 'A' },
64 { "basedir", required_argument
, 0, 'b' },
65 { "config", required_argument
, 0, 'C' },
66 { "symvers", required_argument
, 0, 'E' },
67 { "filesyms", required_argument
, 0, 'F' },
68 { "errsyms", no_argument
, 0, 'e' },
69 { "unresolved-error", no_argument
, 0, 'u' }, /* deprecated */
70 { "quiet", no_argument
, 0, 'q' }, /* deprecated */
71 { "root", no_argument
, 0, 'r' }, /* deprecated */
72 { "verbose", no_argument
, 0, 'v' },
73 { "show", no_argument
, 0, 'n' },
74 { "dry-run", no_argument
, 0, 'n' },
75 { "symbol-prefix", required_argument
, 0, 'P' },
76 { "warn", no_argument
, 0, 'w' },
77 { "map", no_argument
, 0, 'm' }, /* deprecated */
78 { "version", no_argument
, 0, 'V' },
79 { "help", no_argument
, 0, 'h' },
83 static void help(void)
86 "\t%s -[aA] [options] [forced_version]\n"
88 "If no arguments (except options) are given, \"depmod -a\" is assumed\n"
90 "depmod will output a dependency list suitable for the modprobe utility.\n"
93 "\t-a, --all Probe all modules\n"
94 "\t-A, --quick Only does the work if there's a new module\n"
95 "\t-e, --errsyms Report not supplied symbols\n"
96 "\t-n, --show Write the dependency file on stdout only\n"
97 "\t-P, --symbol-prefix Architecture symbol prefix\n"
98 "\t-C, --config=PATH Read configuration from PATH\n"
99 "\t-v, --verbose Enable verbose mode\n"
100 "\t-w, --warn Warn on duplicates\n"
101 "\t-V, --version show version\n"
102 "\t-h, --help show this help\n"
104 "The following options are useful for people managing distributions:\n"
105 "\t-b, --basedir=DIR Use an image of a module tree.\n"
106 "\t-F, --filesyms=FILE Use the file instead of the\n"
107 "\t current kernel symbols.\n"
108 "\t-E, --symvers=FILE Use Module.symvers file to check\n"
109 "\t symbol versions.\n",
110 program_invocation_short_name
);
113 _printf_format_(1, 2)
114 static inline void _show(const char *fmt
, ...)
118 if (verbose
<= DEFAULT_VERBOSE
)
122 vfprintf(stdout
, fmt
, args
);
126 #define SHOW(...) _show(__VA_ARGS__)
129 /* binary index write *************************************************/
130 #include <arpa/inet.h>
131 /* BEGIN: code from module-init-tools/index.c just modified to compile here.
133 * Original copyright:
134 * index.c: module index file shared functions for modprobe and depmod
135 * Copyright (C) 2008 Alan Jenkins <alan-jenkins@tuffmail.co.uk>.
137 * These programs are free software; you can redistribute it and/or modify
138 * it under the terms of the GNU General Public License as published by
139 * the Free Software Foundation; either version 2 of the License, or
140 * (at your option) any later version.
142 * This program is distributed in the hope that it will be useful,
143 * but WITHOUT ANY WARRANTY; without even the implied warranty of
144 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
145 * GNU General Public License for more details.
147 * You should have received a copy of the GNU General Public License
148 * along with these programs. If not, see <http://www.gnu.org/licenses/>.
151 /* see documentation in libkmod/libkmod-index.c */
153 #define INDEX_MAGIC 0xB007F457
154 #define INDEX_VERSION_MAJOR 0x0002
155 #define INDEX_VERSION_MINOR 0x0001
156 #define INDEX_VERSION ((INDEX_VERSION_MAJOR<<16)|INDEX_VERSION_MINOR)
157 #define INDEX_CHILDMAX 128
160 struct index_value
*next
;
161 unsigned int priority
;
165 /* In-memory index (depmod only) */
167 char *prefix
; /* path compression */
168 struct index_value
*values
;
169 unsigned char first
; /* range of child nodes */
171 struct index_node
*children
[INDEX_CHILDMAX
]; /* indexed by character */
175 /* Format of node offsets within index file */
177 INDEX_NODE_FLAGS
= 0xF0000000, /* Flags in high nibble */
178 INDEX_NODE_PREFIX
= 0x80000000,
179 INDEX_NODE_VALUES
= 0x40000000,
180 INDEX_NODE_CHILDS
= 0x20000000,
182 INDEX_NODE_MASK
= 0x0FFFFFFF, /* Offset value */
185 static struct index_node
*index_create(void)
187 struct index_node
*node
;
189 node
= NOFAIL(calloc(sizeof(struct index_node
), 1));
190 node
->prefix
= NOFAIL(strdup(""));
191 node
->first
= INDEX_CHILDMAX
;
196 static void index_values_free(struct index_value
*values
)
199 struct index_value
*value
= values
;
201 values
= value
->next
;
206 static void index_destroy(struct index_node
*node
)
210 for (c
= node
->first
; c
<= node
->last
; c
++) {
211 struct index_node
*child
= node
->children
[c
];
214 index_destroy(child
);
216 index_values_free(node
->values
);
221 static void index__checkstring(const char *str
)
225 for (i
= 0; str
[i
]; i
++) {
228 if (ch
>= INDEX_CHILDMAX
)
229 CRIT("Module index: bad character '%c'=0x%x - only 7-bit ASCII is supported:"
230 "\n%s\n", (char) ch
, (int) ch
, str
);
234 static int index_add_value(struct index_value
**values
,
235 const char *value
, unsigned int priority
)
237 struct index_value
*v
;
241 /* report the presence of duplicate values */
242 for (v
= *values
; v
; v
= v
->next
) {
243 if (streq(v
->value
, value
))
247 /* find position to insert value */
248 while (*values
&& (*values
)->priority
< priority
)
249 values
= &(*values
)->next
;
252 v
= NOFAIL(calloc(sizeof(struct index_value
) + len
+ 1, 1));
254 v
->priority
= priority
;
255 memcpy(v
->value
, value
, len
+ 1);
261 static int index_insert(struct index_node
*node
, const char *key
,
262 const char *value
, unsigned int priority
)
264 int i
= 0; /* index within str */
267 index__checkstring(key
);
268 index__checkstring(value
);
271 int j
; /* index within node->prefix */
273 /* Ensure node->prefix is a prefix of &str[i].
274 If it is not already, then we must split node. */
275 for (j
= 0; node
->prefix
[j
]; j
++) {
276 ch
= node
->prefix
[j
];
278 if (ch
!= key
[i
+j
]) {
279 char *prefix
= node
->prefix
;
280 struct index_node
*n
;
282 /* New child is copy of node with prefix[j+1..N] */
283 n
= NOFAIL(calloc(sizeof(struct index_node
), 1));
284 memcpy(n
, node
, sizeof(struct index_node
));
285 n
->prefix
= NOFAIL(strdup(&prefix
[j
+1]));
287 /* Parent has prefix[0..j], child at prefix[j] */
288 memset(node
, 0, sizeof(struct index_node
));
290 node
->prefix
= prefix
;
293 node
->children
[ch
] = n
;
298 /* j is now length of node->prefix */
303 return index_add_value(&node
->values
, value
, priority
);
305 if (!node
->children
[ch
]) {
306 struct index_node
*child
;
308 if (ch
< node
->first
)
312 node
->children
[ch
] = NOFAIL(calloc(sizeof(struct index_node
), 1));
314 child
= node
->children
[ch
];
315 child
->prefix
= NOFAIL(strdup(&key
[i
+1]));
316 child
->first
= INDEX_CHILDMAX
;
317 index_add_value(&child
->values
, value
, priority
);
322 /* Descend into child node and continue */
323 node
= node
->children
[ch
];
328 static int index__haschildren(const struct index_node
*node
)
330 return node
->first
< INDEX_CHILDMAX
;
333 /* Recursive post-order traversal
335 Pre-order would make for better read-side buffering / readahead / caching.
336 (post-order means you go backwards in the file as you descend the tree).
337 However, index reading is already fast enough.
338 Pre-order is simpler for writing, and depmod is already slow.
340 static uint32_t index_write__node(const struct index_node
*node
, FILE *out
)
342 uint32_t *child_offs
= NULL
;
349 /* Write children and save their offsets */
350 if (index__haschildren(node
)) {
351 const struct index_node
*child
;
354 child_count
= node
->last
- node
->first
+ 1;
355 child_offs
= NOFAIL(malloc(child_count
* sizeof(uint32_t)));
357 for (i
= 0; i
< child_count
; i
++) {
358 child
= node
->children
[node
->first
+ i
];
359 child_offs
[i
] = htonl(index_write__node(child
, out
));
363 /* Now write this node */
366 if (node
->prefix
[0]) {
367 fputs(node
->prefix
, out
);
369 offset
|= INDEX_NODE_PREFIX
;
373 fputc(node
->first
, out
);
374 fputc(node
->last
, out
);
375 fwrite(child_offs
, sizeof(uint32_t), child_count
, out
);
376 offset
|= INDEX_NODE_CHILDS
;
382 const struct index_value
*v
;
383 unsigned int value_count
;
387 for (v
= node
->values
; v
!= NULL
; v
= v
->next
)
389 u
= htonl(value_count
);
390 fwrite(&u
, sizeof(u
), 1, out
);
392 for (v
= node
->values
; v
!= NULL
; v
= v
->next
) {
393 u
= htonl(v
->priority
);
394 fwrite(&u
, sizeof(u
), 1, out
);
395 fputs(v
->value
, out
);
398 offset
|= INDEX_NODE_VALUES
;
404 static void index_write(const struct index_node
*node
, FILE *out
)
406 long initial_offset
, final_offset
;
409 u
= htonl(INDEX_MAGIC
);
410 fwrite(&u
, sizeof(u
), 1, out
);
411 u
= htonl(INDEX_VERSION
);
412 fwrite(&u
, sizeof(u
), 1, out
);
414 /* Second word is reserved for the offset of the root node */
415 initial_offset
= ftell(out
);
416 assert(initial_offset
>= 0);
418 fwrite(&u
, sizeof(uint32_t), 1, out
);
421 u
= htonl(index_write__node(node
, out
));
423 /* Update first word */
424 final_offset
= ftell(out
);
425 assert(final_offset
>= 0);
426 (void)fseek(out
, initial_offset
, SEEK_SET
);
427 fwrite(&u
, sizeof(uint32_t), 1, out
);
428 (void)fseek(out
, final_offset
, SEEK_SET
);
431 /* END: code from module-init-tools/index.c just modified to compile here.
434 /* configuration parsing **********************************************/
435 struct cfg_override
{
436 struct cfg_override
*next
;
448 struct cfg_search
*next
;
449 enum search_type type
;
454 struct cfg_external
{
455 struct cfg_external
*next
;
461 const char *kversion
;
462 char dirname
[PATH_MAX
];
465 uint8_t check_symvers
;
466 uint8_t print_unknown
;
468 struct cfg_override
*overrides
;
469 struct cfg_search
*searches
;
470 struct cfg_external
*externals
;
473 static enum search_type
cfg_define_search_type(const char *path
)
475 if (streq(path
, CFG_BUILTIN_KEY
))
476 return SEARCH_BUILTIN
;
477 if (streq(path
, CFG_EXTERNAL_KEY
))
478 return SEARCH_EXTERNAL
;
482 static int cfg_search_add(struct cfg
*cfg
, const char *path
)
484 struct cfg_search
*s
;
486 enum search_type type
;
488 type
= cfg_define_search_type(path
);
490 if (type
!= SEARCH_PATH
)
493 len
= strlen(path
) + 1;
495 s
= malloc(sizeof(struct cfg_search
) + len
);
497 ERR("search add: out of memory\n");
501 if (type
!= SEARCH_PATH
)
505 memcpy(s
->path
, path
, len
);
508 DBG("search add: %s, search type=%hhu\n", path
, type
);
510 s
->next
= cfg
->searches
;
515 static void cfg_search_free(struct cfg_search
*s
)
520 static int cfg_override_add(struct cfg
*cfg
, const char *modname
, const char *subdir
)
522 struct cfg_override
*o
;
523 size_t modnamelen
= strlen(modname
);
524 size_t subdirlen
= strlen(subdir
);
527 o
= malloc(sizeof(struct cfg_override
) + subdirlen
+ 1
530 ERR("override add: out of memory\n");
533 memcpy(o
->path
, subdir
, subdirlen
);
538 memcpy(o
->path
+ i
, modname
, modnamelen
);
540 o
->path
[i
] = '\0'; /* no extension, so we can match .ko/.ko.gz */
544 DBG("override add: %s\n", o
->path
);
546 o
->next
= cfg
->overrides
;
551 static void cfg_override_free(struct cfg_override
*o
)
556 static int cfg_external_add(struct cfg
*cfg
, const char *path
)
558 struct cfg_external
*ext
;
559 size_t len
= strlen(path
);
561 ext
= malloc(sizeof(struct cfg_external
) + len
+ 1);
563 ERR("external add: out of memory\n");
567 strcpy(ext
->path
, path
);
570 DBG("external add: %s\n", ext
->path
);
572 ext
->next
= cfg
->externals
;
573 cfg
->externals
= ext
;
577 static void cfg_external_free(struct cfg_external
*ext
)
582 static int cfg_kernel_matches(const struct cfg
*cfg
, const char *pattern
)
588 if (streq(pattern
, "*"))
591 if (regcomp(&re
, pattern
, REG_EXTENDED
|REG_NOSUB
) != 0)
594 status
= regexec(&re
, cfg
->kversion
, 0, NULL
, 0);
600 static int cfg_file_parse(struct cfg
*cfg
, const char *filename
)
604 unsigned int linenum
= 0;
607 fp
= fopen(filename
, "r");
610 ERR("file parse %s: %m\n", filename
);
614 while ((line
= freadline_wrapped(fp
, &linenum
)) != NULL
) {
617 if (line
[0] == '\0' || line
[0] == '#')
620 cmd
= strtok_r(line
, "\t ", &saveptr
);
624 if (streq(cmd
, "search")) {
626 while ((sp
= strtok_r(NULL
, "\t ", &saveptr
)) != NULL
) {
627 cfg_search_add(cfg
, sp
);
629 } else if (streq(cmd
, "override")) {
630 const char *modname
= strtok_r(NULL
, "\t ", &saveptr
);
631 const char *version
= strtok_r(NULL
, "\t ", &saveptr
);
632 const char *subdir
= strtok_r(NULL
, "\t ", &saveptr
);
634 if (modname
== NULL
|| version
== NULL
||
638 if (!cfg_kernel_matches(cfg
, version
)) {
639 INF("%s:%u: override kernel did not match %s\n",
640 filename
, linenum
, version
);
644 cfg_override_add(cfg
, modname
, subdir
);
645 } else if (streq(cmd
, "external")) {
646 const char *version
= strtok_r(NULL
, "\t ", &saveptr
);
647 const char *dir
= strtok_r(NULL
, "\t ", &saveptr
);
649 if (version
== NULL
|| dir
== NULL
)
652 if (!cfg_kernel_matches(cfg
, version
)) {
653 INF("%s:%u: external directory did not match %s\n",
654 filename
, linenum
, version
);
658 cfg_external_add(cfg
, dir
);
659 } else if (streq(cmd
, "include")
660 || streq(cmd
, "make_map_files")) {
661 INF("%s:%u: command %s not implemented yet\n",
662 filename
, linenum
, cmd
);
665 ERR("%s:%u: ignoring bad line starting with '%s'\n",
666 filename
, linenum
, cmd
);
678 static int cfg_files_filter_out(DIR *d
, const char *dir
, const char *name
)
680 size_t len
= strlen(name
);
686 if (len
< 6 || !streq(name
+ len
- 5, ".conf")) {
687 INF("All cfg files need .conf: %s/%s\n", dir
, name
);
691 fstatat(dirfd(d
), name
, &st
, 0);
692 if (S_ISDIR(st
.st_mode
)) {
693 ERR("Directories inside directories are not supported: %s/%s\n",
708 static void cfg_file_free(struct cfg_file
*f
)
713 static int cfg_files_insert_sorted(struct cfg_file
***p_files
, size_t *p_n_files
,
714 const char *dir
, const char *name
)
716 struct cfg_file
**files
, *f
;
717 size_t i
, n_files
, namelen
, dirlen
;
720 dirlen
= strlen(dir
);
722 namelen
= strlen(name
);
724 name
= basename(dir
);
725 namelen
= strlen(name
);
726 dirlen
-= namelen
+ 1;
729 n_files
= *p_n_files
;
731 for (i
= 0; i
< n_files
; i
++) {
732 int cmp
= strcmp(name
, files
[i
]->name
);
734 DBG("Ignoring duplicate config file: %.*s/%s\n",
735 (int)dirlen
, dir
, name
);
741 f
= malloc(sizeof(struct cfg_file
) + dirlen
+ namelen
+ 2);
743 ERR("files insert sorted: out of memory\n");
747 tmp
= realloc(files
, sizeof(struct cfg_file
*) * (n_files
+ 1));
749 ERR("files insert sorted: out of memory\n");
753 *p_files
= files
= tmp
;
756 memmove(files
+ i
+ 1, files
+ i
,
757 sizeof(struct cfg_file
*) * (n_files
- i
));
762 f
->namelen
= namelen
;
763 f
->name
= f
->path
+ dirlen
+ 1;
764 memcpy(f
->path
, dir
, dirlen
);
765 f
->path
[dirlen
] = '/';
766 memcpy(f
->path
+ dirlen
+ 1, name
, namelen
);
767 f
->path
[dirlen
+ 1 + namelen
] = '\0';
769 *p_n_files
= n_files
+ 1;
774 * Insert configuration files ignoring duplicates
776 static int cfg_files_list(struct cfg_file
***p_files
, size_t *p_n_files
,
784 if (stat(path
, &st
) != 0) {
786 DBG("could not stat '%s': %m\n", path
);
790 if (!S_ISDIR(st
.st_mode
)) {
791 cfg_files_insert_sorted(p_files
, p_n_files
, path
, NULL
);
797 ERR("files list %s: %m\n", path
);
801 for (dent
= readdir(d
); dent
!= NULL
; dent
= readdir(d
)) {
802 if (cfg_files_filter_out(d
, path
, dent
->d_name
))
805 cfg_files_insert_sorted(p_files
, p_n_files
, path
, dent
->d_name
);
809 DBG("parsed configuration files from %s\n", path
);
813 static int cfg_load(struct cfg
*cfg
, const char * const *cfg_paths
)
815 size_t i
, n_files
= 0;
816 struct cfg_file
**files
= NULL
;
818 if (cfg_paths
== NULL
)
819 cfg_paths
= default_cfg_paths
;
821 for (i
= 0; cfg_paths
[i
] != NULL
; i
++)
822 cfg_files_list(&files
, &n_files
, cfg_paths
[i
]);
824 for (i
= 0; i
< n_files
; i
++) {
825 struct cfg_file
*f
= files
[i
];
826 cfg_file_parse(cfg
, f
->path
);
831 /* For backward compatibility add "updates" to the head of the search
832 * list here. But only if there was no "search" option specified.
834 if (cfg
->searches
== NULL
)
835 cfg_search_add(cfg
, "updates");
840 static void cfg_free(struct cfg
*cfg
)
842 while (cfg
->overrides
) {
843 struct cfg_override
*tmp
= cfg
->overrides
;
844 cfg
->overrides
= cfg
->overrides
->next
;
845 cfg_override_free(tmp
);
848 while (cfg
->searches
) {
849 struct cfg_search
*tmp
= cfg
->searches
;
850 cfg
->searches
= cfg
->searches
->next
;
851 cfg_search_free(tmp
);
854 while (cfg
->externals
) {
855 struct cfg_external
*tmp
= cfg
->externals
;
856 cfg
->externals
= cfg
->externals
->next
;
857 cfg_external_free(tmp
);
862 /* depmod calculations ***********************************************/
865 struct kmod_module
*kmod
;
867 const char *relpath
; /* path relative to '$ROOT/lib/modules/$VER/' */
868 char *uncrelpath
; /* same as relpath but ending in .ko */
869 struct kmod_list
*info_list
;
870 struct kmod_list
*dep_sym_list
;
871 struct array deps
; /* struct symbol */
872 size_t baselen
; /* points to start of basename/filename */
874 int sort_idx
; /* sort index using modules.order */
875 int dep_sort_idx
; /* topological sort index */
876 uint16_t idx
; /* index in depmod->modules.array */
877 uint16_t users
; /* how many modules depend on this one */
878 bool visited
; /* helper field to report cycles */
879 struct vertex
*vertex
; /* helper field to report cycles */
890 const struct cfg
*cfg
;
891 struct kmod_ctx
*ctx
;
892 struct array modules
;
893 struct hash
*modules_by_uncrelpath
;
894 struct hash
*modules_by_name
;
895 struct hash
*symbols
;
898 static void mod_free(struct mod
*mod
)
900 DBG("free %p kmod=%p, path=%s\n", mod
, mod
->kmod
, mod
->path
);
901 array_free_array(&mod
->deps
);
902 kmod_module_unref(mod
->kmod
);
903 kmod_module_info_free_list(mod
->info_list
);
904 kmod_module_dependency_symbols_free_list(mod
->dep_sym_list
);
905 free(mod
->uncrelpath
);
910 static int mod_add_dependency(struct mod
*mod
, struct symbol
*sym
)
914 DBG("%s depends on %s %s\n", mod
->path
, sym
->name
,
915 sym
->owner
!= NULL
? sym
->owner
->path
: "(unknown)");
917 if (sym
->owner
== NULL
)
920 err
= array_append_unique(&mod
->deps
, sym
->owner
);
927 SHOW("%s needs \"%s\": %s\n", mod
->path
, sym
->name
, sym
->owner
->path
);
931 static void symbol_free(struct symbol
*sym
)
933 DBG("free %p sym=%s, owner=%p %s\n", sym
, sym
->name
, sym
->owner
,
934 sym
->owner
!= NULL
? sym
->owner
->path
: "");
938 static int depmod_init(struct depmod
*depmod
, struct cfg
*cfg
,
939 struct kmod_ctx
*ctx
)
946 array_init(&depmod
->modules
, 128);
948 depmod
->modules_by_uncrelpath
= hash_new(512, NULL
);
949 if (depmod
->modules_by_uncrelpath
== NULL
) {
951 goto modules_by_uncrelpath_failed
;
954 depmod
->modules_by_name
= hash_new(512, NULL
);
955 if (depmod
->modules_by_name
== NULL
) {
957 goto modules_by_name_failed
;
960 depmod
->symbols
= hash_new(2048, (void (*)(void *))symbol_free
);
961 if (depmod
->symbols
== NULL
) {
969 hash_free(depmod
->modules_by_name
);
970 modules_by_name_failed
:
971 hash_free(depmod
->modules_by_uncrelpath
);
972 modules_by_uncrelpath_failed
:
976 static void depmod_shutdown(struct depmod
*depmod
)
980 hash_free(depmod
->symbols
);
982 hash_free(depmod
->modules_by_uncrelpath
);
984 hash_free(depmod
->modules_by_name
);
986 for (i
= 0; i
< depmod
->modules
.count
; i
++)
987 mod_free(depmod
->modules
.array
[i
]);
988 array_free_array(&depmod
->modules
);
990 kmod_unref(depmod
->ctx
);
993 static int depmod_module_add(struct depmod
*depmod
, struct kmod_module
*kmod
)
995 const struct cfg
*cfg
= depmod
->cfg
;
996 const char *modname
, *lastslash
;
1001 modname
= kmod_module_get_name(kmod
);
1002 modnamesz
= strlen(modname
) + 1;
1004 mod
= calloc(1, sizeof(struct mod
) + modnamesz
);
1008 mod
->sort_idx
= depmod
->modules
.count
+ 1;
1009 mod
->dep_sort_idx
= INT32_MAX
;
1010 memcpy(mod
->modname
, modname
, modnamesz
);
1011 mod
->modnamesz
= modnamesz
;
1013 array_init(&mod
->deps
, 4);
1015 mod
->path
= strdup(kmod_module_get_path(kmod
));
1016 lastslash
= strrchr(mod
->path
, '/');
1017 mod
->baselen
= lastslash
- mod
->path
;
1018 if (strncmp(mod
->path
, cfg
->dirname
, cfg
->dirnamelen
) == 0 &&
1019 mod
->path
[cfg
->dirnamelen
] == '/')
1020 mod
->relpath
= mod
->path
+ cfg
->dirnamelen
+ 1;
1022 mod
->relpath
= NULL
;
1024 err
= hash_add_unique(depmod
->modules_by_name
, mod
->modname
, mod
);
1026 ERR("hash_add_unique %s: %s\n", mod
->modname
, strerror(-err
));
1030 if (mod
->relpath
!= NULL
) {
1031 size_t uncrelpathlen
= lastslash
- mod
->relpath
+ modnamesz
1032 + strlen(KMOD_EXTENSION_UNCOMPRESSED
);
1033 mod
->uncrelpath
= memdup(mod
->relpath
, uncrelpathlen
+ 1);
1034 mod
->uncrelpath
[uncrelpathlen
] = '\0';
1035 err
= hash_add_unique(depmod
->modules_by_uncrelpath
,
1036 mod
->uncrelpath
, mod
);
1038 ERR("hash_add_unique %s: %s\n",
1039 mod
->uncrelpath
, strerror(-err
));
1040 hash_del(depmod
->modules_by_name
, mod
->modname
);
1045 DBG("add %p kmod=%p, path=%s\n", mod
, kmod
, mod
->path
);
1050 free(mod
->uncrelpath
);
1055 static int depmod_module_del(struct depmod
*depmod
, struct mod
*mod
)
1057 DBG("del %p kmod=%p, path=%s\n", mod
, mod
->kmod
, mod
->path
);
1059 if (mod
->uncrelpath
!= NULL
)
1060 hash_del(depmod
->modules_by_uncrelpath
, mod
->uncrelpath
);
1062 hash_del(depmod
->modules_by_name
, mod
->modname
);
1068 static const char *search_to_string(const struct cfg_search
*s
)
1071 case SEARCH_EXTERNAL
:
1073 case SEARCH_BUILTIN
:
1080 static bool depmod_is_path_starts_with(const char *path
,
1085 if (pathlen
<= prefix_len
)
1087 if (path
[prefix_len
] != '/')
1089 if (memcmp(path
, prefix
, prefix_len
) != 0)
1095 /* returns if existing module @mod is higher priority than newpath.
1096 * note this is the inverse of module-init-tools is_higher_priority()
1098 static int depmod_module_is_higher_priority(const struct depmod
*depmod
, const struct mod
*mod
, size_t baselen
, size_t namelen
, size_t modnamelen
, const char *newpath
)
1100 const struct cfg
*cfg
= depmod
->cfg
;
1101 const struct cfg_override
*ov
;
1102 const struct cfg_search
*se
;
1103 const struct cfg_external
*ext
;
1105 /* baselen includes the last '/' and mod->baselen doesn't. So it's
1106 * actually correct to use modnamelen in the first and modnamesz in
1108 size_t newlen
= baselen
+ modnamelen
;
1109 size_t oldlen
= mod
->baselen
+ mod
->modnamesz
;
1110 const char *oldpath
= mod
->path
;
1111 int i
, bprio
= -1, oldprio
= -1, newprio
= -1;
1112 size_t relnewlen
= 0;
1113 size_t reloldlen
= 0;
1114 const char *relnewpath
= NULL
;
1115 const char *reloldpath
= NULL
;
1117 DBG("comparing priorities of %s and %s\n",
1120 if (strncmp(newpath
, cfg
->dirname
, cfg
->dirnamelen
) == 0) {
1121 relnewpath
= newpath
+ cfg
->dirnamelen
+ 1;
1122 relnewlen
= newlen
- (cfg
->dirnamelen
+ 1);
1124 if (strncmp(oldpath
, cfg
->dirname
, cfg
->dirnamelen
) == 0) {
1125 reloldpath
= oldpath
+ cfg
->dirnamelen
+ 1;
1126 reloldlen
= oldlen
- (cfg
->dirnamelen
+ 1);
1129 for (ov
= cfg
->overrides
; ov
!= NULL
; ov
= ov
->next
) {
1130 DBG("override %s\n", ov
->path
);
1131 if (relnewlen
== ov
->len
&&
1132 memcmp(ov
->path
, relnewpath
, relnewlen
) == 0)
1134 if (reloldlen
== ov
->len
&&
1135 memcmp(ov
->path
, reloldpath
, reloldlen
) == 0)
1139 for (i
= 0, se
= cfg
->searches
; se
!= NULL
; se
= se
->next
, i
++) {
1140 DBG("search %s\n", search_to_string(se
));
1141 if (se
->type
== SEARCH_BUILTIN
)
1143 else if (se
->type
== SEARCH_EXTERNAL
) {
1144 for (ext
= cfg
->externals
; ext
!= NULL
; ext
= ext
->next
, i
++) {
1145 if (depmod_is_path_starts_with(newpath
,
1150 if (depmod_is_path_starts_with(oldpath
,
1156 } else if (relnewlen
> se
->len
&& relnewpath
[se
->len
] == '/' &&
1157 memcmp(se
->path
, relnewpath
, se
->len
) == 0)
1159 else if (reloldlen
> se
->len
&& reloldpath
[se
->len
] == '/' &&
1160 memcmp(se
->path
, reloldpath
, se
->len
) == 0)
1169 DBG("priorities: built-in: %d, old: %d, new: %d\n",
1170 bprio
, oldprio
, newprio
);
1172 return newprio
<= oldprio
;
1175 static int depmod_modules_search_file(struct depmod
*depmod
, size_t baselen
, size_t namelen
, const char *path
)
1177 struct kmod_module
*kmod
;
1179 const char *relpath
;
1180 char modname
[PATH_MAX
];
1184 if (!path_ends_with_kmod_ext(path
+ baselen
, namelen
))
1187 if (path_to_modname(path
, modname
, &modnamelen
) == NULL
) {
1188 ERR("could not get modname from path %s\n", path
);
1192 relpath
= path
+ depmod
->cfg
->dirnamelen
+ 1;
1193 DBG("try %s (%s)\n", relpath
, modname
);
1195 mod
= hash_find(depmod
->modules_by_name
, modname
);
1199 if (depmod_module_is_higher_priority(depmod
, mod
, baselen
,
1200 namelen
, modnamelen
, path
)) {
1201 DBG("Ignored lower priority: %s, higher: %s\n",
1206 DBG("Replace lower priority %s with new module %s\n",
1207 mod
->relpath
, relpath
);
1208 err
= depmod_module_del(depmod
, mod
);
1210 ERR("could not del module %s: %s\n", mod
->path
, strerror(-err
));
1215 err
= kmod_module_new_from_path(depmod
->ctx
, path
, &kmod
);
1217 ERR("could not create module %s: %s\n", path
, strerror(-err
));
1221 err
= depmod_module_add(depmod
, kmod
);
1223 ERR("could not add module %s: %s\n",
1224 path
, strerror(-err
));
1225 kmod_module_unref(kmod
);
1231 static int depmod_modules_search_dir(struct depmod
*depmod
, DIR *d
, size_t baselen
, struct scratchbuf
*s_path
)
1234 int err
= 0, dfd
= dirfd(d
);
1237 while ((de
= readdir(d
)) != NULL
) {
1238 const char *name
= de
->d_name
;
1242 if (name
[0] == '.' && (name
[1] == '\0' ||
1243 (name
[1] == '.' && name
[2] == '\0')))
1245 if (streq(name
, "build") || streq(name
, "source"))
1247 namelen
= strlen(name
);
1248 if (scratchbuf_alloc(s_path
, baselen
+ namelen
+ 2) < 0) {
1254 path
= scratchbuf_str(s_path
);
1255 memcpy(path
+ baselen
, name
, namelen
+ 1);
1257 if (de
->d_type
== DT_REG
)
1259 else if (de
->d_type
== DT_DIR
)
1263 if (fstatat(dfd
, name
, &st
, 0) < 0) {
1264 ERR("fstatat(%d, %s): %m\n", dfd
, name
);
1266 } else if (S_ISREG(st
.st_mode
))
1268 else if (S_ISDIR(st
.st_mode
))
1271 ERR("unsupported file type %s: %o\n",
1272 path
, st
.st_mode
& S_IFMT
);
1280 fd
= openat(dfd
, name
, O_RDONLY
);
1282 ERR("openat(%d, %s, O_RDONLY): %m\n",
1286 subdir
= fdopendir(fd
);
1287 if (subdir
== NULL
) {
1288 ERR("fdopendir(%d): %m\n", fd
);
1292 path
[baselen
+ namelen
] = '/';
1293 path
[baselen
+ namelen
+ 1] = '\0';
1294 err
= depmod_modules_search_dir(depmod
, subdir
,
1295 baselen
+ namelen
+ 1,
1299 err
= depmod_modules_search_file(depmod
, baselen
,
1304 path
[baselen
+ namelen
] = '\0';
1305 ERR("failed %s: %s\n", path
, strerror(-err
));
1306 err
= 0; /* ignore errors */
1312 static int depmod_modules_search_path(struct depmod
*depmod
,
1316 _cleanup_(scratchbuf_release
) struct scratchbuf s_path_buf
=
1317 SCRATCHBUF_INITIALIZER(buf
);
1326 ERR("could not open directory %s: %m\n", path
);
1330 baselen
= strlen(path
);
1332 if (scratchbuf_alloc(&s_path_buf
, baselen
+ 2) < 0) {
1336 path_buf
= scratchbuf_str(&s_path_buf
);
1338 memcpy(path_buf
, path
, baselen
);
1339 path_buf
[baselen
] = '/';
1341 path_buf
[baselen
] = '\0';
1343 err
= depmod_modules_search_dir(depmod
, d
, baselen
, &s_path_buf
);
1349 static int depmod_modules_search(struct depmod
*depmod
)
1352 struct cfg_external
*ext
;
1354 err
= depmod_modules_search_path(depmod
, depmod
->cfg
->dirname
);
1358 for (ext
= depmod
->cfg
->externals
; ext
!= NULL
; ext
= ext
->next
) {
1359 err
= depmod_modules_search_path(depmod
, ext
->path
);
1360 if (err
< 0 && err
== -ENOENT
)
1361 /* ignore external dir absense */
1368 static int mod_cmp(const void *pa
, const void *pb
) {
1369 const struct mod
*a
= *(const struct mod
**)pa
;
1370 const struct mod
*b
= *(const struct mod
**)pb
;
1371 return a
->sort_idx
- b
->sort_idx
;
1374 static int depmod_modules_build_array(struct depmod
*depmod
)
1376 struct hash_iter module_iter
;
1380 hash_iter_init(depmod
->modules_by_name
, &module_iter
);
1381 while (hash_iter_next(&module_iter
, NULL
, &v
)) {
1382 struct mod
*mod
= (struct mod
*) v
;
1383 mod
->idx
= depmod
->modules
.count
;
1384 err
= array_append(&depmod
->modules
, mod
);
1392 static void depmod_modules_sort(struct depmod
*depmod
)
1394 char order_file
[PATH_MAX
], line
[PATH_MAX
];
1396 unsigned idx
= 0, total
= 0;
1398 snprintf(order_file
, sizeof(order_file
), "%s/modules.order",
1399 depmod
->cfg
->dirname
);
1400 fp
= fopen(order_file
, "r");
1402 WRN("could not open %s: %m\n", order_file
);
1406 while (fgets(line
, sizeof(line
), fp
) != NULL
) {
1407 size_t len
= strlen(line
);
1411 if (line
[len
- 1] != '\n') {
1412 ERR("%s:%u corrupted line misses '\\n'\n",
1419 fseek(fp
, 0, SEEK_SET
);
1420 while (fgets(line
, sizeof(line
), fp
) != NULL
) {
1421 size_t len
= strlen(line
);
1427 line
[len
- 1] = '\0';
1429 mod
= hash_find(depmod
->modules_by_uncrelpath
, line
);
1432 mod
->sort_idx
= idx
- total
;
1435 array_sort(&depmod
->modules
, mod_cmp
);
1436 for (idx
= 0; idx
< depmod
->modules
.count
; idx
++) {
1437 struct mod
*m
= depmod
->modules
.array
[idx
];
1445 static int depmod_symbol_add(struct depmod
*depmod
, const char *name
,
1446 bool prefix_skipped
, uint64_t crc
,
1447 const struct mod
*owner
)
1453 if (!prefix_skipped
&& (name
[0] == depmod
->cfg
->sym_prefix
))
1456 namelen
= strlen(name
) + 1;
1457 sym
= malloc(sizeof(struct symbol
) + namelen
);
1461 sym
->owner
= (struct mod
*)owner
;
1463 memcpy(sym
->name
, name
, namelen
);
1465 err
= hash_add(depmod
->symbols
, sym
->name
, sym
);
1471 DBG("add %p sym=%s, owner=%p %s\n", sym
, sym
->name
, owner
,
1472 owner
!= NULL
? owner
->path
: "");
1477 static struct symbol
*depmod_symbol_find(const struct depmod
*depmod
,
1480 if (name
[0] == '.') /* PPC64 needs this: .foo == foo */
1482 if (name
[0] == depmod
->cfg
->sym_prefix
)
1484 return hash_find(depmod
->symbols
, name
);
1487 static int depmod_load_modules(struct depmod
*depmod
)
1489 struct mod
**itr
, **itr_end
;
1491 DBG("load symbols (%zd modules)\n", depmod
->modules
.count
);
1493 itr
= (struct mod
**)depmod
->modules
.array
;
1494 itr_end
= itr
+ depmod
->modules
.count
;
1495 for (; itr
< itr_end
; itr
++) {
1496 struct mod
*mod
= *itr
;
1497 struct kmod_list
*l
, *list
= NULL
;
1498 int err
= kmod_module_get_symbols(mod
->kmod
, &list
);
1501 DBG("ignoring %s: no symbols\n", mod
->path
);
1503 ERR("failed to load symbols from %s: %s\n",
1504 mod
->path
, strerror(-err
));
1507 kmod_list_foreach(l
, list
) {
1508 const char *name
= kmod_module_symbol_get_symbol(l
);
1509 uint64_t crc
= kmod_module_symbol_get_crc(l
);
1510 depmod_symbol_add(depmod
, name
, false, crc
, mod
);
1512 kmod_module_symbols_free_list(list
);
1515 kmod_module_get_info(mod
->kmod
, &mod
->info_list
);
1516 kmod_module_get_dependency_symbols(mod
->kmod
,
1517 &mod
->dep_sym_list
);
1518 kmod_module_unref(mod
->kmod
);
1522 DBG("loaded symbols (%zd modules, %u symbols)\n",
1523 depmod
->modules
.count
, hash_get_count(depmod
->symbols
));
1528 static int depmod_load_module_dependencies(struct depmod
*depmod
, struct mod
*mod
)
1530 const struct cfg
*cfg
= depmod
->cfg
;
1531 struct kmod_list
*l
;
1533 DBG("do dependencies of %s\n", mod
->path
);
1534 kmod_list_foreach(l
, mod
->dep_sym_list
) {
1535 const char *name
= kmod_module_dependency_symbol_get_symbol(l
);
1536 uint64_t crc
= kmod_module_dependency_symbol_get_crc(l
);
1537 int bindtype
= kmod_module_dependency_symbol_get_bind(l
);
1538 struct symbol
*sym
= depmod_symbol_find(depmod
, name
);
1539 uint8_t is_weak
= bindtype
== KMOD_SYMBOL_WEAK
;
1542 DBG("%s needs (%c) unknown symbol %s\n",
1543 mod
->path
, bindtype
, name
);
1544 if (cfg
->print_unknown
&& !is_weak
)
1545 WRN("%s needs unknown symbol %s\n",
1550 if (cfg
->check_symvers
&& sym
->crc
!= crc
&& !is_weak
) {
1551 DBG("symbol %s (%#"PRIx64
") module %s (%#"PRIx64
")\n",
1552 sym
->name
, sym
->crc
, mod
->path
, crc
);
1553 if (cfg
->print_unknown
)
1554 WRN("%s disagrees about version of symbol %s\n",
1558 mod_add_dependency(mod
, sym
);
1564 static int depmod_load_dependencies(struct depmod
*depmod
)
1566 struct mod
**itr
, **itr_end
;
1568 DBG("load dependencies (%zd modules, %u symbols)\n",
1569 depmod
->modules
.count
, hash_get_count(depmod
->symbols
));
1571 itr
= (struct mod
**)depmod
->modules
.array
;
1572 itr_end
= itr
+ depmod
->modules
.count
;
1573 for (; itr
< itr_end
; itr
++) {
1574 struct mod
*mod
= *itr
;
1576 if (mod
->dep_sym_list
== NULL
) {
1577 DBG("ignoring %s: no dependency symbols\n", mod
->path
);
1581 depmod_load_module_dependencies(depmod
, mod
);
1584 DBG("loaded dependencies (%zd modules, %u symbols)\n",
1585 depmod
->modules
.count
, hash_get_count(depmod
->symbols
));
1590 static int dep_cmp(const void *pa
, const void *pb
)
1592 const struct mod
*a
= *(const struct mod
**)pa
;
1593 const struct mod
*b
= *(const struct mod
**)pb
;
1594 return a
->dep_sort_idx
- b
->dep_sort_idx
;
1597 static void depmod_sort_dependencies(struct depmod
*depmod
)
1599 struct mod
**itr
, **itr_end
;
1600 itr
= (struct mod
**)depmod
->modules
.array
;
1601 itr_end
= itr
+ depmod
->modules
.count
;
1602 for (; itr
< itr_end
; itr
++) {
1603 struct mod
*m
= *itr
;
1604 if (m
->deps
.count
> 1)
1605 array_sort(&m
->deps
, dep_cmp
);
1610 struct vertex
*parent
;
1614 static struct vertex
*vertex_new(struct mod
*mod
, struct vertex
*parent
)
1618 v
= malloc(sizeof(*v
));
1627 static void depmod_list_remove_data(struct kmod_list
**list
, void *data
)
1629 struct kmod_list
*l
;
1631 l
= kmod_list_remove_data(*list
, data
);
1635 static int depmod_report_one_cycle(struct depmod
*depmod
,
1636 struct vertex
*vertex
,
1637 struct kmod_list
**roots
,
1638 struct hash
*loop_set
)
1640 const char sep
[] = " -> ";
1643 struct array reverse
;
1649 array_init(&reverse
, 3);
1652 for (v
= vertex
->parent
, n
= 0;
1654 v
= v
->parent
, n
++) {
1656 sz
+= v
->mod
->modnamesz
- 1;
1657 array_append(&reverse
, v
);
1658 rc
= hash_add(loop_set
, v
->mod
->modname
, NULL
);
1661 /* the hash will be freed where created */
1663 sz
+= vertex
->mod
->modnamesz
- 1;
1665 buf
= malloc(sz
+ n
* strlen(sep
) + 1);
1668 for (i
= reverse
.count
- 1; i
>= 0; i
--) {
1671 v
= reverse
.array
[i
];
1673 len
= v
->mod
->modnamesz
- 1;
1674 memcpy(buf
+ sz
, v
->mod
->modname
, len
);
1676 strcpy(buf
+ sz
, sep
);
1679 depmod_list_remove_data(roots
, v
->mod
);
1681 strcpy(buf
+ sz
, vertex
->mod
->modname
);
1682 ERR("Cycle detected: %s\n", buf
);
1685 array_free_array(&reverse
);
1690 static int depmod_report_cycles_from_root(struct depmod
*depmod
,
1691 struct mod
*root_mod
,
1692 struct kmod_list
**roots
,
1695 struct hash
*loop_set
)
1697 struct kmod_list
*free_list
= NULL
; /* struct vertex */
1698 struct kmod_list
*l
;
1699 struct vertex
*root
;
1700 struct vertex
*vertex
;
1703 struct mod
**itr
, **itr_end
;
1707 root
= vertex_new(root_mod
, NULL
);
1709 ERR("No memory to report cycles\n");
1713 l
= kmod_list_append(free_list
, root
);
1715 ERR("No memory to report cycles\n");
1721 stack
[is
++] = (void *)root
;
1724 vertex
= stack
[--is
];
1727 * because of the topological sort we can start only
1728 * from part of a loop or from a branch after a loop
1730 if (m
->visited
&& m
== root
->mod
) {
1732 rc
= depmod_report_one_cycle(depmod
, vertex
,
1742 if (m
->deps
.count
== 0) {
1744 * boundary condition: if there is more than one
1745 * single node branch (not a loop), it is
1746 * recognized as a loop by the code above:
1747 * m->visited because more then one,
1748 * m == root->mod since it is a single node.
1749 * So, prevent deeping into the branch second
1752 depmod_list_remove_data(roots
, m
);
1757 itr
= (struct mod
**) m
->deps
.array
;
1758 itr_end
= itr
+ m
->deps
.count
;
1759 for (; itr
< itr_end
; itr
++) {
1760 struct mod
*dep
= *itr
;
1761 v
= vertex_new(dep
, vertex
);
1763 ERR("No memory to report cycles\n");
1766 assert(is
< stack_size
);
1769 l
= kmod_list_append(free_list
, v
);
1771 ERR("No memory to report cycles\n");
1782 v
= free_list
->data
;
1783 l
= kmod_list_remove(free_list
);
1791 static void depmod_report_cycles(struct depmod
*depmod
, uint16_t n_mods
,
1795 struct kmod_list
*roots
= NULL
; /* struct mod */
1796 struct kmod_list
*l
;
1797 size_t n_r
; /* local n_roots */
1800 _cleanup_free_
void **stack
= NULL
;
1803 struct hash
*loop_set
;
1805 for (i
= 0, n_r
= 0; i
< n_mods
; i
++) {
1808 m
= depmod
->modules
.array
[i
];
1809 l
= kmod_list_append(roots
, m
);
1811 ERR("No memory to report cycles\n");
1818 stack
= malloc(n_r
* sizeof(void *));
1819 if (stack
== NULL
) {
1820 ERR("No memory to report cycles\n");
1824 loop_set
= hash_new(16, NULL
);
1825 if (loop_set
== NULL
) {
1826 ERR("No memory to report cycles\n");
1830 while (roots
!= NULL
) {
1832 l
= kmod_list_remove(roots
);
1834 err
= depmod_report_cycles_from_root(depmod
,
1837 stack
, n_r
, loop_set
);
1842 num_cyclic
= hash_get_count(loop_set
);
1843 ERR("Found %d modules in dependency cycles!\n", num_cyclic
);
1846 hash_free(loop_set
);
1848 while (roots
!= NULL
) {
1849 /* no need to free data, come from outside */
1850 roots
= kmod_list_remove(roots
);
1854 static int depmod_calculate_dependencies(struct depmod
*depmod
)
1856 const struct mod
**itrm
;
1857 uint16_t *users
, *roots
, *sorted
;
1858 uint16_t i
, n_roots
= 0, n_sorted
= 0, n_mods
= depmod
->modules
.count
;
1861 users
= malloc(sizeof(uint16_t) * n_mods
* 3);
1864 roots
= users
+ n_mods
;
1865 sorted
= roots
+ n_mods
;
1867 DBG("calculate dependencies and ordering (%hu modules)\n", n_mods
);
1869 assert(depmod
->modules
.count
< UINT16_MAX
);
1871 /* populate modules users (how many modules uses it) */
1872 itrm
= (const struct mod
**)depmod
->modules
.array
;
1873 for (i
= 0; i
< n_mods
; i
++, itrm
++) {
1874 const struct mod
*m
= *itrm
;
1875 users
[i
] = m
->users
;
1876 if (users
[i
] == 0) {
1882 /* topological sort (outputs modules without users first) */
1883 while (n_roots
> 0) {
1884 const struct mod
**itr_dst
, **itr_dst_end
;
1886 uint16_t src_idx
= roots
[--n_roots
];
1888 src
= depmod
->modules
.array
[src_idx
];
1889 src
->dep_sort_idx
= n_sorted
;
1890 sorted
[n_sorted
] = src_idx
;
1893 itr_dst
= (const struct mod
**)src
->deps
.array
;
1894 itr_dst_end
= itr_dst
+ src
->deps
.count
;
1895 for (; itr_dst
< itr_dst_end
; itr_dst
++) {
1896 const struct mod
*dst
= *itr_dst
;
1897 uint16_t dst_idx
= dst
->idx
;
1898 assert(users
[dst_idx
] > 0);
1900 if (users
[dst_idx
] == 0) {
1901 roots
[n_roots
] = dst_idx
;
1907 if (n_sorted
< n_mods
) {
1908 depmod_report_cycles(depmod
, n_mods
, users
);
1913 depmod_sort_dependencies(depmod
);
1915 DBG("calculated dependencies and ordering (%hu modules)\n", n_mods
);
1922 static int depmod_load(struct depmod
*depmod
)
1926 err
= depmod_load_modules(depmod
);
1930 err
= depmod_load_dependencies(depmod
);
1934 err
= depmod_calculate_dependencies(depmod
);
1941 static size_t mod_count_all_dependencies(const struct mod
*mod
)
1943 size_t i
, count
= 0;
1944 for (i
= 0; i
< mod
->deps
.count
; i
++) {
1945 const struct mod
*d
= mod
->deps
.array
[i
];
1946 count
+= 1 + mod_count_all_dependencies(d
);
1951 static int mod_fill_all_unique_dependencies(const struct mod
*mod
, const struct mod
**deps
, size_t n_deps
, size_t *last
)
1955 for (i
= 0; i
< mod
->deps
.count
; i
++) {
1956 const struct mod
*d
= mod
->deps
.array
[i
];
1960 for (j
= 0; j
< *last
; j
++) {
1970 if (*last
>= n_deps
)
1974 err
= mod_fill_all_unique_dependencies(d
, deps
, n_deps
, last
);
1981 static const struct mod
**mod_get_all_sorted_dependencies(const struct mod
*mod
, size_t *n_deps
)
1983 const struct mod
**deps
;
1986 *n_deps
= mod_count_all_dependencies(mod
);
1990 deps
= malloc(sizeof(struct mod
*) * (*n_deps
));
1994 if (mod_fill_all_unique_dependencies(mod
, deps
, *n_deps
, &last
) < 0) {
1999 qsort(deps
, last
, sizeof(struct mod
*), dep_cmp
);
2004 static inline const char *mod_get_compressed_path(const struct mod
*mod
)
2006 if (mod
->relpath
!= NULL
)
2007 return mod
->relpath
;
2011 static int output_deps(struct depmod
*depmod
, FILE *out
)
2015 for (i
= 0; i
< depmod
->modules
.count
; i
++) {
2016 const struct mod
**deps
, *mod
= depmod
->modules
.array
[i
];
2017 const char *p
= mod_get_compressed_path(mod
);
2020 fprintf(out
, "%s:", p
);
2022 if (mod
->deps
.count
== 0)
2025 deps
= mod_get_all_sorted_dependencies(mod
, &n_deps
);
2027 ERR("could not get all sorted dependencies of %s\n", p
);
2031 for (j
= 0; j
< n_deps
; j
++) {
2032 const struct mod
*d
= deps
[j
];
2033 fprintf(out
, " %s", mod_get_compressed_path(d
));
2043 static int output_deps_bin(struct depmod
*depmod
, FILE *out
)
2045 struct index_node
*idx
;
2051 idx
= index_create();
2055 for (i
= 0; i
< depmod
->modules
.count
; i
++) {
2056 const struct mod
**deps
, *mod
= depmod
->modules
.array
[i
];
2057 const char *p
= mod_get_compressed_path(mod
);
2059 size_t j
, n_deps
, linepos
, linelen
, slen
;
2062 deps
= mod_get_all_sorted_dependencies(mod
, &n_deps
);
2063 if (deps
== NULL
&& n_deps
> 0) {
2064 ERR("could not get all sorted dependencies of %s\n", p
);
2068 linelen
= strlen(p
) + 1;
2069 for (j
= 0; j
< n_deps
; j
++) {
2070 const struct mod
*d
= deps
[j
];
2071 linelen
+= 1 + strlen(mod_get_compressed_path(d
));
2074 line
= malloc(linelen
+ 1);
2077 ERR("modules.deps.bin: out of memory\n");
2083 memcpy(line
+ linepos
, p
, slen
);
2085 line
[linepos
] = ':';
2088 for (j
= 0; j
< n_deps
; j
++) {
2089 const struct mod
*d
= deps
[j
];
2092 line
[linepos
] = ' ';
2095 dp
= mod_get_compressed_path(d
);
2097 memcpy(line
+ linepos
, dp
, slen
);
2100 line
[linepos
] = '\0';
2102 duplicate
= index_insert(idx
, mod
->modname
, line
, mod
->idx
);
2103 if (duplicate
&& depmod
->cfg
->warn_dups
)
2104 WRN("duplicate module deps:\n%s\n", line
);
2109 index_write(idx
, out
);
2115 static int output_aliases(struct depmod
*depmod
, FILE *out
)
2119 fputs("# Aliases extracted from modules themselves.\n", out
);
2121 for (i
= 0; i
< depmod
->modules
.count
; i
++) {
2122 const struct mod
*mod
= depmod
->modules
.array
[i
];
2123 struct kmod_list
*l
;
2125 kmod_list_foreach(l
, mod
->info_list
) {
2126 const char *key
= kmod_module_info_get_key(l
);
2127 const char *value
= kmod_module_info_get_value(l
);
2129 if (!streq(key
, "alias"))
2132 fprintf(out
, "alias %s %s\n", value
, mod
->modname
);
2139 static int output_aliases_bin(struct depmod
*depmod
, FILE *out
)
2141 struct index_node
*idx
;
2147 idx
= index_create();
2151 for (i
= 0; i
< depmod
->modules
.count
; i
++) {
2152 const struct mod
*mod
= depmod
->modules
.array
[i
];
2153 struct kmod_list
*l
;
2155 kmod_list_foreach(l
, mod
->info_list
) {
2156 const char *key
= kmod_module_info_get_key(l
);
2157 const char *value
= kmod_module_info_get_value(l
);
2162 if (!streq(key
, "alias"))
2165 if (alias_normalize(value
, buf
, NULL
) < 0) {
2166 WRN("Unmatched bracket in %s\n", value
);
2171 duplicate
= index_insert(idx
, alias
, mod
->modname
,
2173 if (duplicate
&& depmod
->cfg
->warn_dups
)
2174 WRN("duplicate module alias:\n%s %s\n",
2175 alias
, mod
->modname
);
2179 index_write(idx
, out
);
2185 static int output_softdeps(struct depmod
*depmod
, FILE *out
)
2189 fputs("# Soft dependencies extracted from modules themselves.\n", out
);
2191 for (i
= 0; i
< depmod
->modules
.count
; i
++) {
2192 const struct mod
*mod
= depmod
->modules
.array
[i
];
2193 struct kmod_list
*l
;
2195 kmod_list_foreach(l
, mod
->info_list
) {
2196 const char *key
= kmod_module_info_get_key(l
);
2197 const char *value
= kmod_module_info_get_value(l
);
2199 if (!streq(key
, "softdep"))
2202 fprintf(out
, "softdep %s %s\n", mod
->modname
, value
);
2209 static int output_symbols(struct depmod
*depmod
, FILE *out
)
2211 struct hash_iter iter
;
2214 fputs("# Aliases for symbols, used by symbol_request().\n", out
);
2216 hash_iter_init(depmod
->symbols
, &iter
);
2218 while (hash_iter_next(&iter
, NULL
, &v
)) {
2219 const struct symbol
*sym
= v
;
2220 if (sym
->owner
== NULL
)
2223 fprintf(out
, "alias symbol:%s %s\n",
2224 sym
->name
, sym
->owner
->modname
);
2230 static int output_symbols_bin(struct depmod
*depmod
, FILE *out
)
2232 struct index_node
*idx
;
2234 _cleanup_(scratchbuf_release
) struct scratchbuf salias
=
2235 SCRATCHBUF_INITIALIZER(alias
);
2236 size_t baselen
= sizeof("symbol:") - 1;
2237 struct hash_iter iter
;
2244 idx
= index_create();
2248 memcpy(alias
, "symbol:", baselen
);
2250 hash_iter_init(depmod
->symbols
, &iter
);
2252 while (hash_iter_next(&iter
, NULL
, &v
)) {
2254 const struct symbol
*sym
= v
;
2257 if (sym
->owner
== NULL
)
2260 len
= strlen(sym
->name
);
2262 if (scratchbuf_alloc(&salias
, baselen
+ len
+ 1) < 0) {
2264 goto err_scratchbuf
;
2266 memcpy(scratchbuf_str(&salias
) + baselen
, sym
->name
, len
+ 1);
2267 duplicate
= index_insert(idx
, alias
, sym
->owner
->modname
,
2270 if (duplicate
&& depmod
->cfg
->warn_dups
)
2271 WRN("duplicate module syms:\n%s %s\n",
2272 alias
, sym
->owner
->modname
);
2275 index_write(idx
, out
);
2281 ERR("output symbols: %s\n", strerror(-ret
));
2286 static int output_builtin_bin(struct depmod
*depmod
, FILE *out
)
2289 struct index_node
*idx
;
2290 char infile
[PATH_MAX
], line
[PATH_MAX
], modname
[PATH_MAX
];
2295 snprintf(infile
, sizeof(infile
), "%s/modules.builtin",
2296 depmod
->cfg
->dirname
);
2297 in
= fopen(infile
, "r");
2299 WRN("could not open %s: %m\n", infile
);
2303 idx
= index_create();
2309 while (fgets(line
, sizeof(line
), in
) != NULL
) {
2310 if (!isalpha(line
[0])) {
2311 ERR("Invalid modules.builtin line: %s\n", line
);
2315 path_to_modname(line
, modname
, NULL
);
2316 index_insert(idx
, modname
, "", 0);
2319 index_write(idx
, out
);
2326 static int output_devname(struct depmod
*depmod
, FILE *out
)
2331 for (i
= 0; i
< depmod
->modules
.count
; i
++) {
2332 const struct mod
*mod
= depmod
->modules
.array
[i
];
2333 struct kmod_list
*l
;
2334 const char *devname
= NULL
;
2336 unsigned int major
= 0, minor
= 0;
2338 kmod_list_foreach(l
, mod
->info_list
) {
2339 const char *key
= kmod_module_info_get_key(l
);
2340 const char *value
= kmod_module_info_get_value(l
);
2341 unsigned int maj
, min
;
2343 if (!streq(key
, "alias"))
2346 if (strstartswith(value
, "devname:"))
2347 devname
= value
+ sizeof("devname:") - 1;
2348 else if (sscanf(value
, "char-major-%u-%u",
2353 } else if (sscanf(value
, "block-major-%u-%u",
2360 if (type
!= '\0' && devname
!= NULL
)
2364 if (devname
!= NULL
) {
2367 fputs("# Device nodes to trigger on-demand module loading.\n",
2371 fprintf(out
, "%s %s %c%u:%u\n", mod
->modname
,
2372 devname
, type
, major
, minor
);
2374 ERR("Module '%s' has devname (%s) but "
2375 "lacks major and minor information. "
2376 "Ignoring.\n", mod
->modname
, devname
);
2383 static int depmod_output(struct depmod
*depmod
, FILE *out
)
2385 static const struct depfile
{
2387 int (*cb
)(struct depmod
*depmod
, FILE *out
);
2388 } *itr
, depfiles
[] = {
2389 { "modules.dep", output_deps
},
2390 { "modules.dep.bin", output_deps_bin
},
2391 { "modules.alias", output_aliases
},
2392 { "modules.alias.bin", output_aliases_bin
},
2393 { "modules.softdep", output_softdeps
},
2394 { "modules.symbols", output_symbols
},
2395 { "modules.symbols.bin", output_symbols_bin
},
2396 { "modules.builtin.bin", output_builtin_bin
},
2397 { "modules.devname", output_devname
},
2400 const char *dname
= depmod
->cfg
->dirname
;
2404 gettimeofday(&tv
, NULL
);
2409 dfd
= open(dname
, O_RDONLY
);
2412 CRIT("could not open directory %s: %m\n", dname
);
2417 for (itr
= depfiles
; itr
->name
!= NULL
; itr
++) {
2419 char tmp
[NAME_MAX
] = "";
2423 int flags
= O_CREAT
| O_EXCL
| O_WRONLY
;
2427 snprintf(tmp
, sizeof(tmp
), "%s.%i.%li.%li", itr
->name
, getpid(),
2428 tv
.tv_usec
, tv
.tv_sec
);
2429 fd
= openat(dfd
, tmp
, flags
, mode
);
2431 ERR("openat(%s, %s, %o, %o): %m\n",
2432 dname
, tmp
, flags
, mode
);
2435 fp
= fdopen(fd
, "wb");
2437 ERR("fdopen(%d=%s/%s): %m\n", fd
, dname
, tmp
);
2443 r
= itr
->cb(depmod
, fp
);
2447 ferr
= ferror(fp
) | fclose(fp
);
2450 if (unlinkat(dfd
, tmp
, 0) != 0)
2451 ERR("unlinkat(%s, %s): %m\n", dname
, tmp
);
2453 ERR("Could not write index '%s': %s\n", itr
->name
,
2459 if (renameat(dfd
, tmp
, dfd
, itr
->name
) != 0) {
2461 CRIT("renameat(%s, %s, %s, %s): %m\n",
2462 dname
, tmp
, dname
, itr
->name
);
2468 ERR("Could not create index '%s'. Output is truncated: %s\n",
2469 itr
->name
, strerror(-err
));
2480 static void depmod_add_fake_syms(struct depmod
*depmod
)
2482 /* __this_module is magic inserted by kernel loader. */
2483 depmod_symbol_add(depmod
, "__this_module", true, 0, NULL
);
2484 /* On S390, this is faked up too */
2485 depmod_symbol_add(depmod
, "_GLOBAL_OFFSET_TABLE_", true, 0, NULL
);
2486 /* On PowerPC64 ABIv2, .TOC. is more or less _GLOBAL_OFFSET_TABLE_ */
2487 if (!depmod_symbol_find(depmod
, "TOC."))
2488 depmod_symbol_add(depmod
, "TOC.", true, 0, NULL
);
2491 static int depmod_load_symvers(struct depmod
*depmod
, const char *filename
)
2495 unsigned int linenum
= 0;
2497 fp
= fopen(filename
, "r");
2500 DBG("load symvers: %s: %m\n", filename
);
2503 DBG("load symvers: %s\n", filename
);
2505 /* eg. "0xb352177e\tfind_first_bit\tvmlinux\tEXPORT_SYMBOL" */
2506 while (fgets(line
, sizeof(line
), fp
) != NULL
) {
2507 const char *ver
, *sym
, *where
;
2513 ver
= strtok(line
, " \t");
2514 sym
= strtok(NULL
, " \t");
2515 where
= strtok(NULL
, " \t");
2516 if (!ver
|| !sym
|| !where
)
2519 if (!streq(where
, "vmlinux"))
2522 crc
= strtoull(ver
, &verend
, 16);
2523 if (verend
[0] != '\0') {
2524 ERR("%s:%u Invalid symbol version %s: %m\n",
2525 filename
, linenum
, ver
);
2529 depmod_symbol_add(depmod
, sym
, false, crc
, NULL
);
2531 depmod_add_fake_syms(depmod
);
2533 DBG("loaded symvers: %s\n", filename
);
2539 static int depmod_load_system_map(struct depmod
*depmod
, const char *filename
)
2541 const char ksymstr
[] = "__ksymtab_";
2542 const size_t ksymstr_len
= sizeof(ksymstr
) - 1;
2545 unsigned int linenum
= 0;
2547 fp
= fopen(filename
, "r");
2550 DBG("load System.map: %s: %m\n", filename
);
2553 DBG("load System.map: %s\n", filename
);
2555 /* eg. c0294200 R __ksymtab_devfs_alloc_devnum */
2556 while (fgets(line
, sizeof(line
), fp
) != NULL
) {
2561 p
= strchr(line
, ' ');
2563 goto invalid_syntax
;
2567 goto invalid_syntax
;
2571 if (p
[0] == depmod
->cfg
->sym_prefix
)
2574 /* Covers gpl-only and normal symbols. */
2575 if (strncmp(p
, ksymstr
, ksymstr_len
) != 0)
2578 end
= strchr(p
, '\n');
2582 depmod_symbol_add(depmod
, p
+ ksymstr_len
, true, 0, NULL
);
2586 ERR("%s:%u: invalid line: %s\n", filename
, linenum
, line
);
2588 depmod_add_fake_syms(depmod
);
2590 DBG("loaded System.map: %s\n", filename
);
2597 static int depfile_up_to_date_dir(DIR *d
, time_t mtime
, size_t baselen
, char *path
)
2600 int err
= 1, dfd
= dirfd(d
);
2602 while ((de
= readdir(d
)) != NULL
) {
2603 const char *name
= de
->d_name
;
2607 if (name
[0] == '.' && (name
[1] == '\0' ||
2608 (name
[1] == '.' && name
[2] == '\0')))
2610 if (streq(name
, "build") || streq(name
, "source"))
2612 namelen
= strlen(name
);
2613 if (baselen
+ namelen
+ 2 >= PATH_MAX
) {
2614 path
[baselen
] = '\0';
2615 ERR("path is too long %s%s\n", path
, name
);
2619 if (fstatat(dfd
, name
, &st
, 0) < 0) {
2620 ERR("fstatat(%d, %s): %m\n", dfd
, name
);
2624 if (S_ISDIR(st
.st_mode
)) {
2627 memcpy(path
+ baselen
, name
, namelen
+ 1);
2628 if (baselen
+ namelen
+ 2 + NAME_MAX
>= PATH_MAX
) {
2629 ERR("directory path is too long %s\n", path
);
2632 fd
= openat(dfd
, name
, O_RDONLY
);
2634 ERR("openat(%d, %s, O_RDONLY): %m\n",
2638 subdir
= fdopendir(fd
);
2639 if (subdir
== NULL
) {
2640 ERR("fdopendir(%d): %m\n", fd
);
2644 path
[baselen
+ namelen
] = '/';
2645 path
[baselen
+ namelen
+ 1] = '\0';
2646 err
= depfile_up_to_date_dir(subdir
, mtime
,
2647 baselen
+ namelen
+ 1,
2650 } else if (S_ISREG(st
.st_mode
)) {
2651 if (!path_ends_with_kmod_ext(name
, namelen
))
2654 memcpy(path
+ baselen
, name
, namelen
+ 1);
2655 err
= st
.st_mtime
<= mtime
;
2657 DBG("%s %"PRIu64
" is newer than %"PRIu64
"\n",
2658 path
, (uint64_t)st
.st_mtime
,
2662 ERR("unsupported file type %s: %o\n",
2663 path
, st
.st_mode
& S_IFMT
);
2668 break; /* outdated! */
2670 path
[baselen
+ namelen
] = '\0';
2671 ERR("failed %s: %s\n", path
, strerror(-err
));
2672 err
= 1; /* ignore errors */
2679 /* uptodate: 1, outdated: 0, errors < 0 */
2680 static int depfile_up_to_date(const char *dirname
)
2682 char path
[PATH_MAX
];
2683 DIR *d
= opendir(dirname
);
2689 ERR("could not open directory %s: %m\n", dirname
);
2693 if (fstatat(dirfd(d
), "modules.dep", &st
, 0) != 0) {
2695 ERR("could not fstatat(%s, modules.dep): %m\n", dirname
);
2700 baselen
= strlen(dirname
);
2701 memcpy(path
, dirname
, baselen
);
2702 path
[baselen
] = '/';
2704 path
[baselen
] = '\0';
2706 err
= depfile_up_to_date_dir(d
, st
.st_mtime
, baselen
, path
);
2711 static int is_version_number(const char *version
)
2713 unsigned int d1
, d2
;
2714 return (sscanf(version
, "%u.%u", &d1
, &d2
) == 2);
2717 static int do_depmod(int argc
, char *argv
[])
2720 int err
= 0, all
= 0, maybe_all
= 0, n_config_paths
= 0;
2721 _cleanup_free_
char *root
= NULL
;
2722 _cleanup_free_
const char **config_paths
= NULL
;
2723 const char *system_map
= NULL
;
2724 const char *module_symvers
= NULL
;
2725 const char *null_kmod_config
= NULL
;
2727 struct kmod_ctx
*ctx
= NULL
;
2729 struct depmod depmod
;
2731 memset(&cfg
, 0, sizeof(cfg
));
2732 memset(&depmod
, 0, sizeof(depmod
));
2736 c
= getopt_long(argc
, argv
, cmdopts_s
, cmdopts
, &idx
);
2749 root
= path_make_absolute_cwd(optarg
);
2752 size_t bytes
= sizeof(char *) * (n_config_paths
+ 2);
2753 void *tmp
= realloc(config_paths
, bytes
);
2755 fputs("Error: out-of-memory\n", stderr
);
2756 goto cmdline_failed
;
2759 config_paths
[n_config_paths
] = optarg
;
2761 config_paths
[n_config_paths
] = NULL
;
2765 module_symvers
= optarg
;
2766 cfg
.check_symvers
= 1;
2769 system_map
= optarg
;
2772 cfg
.print_unknown
= 1;
2781 if (optarg
[1] != '\0') {
2782 CRIT("-P only takes a single char\n");
2783 goto cmdline_failed
;
2785 cfg
.sym_prefix
= optarg
[0];
2795 WRN("Ignored deprecated option --%s\n",
2798 WRN("Ignored deprecated option -%c\n", c
);
2803 return EXIT_SUCCESS
;
2805 puts(PACKAGE
" version " VERSION
);
2806 puts(KMOD_FEATURES
);
2807 return EXIT_SUCCESS
;
2809 goto cmdline_failed
;
2811 ERR("unexpected getopt_long() value '%c'.\n", c
);
2812 goto cmdline_failed
;
2816 if (optind
< argc
) {
2817 if (!is_version_number(argv
[optind
])) {
2818 ERR("Bad version passed %s\n", argv
[optind
]);
2819 goto cmdline_failed
;
2821 cfg
.kversion
= argv
[optind
];
2824 if (uname(&un
) < 0) {
2825 CRIT("uname() failed: %s\n", strerror(errno
));
2826 goto cmdline_failed
;
2828 cfg
.kversion
= un
.release
;
2831 cfg
.dirnamelen
= snprintf(cfg
.dirname
, PATH_MAX
,
2832 "%s/lib/modules/%s",
2833 root
== NULL
? "" : root
, cfg
.kversion
);
2841 /* ignore up-to-date errors (< 0) */
2842 if (depfile_up_to_date(cfg
.dirname
) == 1)
2847 ctx
= kmod_new(cfg
.dirname
, &null_kmod_config
);
2849 CRIT("kmod_new(\"%s\", {NULL}) failed: %m\n", cfg
.dirname
);
2850 goto cmdline_failed
;
2853 log_setup_kmod_log(ctx
, verbose
);
2855 err
= depmod_init(&depmod
, &cfg
, ctx
);
2857 CRIT("depmod_init: %s\n", strerror(-err
));
2858 goto depmod_init_failed
;
2860 ctx
= NULL
; /* owned by depmod */
2862 if (module_symvers
!= NULL
) {
2863 err
= depmod_load_symvers(&depmod
, module_symvers
);
2865 CRIT("could not load %s: %s\n", module_symvers
,
2867 goto cmdline_failed
;
2869 } else if (system_map
!= NULL
) {
2870 err
= depmod_load_system_map(&depmod
, system_map
);
2872 CRIT("could not load %s: %s\n", system_map
,
2874 goto cmdline_failed
;
2876 } else if (cfg
.print_unknown
) {
2877 WRN("-e needs -E or -F\n");
2878 cfg
.print_unknown
= 0;
2882 err
= cfg_load(&cfg
, config_paths
);
2884 CRIT("could not load configuration files\n");
2885 goto cmdline_modules_failed
;
2887 err
= depmod_modules_search(&depmod
);
2889 CRIT("could not search modules: %s\n", strerror(-err
));
2890 goto cmdline_modules_failed
;
2895 for (i
= optind
; i
< argc
; i
++) {
2896 const char *path
= argv
[i
];
2897 struct kmod_module
*mod
;
2899 if (path
[0] != '/') {
2900 CRIT("%s: not absolute path.\n", path
);
2901 goto cmdline_modules_failed
;
2904 err
= kmod_module_new_from_path(depmod
.ctx
, path
, &mod
);
2906 CRIT("could not create module %s: %s\n",
2907 path
, strerror(-err
));
2908 goto cmdline_modules_failed
;
2911 err
= depmod_module_add(&depmod
, mod
);
2913 CRIT("could not add module %s: %s\n",
2914 path
, strerror(-err
));
2915 kmod_module_unref(mod
);
2916 goto cmdline_modules_failed
;
2921 err
= depmod_modules_build_array(&depmod
);
2923 CRIT("could not build module array: %s\n",
2925 goto cmdline_modules_failed
;
2928 depmod_modules_sort(&depmod
);
2929 err
= depmod_load(&depmod
);
2931 goto cmdline_modules_failed
;
2933 err
= depmod_output(&depmod
, out
);
2936 depmod_shutdown(&depmod
);
2938 return err
>= 0 ? EXIT_SUCCESS
: EXIT_FAILURE
;
2940 cmdline_modules_failed
:
2941 depmod_shutdown(&depmod
);
2947 return EXIT_FAILURE
;
2950 const struct kmod_cmd kmod_cmd_compat_depmod
= {
2953 .help
= "compat depmod command",