mirror of
https://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git
synced 2024-11-15 06:53:44 +08:00
b5a2cd070d
Drop the lengthy license from each file and just use SPDX like most projects nowadays. This doesn't have any change to license, just how they are recorded in each file. This follows the kernel approach: header files use '/*' for comments while .c files use '//'. For .m4, use "#". Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com> Link: https://lore.kernel.org/r/20240723185921.1005569-2-lucas.de.marchi@gmail.com Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
80 lines
1.7 KiB
C
80 lines
1.7 KiB
C
// SPDX-License-Identifier: LGPL-2.1-or-later
|
|
/*
|
|
* Copyright (C) 2012-2013 ProFUSION embedded systems
|
|
*/
|
|
|
|
#include <errno.h>
|
|
#include <inttypes.h>
|
|
#include <stddef.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
|
|
#include <libkmod/libkmod.h>
|
|
|
|
#include "testsuite.h"
|
|
|
|
static int loaded_1(const struct test *t)
|
|
{
|
|
struct kmod_ctx *ctx;
|
|
const char *null_config = NULL;
|
|
struct kmod_list *list, *itr;
|
|
int err;
|
|
|
|
ctx = kmod_new(NULL, &null_config);
|
|
if (ctx == NULL)
|
|
exit(EXIT_FAILURE);
|
|
|
|
err = kmod_module_new_from_loaded(ctx, &list);
|
|
if (err < 0) {
|
|
fprintf(stderr, "%s\n", strerror(-err));
|
|
kmod_unref(ctx);
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
printf("Module Size Used by\n");
|
|
|
|
kmod_list_foreach(itr, list) {
|
|
struct kmod_module *mod = kmod_module_get_module(itr);
|
|
const char *name = kmod_module_get_name(mod);
|
|
int use_count = kmod_module_get_refcnt(mod);
|
|
long size = kmod_module_get_size(mod);
|
|
struct kmod_list *holders, *hitr;
|
|
int first = 1;
|
|
|
|
printf("%-19s %8ld %d ", name, size, use_count);
|
|
holders = kmod_module_get_holders(mod);
|
|
kmod_list_foreach(hitr, holders) {
|
|
struct kmod_module *hm = kmod_module_get_module(hitr);
|
|
|
|
if (!first)
|
|
putchar(',');
|
|
else
|
|
first = 0;
|
|
|
|
fputs(kmod_module_get_name(hm), stdout);
|
|
kmod_module_unref(hm);
|
|
}
|
|
putchar('\n');
|
|
kmod_module_unref_list(holders);
|
|
kmod_module_unref(mod);
|
|
}
|
|
kmod_module_unref_list(list);
|
|
|
|
kmod_unref(ctx);
|
|
|
|
return EXIT_SUCCESS;
|
|
}
|
|
DEFINE_TEST(loaded_1,
|
|
.description = "check if list of module is created",
|
|
.config = {
|
|
[TC_ROOTFS] = TESTSUITE_ROOTFS "test-loaded/",
|
|
},
|
|
.need_spawn = true,
|
|
.output = {
|
|
.out = TESTSUITE_ROOTFS "test-loaded/correct.txt",
|
|
});
|
|
|
|
TESTSUITE_MAIN();
|