mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-20 17:49:10 +00:00
Remove pad4 writer because it's buggy and doesn't seem required
According to https://docs.kernel.org/driver-api/early-userspace/buffer-format.html Signed-off-by: David Gageot <david.gageot@docker.com>
This commit is contained in:
parent
61a07e26cf
commit
c61ddd0482
@ -9,14 +9,12 @@ import (
|
|||||||
|
|
||||||
// drop-in 100% compatible replacement and 17% faster than compress/gzip.
|
// drop-in 100% compatible replacement and 17% faster than compress/gzip.
|
||||||
gzip "github.com/klauspost/pgzip"
|
gzip "github.com/klauspost/pgzip"
|
||||||
"github.com/linuxkit/linuxkit/src/cmd/linuxkit/pad4"
|
|
||||||
"github.com/surma/gocpio"
|
"github.com/surma/gocpio"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Writer is an io.WriteCloser that writes to an initrd
|
// Writer is an io.WriteCloser that writes to an initrd
|
||||||
// This is a compressed cpio archive, zero padded to 4 bytes
|
// This is a compressed cpio archive, zero padded to 4 bytes
|
||||||
type Writer struct {
|
type Writer struct {
|
||||||
pw *pad4.Writer
|
|
||||||
gw *gzip.Writer
|
gw *gzip.Writer
|
||||||
cw *cpio.Writer
|
cw *cpio.Writer
|
||||||
}
|
}
|
||||||
@ -136,8 +134,7 @@ func CopySplitTar(w *Writer, r *tar.Reader) (kernel []byte, cmdline string, ucod
|
|||||||
// NewWriter creates a writer that will output an initrd stream
|
// NewWriter creates a writer that will output an initrd stream
|
||||||
func NewWriter(w io.Writer) *Writer {
|
func NewWriter(w io.Writer) *Writer {
|
||||||
initrd := new(Writer)
|
initrd := new(Writer)
|
||||||
initrd.pw = pad4.NewWriter(w)
|
initrd.gw = gzip.NewWriter(w)
|
||||||
initrd.gw = gzip.NewWriter(initrd.pw)
|
|
||||||
initrd.cw = cpio.NewWriter(initrd.gw)
|
initrd.cw = cpio.NewWriter(initrd.gw)
|
||||||
|
|
||||||
return initrd
|
return initrd
|
||||||
@ -157,15 +154,11 @@ func (w *Writer) Write(b []byte) (n int, e error) {
|
|||||||
func (w *Writer) Close() error {
|
func (w *Writer) Close() error {
|
||||||
err1 := w.cw.Close()
|
err1 := w.cw.Close()
|
||||||
err2 := w.gw.Close()
|
err2 := w.gw.Close()
|
||||||
err3 := w.pw.Close()
|
|
||||||
if err1 != nil {
|
if err1 != nil {
|
||||||
return err1
|
return err1
|
||||||
}
|
}
|
||||||
if err2 != nil {
|
if err2 != nil {
|
||||||
return err2
|
return err2
|
||||||
}
|
}
|
||||||
if err3 != nil {
|
|
||||||
return err3
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -1,46 +0,0 @@
|
|||||||
package pad4
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"io"
|
|
||||||
)
|
|
||||||
|
|
||||||
// A Writer is an io.WriteCloser. Writes are padded with zeros to 4 byte boundary
|
|
||||||
type Writer struct {
|
|
||||||
w io.Writer
|
|
||||||
count int
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write writes output
|
|
||||||
func (pad *Writer) Write(p []byte) (int, error) {
|
|
||||||
n, err := pad.w.Write(p)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
pad.count += n
|
|
||||||
return n, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close adds the padding
|
|
||||||
func (pad *Writer) Close() error {
|
|
||||||
mod4 := pad.count & 3
|
|
||||||
if mod4 == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
zero := make([]byte, 4-mod4)
|
|
||||||
buf := bytes.NewBuffer(zero)
|
|
||||||
n, err := io.Copy(pad.w, buf)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
pad.count += int(n)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewWriter provides a new io.WriteCloser that zero pads the
|
|
||||||
// output to a multiple of four bytes
|
|
||||||
func NewWriter(w io.Writer) *Writer {
|
|
||||||
pad := new(Writer)
|
|
||||||
pad.w = w
|
|
||||||
return pad
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user