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