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

Function copyTarEntry

src/cmd/linuxkit/initrd/initrd.go:54–90  ·  view source on GitHub ↗
(w *Writer, thdr *tar.Header, r io.Reader)

Source from the content-addressed store, hash-verified

52}
53
54func copyTarEntry(w *Writer, thdr *tar.Header, r io.Reader) (written int64, err error) {
55 tp := typeconv(thdr)
56 if tp == -1 {
57 return written, errors.New("cannot convert tar file")
58 }
59 size := thdr.Size
60 if tp == cpio.TYPE_SYMLINK {
61 size = int64(len(thdr.Linkname))
62 }
63 chdr := cpio.Header{
64 Mode: thdr.Mode,
65 Uid: thdr.Uid,
66 Gid: thdr.Gid,
67 Mtime: thdr.ModTime.Unix(),
68 Size: size,
69 Devmajor: thdr.Devmajor,
70 Devminor: thdr.Devminor,
71 Type: tp,
72 Name: thdr.Name,
73 }
74 err = w.WriteHeader(&chdr)
75 if err != nil {
76 return
77 }
78 var n int64
79 switch tp {
80 case cpio.TYPE_SYMLINK:
81 var count int
82 count, err = w.Write([]byte(thdr.Linkname))
83 n = int64(count)
84 case cpio.TYPE_REG:
85 n, err = io.Copy(w, r)
86 }
87 written += n
88
89 return
90}
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) {

Callers 1

CopySplitTarFunction · 0.85

Calls 3

typeconvFunction · 0.85
WriteHeaderMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected