github.com/jlowellwofford/u-root@v1.0.0/pkg/cpio/newc_test.go (about)

     1  // Copyright 2012 the u-root 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 cpio
     6  
     7  import (
     8  	"bytes"
     9  	"io"
    10  	"io/ioutil"
    11  	"reflect"
    12  	"syscall"
    13  	"testing"
    14  
    15  	"github.com/u-root/u-root/pkg/uio"
    16  )
    17  
    18  func TestSimple(t *testing.T) {
    19  	r := Newc.Reader(bytes.NewReader(testCPIO))
    20  	files, err := ReadAllRecords(r)
    21  	if err != nil {
    22  		t.Fatal(err)
    23  	}
    24  
    25  	for i, f := range files {
    26  		if f.String() != testResult[i] {
    27  			t.Errorf("Value %d: got \n%s, want \n%s", i, f.String(), testResult[i])
    28  		}
    29  		t.Logf("Value %d: got \n%s, want \n%s", i, f.String(), testResult[i])
    30  	}
    31  }
    32  
    33  func TestWriteRead(t *testing.T) {
    34  	contents := []byte("LANAAAAAAAAAA")
    35  	rec := StaticRecord(contents, Info{
    36  		Ino:      1,
    37  		Mode:     syscall.S_IFREG | 2,
    38  		UID:      3,
    39  		GID:      4,
    40  		NLink:    5,
    41  		MTime:    6,
    42  		FileSize: 7,
    43  		Major:    8,
    44  		Minor:    9,
    45  		Rmajor:   10,
    46  		Rminor:   11,
    47  		Name:     "foobar",
    48  	})
    49  
    50  	buf := &bytes.Buffer{}
    51  	w := Newc.Writer(buf)
    52  	if err := w.WriteRecord(rec); err != nil {
    53  		t.Errorf("Could not write record %q: %v", rec.Name, err)
    54  	}
    55  
    56  	if err := WriteTrailer(w); err != nil {
    57  		t.Errorf("Could not write trailer: %v", err)
    58  	}
    59  
    60  	r := Newc.Reader(bytes.NewReader(buf.Bytes()))
    61  	rec2, err := r.ReadRecord()
    62  	if err != nil {
    63  		t.Errorf("Could not read record: %v", err)
    64  	}
    65  
    66  	if rec2.Info != rec.Info {
    67  		t.Errorf("Records not equal:\n%#v\n%#v", rec.Info, rec2.Info)
    68  	}
    69  
    70  	contents2, err := ioutil.ReadAll(uio.Reader(rec2))
    71  	if err != nil {
    72  		t.Errorf("Could not read %q: %v", rec2.Name, err)
    73  	}
    74  
    75  	if bytes.Compare(contents2, contents) != 0 {
    76  		t.Errorf("Read(%q) = %s, want %s", rec2.Name, string(contents2), contents)
    77  	}
    78  }
    79  
    80  func TestReadWrite(t *testing.T) {
    81  	r := Newc.Reader(bytes.NewReader(testCPIO))
    82  	files, err := ReadAllRecords(r)
    83  	if err != nil {
    84  		t.Fatalf("Reading testCPIO reader: %v", err)
    85  	}
    86  
    87  	buf := &bytes.Buffer{}
    88  	w := Newc.Writer(buf)
    89  	if err := WriteRecords(w, files); err != nil {
    90  		t.Fatalf("WriteRecords: %v", err)
    91  	}
    92  
    93  	if err := WriteTrailer(w); err != nil {
    94  		t.Fatalf("WriteTrailer: %v", err)
    95  	}
    96  
    97  	r = Newc.Reader(bytes.NewReader(testCPIO))
    98  	files, err = ReadAllRecords(r)
    99  	if err != nil {
   100  		t.Fatalf("Reading testCPIO reader: %v", err)
   101  	}
   102  
   103  	r = Newc.Reader(bytes.NewReader(buf.Bytes()))
   104  	filesReadBack, err := ReadAllRecords(r)
   105  	if err != nil {
   106  		t.Fatalf("TestReadWrite: reading generated data: %v", err)
   107  	}
   108  
   109  	// Now check a few things: arrays should be same length, Headers should match,
   110  	// names should be the same, and data should be the same. If this all works,
   111  	// it means we read in serialized data, wrote it out, read it in, and the
   112  	// structs all matched.
   113  	if len(files) != len(filesReadBack) {
   114  		t.Fatalf("[]file len from testCPIO %v and generated %v are not the same and should be", len(files), len(filesReadBack))
   115  	}
   116  	for i := range files {
   117  		f1 := files[i]
   118  		f2 := filesReadBack[i]
   119  
   120  		if f1.Info != f2.Info {
   121  			t.Errorf("index %d: testCPIO Info\n%v\ngenerated Info\n%v\n", i, f1.Info, f2.Info)
   122  		}
   123  
   124  		contents1, err := ioutil.ReadAll(uio.Reader(f1))
   125  		if err != nil {
   126  			t.Errorf("index %d(%q): can't read from the source: %v", i, f1.Name, err)
   127  		}
   128  		contents2, err := ioutil.ReadAll(uio.Reader(f2))
   129  		if err != nil {
   130  			t.Errorf("index %d(%q): can't read from the dest: %v", i, f2.Name, err)
   131  		}
   132  		if !bytes.Equal(contents1, contents2) {
   133  			t.Errorf("index %d content: file 1 (%q) is %v, file 2 (%q) wanted %v", i, f1.Name, contents1, f2.Name, contents2)
   134  		}
   135  	}
   136  }
   137  
   138  func TestBad(t *testing.T) {
   139  	r := Newc.Reader(bytes.NewReader(badCPIO))
   140  	if _, err := r.ReadRecord(); err != io.EOF {
   141  		t.Errorf("ReadRecord(badCPIO) got %v, want %v", err, io.EOF)
   142  	}
   143  
   144  	r = Newc.Reader(bytes.NewReader(badMagicCPIO))
   145  	if _, err := r.ReadRecord(); err == nil {
   146  		t.Errorf("Wanted bad magic err, got nil")
   147  	}
   148  }
   149  
   150  /*
   151  drwxrwxr-x   9 rminnich rminnich        0 Jan 22 22:18 .
   152  drwxr-xr-x   2 root     root            0 Jan 22 22:18 etc
   153  -rw-r--r--   1 root     root          118 Jan 22 22:18 etc/localtime
   154  -rw-r--r--   1 root     root           81 Jan 22 22:18 etc/resolv.conf
   155  drwxr-xr-x   2 root     root            0 Jan 22 22:18 lib64
   156  drwxr-xr-x   2 root     root            0 Jan 22 22:18 tcz
   157  drwxr-xr-x   2 root     root            0 Jan 22 22:18 bin
   158  drwxr-xr-x   2 root     root            0 Jan 22 22:18 tmp
   159  drwxr-xr-x   2 root     root            0 Jan 22 22:18 dev
   160  crw-r--r--   1 root     root       5,   1 Jan 22 22:18 dev/console
   161  crw-r--r--   1 root     root       4,  64 Jan 22 22:18 dev/ttyS0
   162  brw-rw----   1 root     root       7,   2 Jan 22 22:18 dev/loop2
   163  crw-------   1 root     root      10, 237 Jan 22 22:18 dev/loop-control
   164  brw-rw----   1 root     root       7,   7 Jan 22 22:18 dev/loop7
   165  brw-rw----   1 root     root       7,   6 Jan 22 22:18 dev/loop6
   166  brw-rw----   1 root     root       7,   4 Jan 22 22:18 dev/loop4
   167  brw-rw----   1 root     root       7,   1 Jan 22 22:18 dev/loop1
   168  brw-rw----   1 root     root       7,   5 Jan 22 22:18 dev/loop5
   169  crw-r--r--   1 root     root       1,   3 Jan 22 22:18 dev/null
   170  brw-rw----   1 root     root       7,   0 Jan 22 22:18 dev/loop0
   171  brw-rw----   1 root     root       7,   3 Jan 22 22:18 dev/loop3
   172  drwxr-xr-x   3 root     root            0 Jan 22 22:18 usr
   173  drwxr-xr-x   2 root     root            0 Jan 22 22:18 usr/lib
   174  */
   175  var (
   176  	badCPIO      = []byte{}
   177  	badMagicCPIO = []byte{0, 0, 0, 0, 0, 0}
   178  	testCPIO     = []byte{
   179  		0x30, 0x37, 0x30, 0x37, 0x30, 0x31, 0x30, 0x30, 0x33, 0x30, 0x45, 0x33,
   180  		0x43, 0x31, 0x30, 0x30, 0x30, 0x30, 0x34, 0x31, 0x46, 0x44, 0x30, 0x30,
   181  		0x30, 0x30, 0x30, 0x33, 0x45, 0x38, 0x30, 0x30, 0x30, 0x30, 0x30, 0x33,
   182  		0x45, 0x38, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x39, 0x35, 0x38,
   183  		0x38, 0x35, 0x41, 0x30, 0x34, 0x45, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   184  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x46, 0x43, 0x30, 0x30,
   185  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   186  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   187  		0x30, 0x30, 0x30, 0x30, 0x30, 0x32, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   188  		0x30, 0x30, 0x2e, 0x00, 0x30, 0x37, 0x30, 0x37, 0x30, 0x31, 0x30, 0x30,
   189  		0x33, 0x30, 0x45, 0x33, 0x43, 0x35, 0x30, 0x30, 0x30, 0x30, 0x34, 0x31,
   190  		0x45, 0x44, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   191  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   192  		0x30, 0x32, 0x35, 0x38, 0x38, 0x35, 0x41, 0x30, 0x34, 0x41, 0x30, 0x30,
   193  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   194  		0x46, 0x43, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   195  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   196  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x34, 0x30, 0x30,
   197  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x65, 0x74, 0x63, 0x00, 0x00, 0x00,
   198  		0x30, 0x37, 0x30, 0x37, 0x30, 0x31, 0x30, 0x30, 0x33, 0x30, 0x43, 0x32,
   199  		0x30, 0x43, 0x30, 0x30, 0x30, 0x30, 0x38, 0x31, 0x41, 0x34, 0x30, 0x30,
   200  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   201  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x35, 0x38,
   202  		0x38, 0x35, 0x41, 0x30, 0x34, 0x41, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   203  		0x37, 0x36, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x46, 0x43, 0x30, 0x30,
   204  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   205  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   206  		0x30, 0x30, 0x30, 0x30, 0x30, 0x45, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   207  		0x30, 0x30, 0x65, 0x74, 0x63, 0x2f, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x74,
   208  		0x69, 0x6d, 0x65, 0x00, 0x54, 0x5a, 0x69, 0x66, 0x32, 0x00, 0x00, 0x00,
   209  		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   210  		0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
   211  		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04,
   212  		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0x54, 0x43, 0x00, 0x00, 0x00,
   213  		0x54, 0x5a, 0x69, 0x66, 0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   214  		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
   215  		0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   216  		0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00,
   217  		0x00, 0x00, 0x55, 0x54, 0x43, 0x00, 0x00, 0x00, 0x0a, 0x55, 0x54, 0x43,
   218  		0x30, 0x0a, 0x00, 0x00, 0x30, 0x37, 0x30, 0x37, 0x30, 0x31, 0x30, 0x30,
   219  		0x33, 0x30, 0x37, 0x42, 0x30, 0x44, 0x30, 0x30, 0x30, 0x30, 0x38, 0x31,
   220  		0x41, 0x34, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   221  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   222  		0x30, 0x31, 0x35, 0x38, 0x38, 0x35, 0x41, 0x30, 0x34, 0x41, 0x30, 0x30,
   223  		0x30, 0x30, 0x30, 0x30, 0x35, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   224  		0x46, 0x43, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   225  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   226  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x30, 0x30, 0x30,
   227  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x65, 0x74, 0x63, 0x2f, 0x72, 0x65,
   228  		0x73, 0x6f, 0x6c, 0x76, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x00, 0x00, 0x00,
   229  		0x6e, 0x61, 0x6d, 0x65, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x20, 0x31,
   230  		0x39, 0x32, 0x2e, 0x31, 0x36, 0x38, 0x2e, 0x31, 0x2e, 0x31, 0x30, 0x0a,
   231  		0x73, 0x65, 0x61, 0x72, 0x63, 0x68, 0x20, 0x48, 0x6f, 0x6d, 0x65, 0x2e,
   232  		0x0a, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x73, 0x69, 0x6e,
   233  		0x67, 0x6c, 0x65, 0x2d, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x20,
   234  		0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x3a, 0x31, 0x20, 0x61, 0x74,
   235  		0x74, 0x65, 0x6d, 0x70, 0x74, 0x73, 0x3a, 0x35, 0x0a, 0x00, 0x00, 0x00,
   236  		0x30, 0x37, 0x30, 0x37, 0x30, 0x31, 0x30, 0x30, 0x33, 0x30, 0x45, 0x33,
   237  		0x43, 0x42, 0x30, 0x30, 0x30, 0x30, 0x34, 0x31, 0x45, 0x44, 0x30, 0x30,
   238  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   239  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x32, 0x35, 0x38,
   240  		0x38, 0x35, 0x41, 0x30, 0x34, 0x41, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   241  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x46, 0x43, 0x30, 0x30,
   242  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   243  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   244  		0x30, 0x30, 0x30, 0x30, 0x30, 0x36, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   245  		0x30, 0x30, 0x6c, 0x69, 0x62, 0x36, 0x34, 0x00, 0x30, 0x37, 0x30, 0x37,
   246  		0x30, 0x31, 0x30, 0x30, 0x33, 0x30, 0x45, 0x33, 0x43, 0x34, 0x30, 0x30,
   247  		0x30, 0x30, 0x34, 0x31, 0x45, 0x44, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   248  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   249  		0x30, 0x30, 0x30, 0x30, 0x30, 0x32, 0x35, 0x38, 0x38, 0x35, 0x41, 0x30,
   250  		0x34, 0x41, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   251  		0x30, 0x30, 0x30, 0x30, 0x46, 0x43, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   252  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   253  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   254  		0x30, 0x34, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x74, 0x63,
   255  		0x7a, 0x00, 0x00, 0x00, 0x30, 0x37, 0x30, 0x37, 0x30, 0x31, 0x30, 0x30,
   256  		0x33, 0x30, 0x45, 0x33, 0x43, 0x43, 0x30, 0x30, 0x30, 0x30, 0x34, 0x31,
   257  		0x45, 0x44, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   258  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   259  		0x30, 0x32, 0x35, 0x38, 0x38, 0x35, 0x41, 0x30, 0x34, 0x41, 0x30, 0x30,
   260  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   261  		0x46, 0x43, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   262  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   263  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x34, 0x30, 0x30,
   264  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x62, 0x69, 0x6e, 0x00, 0x00, 0x00,
   265  		0x30, 0x37, 0x30, 0x37, 0x30, 0x31, 0x30, 0x30, 0x33, 0x30, 0x45, 0x33,
   266  		0x43, 0x44, 0x30, 0x30, 0x30, 0x30, 0x34, 0x31, 0x45, 0x44, 0x30, 0x30,
   267  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   268  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x32, 0x35, 0x38,
   269  		0x38, 0x35, 0x41, 0x30, 0x34, 0x41, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   270  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x46, 0x43, 0x30, 0x30,
   271  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   272  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   273  		0x30, 0x30, 0x30, 0x30, 0x30, 0x34, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   274  		0x30, 0x30, 0x74, 0x6d, 0x70, 0x00, 0x00, 0x00, 0x30, 0x37, 0x30, 0x37,
   275  		0x30, 0x31, 0x30, 0x30, 0x33, 0x30, 0x45, 0x33, 0x43, 0x36, 0x30, 0x30,
   276  		0x30, 0x30, 0x34, 0x31, 0x45, 0x44, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   277  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   278  		0x30, 0x30, 0x30, 0x30, 0x30, 0x32, 0x35, 0x38, 0x38, 0x35, 0x41, 0x30,
   279  		0x34, 0x41, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   280  		0x30, 0x30, 0x30, 0x30, 0x46, 0x43, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   281  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   282  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   283  		0x30, 0x34, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x64, 0x65,
   284  		0x76, 0x00, 0x00, 0x00, 0x30, 0x37, 0x30, 0x37, 0x30, 0x31, 0x30, 0x30,
   285  		0x33, 0x30, 0x43, 0x43, 0x32, 0x31, 0x30, 0x30, 0x30, 0x30, 0x32, 0x31,
   286  		0x41, 0x34, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   287  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   288  		0x30, 0x31, 0x35, 0x38, 0x38, 0x35, 0x41, 0x30, 0x34, 0x41, 0x30, 0x30,
   289  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   290  		0x46, 0x43, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   291  		0x30, 0x30, 0x30, 0x30, 0x30, 0x35, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   292  		0x30, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x43, 0x30, 0x30,
   293  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x64, 0x65, 0x76, 0x2f, 0x63, 0x6f,
   294  		0x6e, 0x73, 0x6f, 0x6c, 0x65, 0x00, 0x00, 0x00, 0x30, 0x37, 0x30, 0x37,
   295  		0x30, 0x31, 0x30, 0x30, 0x33, 0x30, 0x43, 0x43, 0x32, 0x32, 0x30, 0x30,
   296  		0x30, 0x30, 0x32, 0x31, 0x41, 0x34, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   297  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   298  		0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x35, 0x38, 0x38, 0x35, 0x41, 0x30,
   299  		0x34, 0x41, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   300  		0x30, 0x30, 0x30, 0x30, 0x46, 0x43, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   301  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x34, 0x30, 0x30,
   302  		0x30, 0x30, 0x30, 0x30, 0x34, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   303  		0x30, 0x41, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x64, 0x65,
   304  		0x76, 0x2f, 0x74, 0x74, 0x79, 0x53, 0x30, 0x00, 0x30, 0x37, 0x30, 0x37,
   305  		0x30, 0x31, 0x30, 0x30, 0x33, 0x30, 0x43, 0x43, 0x32, 0x33, 0x30, 0x30,
   306  		0x30, 0x30, 0x36, 0x31, 0x42, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   307  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   308  		0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x35, 0x38, 0x38, 0x35, 0x41, 0x30,
   309  		0x34, 0x41, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   310  		0x30, 0x30, 0x30, 0x30, 0x46, 0x43, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   311  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x37, 0x30, 0x30,
   312  		0x30, 0x30, 0x30, 0x30, 0x30, 0x32, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   313  		0x30, 0x41, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x64, 0x65,
   314  		0x76, 0x2f, 0x6c, 0x6f, 0x6f, 0x70, 0x32, 0x00, 0x30, 0x37, 0x30, 0x37,
   315  		0x30, 0x31, 0x30, 0x30, 0x33, 0x30, 0x43, 0x43, 0x31, 0x46, 0x30, 0x30,
   316  		0x30, 0x30, 0x32, 0x31, 0x38, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   317  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   318  		0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x35, 0x38, 0x38, 0x35, 0x41, 0x30,
   319  		0x34, 0x41, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   320  		0x30, 0x30, 0x30, 0x30, 0x46, 0x43, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   321  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x41, 0x30, 0x30,
   322  		0x30, 0x30, 0x30, 0x30, 0x45, 0x44, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   323  		0x31, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x64, 0x65,
   324  		0x76, 0x2f, 0x6c, 0x6f, 0x6f, 0x70, 0x2d, 0x63, 0x6f, 0x6e, 0x74, 0x72,
   325  		0x6f, 0x6c, 0x00, 0x00, 0x30, 0x37, 0x30, 0x37, 0x30, 0x31, 0x30, 0x30,
   326  		0x33, 0x30, 0x43, 0x43, 0x32, 0x30, 0x30, 0x30, 0x30, 0x30, 0x36, 0x31,
   327  		0x42, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   328  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   329  		0x30, 0x31, 0x35, 0x38, 0x38, 0x35, 0x41, 0x30, 0x34, 0x41, 0x30, 0x30,
   330  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   331  		0x46, 0x43, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   332  		0x30, 0x30, 0x30, 0x30, 0x30, 0x37, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   333  		0x30, 0x37, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x41, 0x30, 0x30,
   334  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x64, 0x65, 0x76, 0x2f, 0x6c, 0x6f,
   335  		0x6f, 0x70, 0x37, 0x00, 0x30, 0x37, 0x30, 0x37, 0x30, 0x31, 0x30, 0x30,
   336  		0x33, 0x30, 0x43, 0x43, 0x31, 0x37, 0x30, 0x30, 0x30, 0x30, 0x36, 0x31,
   337  		0x42, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   338  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   339  		0x30, 0x31, 0x35, 0x38, 0x38, 0x35, 0x41, 0x30, 0x34, 0x41, 0x30, 0x30,
   340  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   341  		0x46, 0x43, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   342  		0x30, 0x30, 0x30, 0x30, 0x30, 0x37, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   343  		0x30, 0x36, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x41, 0x30, 0x30,
   344  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x64, 0x65, 0x76, 0x2f, 0x6c, 0x6f,
   345  		0x6f, 0x70, 0x36, 0x00, 0x30, 0x37, 0x30, 0x37, 0x30, 0x31, 0x30, 0x30,
   346  		0x33, 0x30, 0x43, 0x43, 0x31, 0x42, 0x30, 0x30, 0x30, 0x30, 0x36, 0x31,
   347  		0x42, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   348  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   349  		0x30, 0x31, 0x35, 0x38, 0x38, 0x35, 0x41, 0x30, 0x34, 0x41, 0x30, 0x30,
   350  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   351  		0x46, 0x43, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   352  		0x30, 0x30, 0x30, 0x30, 0x30, 0x37, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   353  		0x30, 0x34, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x41, 0x30, 0x30,
   354  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x64, 0x65, 0x76, 0x2f, 0x6c, 0x6f,
   355  		0x6f, 0x70, 0x34, 0x00, 0x30, 0x37, 0x30, 0x37, 0x30, 0x31, 0x30, 0x30,
   356  		0x33, 0x30, 0x43, 0x43, 0x31, 0x44, 0x30, 0x30, 0x30, 0x30, 0x36, 0x31,
   357  		0x42, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   358  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   359  		0x30, 0x31, 0x35, 0x38, 0x38, 0x35, 0x41, 0x30, 0x34, 0x41, 0x30, 0x30,
   360  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   361  		0x46, 0x43, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   362  		0x30, 0x30, 0x30, 0x30, 0x30, 0x37, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   363  		0x30, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x41, 0x30, 0x30,
   364  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x64, 0x65, 0x76, 0x2f, 0x6c, 0x6f,
   365  		0x6f, 0x70, 0x31, 0x00, 0x30, 0x37, 0x30, 0x37, 0x30, 0x31, 0x30, 0x30,
   366  		0x33, 0x30, 0x43, 0x43, 0x31, 0x45, 0x30, 0x30, 0x30, 0x30, 0x36, 0x31,
   367  		0x42, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   368  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   369  		0x30, 0x31, 0x35, 0x38, 0x38, 0x35, 0x41, 0x30, 0x34, 0x41, 0x30, 0x30,
   370  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   371  		0x46, 0x43, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   372  		0x30, 0x30, 0x30, 0x30, 0x30, 0x37, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   373  		0x30, 0x35, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x41, 0x30, 0x30,
   374  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x64, 0x65, 0x76, 0x2f, 0x6c, 0x6f,
   375  		0x6f, 0x70, 0x35, 0x00, 0x30, 0x37, 0x30, 0x37, 0x30, 0x31, 0x30, 0x30,
   376  		0x33, 0x30, 0x43, 0x43, 0x32, 0x34, 0x30, 0x30, 0x30, 0x30, 0x32, 0x31,
   377  		0x41, 0x34, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   378  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   379  		0x30, 0x31, 0x35, 0x38, 0x38, 0x35, 0x41, 0x30, 0x34, 0x41, 0x30, 0x30,
   380  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   381  		0x46, 0x43, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   382  		0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   383  		0x30, 0x33, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x39, 0x30, 0x30,
   384  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x64, 0x65, 0x76, 0x2f, 0x6e, 0x75,
   385  		0x6c, 0x6c, 0x00, 0x00, 0x30, 0x37, 0x30, 0x37, 0x30, 0x31, 0x30, 0x30,
   386  		0x33, 0x30, 0x43, 0x43, 0x31, 0x38, 0x30, 0x30, 0x30, 0x30, 0x36, 0x31,
   387  		0x42, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   388  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   389  		0x30, 0x31, 0x35, 0x38, 0x38, 0x35, 0x41, 0x30, 0x34, 0x41, 0x30, 0x30,
   390  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   391  		0x46, 0x43, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   392  		0x30, 0x30, 0x30, 0x30, 0x30, 0x37, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   393  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x41, 0x30, 0x30,
   394  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x64, 0x65, 0x76, 0x2f, 0x6c, 0x6f,
   395  		0x6f, 0x70, 0x30, 0x00, 0x30, 0x37, 0x30, 0x37, 0x30, 0x31, 0x30, 0x30,
   396  		0x33, 0x30, 0x43, 0x43, 0x31, 0x43, 0x30, 0x30, 0x30, 0x30, 0x36, 0x31,
   397  		0x42, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   398  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   399  		0x30, 0x31, 0x35, 0x38, 0x38, 0x35, 0x41, 0x30, 0x34, 0x41, 0x30, 0x30,
   400  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   401  		0x46, 0x43, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   402  		0x30, 0x30, 0x30, 0x30, 0x30, 0x37, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   403  		0x30, 0x33, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x41, 0x30, 0x30,
   404  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x64, 0x65, 0x76, 0x2f, 0x6c, 0x6f,
   405  		0x6f, 0x70, 0x33, 0x00, 0x30, 0x37, 0x30, 0x37, 0x30, 0x31, 0x30, 0x30,
   406  		0x33, 0x30, 0x45, 0x33, 0x43, 0x39, 0x30, 0x30, 0x30, 0x30, 0x34, 0x31,
   407  		0x45, 0x44, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   408  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   409  		0x30, 0x33, 0x35, 0x38, 0x38, 0x35, 0x41, 0x30, 0x34, 0x41, 0x30, 0x30,
   410  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   411  		0x46, 0x43, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   412  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   413  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x34, 0x30, 0x30,
   414  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x75, 0x73, 0x72, 0x00, 0x00, 0x00,
   415  		0x30, 0x37, 0x30, 0x37, 0x30, 0x31, 0x30, 0x30, 0x33, 0x30, 0x45, 0x33,
   416  		0x43, 0x41, 0x30, 0x30, 0x30, 0x30, 0x34, 0x31, 0x45, 0x44, 0x30, 0x30,
   417  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   418  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x32, 0x35, 0x38,
   419  		0x38, 0x35, 0x41, 0x30, 0x34, 0x41, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   420  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x46, 0x43, 0x30, 0x30,
   421  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   422  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   423  		0x30, 0x30, 0x30, 0x30, 0x30, 0x38, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   424  		0x30, 0x30, 0x75, 0x73, 0x72, 0x2f, 0x6c, 0x69, 0x62, 0x00, 0x00, 0x00,
   425  		0x30, 0x37, 0x30, 0x37, 0x30, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   426  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   427  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   428  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x30, 0x30,
   429  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   430  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   431  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   432  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   433  		0x30, 0x30, 0x30, 0x30, 0x30, 0x42, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   434  		0x30, 0x30, 0x54, 0x52, 0x41, 0x49, 0x4c, 0x45, 0x52, 0x21, 0x21, 0x21,
   435  		0, 0, 0, 0,
   436  	}
   437  
   438  	testResult = []string{
   439  		".: Ino 3204033 Mode 040775 UID 1000 GID 1000 NLink 9 MTime 2017-01-23 06:18:54 +0000 UTC FileSize 0 Major 252 Minor 0 Rmajor 0 Rminor 0",
   440  		"etc: Ino 3204037 Mode 040755 UID 0 GID 0 NLink 2 MTime 2017-01-23 06:18:50 +0000 UTC FileSize 0 Major 252 Minor 0 Rmajor 0 Rminor 0",
   441  		"etc/localtime: Ino 3195404 Mode 0100644 UID 0 GID 0 NLink 1 MTime 2017-01-23 06:18:50 +0000 UTC FileSize 118 Major 252 Minor 0 Rmajor 0 Rminor 0",
   442  		"etc/resolv.conf: Ino 3177229 Mode 0100644 UID 0 GID 0 NLink 1 MTime 2017-01-23 06:18:50 +0000 UTC FileSize 81 Major 252 Minor 0 Rmajor 0 Rminor 0",
   443  		"lib64: Ino 3204043 Mode 040755 UID 0 GID 0 NLink 2 MTime 2017-01-23 06:18:50 +0000 UTC FileSize 0 Major 252 Minor 0 Rmajor 0 Rminor 0",
   444  		"tcz: Ino 3204036 Mode 040755 UID 0 GID 0 NLink 2 MTime 2017-01-23 06:18:50 +0000 UTC FileSize 0 Major 252 Minor 0 Rmajor 0 Rminor 0",
   445  		"bin: Ino 3204044 Mode 040755 UID 0 GID 0 NLink 2 MTime 2017-01-23 06:18:50 +0000 UTC FileSize 0 Major 252 Minor 0 Rmajor 0 Rminor 0",
   446  		"tmp: Ino 3204045 Mode 040755 UID 0 GID 0 NLink 2 MTime 2017-01-23 06:18:50 +0000 UTC FileSize 0 Major 252 Minor 0 Rmajor 0 Rminor 0",
   447  		"dev: Ino 3204038 Mode 040755 UID 0 GID 0 NLink 2 MTime 2017-01-23 06:18:50 +0000 UTC FileSize 0 Major 252 Minor 0 Rmajor 0 Rminor 0",
   448  		"dev/console: Ino 3197985 Mode 020644 UID 0 GID 0 NLink 1 MTime 2017-01-23 06:18:50 +0000 UTC FileSize 0 Major 252 Minor 0 Rmajor 5 Rminor 1",
   449  		"dev/ttyS0: Ino 3197986 Mode 020644 UID 0 GID 0 NLink 1 MTime 2017-01-23 06:18:50 +0000 UTC FileSize 0 Major 252 Minor 0 Rmajor 4 Rminor 64",
   450  		"dev/loop2: Ino 3197987 Mode 060660 UID 0 GID 0 NLink 1 MTime 2017-01-23 06:18:50 +0000 UTC FileSize 0 Major 252 Minor 0 Rmajor 7 Rminor 2",
   451  		"dev/loop-control: Ino 3197983 Mode 020600 UID 0 GID 0 NLink 1 MTime 2017-01-23 06:18:50 +0000 UTC FileSize 0 Major 252 Minor 0 Rmajor 10 Rminor 237",
   452  		"dev/loop7: Ino 3197984 Mode 060660 UID 0 GID 0 NLink 1 MTime 2017-01-23 06:18:50 +0000 UTC FileSize 0 Major 252 Minor 0 Rmajor 7 Rminor 7",
   453  		"dev/loop6: Ino 3197975 Mode 060660 UID 0 GID 0 NLink 1 MTime 2017-01-23 06:18:50 +0000 UTC FileSize 0 Major 252 Minor 0 Rmajor 7 Rminor 6",
   454  		"dev/loop4: Ino 3197979 Mode 060660 UID 0 GID 0 NLink 1 MTime 2017-01-23 06:18:50 +0000 UTC FileSize 0 Major 252 Minor 0 Rmajor 7 Rminor 4",
   455  		"dev/loop1: Ino 3197981 Mode 060660 UID 0 GID 0 NLink 1 MTime 2017-01-23 06:18:50 +0000 UTC FileSize 0 Major 252 Minor 0 Rmajor 7 Rminor 1",
   456  		"dev/loop5: Ino 3197982 Mode 060660 UID 0 GID 0 NLink 1 MTime 2017-01-23 06:18:50 +0000 UTC FileSize 0 Major 252 Minor 0 Rmajor 7 Rminor 5",
   457  		"dev/null: Ino 3197988 Mode 020644 UID 0 GID 0 NLink 1 MTime 2017-01-23 06:18:50 +0000 UTC FileSize 0 Major 252 Minor 0 Rmajor 1 Rminor 3",
   458  		"dev/loop0: Ino 3197976 Mode 060660 UID 0 GID 0 NLink 1 MTime 2017-01-23 06:18:50 +0000 UTC FileSize 0 Major 252 Minor 0 Rmajor 7 Rminor 0",
   459  		"dev/loop3: Ino 3197980 Mode 060660 UID 0 GID 0 NLink 1 MTime 2017-01-23 06:18:50 +0000 UTC FileSize 0 Major 252 Minor 0 Rmajor 7 Rminor 3",
   460  		"usr: Ino 3204041 Mode 040755 UID 0 GID 0 NLink 3 MTime 2017-01-23 06:18:50 +0000 UTC FileSize 0 Major 252 Minor 0 Rmajor 0 Rminor 0",
   461  		"usr/lib: Ino 3204042 Mode 040755 UID 0 GID 0 NLink 2 MTime 2017-01-23 06:18:50 +0000 UTC FileSize 0 Major 252 Minor 0 Rmajor 0 Rminor 0",
   462  	}
   463  )
   464  
   465  // testReproducible verifies that we can produce reproducible cpio archives for newc format.
   466  func TestReproducible(t *testing.T) {
   467  	contents := []byte("LANAAAAAAAAAA")
   468  	rec := []Record{StaticRecord(contents, Info{
   469  		Ino:      1,
   470  		Mode:     syscall.S_IFREG | 2,
   471  		UID:      3,
   472  		GID:      4,
   473  		NLink:    5,
   474  		MTime:    6,
   475  		FileSize: 7,
   476  		Major:    8,
   477  		Minor:    9,
   478  		Rmajor:   10,
   479  		Rminor:   11,
   480  		Name:     "foobar",
   481  	}),
   482  	}
   483  
   484  	// First test that it fails unless we make it reproducible
   485  
   486  	b1 := &bytes.Buffer{}
   487  	w := Newc.Writer(b1)
   488  	if err := WriteRecords(w, rec); err != nil {
   489  		t.Errorf("Could not write record %q: %v", rec[0].Name, err)
   490  	}
   491  	rec[0].ReaderAt = bytes.NewReader(contents)
   492  	b2 := &bytes.Buffer{}
   493  	w = Newc.Writer(b2)
   494  	rec[0].MTime++
   495  	if err := WriteRecords(w, rec); err != nil {
   496  		t.Errorf("Could not write record %q: %v", rec[0].Name, err)
   497  	}
   498  
   499  	if reflect.DeepEqual(b1.Bytes()[:], b2.Bytes()[:]) {
   500  		t.Error("Reproducible: compared as same, wanted different")
   501  	}
   502  
   503  	// Second test that it works if we make it reproducible
   504  	// It does indeed fail without the second call.
   505  
   506  	b1 = &bytes.Buffer{}
   507  	w = Newc.Writer(b1)
   508  	rec[0].ReaderAt = bytes.NewReader([]byte(contents))
   509  	MakeAllReproducible(rec)
   510  	if err := WriteRecords(w, rec); err != nil {
   511  		t.Errorf("Could not write record %q: %v", rec[0].Name, err)
   512  	}
   513  
   514  	b2 = &bytes.Buffer{}
   515  	w = Newc.Writer(b2)
   516  	rec[0].MTime++
   517  	rec[0].ReaderAt = bytes.NewReader([]byte(contents))
   518  	MakeAllReproducible(rec)
   519  	if err := WriteRecords(w, rec); err != nil {
   520  		t.Errorf("Could not write record %q: %v", rec[0].Name, err)
   521  	}
   522  
   523  	if len(b1.Bytes()) != len(b2.Bytes()) {
   524  		t.Fatalf("Reproducible \n%v,\n%v: len is different, wanted same", b1.Bytes()[:], b2.Bytes()[:])
   525  	}
   526  	if !reflect.DeepEqual(b1.Bytes()[:], b2.Bytes()[:]) {
   527  		t.Error("Reproducible: compared different, wanted same")
   528  		for i := range b1.Bytes() {
   529  			a := b1.Bytes()[i]
   530  			b := b2.Bytes()[i]
   531  			if a != b {
   532  				t.Errorf("\tb1[%d] is %v, b2[%d] is %v", i, a, i, b)
   533  			}
   534  		}
   535  	}
   536  }