github.com/mem/u-root@v2.0.1-0.20181004165302-9b18b4636a33+incompatible/cmds/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  // Insert a module into the Linux kernel
     6  //
     7  // Synopsis:
     8  //	insmod [filename] [module options...]
     9  //
    10  // Description:
    11  //	insmod is a clone of insmod(8)
    12  package main
    13  
    14  import (
    15  	"log"
    16  	"os"
    17  	"strings"
    18  
    19  	"github.com/u-root/u-root/pkg/kmodule"
    20  )
    21  
    22  func main() {
    23  	if len(os.Args) < 2 {
    24  		log.Fatalf("insmod: ERROR: missing filename.\n")
    25  	}
    26  
    27  	// get filename from argv[1]
    28  	filename := os.Args[1]
    29  
    30  	// Everything else is module options
    31  	options := strings.Join(os.Args[2:], " ")
    32  
    33  	f, err := os.Open(filename)
    34  	if err != nil {
    35  		log.Fatalf("could not open %q: %v", filename, err)
    36  	}
    37  	defer f.Close()
    38  
    39  	if err := kmodule.FileInit(f, options, 0); err != nil {
    40  		log.Fatalf("insmod: could not load %q: %v", filename, err)
    41  	}
    42  }