github.com/linuxboot/fiano@v1.2.0/pkg/cbfs/empty.go (about)

     1  // Copyright 2018-2021 the LinuxBoot 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 cbfs
     6  
     7  import (
     8  	"io"
     9  	"log"
    10  )
    11  
    12  func init() {
    13  	if err := RegisterFileReader(&SegReader{Type: TypeDeleted, Name: "CBFSEmpty", New: NewEmptyRecord}); err != nil {
    14  		log.Fatal(err)
    15  	}
    16  	if err := RegisterFileReader(&SegReader{Type: TypeDeleted2, Name: "CBFSEmpty", New: NewEmptyRecord}); err != nil {
    17  		log.Fatal(err)
    18  	}
    19  }
    20  
    21  func NewEmptyRecord(f *File) (ReadWriter, error) {
    22  	r := &EmptyRecord{File: *f}
    23  	Debug("Got header %v", r.String())
    24  	r.Type = TypeDeleted2
    25  	r.Attr = make([]byte, 16)
    26  	r.FData = ffbyte(f.Size)
    27  	return r, nil
    28  }
    29  
    30  func (r *EmptyRecord) Read(in io.ReadSeeker) error {
    31  	return nil
    32  }
    33  
    34  func (r *EmptyRecord) String() string {
    35  	return recString("(empty)", r.RecordStart, r.Type.String(), r.Size, "none")
    36  }
    37  
    38  func (r *EmptyRecord) Write(w io.Writer) error {
    39  	return Write(w, r.FData)
    40  }
    41  
    42  func (r *EmptyRecord) GetFile() *File {
    43  	return &r.File
    44  }