kmod

package
v0.0.0-...-8d377ce Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 29, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddPattern

func AddPattern(root *kmodpb.RadixNode, pattern string, moduleIndex uint32) error

AddPattern adds a new pattern associated with a moduleIndex to the radix tree rooted at root.

func LoadModule

func LoadModule(file syscall.Conn, params string, flags uintptr) error

LoadModule loads a kernel module into the kernel.

func LookupModules

func LookupModules(meta *kmodpb.Meta, modalias string) (mods []*kmodpb.Module)

LookupModules looks up all matching modules for a given modalias device identifier.

func MakeMetaFromModuleInfo

func MakeMetaFromModuleInfo(modinfos []ModuleInfo) (*kmodpb.Meta, error)

MakeMetaFromModuleInfo is a more flexible alternative to MakeMeta. It only relies on ModuleInfo structures, additional processing can be done outside of this function. It does however require that for dynamically-loaded modules the "path" key is set to the path of the .ko file relative to the module root.

func PrintTree

func PrintTree(r *kmodpb.RadixNode)

PrintTree prints the tree from the given root node to standard out. The output is not stable and should only be used for debugging/diagnostics. It will log and exit the process if it encounters invalid nodes.

func UnloadModule

func UnloadModule(name string, flags uintptr) error

UnloadModule unloads a kernel module from the kernel.

Types

type ErrNotFound

type ErrNotFound struct {
	Name string
}

ErrNotFound is returned when an attempt is made to load a module which does not exist according to the loaded metadata.

func (*ErrNotFound) Error

func (e *ErrNotFound) Error() string

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager contains all the logic and metadata required to efficiently load Linux kernel modules. It has internal loading tracking, thus it's recommended to only keep one Manager instance running per kernel. It can recreate its internal state quite well, but there are edge cases where the kernel makes it hard to do so (MODULE_STATE_UNFORMED) thus if possible that single instance should be kept alive. It currently does not support unloading modules, but that can be added to the existing design if deemed necessary.

func NewManager

func NewManager(meta *kmodpb.Meta, modulesPath string) (*Manager, error)

NewManager instantiates a kernel module loading manager. Please take a look at the additional considerations on the Manager type itself.

func NewManagerFromPath

func NewManagerFromPath(modulesPath string) (*Manager, error)

NewManagerFromPath instantiates a new kernel module loading manager from a path containing a meta.pb file containing a kmod.Meta message as well as the kernel modules within. Please take a look at the additional considerations on the Manager type itself.

func (*Manager) LoadModule

func (s *Manager) LoadModule(name string) error

LoadModule loads the module with the given name. If the module is already loaded or built-in, it returns no error. If it failed loading the module or the module does not exist, it returns an error.

func (*Manager) LoadModulesForDevice

func (s *Manager) LoadModulesForDevice(devModalias string) error

LoadModulesForDevice loads all modules whose device match expressions (modaliases) match the given device modalias. It only returns an error if a module which matched the device or one of its dependencies caused an error when loading. A device modalias string which matches nothing is not an error.

type ModuleInfo

type ModuleInfo map[string][]string

ModuleInfo contains Linux kernel module metadata. It maps keys to a list of values. For known keys accessor functions are provided.

func GetBuiltinModulesInfo

func GetBuiltinModulesInfo(f io.Reader) ([]ModuleInfo, error)

GetBuiltinModulesInfo parses all modinfo structures for builtin modules from a modinfo file (modules.builtin.modinfo).

func GetModuleInfo

func GetModuleInfo(e *elf.File) (ModuleInfo, error)

GetModuleInfo looks for a ".modinfo" section in the passed ELF Linux kernel module and parses it into a ModuleInfo structure.

func (ModuleInfo) Aliases

func (i ModuleInfo) Aliases() []string

Aliases returns a list of match expressions for matching devices handled by this module. Every returned string consists of a literal as well as '*' wildcards matching one or more characters. These should be matched against the kobject MODALIAS field or the modalias sysfs file.

func (ModuleInfo) Authors

func (i ModuleInfo) Authors() []string

Authors returns the list of a authors of the module.

func (ModuleInfo) Description

func (i ModuleInfo) Description() string

Description returns a human-readable description of the module or an empty string if it is not available.

func (ModuleInfo) Firmware

func (i ModuleInfo) Firmware() []string

Firmware returns a list of firmware file paths required by this module. These paths are usually relative to the root of a linux-firmware install unless the firmware is non-redistributable.

func (ModuleInfo) Get

func (i ModuleInfo) Get(key string) string

Get returns the first value of the given key or an empty string if the key does not exist.

func (ModuleInfo) GetDependencies

func (i ModuleInfo) GetDependencies() []string

GetDependencies returns a list of module names which need to be loaded before this one.

func (ModuleInfo) GetOptionalDependencies

func (i ModuleInfo) GetOptionalDependencies() OptionalDependencies

GetOptionalDependencies returns a set of modules which are recommended to be loaded before and after this module. These are optional, but enhance the functionality of this module.

func (ModuleInfo) IsInTree

func (i ModuleInfo) IsInTree() bool

IsInTree returns true if the module was built in the Linux source tree and not externally. This does not necessarily mean that the module is in the mainline kernel.

func (ModuleInfo) Licenses

func (i ModuleInfo) Licenses() []string

License returns the licenses use of this module is governed by. For mainline modules, the list of valid license strings is documented in the kernel's Documentation/process/license-rules.rst file under the `MODULE_LICENSE` section.

func (ModuleInfo) Name

func (i ModuleInfo) Name() string

Name returns the name of the module as defined in kbuild.

type OptionalDependencies

type OptionalDependencies struct {
	// Pre contains a list of module names to be optionally loaded before the
	// module itself.
	Pre []string
	// Post contains a list of module names to be optionally loaded after the
	// module itself.
	Post []string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL