github.com/u-root/u-root@v7.0.1-0.20200915234505-ad7babab0a8e+incompatible/pkg/libinit/root_plan9.go (about) 1 // Copyright 2014-2019 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 // Package libinit creates the environment and root file system for u-root. 6 package libinit 7 8 import ( 9 "fmt" 10 "os" 11 12 "github.com/u-root/u-root/pkg/ulog" 13 ) 14 15 type creator interface { 16 create() error 17 fmt.Stringer 18 } 19 20 type dir struct { 21 Name string 22 Mode os.FileMode 23 } 24 25 func (d dir) create() error { 26 return os.MkdirAll(d.Name, d.Mode) 27 } 28 29 func (d dir) String() string { 30 return fmt.Sprintf("dir %q (mode %#o)", d.Name, d.Mode) 31 } 32 33 type mount struct { 34 Source string 35 Flag uint 36 Target string 37 } 38 39 func (m mount) create() error { 40 return fmt.Errorf("Not yet") 41 } 42 43 func (m mount) String() string { 44 return fmt.Sprintf("mount source %q target %q flags %#x", m.Source, m.Target, m.Flag) 45 } 46 47 var ( 48 // These have to be created / mounted first, so that the logging works correctly. 49 preNamespace = []creator{} 50 namespace = []creator{} 51 ) 52 53 func goBin() string { 54 return "/bin" 55 } 56 57 func create(namespace []creator, optional bool) { 58 for _, c := range namespace { 59 if err := c.create(); err != nil { 60 if optional { 61 ulog.KernelLog.Printf("u-root init [optional]: warning creating %s: %v", c, err) 62 } else { 63 ulog.KernelLog.Printf("u-root init: error creating %s: %v", c, err) 64 } 65 } 66 } 67 } 68 69 // SetEnv sets the default u-root environment. 70 func SetEnv() { 71 env := map[string]string{ 72 "LD_LIBRARY_PATH": "/usr/local/lib", 73 "GOROOT": "/go", 74 "GOPATH": "/", 75 "GOBIN": "/ubin", 76 "CGO_ENABLED": "0", 77 } 78 79 // Not all these paths may be populated or even exist but OTOH they might. 80 path := "/ubin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/bin:/usr/local/sbin:/buildbin:/bbin" 81 82 env["PATH"] = fmt.Sprintf("%v:%v", goBin(), path) 83 for k, v := range env { 84 os.Setenv(k, v) 85 } 86 } 87 88 // CreateRootfs creates the default u-root file system. 89 func CreateRootfs() { 90 }