MCPcopy Index your code
hub / github.com/linuxkit/linuxkit / CopySplitTar

Function CopySplitTar

src/cmd/linuxkit/initrd/initrd.go:93–130  ·  view source on GitHub ↗

CopySplitTar copies a tar stream into an initrd, but splits out kernel, cmdline, and ucode

(w *Writer, r *tar.Reader)

Source from the content-addressed store, hash-verified

91
92// CopySplitTar copies a tar stream into an initrd, but splits out kernel, cmdline, and ucode
93func CopySplitTar(w *Writer, r *tar.Reader) (kernel []byte, cmdline string, ucode []byte, err error) {
94 for {
95 var thdr *tar.Header
96 thdr, err = r.Next()
97 if err == io.EOF {
98 return kernel, cmdline, ucode, nil
99 }
100 if err != nil {
101 return
102 }
103 switch {
104 case thdr.Name == "boot/kernel":
105 kernel, err = io.ReadAll(r)
106 if err != nil {
107 return
108 }
109 case thdr.Name == "boot/cmdline":
110 var buf []byte
111 buf, err = io.ReadAll(r)
112 if err != nil {
113 return
114 }
115 cmdline = string(buf)
116 case thdr.Name == "boot/ucode.cpio":
117 ucode, err = io.ReadAll(r)
118 if err != nil {
119 return
120 }
121 case strings.HasPrefix(thdr.Name, "boot/"):
122 // skip the rest of ./boot
123 default:
124 _, err = copyTarEntry(w, thdr, r)
125 if err != nil {
126 return
127 }
128 }
129 }
130}
131
132// NewWriter creates a writer that will output an initrd stream
133func NewWriter(w io.Writer) *Writer {

Callers

nothing calls this directly

Calls 1

copyTarEntryFunction · 0.85

Tested by

no test coverage detected