### Build and Install kmod Source: https://github.com/kmod-project/kmod/blob/master/README.md Standard build and installation process for kmod using meson. For end-users and distributions, a release build type is recommended. ```bash meson setup builddir/ meson compile -C builddir/ sudo meson install -C builddir/ ``` ```bash meson setup --buildtype release builddir/ ``` -------------------------------- ### Include Order Example Source: https://github.com/kmod-project/kmod/blob/master/CODING-STYLE.md Includes should be sorted in a specific order: system headers, shared/*, libkmod, tool, and then local headers. This aids in organizing dependencies. ```c < system headers > < shared/* > < libkmod > < tool > "local headers" ``` -------------------------------- ### Variable Initialization - Avoid Unnecessary Source: https://github.com/kmod-project/kmod/blob/master/CODING-STYLE.md When declaring variables, avoid initializing them unless it is strictly necessary. This example shows an incorrect initialization. ```c int i = 1; // wrong for (i = 0; i < 3; i++) { } ``` -------------------------------- ### Module Information Retrieval Source: https://github.com/kmod-project/kmod/blob/master/libkmod/docs/libkmod-sections.txt Functions to get various properties and dependencies of a module. ```APIDOC ## kmod_module_get_module ### Description Gets the kmod_module object itself. ## kmod_module_get_dependencies ### Description Gets the list of module dependencies. ## kmod_module_get_softdeps ### Description Gets the list of soft dependencies. ## kmod_module_get_weakdeps ### Description Gets the list of weak dependencies. ## kmod_filter ### Description Applies a filter to module information. ## kmod_module_apply_filter ### Description Applies a filter to a specific kmod_module. ## kmod_module_get_filtered_blacklist ### Description Gets the filtered blacklist information for a module. ## kmod_module_get_install_commands ### Description Gets the installation commands for a module. ## kmod_module_get_remove_commands ### Description Gets the removal commands for a module. ## kmod_module_get_name ### Description Gets the name of the module. ## kmod_module_get_options ### Description Gets the options for the module. ## kmod_module_get_path ### Description Gets the file path of the module. ``` -------------------------------- ### String Literal Example - Line Wrap Exception Source: https://github.com/kmod-project/kmod/blob/master/CODING-STYLE.md When a string literal exceeds the line limit, it is preferred not to break it to facilitate grepping. This is an exception to the general line wrapping rule. ```c err = my_function(ctx, "this is a long string that will pass the 80chr limit"); ``` -------------------------------- ### Create and Manage kmod Context Source: https://github.com/kmod-project/kmod/blob/master/libkmod/README.md Initialize and clean up the library context. Always create and manage your own context. ```c struct kmod_ctx *ctx = kmod_new(kernel_dirname); kmod_unref(ctx); ``` -------------------------------- ### Create Module from Path Source: https://github.com/kmod-project/kmod/blob/master/libkmod/README.md Create a module object from a given file path. Handle potential errors and unreference the module when done. ```c struct kmod_module *mod; int err; err = kmod_module_new_from_path(ctx, path, &mod); if (err < 0) { /* code */ } else { /* code */ kmod_module_unref(mod); } ``` -------------------------------- ### Create Module from Name Source: https://github.com/kmod-project/kmod/blob/master/libkmod/README.md Create a module object from its name. Handle potential errors and unreference the module when done. ```c struct kmod_module *mod; int err; err = kmod_module_new_from_name(ctx, name, &mod); if (err < 0) { /* code */ } else { /* code */ kmod_module_unref(mod); } ``` -------------------------------- ### kmod_ctx and Context Management Source: https://github.com/kmod-project/kmod/blob/master/libkmod/docs/libkmod-sections.txt Functions for creating, referencing, and destroying the libkmod context. ```APIDOC ## kmod_ctx ### Description Represents the context for libkmod operations. ## kmod_new ### Description Creates a new libkmod context. ## kmod_ref ### Description Increments the reference count of a kmod context. ## kmod_unref ### Description Decrements the reference count of a kmod context and frees it if the count reaches zero. ``` -------------------------------- ### Development Build and Test kmod Source: https://github.com/kmod-project/kmod/blob/master/README.md Configuration for development builds using a native file and executing the testsuite. Kernel headers may need to be pre-installed. ```bash meson setup --native-file build-dev.ini builddir/ ``` ```bash meson test -C builddir ``` ```bash KDIR=any meson test -C builddir ``` ```bash KDIR=/path/to/specific/headers meson test -C builddir ``` -------------------------------- ### Configuration Iteration Source: https://github.com/kmod-project/kmod/blob/master/libkmod/docs/libkmod-sections.txt Functions for iterating through module configuration options. ```APIDOC ## kmod_config_iter ### Description Represents an iterator for configuration data. ## kmod_config_get_blacklists ### Description Gets the list of blacklisted modules from the configuration. ## kmod_config_get_install_commands ### Description Gets the installation commands from the configuration. ## kmod_config_get_remove_commands ### Description Gets the removal commands from the configuration. ## kmod_config_get_aliases ### Description Gets the module aliases from the configuration. ## kmod_config_get_options ### Description Gets the module options from the configuration. ## kmod_config_get_softdeps ### Description Gets the soft dependencies from the configuration. ## kmod_config_get_weakdeps ### Description Gets the weak dependencies from the configuration. ## kmod_config_iter_get_key ### Description Gets the key of the current configuration item. ## kmod_config_iter_get_value ### Description Gets the value of the current configuration item. ## kmod_config_iter_next ### Description Advances the configuration iterator to the next item. ## kmod_config_iter_free_iter ### Description Frees the configuration iterator. ``` -------------------------------- ### Index and Logging Source: https://github.com/kmod-project/kmod/blob/master/libkmod/docs/libkmod-sections.txt Functions for managing the module index and setting logging preferences. ```APIDOC ## kmod_index ### Description Represents the module index. ## kmod_dump_index ### Description Dumps the contents of the module index. ## kmod_set_log_priority ### Description Sets the log priority for libkmod. ## kmod_get_log_priority ### Description Gets the current log priority for libkmod. ## kmod_set_log_fn ### Description Sets a custom logging function for libkmod. ## kmod_get_userdata ### Description Gets the user-defined data associated with the context. ## kmod_set_userdata ### Description Sets user-defined data associated with the context. ## kmod_get_dirname ### Description Gets the directory name used by libkmod. ``` -------------------------------- ### Module Info and Sections Source: https://github.com/kmod-project/kmod/blob/master/libkmod/docs/libkmod-sections.txt Functions for retrieving module information key-value pairs and section details. ```APIDOC ## kmod_module_get_info ### Description Gets the key-value information for a module. ## kmod_module_info_get_key ### Description Gets the key of a module info item. ## kmod_module_info_get_value ### Description Gets the value of a module info item. ## kmod_module_info_free_list ### Description Frees a list of module info items. ## kmod_module_get_sections ### Description Gets the sections of a module. ## kmod_module_section_get_address ### Description Gets the address of a module section. ## kmod_module_section_get_name ### Description Gets the name of a module section. ## kmod_module_section_free_list ### Description Frees a list of module sections. ``` -------------------------------- ### Module Insertion, Probing, and Removal Source: https://github.com/kmod-project/kmod/blob/master/libkmod/docs/libkmod-sections.txt Functions for inserting, probing, and removing kernel modules. ```APIDOC ## kmod_insert ### Description Inserts a kernel module. ## kmod_module_insert_module ### Description Inserts a specific kmod_module. ## kmod_probe ### Description Probes for a kernel module. ## kmod_module_probe_insert_module ### Description Probes and inserts a specific kmod_module. ## kmod_remove ### Description Removes a kernel module. ## kmod_module_remove_module ### Description Removes a specific kmod_module. ``` -------------------------------- ### Early Return Pattern - Better Source: https://github.com/kmod-project/kmod/blob/master/CODING-STYLE.md This pattern demonstrates the preferred 'early return' or 'exit early' approach in functions, which avoids deeply nested if-else structures and improves readability. ```c if (!x) return b; ... ... ... ... return a; ``` -------------------------------- ### Resource Management Source: https://github.com/kmod-project/kmod/blob/master/libkmod/docs/libkmod-sections.txt Functions for loading, unloading, and validating module resources. ```APIDOC ## kmod_load_resources ### Description Loads module resources into the context. ## kmod_unload_resources ### Description Unloads module resources from the context. ## kmod_resources ### Description Retrieves the loaded module resources. ## kmod_validate_resources ### Description Validates the loaded module resources. ``` -------------------------------- ### Symbol and Version Information Source: https://github.com/kmod-project/kmod/blob/master/libkmod/docs/libkmod-sections.txt Functions for retrieving symbol binding, CRC, and version information for modules. ```APIDOC ## kmod_module_get_dependency_symbols ### Description Gets the dependency symbols for a module. ## kmod_symbol_bind ### Description Binds a symbol. ## kmod_module_dependency_symbol_get_bind ### Description Gets the bind information for a dependency symbol. ## kmod_module_dependency_symbol_get_crc ### Description Gets the CRC of a dependency symbol. ## kmod_module_dependency_symbol_get_symbol ### Description Gets the symbol name of a dependency symbol. ## kmod_module_dependency_symbols_free_list ### Description Frees a list of dependency symbols. ## kmod_module_get_symbols ### Description Gets the symbols exported by a module. ## kmod_module_symbol_get_crc ### Description Gets the CRC of a module symbol. ## kmod_module_symbol_get_symbol ### Description Gets the symbol name of a module symbol. ## kmod_module_symbols_free_list ### Description Frees a list of module symbols. ## kmod_module_get_versions ### Description Gets the version information for a module. ## kmod_module_version_get_crc ### Description Gets the CRC of a module version. ## kmod_module_version_get_symbol ### Description Gets the symbol name of a module version. ## kmod_module_versions_free_list ### Description Frees a list of module versions. ``` -------------------------------- ### Resolve Module from Alias Source: https://github.com/kmod-project/kmod/blob/master/libkmod/README.md Look up modules based on an alias, which may resolve to multiple alternatives. Iterate through the list of found modules. ```c struct kmod_list *list, *itr; int err; err = kmod_module_new_from_lookup(ctx, alias, &list); if (err < 0) { /* code */ } else { kmod_list_foreach(itr, list) { struct kmod_module *mod = kmod_module_get_module(itr); /* code */ } } ``` -------------------------------- ### Loaded Module Information Source: https://github.com/kmod-project/kmod/blob/master/libkmod/docs/libkmod-sections.txt Functions for retrieving information about currently loaded modules. ```APIDOC ## kmod_module_new_from_loaded ### Description Creates a kmod_module object from a loaded module. ## kmod_module_initstate ### Description Represents the initialization state of a module. ## kmod_module_get_initstate ### Description Gets the initialization state of a module. ## kmod_module_initstate_str ### Description Converts the initialization state to a string. ## kmod_module_get_size ### Description Gets the size of a loaded module. ## kmod_module_get_refcnt ### Description Gets the reference count of a loaded module. ## kmod_module_get_holders ### Description Gets the list of modules holding this module. ``` -------------------------------- ### kmod_module and Module Operations Source: https://github.com/kmod-project/kmod/blob/master/libkmod/docs/libkmod-sections.txt Functions for creating, referencing, and manipulating module objects. ```APIDOC ## kmod_module ### Description Represents a kernel module. ## kmod_module_new_from_lookup ### Description Creates a kmod_module object by looking it up. ## kmod_module_new_from_name_lookup ### Description Creates a kmod_module object by looking it up using its name. ## kmod_module_new_from_name ### Description Creates a kmod_module object from its name. ## kmod_module_new_from_path ### Description Creates a kmod_module object from its file path. ## kmod_module_ref ### Description Increments the reference count of a kmod_module. ## kmod_module_unref ### Description Decrements the reference count of a kmod_module. ## kmod_module_unref_list ### Description Decrements the reference count for all modules in a list. ``` -------------------------------- ### List Operations Source: https://github.com/kmod-project/kmod/blob/master/libkmod/docs/libkmod-sections.txt Functions for manipulating lists, commonly used for module dependencies or results. ```APIDOC ## kmod_list ### Description Represents a list structure. ## kmod_list_foreach ### Description Iterates over a list. ## kmod_list_foreach_reverse ### Description Iterates over a list in reverse. ## kmod_list_last ### Description Gets the last element of a list. ## kmod_list_next ### Description Gets the next element in a list. ## kmod_list_prev ### Description Gets the previous element in a list. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.