### Get Module Install Commands Source: https://kmod-project.github.io/v33/libkmod-libkmod-module.html Retrieves installation commands for a kmod module from its configuration. Commands are cached and returned as a semicolon-separated string. ```c const char * kmod_module_get_install_commands (_const struct kmod_module *mod_); ``` -------------------------------- ### kmod_module_get_install_commands Source: https://kmod-project.github.io/v33/libkmod-libkmod-module.html Retrieves the install commands for a specific kmod module. ```APIDOC ## kmod_module_get_install_commands ### Description Get install commands for this kmod module from the configuration file. The first call searches the configuration, and subsequent calls return the cached string. ### Parameters #### Path Parameters - **mod** (kmod module) - Required ### Response #### Success Response (string) - **Returns** (const char *) - A string with all install commands separated by semicolons. ``` -------------------------------- ### Get Module Options Source: https://kmod-project.github.io/v33/libkmod-libkmod-module.html Retrieves the options for a kmod module from its configuration. Options are cached and returned as a space-separated string. ```c const char * kmod_module_get_options (_const struct kmod_module *mod_); ``` -------------------------------- ### Get Weak Dependencies Source: https://kmod-project.github.io/v33/libkmod-libkmod-module.html Retrieves weak dependencies for a kmod module. ```c int kmod_module_get_weakdeps (_const struct kmod_module *mod_, _struct kmod_list **weak_); ``` -------------------------------- ### Get logging priority Source: https://kmod-project.github.io/v33/libkmod-libkmod.html Retrieves the currently configured logging priority for the kmod context. ```c int kmod_get_log_priority (const struct kmod_ctx *ctx); ``` -------------------------------- ### Get Module Initialization State Source: https://kmod-project.github.io/v33/libkmod-libkmod-loaded.html Retrieves the initialization state of a module as reported by the Linux Kernel. Valid states include KMOD_MODULE_BUILTIN, KMOD_MODULE_LIVE, KMOD_MODULE_COMING, and KMOD_MODULE_GOING. ```c int kmod_module_get_initstate (_const struct kmod_module *mod_); ``` -------------------------------- ### Get Module Dependencies Source: https://kmod-project.github.io/v33/libkmod-libkmod-module.html Searches the modules.dep index for dependencies of a given module. The result is cached and can be released using kmod_module_unref_list(). ```c struct kmod_list * kmod_module_get_dependencies (_const struct kmod_module *mod_); ``` -------------------------------- ### Get Soft Dependencies Source: https://kmod-project.github.io/v33/libkmod-libkmod-module.html Retrieves soft dependencies for a kmod module from configuration files. Both pre and post soft dependencies are returned as newly created lists that must be unreferenced. ```c int kmod_module_get_softdeps (_const struct kmod_module *mod_, _struct kmod_list **pre_, _struct kmod_list **post_); ``` -------------------------------- ### Get kmod module info key Source: https://kmod-project.github.io/v33/libkmod-libkmod-module.html Retrieves the key of a kmod module info entry. The returned string is owned by the info and should not be freed. ```c const char * kmod_module_info_get_key (_const struct kmod_list *entry_); ``` -------------------------------- ### Get module directory path Source: https://kmod-project.github.io/v33/libkmod-libkmod.html Retrieves the absolute path used for Linux modules, determined during kmod_new(). ```c const char *kmod_get_dirname (const struct kmod_ctx *ctx); ``` -------------------------------- ### Get Module Path Source: https://kmod-project.github.io/v33/libkmod-libkmod-module.html Retrieves the path of a kmod module. It may search modules.dep to find the path if not directly available. ```c const char * kmod_module_get_path (_const struct kmod_module *mod_); ``` -------------------------------- ### Get Filtered Blacklist Module List Source: https://kmod-project.github.io/v33/libkmod-libkmod-module.html This function filters a list of modules based on the configuration's blacklist. It is deprecated and kmod_module_apply_filter should be used instead. ```c int kmod_module_get_filtered_blacklist (_const struct kmod_ctx *ctx_, _const struct kmod_list *input_, _struct kmod_list **output_); ``` -------------------------------- ### Get Module Reference Count Source: https://kmod-project.github.io/v33/libkmod-libkmod-loaded.html Fetches the current reference count of a module from the Linux Kernel by reading the /sys filesystem. Returns < 0 on failure. ```c int kmod_module_get_refcnt (_const struct kmod_module *mod_); ``` -------------------------------- ### Get kmod module info list Source: https://kmod-project.github.io/v33/libkmod-libkmod-module.html Retrieves a list of entries from the ELF section ".modinfo" of a kmod module. This includes information like alias, license, depends, vermagic, and module signature details if the module is signed. The list must be freed using `kmod_module_info_free_list()` after use. ```c int kmod_module_get_info (_const struct kmod_module *mod_, _struct kmod_list **list_); ``` -------------------------------- ### Get kmod Module from List Entry Source: https://kmod-project.github.io/v33/libkmod-libkmod-module.html Retrieves a kmod module from a list entry and increments its reference count. Remember to unreference the module after use. ```c struct kmod_module * kmod_module_get_module (_const struct kmod_list *entry_); ``` -------------------------------- ### Get kmod module info value Source: https://kmod-project.github.io/v33/libkmod-libkmod-module.html Retrieves the value of a kmod module info entry. The returned string is owned by the info and should not be freed. ```c const char * kmod_module_info_get_value (_const struct kmod_list *entry_); ``` -------------------------------- ### Get Module Name Source: https://kmod-project.github.io/v33/libkmod-libkmod-module.html Retrieves the normalized name of a kmod module. The name is always available and dashes are replaced with underscores. ```c const char * kmod_module_get_name (_const struct kmod_module *mod_); ``` -------------------------------- ### Get user data Source: https://kmod-project.github.io/v33/libkmod-libkmod.html Retrieves the custom data pointer stored within the library context, often used in callbacks. ```c void *kmod_get_userdata (const struct kmod_ctx *ctx); ``` -------------------------------- ### Get Dependency Symbol Bind Type Source: https://kmod-project.github.io/v33/libkmod-libkmod-module.html Retrieves the bind type of a kmod module dependency symbol. ```c int kmod_module_dependency_symbol_get_bind (_const struct kmod_list *entry_); ``` -------------------------------- ### Get Module Remove Commands Source: https://kmod-project.github.io/v33/libkmod-libkmod-module.html Retrieves removal commands for a kmod module from its configuration. Commands are cached and returned as a semicolon-separated string. ```c const char * kmod_module_get_remove_commands (_const struct kmod_module *mod_); ``` -------------------------------- ### Get kmod module version symbol Source: https://kmod-project.github.io/v33/libkmod-libkmod-module.html Retrieves the symbol of a kmod module version. The returned string is owned by the versions and should not be freed. ```c const char * kmod_module_version_get_symbol (_const struct kmod_list *entry_); ``` -------------------------------- ### Get Module Dependency Symbols Source: https://kmod-project.github.io/v33/libkmod-libkmod-module.html Retrieves a list of dependency symbols from the module's ELF sections. The returned list must be freed using kmod_module_dependency_symbols_free_list(). ```c int kmod_module_get_dependency_symbols (_const struct kmod_module *mod_, _struct kmod_list **list_); ``` -------------------------------- ### Get Modules Holding This Module Source: https://kmod-project.github.io/v33/libkmod-libkmod-loaded.html Retrieves a list of kmod modules that currently depend on the specified module. The returned list must be freed using kmod_module_unref_list(). ```c struct kmod_list * kmod_module_get_holders (_const struct kmod_module *mod_); ``` -------------------------------- ### Get Module Size Source: https://kmod-project.github.io/v33/libkmod-libkmod-loaded.html Retrieves the size of a kmod module. For newer kernels, this reads the coresize attribute from /sys/module. Older kernels fall back to parsing /proc/modules. ```c long kmod_module_get_size (_const struct kmod_module *mod_); ``` -------------------------------- ### Get Last Element of kmod_list Source: https://kmod-project.github.io/v33/libkmod-libkmod-list.html Retrieves the last element of a circular kmod_list. This is an O(1) operation. If the list contains only one element, it returns the list itself. ```c struct kmod_list * kmod_list_last (_const struct kmod_list *list_); ``` -------------------------------- ### Get Next Element in kmod_list Source: https://kmod-project.github.io/v33/libkmod-libkmod-list.html Retrieves the next element in a kmod_list relative to the current element, treating the list as non-circular. Returns NULL if the current element is the last or the list is empty. ```c struct kmod_list * kmod_list_next (_const struct kmod_list *list_, _const struct kmod_list *curr_); ``` -------------------------------- ### Get Previous Element in kmod_list Source: https://kmod-project.github.io/v33/libkmod-libkmod-list.html Retrieves the previous element in a kmod_list relative to the current element, treating the list as non-circular. The previous element of the head is NULL. Returns NULL if the current element is the head or the list is empty. ```c struct kmod_list * kmod_list_prev (_const struct kmod_list *list_, _const struct kmod_list *curr_); ``` -------------------------------- ### Create a module list from lookup Source: https://kmod-project.github.io/v33/libkmod-libkmod-module.html Creates a list of kmod modules by searching configuration files and indexes based on an alias or name. ```c int kmod_module_new_from_lookup (_struct kmod_ctx *ctx_, _const char *given_alias_, _struct kmod_list **list_); ``` -------------------------------- ### Create kmod library context Source: https://kmod-project.github.io/v33/libkmod-libkmod.html Initializes the kmod library context by reading configuration and setting default values. ```c struct kmod_ctx * kmod_new (const char *dirname, const char * const *config_paths); ``` -------------------------------- ### kmod_new Source: https://kmod-project.github.io/v33/libkmod-libkmod.html Creates a new kmod library context, reading configuration and setting default values. ```APIDOC ## kmod_new ### Description Create kmod library context. This reads the kmod configuration and fills in the default values. ### Parameters #### Path Parameters - **dirname** (const char *) - Required - What to consider as linux module's directory. - **config_paths** (const char * const *) - Required - Ordered array of paths where to load user-defined configuration parameters. ### Response - **kmod_ctx** (struct) - A new kmod library context. ``` -------------------------------- ### Create a kmod_module from path Source: https://kmod-project.github.io/v33/libkmod-libkmod-module.html Creates a new kmod_module structure from a file path. The path must point to an existing file accessible to libkmod. ```c int kmod_module_new_from_path (_struct kmod_ctx *ctx_, _const char *path_, _struct kmod_module **mod_); ``` -------------------------------- ### Probe and insert a module Source: https://kmod-project.github.io/v33/libkmod-libkmod-module.html Inserts a module while resolving dependencies, soft dependencies, and applying blacklists. ```c int kmod_module_probe_insert_module (_struct kmod_module *mod_, _unsigned int flags_, _const char *extra_options_, _int (*run_install) (struct kmod_module *m, const char *cmdline, void *data)_, _const void *data_, _void (*print_action) (struct kmod_module *m, bool install, const char *options)_); ``` -------------------------------- ### kmod_module_get_initstate Source: https://kmod-project.github.io/v33/libkmod-libkmod-loaded.html Retrieves the initialization state of a loaded module. ```APIDOC ## kmod_module_get_initstate ### Description Get the initstate of this _`mod`_, as returned by Linux Kernel, by reading /sys filesystem. ### Method int ### Endpoint N/A (Function Call) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response Returns the module state if found in kernel. Valid states are KMOD_MODULE_BUILTIN, KMOD_MODULE_LIVE, KMOD_MODULE_COMING, KMOD_MODULE_GOING. #### Error Response (< 0) Returns < 0 on error. #### Response Example KMOD_MODULE_LIVE ``` -------------------------------- ### kmod_module_new_from_loaded Source: https://kmod-project.github.io/v33/libkmod-libkmod-loaded.html Creates a list of all modules currently loaded in the kernel. ```APIDOC ## kmod_module_new_from_loaded ### Description Creates a new list of kmod modules with all modules currently loaded in the 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. ### Method int ### Endpoint N/A (Function Call) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (0) Returns 0 on success. #### Error Response (< 0) Returns < 0 on error. #### Response Example 0 on success, < 0 on error. ``` -------------------------------- ### kmod_module_probe_insert_module Source: https://kmod-project.github.io/v33/libkmod-libkmod-module.html Inserts a module resolving dependencies and applying blacklist. ```APIDOC ## kmod_module_probe_insert_module ### Description Insert a module in Linux kernel resolving dependencies, soft dependencies, install commands and applying blacklist. ### Parameters - **mod** (struct kmod_module *) - Required - kmod module - **flags** (unsigned int) - Required - flags - **extra_options** (const char *) - Required - extra options - **run_install** (function pointer) - Optional - callback for install command - **data** (const void *) - Optional - data for callback - **print_action** (function pointer) - Optional - callback for printing action ``` -------------------------------- ### Create List of Loaded Modules Source: https://kmod-project.github.io/v33/libkmod-libkmod-loaded.html Creates a list of all modules currently loaded in the kernel. The returned list must be released using kmod_module_unref_list(). ```c int kmod_module_new_from_loaded (_struct kmod_ctx *ctx_, _struct kmod_list **list_); ``` -------------------------------- ### Create a kmod_module from name Source: https://kmod-project.github.io/v33/libkmod-libkmod-module.html Creates a new kmod_module structure using a module name. The name must be a valid module name, not an alias or file path. ```c int kmod_module_new_from_name (_struct kmod_ctx *ctx_, _const char *name_, _struct kmod_module **mod_); ``` -------------------------------- ### Free kmod module info list Source: https://kmod-project.github.io/v33/libkmod-libkmod-module.html Releases the resources allocated for a kmod module info list. ```c void kmod_module_info_free_list (_struct kmod_list *list_); ``` -------------------------------- ### kmod_module_get_options Source: https://kmod-project.github.io/v33/libkmod-libkmod-module.html Retrieves the options for a kmod module. ```APIDOC ## kmod_module_get_options ### Description Get options of this kmod module from the configuration file. The first call searches the configuration, and subsequent calls return the cached string. ### Parameters #### Path Parameters - **mod** (kmod module) - Required ### Response #### Success Response (string) - **Returns** (const char *) - A string with all the options separated by spaces. ``` -------------------------------- ### Define kmod_list_foreach Source: https://kmod-project.github.io/v33/libkmod-libkmod-list.html Macro for iterating over a kmod_list. Use this to traverse the list from the beginning. ```c #define kmod_list_foreach(list_entry, first_entry) ``` -------------------------------- ### Convert Module Initstate to String Source: https://kmod-project.github.io/v33/libkmod-libkmod-loaded.html Translates a module initialization state enum value into a human-readable string. The returned string is statically allocated and should not be freed. ```c const char * kmod_module_initstate_str (_enum kmod_module_initstate state_); ``` -------------------------------- ### libkmod Configuration Retrieval Functions Source: https://kmod-project.github.io/v33/libkmod-libkmod-config.html Functions to retrieve iterators for various kernel module configuration settings. ```APIDOC ## kmod_config_get_blacklists ### Description Retrieve an iterator to deal with the blacklist maintained inside the library. ### Parameters #### Path Parameters - **ctx** (struct kmod_ctx *) - Required - The kmod library context. ### Response - **Returns** (struct kmod_config_iter *) - A new iterator over the blacklists or NULL on failure. --- ## kmod_config_get_install_commands ### Description Retrieve an iterator to deal with the install commands maintained inside the library. ### Parameters #### Path Parameters - **ctx** (struct kmod_ctx *) - Required - The kmod library context. ### Response - **Returns** (struct kmod_config_iter *) - A new iterator over the install commands or NULL on failure. --- ## kmod_config_get_remove_commands ### Description Retrieve an iterator to deal with the remove commands maintained inside the library. ### Parameters #### Path Parameters - **ctx** (struct kmod_ctx *) - Required - The kmod library context. ### Response - **Returns** (struct kmod_config_iter *) - A new iterator over the remove commands or NULL on failure. --- ## kmod_config_get_aliases ### Description Retrieve an iterator to deal with the aliases maintained inside the library. ### Parameters #### Path Parameters - **ctx** (struct kmod_ctx *) - Required - The kmod library context. ### Response - **Returns** (struct kmod_config_iter *) - A new iterator over the aliases or NULL on failure. --- ## kmod_config_get_options ### Description Retrieve an iterator to deal with the options maintained inside the library. ### Parameters #### Path Parameters - **ctx** (struct kmod_ctx *) - Required - The kmod library context. ### Response - **Returns** (struct kmod_config_iter *) - A new iterator over the options or NULL on failure. --- ## kmod_config_get_softdeps ### Description Retrieve an iterator to deal with the softdeps maintained inside the library. ### Parameters #### Path Parameters - **ctx** (struct kmod_ctx *) - Required - The kmod library context. ### Response - **Returns** (struct kmod_config_iter *) - A new iterator over the softdeps or NULL on failure. --- ## kmod_config_get_weakdeps ### Description Retrieve an iterator to deal with the weakdeps maintained inside the library. ### Parameters #### Path Parameters - **ctx** (struct kmod_ctx *) - Required - The kmod library context. ### Response - **Returns** (struct kmod_config_iter *) - A new iterator over the weakdeps or NULL on failure. ``` -------------------------------- ### Load and unload kmod resources Source: https://kmod-project.github.io/v33/libkmod-libkmod.html Manages the loading and unloading of indexes to optimize lookup performance. ```c int kmod_load_resources (struct kmod_ctx *ctx); ``` ```c void kmod_unload_resources (struct kmod_ctx *ctx); ``` -------------------------------- ### kmod_module_new_from_lookup Source: https://kmod-project.github.io/v33/libkmod-libkmod-module.html Creates a new list of kmod modules by looking up an alias or module name in libkmod's configuration files and indexes. ```APIDOC ## kmod_module_new_from_lookup() ### Description Creates a new list of kmod modules using an alias or module name and lookup libkmod's configuration files and indexes in order to find the module. Once it's found in one of the places, it stops searching and create the list of modules that is saved in _`list`_. The search order is: 1. aliases in configuration file; 2. module names in modules.dep index; 3. symbol aliases in modules.symbols index; 4. aliases from install commands; 5. builtin indexes from kernel. 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. ### Parameters - **ctx** (struct kmod_ctx *) - kmod library context - **given_alias** (const char *) - alias to look for - **list** (struct kmod_list **) - an empty list where to save the list of modules matching _`given_alias`_ ### Returns 0 on success or < 0 otherwise. It fails if any of the lookup methods failed, which is basically due to memory allocation fail. If module is not found, it still returns 0, but _`list`_is an empty list. ``` -------------------------------- ### kmod_module_get_info Source: https://kmod-project.github.io/v33/libkmod-libkmod-module.html Retrieves a list of entries from the ELF section ".modinfo" for a given kmod module. This includes keys like alias, license, depends, vermagic, and signature information if the module is signed. The returned list must be freed using `kmod_module_info_free_list()`. ```APIDOC ## kmod_module_get_info ### Description Get a list of entries in ELF section ".modinfo", these contain alias, license, depends, vermagic and other keys with respective values. If the module is signed (CONFIG_MODULE_SIG), information about the module signature is included as well: signer, sig_key and sig_hashalgo. ### Method N/A (C function) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (int) - **count** (int) - The number of entries in the returned list. #### Response Example N/A ``` -------------------------------- ### Logging Configuration API Source: https://kmod-project.github.io/v33/libkmod-libkmod.html Functions for setting and retrieving the logging priority and defining custom logging callbacks. ```APIDOC ## kmod_set_log_priority ### Description Set the current logging priority. The value controls which messages are logged. ### Parameters - **ctx** (struct kmod_ctx*) - Required - kmod library context - **priority** (int) - Required - the new logging priority ## kmod_get_log_priority ### Description Retrieve the current logging priority. ### Parameters - **ctx** (const struct kmod_ctx*) - Required - kmod library context ### Returns - **int** - the current logging priority ## kmod_set_log_fn ### Description Overrides the built-in stderr logging with a custom function to plug log messages into the user's logging functionality. ### Parameters - **ctx** (struct kmod_ctx*) - Required - kmod library context - **log_fn** (function pointer) - Required - function to be called for logging messages - **data** (const void*) - Required - data to pass to log function ``` -------------------------------- ### User Data and Context Management Source: https://kmod-project.github.io/v33/libkmod-libkmod.html Functions for managing custom user data and retrieving context-specific configuration paths. ```APIDOC ## kmod_get_userdata ### Description Retrieve stored data pointer from library context. This might be useful to access from callbacks. ### Parameters - **ctx** (const struct kmod_ctx*) - Required - kmod library context ### Returns - **void*** - stored userdata ## kmod_set_userdata ### Description Store custom userdata in the library context. ### Parameters - **ctx** (struct kmod_ctx*) - Required - kmod library context - **userdata** (const void*) - Required - data pointer ## kmod_get_dirname ### Description Retrieve the absolute path used for linux modules in this context. The path is computed from the arguments to kmod_new(). ### Parameters - **ctx** (const struct kmod_ctx*) - Required - kmod library context ``` -------------------------------- ### Insert a module into the kernel Source: https://kmod-project.github.io/v33/libkmod-libkmod-module.html Inserts a module into the Linux kernel by opening and mmap'ing the module file. ```c int kmod_module_insert_module (_struct kmod_module *mod_, _unsigned int flags_, _const char *options_); ``` -------------------------------- ### Free kmod module versions list Source: https://kmod-project.github.io/v33/libkmod-libkmod-module.html Releases the resources allocated for a kmod module versions list. ```c void kmod_module_versions_free_list (_struct kmod_list *list_); ``` -------------------------------- ### Advance configuration iterator Source: https://kmod-project.github.io/v33/libkmod-libkmod-config.html Moves the iterator to the next configuration item. Returns false when the end is reached, and can be called again to restart iteration. ```c bool kmod_config_iter_next (struct kmod_config_iter *iter); ``` -------------------------------- ### Define kmod context structure Source: https://kmod-project.github.io/v33/libkmod-libkmod.html Represents the opaque library context object. ```c struct kmod_ctx; ``` -------------------------------- ### kmod_module_get_dependencies Source: https://kmod-project.github.io/v33/libkmod-libkmod-module.html Searches for dependencies of a given module. ```APIDOC ## kmod_module_get_dependencies ### Description Search the modules.dep index to find the dependencies of the given mod. ### Parameters #### Path Parameters - **mod** (const struct kmod_module *) - Required - kmod module ### Response - **Returns** (struct kmod_list *) - NULL on failure. Otherwise it returns a list of kmod modules. ``` -------------------------------- ### kmod_module_new_from_path Source: https://kmod-project.github.io/v33/libkmod-libkmod-module.html Creates a new struct kmod_module using the module path. ```APIDOC ## kmod_module_new_from_path ### Description Create a new struct kmod_module using the module path. The path must be an existent file within the filesystem. ### Parameters - **ctx** (struct kmod_ctx *) - Required - kmod library context - **path** (const char *) - Required - path where to find the given module - **mod** (struct kmod_module **) - Required - where to save the created struct kmod_module ### Response - **Returns** (int) - 0 on success or < 0 otherwise. ``` -------------------------------- ### Free configuration iterator Source: https://kmod-project.github.io/v33/libkmod-libkmod-config.html Releases resources associated with the specified iterator. ```c void kmod_config_iter_free_iter (struct kmod_config_iter *iter); ``` -------------------------------- ### Retrieve configuration key Source: https://kmod-project.github.io/v33/libkmod-libkmod-config.html Returns the key of the current configuration pointed to by the iterator. Requires a prior call to kmod_config_iter_next() to initialize the position. ```c const char * kmod_config_iter_get_key (const struct kmod_config_iter *iter); ``` -------------------------------- ### Lookup a single module by name Source: https://kmod-project.github.io/v33/libkmod-libkmod-module.html Resolves a single module by its exact name, bypassing alias lookups. ```c int kmod_module_new_from_name_lookup (_struct kmod_ctx *ctx_, _const char *modname_, _struct kmod_module **mod_); ``` -------------------------------- ### kmod_module_get_versions Source: https://kmod-project.github.io/v33/libkmod-libkmod-module.html Retrieves a list of version information from a kmod module. ```APIDOC ## kmod_module_get_versions () ### Description Get a list of entries in ELF section "__versions". After use, free the _`list`_ by calling `kmod_module_versions_free_list()`. ### Parameters - **mod** (struct kmod_module *) - kmod module. - **list** (struct kmod_list **) - Where to return list of module versions. Use `kmod_module_version_get_symbol()` and `kmod_module_version_get_crc()`. Release this list with `kmod_module_versions_free_list()`. ### Returns - int - 0 on success or < 0 otherwise. ``` -------------------------------- ### Manage kmod context references Source: https://kmod-project.github.io/v33/libkmod-libkmod.html Functions to increment or decrement the reference count of the kmod context. ```c struct kmod_ctx * kmod_ref (struct kmod_ctx *ctx); ``` ```c struct kmod_ctx * kmod_unref (struct kmod_ctx *ctx); ``` -------------------------------- ### kmod_module_info_get_key Source: https://kmod-project.github.io/v33/libkmod-libkmod-module.html Retrieves the key from a kmod module info list entry. The returned string is owned by the info entry and should not be freed. ```APIDOC ## kmod_module_info_get_key ### Description Get the key of a kmod module info. ### Method N/A (C function) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response - **key** (const char *) - The key of the kmod module info. #### Response Example N/A ``` -------------------------------- ### kmod_config_iter_next Source: https://kmod-project.github.io/v33/libkmod-libkmod-config.html Advances the iterator to the next item in the configuration. Returns false if the end is reached. ```APIDOC ## kmod_config_iter_next () ### Description Advances the iterator to the next item of a configuration. It's an automatically recycling iterator. When it reaches the end, false is returned; then if the user wants to iterate again, it's sufficient to call this function once more. ### Method N/A (C function) ### Endpoint N/A (C function) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) - **bool** - true if the next position of the iterator is valid, false if its end is reached. #### Response Example ``` true ``` ``` -------------------------------- ### kmod_module_versions_free_list Source: https://kmod-project.github.io/v33/libkmod-libkmod-module.html Releases the resources associated with a list of kmod module versions. ```APIDOC ## kmod_module_versions_free_list ### Description Release the resources taken by a kmod module versions list. ### Method N/A (C function) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response void #### Response Example N/A ``` -------------------------------- ### kmod_module_info_free_list Source: https://kmod-project.github.io/v33/libkmod-libkmod-module.html Releases the resources associated with a list of kmod module information. ```APIDOC ## kmod_module_info_free_list ### Description Release the resources taken by a kmod module info list. ### Method N/A (C function) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response void #### Response Example N/A ``` -------------------------------- ### kmod_module_initstate_str Source: https://kmod-project.github.io/v33/libkmod-libkmod-loaded.html Translates an initstate enum value to its string representation. ```APIDOC ## kmod_module_initstate_str ### Description Translate a initstate to a string. ### Method const char * ### Endpoint N/A (Function Call) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response Returns the string associated to the _`state`_. This string is statically allocated, do not free it. #### Response Example "live" ``` -------------------------------- ### kmod_module_new_from_name_lookup Source: https://kmod-project.github.io/v33/libkmod-libkmod-module.html Looks up a module by its name, without considering aliases, and returns a single kmod_module. ```APIDOC ## kmod_module_new_from_name_lookup () ### Description Lookup by module name, without considering possible aliases. This is similar to `kmod_module_new_from_lookup()`, but don't consider as source indexes and configurations that work with aliases. When succesful, this always resolves to one and only one module. The search order is: 1. module names in modules.dep index; 1. builtin indexes from kernel. The initial refcount is 1, and needs to be decremented to release the resources of the kmod_module. 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. ### Parameters - **ctx** (struct kmod_ctx *) - kmod library context - **modname** (const char *) - module name to look for - **mod** (struct kmod_module **) - returned module on success ### Returns 0 on success or < 0 otherwise. It fails if any of the lookup methods failed, which is basically due to memory allocation failure. If module is not found, it still returns 0, but _`mod`_is left untouched. ``` -------------------------------- ### Retrieve configuration value Source: https://kmod-project.github.io/v33/libkmod-libkmod-config.html Returns the value of the current configuration pointed to by the iterator. Requires a prior call to kmod_config_iter_next() to initialize the position. ```c const char * kmod_config_iter_get_value (const struct kmod_config_iter *iter); ``` -------------------------------- ### Validate kmod resources Source: https://kmod-project.github.io/v33/libkmod-libkmod.html Checks if the current context's indexes or configuration files have changed on disk. ```c int kmod_validate_resources (struct kmod_ctx *ctx); ``` -------------------------------- ### kmod_module_insert_module Source: https://kmod-project.github.io/v33/libkmod-libkmod-module.html Inserts a module into the Linux kernel. ```APIDOC ## kmod_module_insert_module ### Description Insert a module in Linux kernel. It opens the file pointed by mod, mmap'ing it and passing to kernel. ### Parameters - **mod** (struct kmod_module *) - Required - kmod module - **flags** (unsigned int) - Required - KMOD_INSERT_FORCE_VERMAGIC or KMOD_INSERT_FORCE_MODVERSION - **options** (const char *) - Required - module's options to pass to Linux Kernel ### Response - **Returns** (int) - 0 on success or < 0 on failure. ``` -------------------------------- ### Set logging priority Source: https://kmod-project.github.io/v33/libkmod-libkmod.html Configures the logging level for the kmod context to filter output messages. ```c void kmod_set_log_priority (struct kmod_ctx *ctx, int priority); ``` -------------------------------- ### Dump kmod index Source: https://kmod-project.github.io/v33/libkmod-libkmod.html Writes the specified index to a file descriptor. ```c int kmod_dump_index (struct kmod_ctx *ctx, enum kmod_index type, int fd); ``` -------------------------------- ### kmod_module_new_from_name Source: https://kmod-project.github.io/v33/libkmod-libkmod-module.html Creates a new struct kmod_module using the module name. ```APIDOC ## kmod_module_new_from_name ### Description Create a new struct kmod_module using the module name. The name cannot be an alias or file name. ### Parameters - **ctx** (struct kmod_ctx *) - Required - kmod library context - **name** (const char *) - Required - name of the module - **mod** (struct kmod_module **) - Required - where to save the created struct kmod_module ### Response - **Returns** (int) - 0 on success or < 0 otherwise. ``` -------------------------------- ### kmod_config_iter_get_key Source: https://kmod-project.github.io/v33/libkmod-libkmod-config.html Retrieves the key of the current configuration item pointed to by the iterator. ```APIDOC ## kmod_config_iter_get_key () ### Description Retrieves the key of the current configuration pointed to by the iterator. ### Method N/A (C function) ### Endpoint N/A (C function) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) - **const char *** - The key of the current configuration item. #### Response Example ``` "example_key" ``` ``` -------------------------------- ### kmod_module_unref_list Source: https://kmod-project.github.io/v33/libkmod-libkmod-module.html Releases a list of kmod modules. ```APIDOC ## kmod_module_unref_list ### Description Drop a reference of each kmod module in list and releases the resources taken by the list itself. ### Parameters - **list** (struct kmod_list *) - Required - list of kmod modules ### Response - **Returns** (int) - 0 ``` -------------------------------- ### Define kmod_list_foreach_reverse Source: https://kmod-project.github.io/v33/libkmod-libkmod-list.html Macro for iterating over a kmod_list in reverse. Use this to traverse the list from the end. ```c #define kmod_list_foreach_reverse(list_entry, first_entry) ``` -------------------------------- ### libkmod-list Functions Source: https://kmod-project.github.io/v33/libkmod-libkmod-list.html Functions for traversing and retrieving elements from a kmod_list structure. ```APIDOC ## kmod_list_foreach() ### Description Macro to iterate over a list. ### Parameters - **list_entry** - The current entry during iteration - **first_entry** - The head of the list --- ## kmod_list_foreach_reverse() ### Description Macro to iterate over a list in reverse order. ### Parameters - **list_entry** - The current entry during iteration - **first_entry** - The head of the list --- ## kmod_list_last() ### Description Get the last element of the list. As the list is circular, this is a cheap O(1) operation. ### Parameters #### Path Parameters - **list** (struct kmod_list*) - Required - The head of the list ### Response - **Returns** (struct kmod_list*) - Last node at list or NULL if the list is empty. --- ## kmod_list_next() ### Description Get the next node in the list relative to the current node as if the list was not circular. ### Parameters #### Path Parameters - **list** (struct kmod_list*) - Required - The head of the list - **curr** (struct kmod_list*) - Required - The current node in the list ### Response - **Returns** (struct kmod_list*) - Node next to curr or NULL if either this node is the last or list is empty. --- ## kmod_list_prev() ### Description Get the previous node in the list relative to the current node as if the list was not circular. ### Parameters #### Path Parameters - **list** (struct kmod_list*) - Required - The head of the list - **curr** (struct kmod_list*) - Required - The current node in the list ### Response - **Returns** (struct kmod_list*) - Node previous to curr or NULL if either this node is the head of the list or the list is empty. ``` -------------------------------- ### kmod_validate_resources Source: https://kmod-project.github.io/v33/libkmod-libkmod.html Checks if indexes and configuration files have changed on disk. ```APIDOC ## kmod_validate_resources ### Description Check if indexes and configuration files changed on disk and the current context is not valid anymore. ### Parameters #### Path Parameters - **ctx** (struct kmod_ctx *) - Required - The kmod library context. ### Response - **int** (integer) - KMOD_RESOURCES_OK, KMOD_RESOURCES_MUST_RELOAD, or KMOD_RESOURCES_MUST_RECREATE. ``` -------------------------------- ### kmod_module_get_softdeps Source: https://kmod-project.github.io/v33/libkmod-libkmod-module.html Retrieves soft dependencies for a kmod module. ```APIDOC ## kmod_module_get_softdeps ### Description Get soft dependencies for this kmod module from configuration file. ### Parameters #### Path Parameters - **mod** (const struct kmod_module *) - Required - kmod module - **pre** (struct kmod_list **) - Required - where to save the list of preceding soft dependencies. - **post** (struct kmod_list **) - Required - where to save the list of post soft dependencies. ### Response - **Returns** (int) - 0 on success or < 0 otherwise. ``` -------------------------------- ### Set user data Source: https://kmod-project.github.io/v33/libkmod-libkmod.html Stores a custom data pointer in the library context for later retrieval. ```c void kmod_set_userdata (struct kmod_ctx *ctx, const void *userdata); ``` -------------------------------- ### kmod_module_get_filtered_blacklist Source: https://kmod-project.github.io/v33/libkmod-libkmod-module.html Filters a list of kmod modules based on the configuration's blacklist. ```APIDOC ## kmod_module_get_filtered_blacklist ### Description Filters a list of kmod modules based on the configuration's blacklist and saves the result in the output list. Note: This function is deprecated; use kmod_module_apply_filter instead. ### Parameters #### Path Parameters - **ctx** (kmod library context) - Required - **input** (list of kmod_module) - Required - **output** (struct kmod_list **) - Required ### Response #### Success Response (0) - **Returns** (int) - 0 on success or < 0 otherwise. ``` -------------------------------- ### kmod_ref / kmod_unref Source: https://kmod-project.github.io/v33/libkmod-libkmod.html Manages the reference counting for the kmod library context. ```APIDOC ## kmod_ref / kmod_unref ### Description Take or drop a reference of the kmod library context. If the refcount reaches zero, the resources of the context will be released. ### Parameters #### Path Parameters - **ctx** (struct kmod_ctx *) - Required - The kmod library context. ### Response - **kmod_ctx** (struct) - The passed kmod library context or NULL if it's freed. ``` -------------------------------- ### kmod_module_get_module Source: https://kmod-project.github.io/v33/libkmod-libkmod-module.html Retrieves a kmod module from a list entry. ```APIDOC ## kmod_module_get_module ### Description Get the kmod module of this entry in the list, increasing its refcount. After it's used, unref it. ### Parameters #### Path Parameters - **entry** (const struct kmod_list *) - Required - an entry in a list of kmod modules. ### Response - **Returns** (struct kmod_module *) - NULL on failure or the kmod_module contained in this list entry with its refcount incremented. ``` -------------------------------- ### kmod_module_get_dependency_symbols Source: https://kmod-project.github.io/v33/libkmod-libkmod-module.html Retrieves a list of dependency symbols for a kmod module. ```APIDOC ## kmod_module_get_dependency_symbols ### Description Get a list of entries in ELF section ".symtab" or "__ksymtab_strings". ### Parameters #### Path Parameters - **mod** (kmod module) - Required - **list** (struct kmod_list **) - Required ### Response #### Success Response (0) - **Returns** (int) - 0 on success or < 0 otherwise. ``` -------------------------------- ### kmod_module_get_sections Source: https://kmod-project.github.io/v33/libkmod-libkmod-module.html Retrieves a list of kmod module sections, as returned by the Linux Kernel. ```APIDOC ## kmod_module_get_sections () ### Description Get a list of kmod sections of this _`mod`_, as returned by Linux Kernel. The structure contained in this list is internal to libkmod and their fields can be obtained by calling `kmod_module_section_get_name()` and `kmod_module_section_get_address()`. After use, free the _`list`_ by calling `kmod_module_section_free_list()`. ### Parameters - **mod** (struct kmod_module *) - kmod module. ### Returns - struct kmod_list * - A new list of kmod module sections on success or NULL on failure. ``` -------------------------------- ### Apply Filter to Module List Source: https://kmod-project.github.io/v33/libkmod-libkmod-module.html Filters a list of kmod modules based on a specified filter type and saves the result to an output list. ```c int kmod_module_apply_filter (_const struct kmod_ctx *ctx_, _enum kmod_filter filter_type_, _const struct kmod_list *input_, _struct kmod_list **output_); ``` -------------------------------- ### kmod_module_get_refcnt Source: https://kmod-project.github.io/v33/libkmod-libkmod-loaded.html Retrieves the reference count of a loaded module. ```APIDOC ## kmod_module_get_refcnt ### Description Get the ref count of this _`mod`_, as returned by Linux Kernel, by reading /sys filesystem. ### Method int ### Endpoint N/A (Function Call) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response Returns the reference count on success. #### Error Response (< 0) Returns < 0 on failure. #### Response Example 5 ``` -------------------------------- ### Define kmod_config_iter structure Source: https://kmod-project.github.io/v33/libkmod-libkmod-config.html Opaque structure representing an iterator over configuration settings. ```c struct kmod_config_iter; ``` -------------------------------- ### kmod_module_get_size Source: https://kmod-project.github.io/v33/libkmod-libkmod-loaded.html Retrieves the size of a loaded module. ```APIDOC ## kmod_module_get_size ### Description 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. ### Method long ### Endpoint N/A (Function Call) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response Returns the size of this kmod module. #### Response Example 123456 ``` -------------------------------- ### kmod_load_resources / kmod_unload_resources Source: https://kmod-project.github.io/v33/libkmod-libkmod.html Loads or unloads indexes to optimize lookup performance. ```APIDOC ## kmod_load_resources / kmod_unload_resources ### Description Load indexes and keep them open in ctx for faster lookups, or unload them to free resources. ### Parameters #### Path Parameters - **ctx** (struct kmod_ctx *) - Required - The kmod library context. ### Response - **int** (integer) - 0 on success or < 0 otherwise. ``` -------------------------------- ### kmod_module_info_get_value Source: https://kmod-project.github.io/v33/libkmod-libkmod-module.html Retrieves the value from a kmod module info list entry. The returned string is owned by the info entry and should not be freed. ```APIDOC ## kmod_module_info_get_value ### Description Get the value of a kmod module info. ### Method N/A (C function) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response - **value** (const char *) - The value of the kmod module info. #### Response Example N/A ``` -------------------------------- ### kmod_module_section_free_list Source: https://kmod-project.github.io/v33/libkmod-libkmod-module.html Releases the resources associated with a kmod module section list. ```APIDOC ## kmod_module_section_free_list () ### Description Release the resources taken by _`list`_ ### Parameters - **list** (struct kmod_list *) - kmod module section list. ``` -------------------------------- ### kmod_module_dependency_symbols_free_list Source: https://kmod-project.github.io/v33/libkmod-libkmod-module.html Releases the resources associated with a kmod module dependency symbols list. ```APIDOC ## kmod_module_dependency_symbols_free_list () ### Description Release the resources taken by _`list`_ ### Parameters - **list** (struct kmod_list *) - kmod module dependency_symbols list. ``` -------------------------------- ### kmod_module_symbols_free_list Source: https://kmod-project.github.io/v33/libkmod-libkmod-module.html Releases the resources associated with a kmod module symbols list. ```APIDOC ## kmod_module_symbols_free_list () ### Description Release the resources taken by _`list`_ ### Parameters - **list** (struct kmod_list *) - kmod module symbols list. ``` -------------------------------- ### kmod_config_iter_get_value Source: https://kmod-project.github.io/v33/libkmod-libkmod-config.html Retrieves the value of the current configuration item pointed to by the iterator. ```APIDOC ## kmod_config_iter_get_value () ### Description Retrieves the value of the current configuration pointed to by the iterator. ### Method N/A (C function) ### Endpoint N/A (C function) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) - **const char *** - The value of the current configuration item. #### Response Example ``` "example_value" ``` ``` -------------------------------- ### Set custom logging function Source: https://kmod-project.github.io/v33/libkmod-libkmod.html Overrides the default stderr logging with a custom callback function. ```c void kmod_set_log_fn (struct kmod_ctx *ctx, void (*log_fn) (void *log_data, int priority, const char *file, int line, const char *fn, const char *format, va_list args), const void *data); ``` -------------------------------- ### kmod_module_get_path Source: https://kmod-project.github.io/v33/libkmod-libkmod-module.html Retrieves the path of a kmod module. ```APIDOC ## kmod_module_get_path ### Description Get the path of this kmod module. If not created by path, it searches the modules.dep index. ### Parameters #### Path Parameters - **mod** (kmod module) - Required ### Response #### Success Response (string) - **Returns** (const char *) - The path of this kmod module or NULL if not available. ``` -------------------------------- ### kmod_module_get_holders Source: https://kmod-project.github.io/v33/libkmod-libkmod-loaded.html Retrieves a list of modules that are holding the specified module. ```APIDOC ## kmod_module_get_holders ### Description 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()`. ### Method struct kmod_list * ### Endpoint N/A (Function Call) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response Returns a new list of kmod modules on success. #### Error Response (NULL) Returns NULL on failure. #### Response Example struct kmod_list *holders_list = kmod_module_get_holders(my_module); ```