libkmod-loaded

## libkmod-loaded libkmod-loaded — currently loaded modules |

## Synopsis

    int                 kmod_module_new_from_loaded         (struct kmod_ctx *ctx,
                                                             struct kmod_list **list);
    int                 kmod_module_get_initstate           (const struct kmod_module *mod);
    const char *        kmod_module_initstate_str           (enum kmod_module_initstate state);
    long                kmod_module_get_size                (const struct kmod_module *mod);
    int                 kmod_module_get_refcnt              (const struct kmod_module *mod);
    struct kmod_list *  kmod_module_get_holders             (const struct kmod_module *mod);

## Description

Information about currently loaded modules, as reported by Linux kernel. These information are not cached by libkmod and are always read from /sys and /proc/modules.

## Details

### kmod_module_new_from_loaded ()

    int                 kmod_module_new_from_loaded         (struct kmod_ctx *ctx,
                                                             struct kmod_list **list);

Create a new list of kmod modules with all modules currently loaded in kernel. It uses /proc/modules to get the names of loaded modules and to create kmod modules by calling `kmod_module_new_from_name()` in each of them. They are put in `list` in no particular order.

The initial refcount is 1, and needs to be decremented to release the resources of the kmod_module. The returned `list` must be released by calling `kmod_module_unref_list()`. Since libkmod keeps track of all kmod_modules created, they are all released upon `ctx` destruction too. Do not unref `ctx` before all the desired operations with the returned list are completed.

`ctx` : | kmod library context
`list` : | where to save the list of loaded modules
Returns : | 0 on success or < 0 on error.

### kmod_module_get_initstate ()

    int                 kmod_module_get_initstate           (const struct kmod_module *mod);

Get the initstate of this `mod`, as returned by Linux Kernel, by reading /sys filesystem.

`mod` : | kmod module
Returns : | < 0 on error or module state if module is found in kernel, valid states are KMOD_MODULE_BUILTIN: module is builtin; KMOD_MODULE_LIVE: module is live in kernel; KMOD_MODULE_COMING: module is being loaded; KMOD_MODULE_GOING: module is being unloaded.

### kmod_module_initstate_str ()

    const char *        kmod_module_initstate_str           (enum kmod_module_initstate state);

Translate a initstate to a string.

`state` : | the state as returned by `kmod_module_get_initstate()`
Returns : | the string associated to the `state`. This string is statically allocated, do not free it.

### kmod_module_get_size ()

    long                kmod_module_get_size                (const struct kmod_module *mod);

Get the size of this kmod module as returned by Linux kernel. If supported, the size is read from the coresize attribute in /sys/module. For older kernels, this falls back on /proc/modules and searches for the specified module to get its size.

`mod` : | kmod module
Returns : | the size of this kmod module.

### kmod_module_get_refcnt ()

    int                 kmod_module_get_refcnt              (const struct kmod_module *mod);

Get the ref count of this `mod`, as returned by Linux Kernel, by reading /sys filesystem.

`mod` : | kmod module
Returns : | 0 on success or < 0 on failure.

### kmod_module_get_holders ()

    struct kmod_list *  kmod_module_get_holders             (const struct kmod_module *mod);

Get a list of kmod modules that are holding this `mod`, as returned by Linux Kernel. After use, free the `list` by calling `kmod_module_unref_list()`.

`mod` : | kmod module
Returns : | a new list of kmod modules on success or NULL on failure.