Documentation
¶
Overview ¶
Package kmod performs bindings over libkmod to manipulate kernel modules from Golang seemlessly.
libkmod is a well-known library to handle kernel modules and which is used in the kmod set of tools (modprobe, modinfo, depmod etc ...). This Golang wrapper exposes common operations: list installed modules, retrieve information on a module, insert or remove a module from the tree.
The following file shows those abilities in practice are available
package main import ( "fmt" "github.com/ElyKar/golang-kmod/kmod" ) func main() { km, err := kmod.NewKmod() if err != nil { panic(err) } // List all loaded modules list, err := km.List() if err != nil { panic(err) } for _, module := range list { fmt.Printf("%s, %d\n", module.Name(), module.Size()) } // Finds a specific module and display some informations about it if pcspkr, err := km.ModuleFromName("pcspkr"); err == nil { infoMod, err := pcspkr.Info() if err != nil { panic(err) } fmt.Printf("Author: %s\n", infoMod["author"]) fmt.Printf("Description: %s\n", infoMod["description"]) fmt.Printf("License: %s\n", infoMod["license"]) } // Insert a module and its dependencies _ = km.Insert("rtl2832") // Remove a module _ = km.Remove("rtl2832") }
Copyright 2017 Tristan Claverie. All rights reserved. Use of this source code is governed by an Apache license that can be found in the LICENSE file.
Index ¶
- type Kmod
- type Module
- func (mod *Module) Info() (map[string]string, error)
- func (mod *Module) InstallCommands() string
- func (mod *Module) Name() string
- func (mod *Module) Options() string
- func (mod *Module) Path() string
- func (mod *Module) RefCnt() int32
- func (mod *Module) RemoveCommands() string
- func (mod *Module) Size() uint64
- func (mod *Module) Versions() ([]*Version, error)
- type ModuleList
- type Version
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Kmod ¶
type Kmod struct {
// contains filtered or unexported fields
}
Kmod wraps a kmod_context inside it. When garbage collected, all module handles will be freed by libkmod.
func NewKmod ¶
NewKmod creates a new context from default directories and configuration files. It will search for modules in /lib/modules/`uname -r` and configuration files in /run/modprobe.d, /etc/modprobe.d and /lib/modprobe.d.
This function returns an error in case the library encounters a problem for creating and populating the context.
The returned *Kmod must not be discarded, as releasing it will free the underlying C structure and all the modules in the context.
func (*Kmod) Insert ¶
Insert a module in the tree with its name.
It returns an error if the module could not be found or if it could not be inserted.
To insert a wanted module:
kmod := NewKmod() kmod.Insert("pcspkr")
If this module depends on others that are not yet loaded, depencies will be loaded.
func (*Kmod) List ¶
List returns a slice containing all loaded modules.
The method returns an error in case the list can't be retrieved.
func (*Kmod) Lookup ¶
Lookup returns a slice of all modules matching 'alias_name'.
The method returns an error in case the lookup fails
func (*Kmod) ModuleFromName ¶
ModuleFromName returns a module handle from its name.
The method returns an error if the module could not be found.
type Module ¶
type Module struct {
// contains filtered or unexported fields
}
Module wraps a module from kmod.
func (*Module) Info ¶
Info returns the informations about a module (author, description etc ...).
This method returns an error if informations about the module couldn't be read
func (*Module) InstallCommands ¶
InstallCommands returns the install commands of the module.
func (*Module) RemoveCommands ¶
RemoveCommands returns the remove commands of the module.
type ModuleList ¶
type ModuleList struct {
// contains filtered or unexported fields
}
ModuleList wraps a kmod_list structure.