CopySplitTar copies a tar stream into an initrd, but splits out kernel, cmdline, and ucode
(w *Writer, r *tar.Reader)
| 91 | |
| 92 | // CopySplitTar copies a tar stream into an initrd, but splits out kernel, cmdline, and ucode |
| 93 | func 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 |
| 133 | func NewWriter(w io.Writer) *Writer { |
nothing calls this directly
no test coverage detected