...

Source file src/github.com/Microsoft/hcsshim/cmd/tar2ext4/tar2ext4.go

Documentation: github.com/Microsoft/hcsshim/cmd/tar2ext4

     1  package main
     2  
     3  import (
     4  	"flag"
     5  	"fmt"
     6  	"io"
     7  	"os"
     8  
     9  	"github.com/Microsoft/hcsshim/ext4/tar2ext4"
    10  )
    11  
    12  var (
    13  	input      = flag.String("i", "", "input file")
    14  	output     = flag.String("o", "", "output file")
    15  	overlay    = flag.Bool("overlay", false, "produce overlayfs-compatible layer image")
    16  	vhd        = flag.Bool("vhd", false, "add a VHD footer to the end of the image")
    17  	inlineData = flag.Bool("inline", false, "write small file data into the inode; not compatible with DAX")
    18  )
    19  
    20  func main() {
    21  	flag.Parse()
    22  	if flag.NArg() != 0 || len(*output) == 0 {
    23  		flag.Usage()
    24  		os.Exit(1)
    25  	}
    26  
    27  	err := func() (err error) {
    28  		in := os.Stdin
    29  		if *input != "" {
    30  			in, err = os.Open(*input)
    31  			if err != nil {
    32  				return err
    33  			}
    34  		}
    35  		out, err := os.Create(*output)
    36  		if err != nil {
    37  			return err
    38  		}
    39  
    40  		var opts []tar2ext4.Option
    41  		if *overlay {
    42  			opts = append(opts, tar2ext4.ConvertWhiteout)
    43  		}
    44  		if *vhd {
    45  			opts = append(opts, tar2ext4.AppendVhdFooter)
    46  		}
    47  		if *inlineData {
    48  			opts = append(opts, tar2ext4.InlineData)
    49  		}
    50  		err = tar2ext4.Convert(in, out, opts...)
    51  		if err != nil {
    52  			return err
    53  		}
    54  
    55  		// Exhaust the tar stream.
    56  		_, _ = io.Copy(io.Discard, in)
    57  		return nil
    58  	}()
    59  	if err != nil {
    60  		fmt.Fprintln(os.Stderr, err)
    61  		os.Exit(1)
    62  	}
    63  }
    64  

View as plain text