github.com/mvdan/u-root-coreutils@v0.0.0-20230122170626-c2eef2898555/cmds/core/insmod/insmod_linux.go (about)

     1  // Copyright 2012-2017 the u-root Authors. All rights reserved
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // insmod inserts a module into the running Linux kernel.
     6  //
     7  // Synopsis:
     8  //
     9  //	insmod [filename] [module options...]
    10  //
    11  // Description:
    12  //
    13  //	insmod is a clone of insmod(8)
    14  package main
    15  
    16  import (
    17  	"log"
    18  	"os"
    19  	"strings"
    20  
    21  	"github.com/mvdan/u-root-coreutils/pkg/kmodule"
    22  )
    23  
    24  func main() {
    25  	if len(os.Args) < 2 {
    26  		log.Fatalf("insmod: ERROR: missing filename.\n")
    27  	}
    28  
    29  	// get filename from argv[1]
    30  	filename := os.Args[1]
    31  
    32  	// Everything else is module options
    33  	options := strings.Join(os.Args[2:], " ")
    34  
    35  	f, err := os.Open(filename)
    36  	if err != nil {
    37  		log.Fatalf("could not open %q: %v", filename, err)
    38  	}
    39  	defer f.Close()
    40  
    41  	if err := kmodule.FileInit(f, options, 0); err != nil {
    42  		log.Fatalf("insmod: could not load %q: %v", filename, err)
    43  	}
    44  }