github.com/mvdan/u-root-coreutils@v0.0.0-20230122170626-c2eef2898555/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  	"log"
    11  	"os"
    12  	"path/filepath"
    13  	"reflect"
    14  	"syscall"
    15  	"testing"
    16  
    17  	"github.com/mvdan/u-root-coreutils/pkg/uio"
    18  )
    19  
    20  /*
    21  drwxrwxr-x   9 rminnich rminnich        0 Jan 22 22:18 .
    22  drwxr-xr-x   2 root     root            0 Jan 22 22:18 etc
    23  -rw-r--r--   1 root     root          118 Jan 22 22:18 etc/localtime
    24  -rw-r--r--   1 root     root           81 Jan 22 22:18 etc/resolv.conf
    25  drwxr-xr-x   2 root     root            0 Jan 22 22:18 lib64
    26  drwxr-xr-x   2 root     root            0 Jan 22 22:18 tcz
    27  drwxr-xr-x   2 root     root            0 Jan 22 22:18 bin
    28  drwxr-xr-x   2 root     root            0 Jan 22 22:18 tmp
    29  drwxr-xr-x   2 root     root            0 Jan 22 22:18 dev
    30  crw-r--r--   1 root     root       5,   1 Jan 22 22:18 dev/console
    31  crw-r--r--   1 root     root       4,  64 Jan 22 22:18 dev/ttyS0
    32  brw-rw----   1 root     root       7,   2 Jan 22 22:18 dev/loop2
    33  crw-------   1 root     root      10, 237 Jan 22 22:18 dev/loop-control
    34  brw-rw----   1 root     root       7,   7 Jan 22 22:18 dev/loop7
    35  brw-rw----   1 root     root       7,   6 Jan 22 22:18 dev/loop6
    36  brw-rw----   1 root     root       7,   4 Jan 22 22:18 dev/loop4
    37  brw-rw----   1 root     root       7,   1 Jan 22 22:18 dev/loop1
    38  brw-rw----   1 root     root       7,   5 Jan 22 22:18 dev/loop5
    39  crw-r--r--   1 root     root       1,   3 Jan 22 22:18 dev/null
    40  brw-rw----   1 root     root       7,   0 Jan 22 22:18 dev/loop0
    41  brw-rw----   1 root     root       7,   3 Jan 22 22:18 dev/loop3
    42  drwxr-xr-x   3 root     root            0 Jan 22 22:18 usr
    43  drwxr-xr-x   2 root     root            0 Jan 22 22:18 usr/lib
    44  */
    45  var (
    46  	badCPIO      = []byte{}
    47  	badMagicCPIO = []byte{0, 0, 0, 0, 0, 0}
    48  	testCPIO     = []byte{
    49  		0x30, 0x37, 0x30, 0x37, 0x30, 0x31, 0x30, 0x30, 0x33, 0x30, 0x45, 0x33,
    50  		0x43, 0x31, 0x30, 0x30, 0x30, 0x30, 0x34, 0x31, 0x46, 0x44, 0x30, 0x30,
    51  		0x30, 0x30, 0x30, 0x33, 0x45, 0x38, 0x30, 0x30, 0x30, 0x30, 0x30, 0x33,
    52  		0x45, 0x38, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x39, 0x35, 0x38,
    53  		0x38, 0x35, 0x41, 0x30, 0x34, 0x45, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
    54  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x46, 0x43, 0x30, 0x30,
    55  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
    56  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
    57  		0x30, 0x30, 0x30, 0x30, 0x30, 0x32, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
    58  		0x30, 0x30, 0x2e, 0x00, 0x30, 0x37, 0x30, 0x37, 0x30, 0x31, 0x30, 0x30,
    59  		0x33, 0x30, 0x45, 0x33, 0x43, 0x35, 0x30, 0x30, 0x30, 0x30, 0x34, 0x31,
    60  		0x45, 0x44, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
    61  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
    62  		0x30, 0x32, 0x35, 0x38, 0x38, 0x35, 0x41, 0x30, 0x34, 0x41, 0x30, 0x30,
    63  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
    64  		0x46, 0x43, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
    65  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
    66  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x34, 0x30, 0x30,
    67  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x65, 0x74, 0x63, 0x00, 0x00, 0x00,
    68  		0x30, 0x37, 0x30, 0x37, 0x30, 0x31, 0x30, 0x30, 0x33, 0x30, 0x43, 0x32,
    69  		0x30, 0x43, 0x30, 0x30, 0x30, 0x30, 0x38, 0x31, 0x41, 0x34, 0x30, 0x30,
    70  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
    71  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x35, 0x38,
    72  		0x38, 0x35, 0x41, 0x30, 0x34, 0x41, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
    73  		0x37, 0x36, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x46, 0x43, 0x30, 0x30,
    74  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
    75  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
    76  		0x30, 0x30, 0x30, 0x30, 0x30, 0x45, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
    77  		0x30, 0x30, 0x65, 0x74, 0x63, 0x2f, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x74,
    78  		0x69, 0x6d, 0x65, 0x00, 0x54, 0x5a, 0x69, 0x66, 0x32, 0x00, 0x00, 0x00,
    79  		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    80  		0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
    81  		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04,
    82  		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0x54, 0x43, 0x00, 0x00, 0x00,
    83  		0x54, 0x5a, 0x69, 0x66, 0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    84  		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
    85  		0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    86  		0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00,
    87  		0x00, 0x00, 0x55, 0x54, 0x43, 0x00, 0x00, 0x00, 0x0a, 0x55, 0x54, 0x43,
    88  		0x30, 0x0a, 0x00, 0x00, 0x30, 0x37, 0x30, 0x37, 0x30, 0x31, 0x30, 0x30,
    89  		0x33, 0x30, 0x37, 0x42, 0x30, 0x44, 0x30, 0x30, 0x30, 0x30, 0x38, 0x31,
    90  		0x41, 0x34, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
    91  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
    92  		0x30, 0x31, 0x35, 0x38, 0x38, 0x35, 0x41, 0x30, 0x34, 0x41, 0x30, 0x30,
    93  		0x30, 0x30, 0x30, 0x30, 0x35, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
    94  		0x46, 0x43, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
    95  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
    96  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x30, 0x30, 0x30,
    97  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x65, 0x74, 0x63, 0x2f, 0x72, 0x65,
    98  		0x73, 0x6f, 0x6c, 0x76, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x00, 0x00, 0x00,
    99  		0x6e, 0x61, 0x6d, 0x65, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x20, 0x31,
   100  		0x39, 0x32, 0x2e, 0x31, 0x36, 0x38, 0x2e, 0x31, 0x2e, 0x31, 0x30, 0x0a,
   101  		0x73, 0x65, 0x61, 0x72, 0x63, 0x68, 0x20, 0x48, 0x6f, 0x6d, 0x65, 0x2e,
   102  		0x0a, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x73, 0x69, 0x6e,
   103  		0x67, 0x6c, 0x65, 0x2d, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x20,
   104  		0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x3a, 0x31, 0x20, 0x61, 0x74,
   105  		0x74, 0x65, 0x6d, 0x70, 0x74, 0x73, 0x3a, 0x35, 0x0a, 0x00, 0x00, 0x00,
   106  		0x30, 0x37, 0x30, 0x37, 0x30, 0x31, 0x30, 0x30, 0x33, 0x30, 0x45, 0x33,
   107  		0x43, 0x42, 0x30, 0x30, 0x30, 0x30, 0x34, 0x31, 0x45, 0x44, 0x30, 0x30,
   108  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   109  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x32, 0x35, 0x38,
   110  		0x38, 0x35, 0x41, 0x30, 0x34, 0x41, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   111  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x46, 0x43, 0x30, 0x30,
   112  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   113  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   114  		0x30, 0x30, 0x30, 0x30, 0x30, 0x36, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   115  		0x30, 0x30, 0x6c, 0x69, 0x62, 0x36, 0x34, 0x00, 0x30, 0x37, 0x30, 0x37,
   116  		0x30, 0x31, 0x30, 0x30, 0x33, 0x30, 0x45, 0x33, 0x43, 0x34, 0x30, 0x30,
   117  		0x30, 0x30, 0x34, 0x31, 0x45, 0x44, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   118  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   119  		0x30, 0x30, 0x30, 0x30, 0x30, 0x32, 0x35, 0x38, 0x38, 0x35, 0x41, 0x30,
   120  		0x34, 0x41, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   121  		0x30, 0x30, 0x30, 0x30, 0x46, 0x43, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   122  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   123  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   124  		0x30, 0x34, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x74, 0x63,
   125  		0x7a, 0x00, 0x00, 0x00, 0x30, 0x37, 0x30, 0x37, 0x30, 0x31, 0x30, 0x30,
   126  		0x33, 0x30, 0x45, 0x33, 0x43, 0x43, 0x30, 0x30, 0x30, 0x30, 0x34, 0x31,
   127  		0x45, 0x44, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   128  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   129  		0x30, 0x32, 0x35, 0x38, 0x38, 0x35, 0x41, 0x30, 0x34, 0x41, 0x30, 0x30,
   130  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   131  		0x46, 0x43, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   132  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   133  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x34, 0x30, 0x30,
   134  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x62, 0x69, 0x6e, 0x00, 0x00, 0x00,
   135  		0x30, 0x37, 0x30, 0x37, 0x30, 0x31, 0x30, 0x30, 0x33, 0x30, 0x45, 0x33,
   136  		0x43, 0x44, 0x30, 0x30, 0x30, 0x30, 0x34, 0x31, 0x45, 0x44, 0x30, 0x30,
   137  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   138  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x32, 0x35, 0x38,
   139  		0x38, 0x35, 0x41, 0x30, 0x34, 0x41, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   140  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x46, 0x43, 0x30, 0x30,
   141  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   142  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   143  		0x30, 0x30, 0x30, 0x30, 0x30, 0x34, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   144  		0x30, 0x30, 0x74, 0x6d, 0x70, 0x00, 0x00, 0x00, 0x30, 0x37, 0x30, 0x37,
   145  		0x30, 0x31, 0x30, 0x30, 0x33, 0x30, 0x45, 0x33, 0x43, 0x36, 0x30, 0x30,
   146  		0x30, 0x30, 0x34, 0x31, 0x45, 0x44, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   147  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   148  		0x30, 0x30, 0x30, 0x30, 0x30, 0x32, 0x35, 0x38, 0x38, 0x35, 0x41, 0x30,
   149  		0x34, 0x41, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   150  		0x30, 0x30, 0x30, 0x30, 0x46, 0x43, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   151  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   152  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   153  		0x30, 0x34, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x64, 0x65,
   154  		0x76, 0x00, 0x00, 0x00, 0x30, 0x37, 0x30, 0x37, 0x30, 0x31, 0x30, 0x30,
   155  		0x33, 0x30, 0x43, 0x43, 0x32, 0x31, 0x30, 0x30, 0x30, 0x30, 0x32, 0x31,
   156  		0x41, 0x34, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   157  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   158  		0x30, 0x31, 0x35, 0x38, 0x38, 0x35, 0x41, 0x30, 0x34, 0x41, 0x30, 0x30,
   159  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   160  		0x46, 0x43, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   161  		0x30, 0x30, 0x30, 0x30, 0x30, 0x35, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   162  		0x30, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x43, 0x30, 0x30,
   163  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x64, 0x65, 0x76, 0x2f, 0x63, 0x6f,
   164  		0x6e, 0x73, 0x6f, 0x6c, 0x65, 0x00, 0x00, 0x00, 0x30, 0x37, 0x30, 0x37,
   165  		0x30, 0x31, 0x30, 0x30, 0x33, 0x30, 0x43, 0x43, 0x32, 0x32, 0x30, 0x30,
   166  		0x30, 0x30, 0x32, 0x31, 0x41, 0x34, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   167  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   168  		0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x35, 0x38, 0x38, 0x35, 0x41, 0x30,
   169  		0x34, 0x41, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   170  		0x30, 0x30, 0x30, 0x30, 0x46, 0x43, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   171  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x34, 0x30, 0x30,
   172  		0x30, 0x30, 0x30, 0x30, 0x34, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   173  		0x30, 0x41, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x64, 0x65,
   174  		0x76, 0x2f, 0x74, 0x74, 0x79, 0x53, 0x30, 0x00, 0x30, 0x37, 0x30, 0x37,
   175  		0x30, 0x31, 0x30, 0x30, 0x33, 0x30, 0x43, 0x43, 0x32, 0x33, 0x30, 0x30,
   176  		0x30, 0x30, 0x36, 0x31, 0x42, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   177  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   178  		0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x35, 0x38, 0x38, 0x35, 0x41, 0x30,
   179  		0x34, 0x41, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   180  		0x30, 0x30, 0x30, 0x30, 0x46, 0x43, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   181  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x37, 0x30, 0x30,
   182  		0x30, 0x30, 0x30, 0x30, 0x30, 0x32, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   183  		0x30, 0x41, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x64, 0x65,
   184  		0x76, 0x2f, 0x6c, 0x6f, 0x6f, 0x70, 0x32, 0x00, 0x30, 0x37, 0x30, 0x37,
   185  		0x30, 0x31, 0x30, 0x30, 0x33, 0x30, 0x43, 0x43, 0x31, 0x46, 0x30, 0x30,
   186  		0x30, 0x30, 0x32, 0x31, 0x38, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   187  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   188  		0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x35, 0x38, 0x38, 0x35, 0x41, 0x30,
   189  		0x34, 0x41, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   190  		0x30, 0x30, 0x30, 0x30, 0x46, 0x43, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   191  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x41, 0x30, 0x30,
   192  		0x30, 0x30, 0x30, 0x30, 0x45, 0x44, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   193  		0x31, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x64, 0x65,
   194  		0x76, 0x2f, 0x6c, 0x6f, 0x6f, 0x70, 0x2d, 0x63, 0x6f, 0x6e, 0x74, 0x72,
   195  		0x6f, 0x6c, 0x00, 0x00, 0x30, 0x37, 0x30, 0x37, 0x30, 0x31, 0x30, 0x30,
   196  		0x33, 0x30, 0x43, 0x43, 0x32, 0x30, 0x30, 0x30, 0x30, 0x30, 0x36, 0x31,
   197  		0x42, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   198  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   199  		0x30, 0x31, 0x35, 0x38, 0x38, 0x35, 0x41, 0x30, 0x34, 0x41, 0x30, 0x30,
   200  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   201  		0x46, 0x43, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   202  		0x30, 0x30, 0x30, 0x30, 0x30, 0x37, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   203  		0x30, 0x37, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x41, 0x30, 0x30,
   204  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x64, 0x65, 0x76, 0x2f, 0x6c, 0x6f,
   205  		0x6f, 0x70, 0x37, 0x00, 0x30, 0x37, 0x30, 0x37, 0x30, 0x31, 0x30, 0x30,
   206  		0x33, 0x30, 0x43, 0x43, 0x31, 0x37, 0x30, 0x30, 0x30, 0x30, 0x36, 0x31,
   207  		0x42, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   208  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   209  		0x30, 0x31, 0x35, 0x38, 0x38, 0x35, 0x41, 0x30, 0x34, 0x41, 0x30, 0x30,
   210  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   211  		0x46, 0x43, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   212  		0x30, 0x30, 0x30, 0x30, 0x30, 0x37, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   213  		0x30, 0x36, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x41, 0x30, 0x30,
   214  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x64, 0x65, 0x76, 0x2f, 0x6c, 0x6f,
   215  		0x6f, 0x70, 0x36, 0x00, 0x30, 0x37, 0x30, 0x37, 0x30, 0x31, 0x30, 0x30,
   216  		0x33, 0x30, 0x43, 0x43, 0x31, 0x42, 0x30, 0x30, 0x30, 0x30, 0x36, 0x31,
   217  		0x42, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   218  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   219  		0x30, 0x31, 0x35, 0x38, 0x38, 0x35, 0x41, 0x30, 0x34, 0x41, 0x30, 0x30,
   220  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   221  		0x46, 0x43, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   222  		0x30, 0x30, 0x30, 0x30, 0x30, 0x37, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   223  		0x30, 0x34, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x41, 0x30, 0x30,
   224  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x64, 0x65, 0x76, 0x2f, 0x6c, 0x6f,
   225  		0x6f, 0x70, 0x34, 0x00, 0x30, 0x37, 0x30, 0x37, 0x30, 0x31, 0x30, 0x30,
   226  		0x33, 0x30, 0x43, 0x43, 0x31, 0x44, 0x30, 0x30, 0x30, 0x30, 0x36, 0x31,
   227  		0x42, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   228  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   229  		0x30, 0x31, 0x35, 0x38, 0x38, 0x35, 0x41, 0x30, 0x34, 0x41, 0x30, 0x30,
   230  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   231  		0x46, 0x43, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   232  		0x30, 0x30, 0x30, 0x30, 0x30, 0x37, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   233  		0x30, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x41, 0x30, 0x30,
   234  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x64, 0x65, 0x76, 0x2f, 0x6c, 0x6f,
   235  		0x6f, 0x70, 0x31, 0x00, 0x30, 0x37, 0x30, 0x37, 0x30, 0x31, 0x30, 0x30,
   236  		0x33, 0x30, 0x43, 0x43, 0x31, 0x45, 0x30, 0x30, 0x30, 0x30, 0x36, 0x31,
   237  		0x42, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   238  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   239  		0x30, 0x31, 0x35, 0x38, 0x38, 0x35, 0x41, 0x30, 0x34, 0x41, 0x30, 0x30,
   240  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   241  		0x46, 0x43, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   242  		0x30, 0x30, 0x30, 0x30, 0x30, 0x37, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   243  		0x30, 0x35, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x41, 0x30, 0x30,
   244  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x64, 0x65, 0x76, 0x2f, 0x6c, 0x6f,
   245  		0x6f, 0x70, 0x35, 0x00, 0x30, 0x37, 0x30, 0x37, 0x30, 0x31, 0x30, 0x30,
   246  		0x33, 0x30, 0x43, 0x43, 0x32, 0x34, 0x30, 0x30, 0x30, 0x30, 0x32, 0x31,
   247  		0x41, 0x34, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   248  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   249  		0x30, 0x31, 0x35, 0x38, 0x38, 0x35, 0x41, 0x30, 0x34, 0x41, 0x30, 0x30,
   250  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   251  		0x46, 0x43, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   252  		0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   253  		0x30, 0x33, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x39, 0x30, 0x30,
   254  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x64, 0x65, 0x76, 0x2f, 0x6e, 0x75,
   255  		0x6c, 0x6c, 0x00, 0x00, 0x30, 0x37, 0x30, 0x37, 0x30, 0x31, 0x30, 0x30,
   256  		0x33, 0x30, 0x43, 0x43, 0x31, 0x38, 0x30, 0x30, 0x30, 0x30, 0x36, 0x31,
   257  		0x42, 0x30, 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, 0x31, 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, 0x37, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   263  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x41, 0x30, 0x30,
   264  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x64, 0x65, 0x76, 0x2f, 0x6c, 0x6f,
   265  		0x6f, 0x70, 0x30, 0x00, 0x30, 0x37, 0x30, 0x37, 0x30, 0x31, 0x30, 0x30,
   266  		0x33, 0x30, 0x43, 0x43, 0x31, 0x43, 0x30, 0x30, 0x30, 0x30, 0x36, 0x31,
   267  		0x42, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   268  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   269  		0x30, 0x31, 0x35, 0x38, 0x38, 0x35, 0x41, 0x30, 0x34, 0x41, 0x30, 0x30,
   270  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   271  		0x46, 0x43, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   272  		0x30, 0x30, 0x30, 0x30, 0x30, 0x37, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   273  		0x30, 0x33, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x41, 0x30, 0x30,
   274  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x64, 0x65, 0x76, 0x2f, 0x6c, 0x6f,
   275  		0x6f, 0x70, 0x33, 0x00, 0x30, 0x37, 0x30, 0x37, 0x30, 0x31, 0x30, 0x30,
   276  		0x33, 0x30, 0x45, 0x33, 0x43, 0x39, 0x30, 0x30, 0x30, 0x30, 0x34, 0x31,
   277  		0x45, 0x44, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   278  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   279  		0x30, 0x33, 0x35, 0x38, 0x38, 0x35, 0x41, 0x30, 0x34, 0x41, 0x30, 0x30,
   280  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   281  		0x46, 0x43, 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, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x34, 0x30, 0x30,
   284  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x75, 0x73, 0x72, 0x00, 0x00, 0x00,
   285  		0x30, 0x37, 0x30, 0x37, 0x30, 0x31, 0x30, 0x30, 0x33, 0x30, 0x45, 0x33,
   286  		0x43, 0x41, 0x30, 0x30, 0x30, 0x30, 0x34, 0x31, 0x45, 0x44, 0x30, 0x30,
   287  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   288  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x32, 0x35, 0x38,
   289  		0x38, 0x35, 0x41, 0x30, 0x34, 0x41, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   290  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x46, 0x43, 0x30, 0x30,
   291  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   292  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   293  		0x30, 0x30, 0x30, 0x30, 0x30, 0x38, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   294  		0x30, 0x30, 0x75, 0x73, 0x72, 0x2f, 0x6c, 0x69, 0x62, 0x00, 0x00, 0x00,
   295  		0x30, 0x37, 0x30, 0x37, 0x30, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   296  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 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, 0x30, 0x30, 0x30, 0x30, 0x31, 0x30, 0x30,
   299  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   300  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   301  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   302  		0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   303  		0x30, 0x30, 0x30, 0x30, 0x30, 0x42, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
   304  		0x30, 0x30, 0x54, 0x52, 0x41, 0x49, 0x4c, 0x45, 0x52, 0x21, 0x21, 0x21,
   305  		0, 0, 0, 0,
   306  	}
   307  
   308  	testResult = []Record{
   309  		{Info: Info{Name: ".", Ino: 3204033, Mode: 040775, UID: 1000, GID: 1000, NLink: 9, MTime: 1485152334, FileSize: 0, Major: 252, Minor: 0, Rmajor: 0, Rminor: 0}},
   310  		{Info: Info{Name: "etc", Ino: 3204037, Mode: 040755, UID: 0, GID: 0, NLink: 2, MTime: 1485152330, FileSize: 0, Major: 252, Minor: 0, Rmajor: 0, Rminor: 0}},
   311  		{Info: Info{Name: "etc/localtime", Ino: 3195404, Mode: 0100644, UID: 0, GID: 0, NLink: 1, MTime: 1485152330, FileSize: 118, Major: 252, Minor: 0, Rmajor: 0, Rminor: 0}},
   312  		{Info: Info{Name: "etc/resolv.conf", Ino: 3177229, Mode: 0100644, UID: 0, GID: 0, NLink: 1, MTime: 1485152330, FileSize: 81, Major: 252, Minor: 0, Rmajor: 0, Rminor: 0}},
   313  		{Info: Info{Name: "lib64", Ino: 3204043, Mode: 040755, UID: 0, GID: 0, NLink: 2, MTime: 1485152330, FileSize: 0, Major: 252, Minor: 0, Rmajor: 0, Rminor: 0}},
   314  		{Info: Info{Name: "tcz", Ino: 3204036, Mode: 040755, UID: 0, GID: 0, NLink: 2, MTime: 1485152330, FileSize: 0, Major: 252, Minor: 0, Rmajor: 0, Rminor: 0}},
   315  		{Info: Info{Name: "bin", Ino: 3204044, Mode: 040755, UID: 0, GID: 0, NLink: 2, MTime: 1485152330, FileSize: 0, Major: 252, Minor: 0, Rmajor: 0, Rminor: 0}},
   316  		{Info: Info{Name: "tmp", Ino: 3204045, Mode: 040755, UID: 0, GID: 0, NLink: 2, MTime: 1485152330, FileSize: 0, Major: 252, Minor: 0, Rmajor: 0, Rminor: 0}},
   317  		{Info: Info{Name: "dev", Ino: 3204038, Mode: 040755, UID: 0, GID: 0, NLink: 2, MTime: 1485152330, FileSize: 0, Major: 252, Minor: 0, Rmajor: 0, Rminor: 0}},
   318  		{Info: Info{Name: "dev/console", Ino: 3197985, Mode: 020644, UID: 0, GID: 0, NLink: 1, MTime: 1485152330, FileSize: 0, Major: 252, Minor: 0, Rmajor: 5, Rminor: 1}},
   319  		{Info: Info{Name: "dev/ttyS0", Ino: 3197986, Mode: 020644, UID: 0, GID: 0, NLink: 1, MTime: 1485152330, FileSize: 0, Major: 252, Minor: 0, Rmajor: 4, Rminor: 64}},
   320  		{Info: Info{Name: "dev/loop2", Ino: 3197987, Mode: 060660, UID: 0, GID: 0, NLink: 1, MTime: 1485152330, FileSize: 0, Major: 252, Minor: 0, Rmajor: 7, Rminor: 2}},
   321  		{Info: Info{Name: "dev/loop-control", Ino: 3197983, Mode: 020600, UID: 0, GID: 0, NLink: 1, MTime: 1485152330, FileSize: 0, Major: 252, Minor: 0, Rmajor: 10, Rminor: 237}},
   322  		{Info: Info{Name: "dev/loop7", Ino: 3197984, Mode: 060660, UID: 0, GID: 0, NLink: 1, MTime: 1485152330, FileSize: 0, Major: 252, Minor: 0, Rmajor: 7, Rminor: 7}},
   323  		{Info: Info{Name: "dev/loop6", Ino: 3197975, Mode: 060660, UID: 0, GID: 0, NLink: 1, MTime: 1485152330, FileSize: 0, Major: 252, Minor: 0, Rmajor: 7, Rminor: 6}},
   324  		{Info: Info{Name: "dev/loop4", Ino: 3197979, Mode: 060660, UID: 0, GID: 0, NLink: 1, MTime: 1485152330, FileSize: 0, Major: 252, Minor: 0, Rmajor: 7, Rminor: 4}},
   325  		{Info: Info{Name: "dev/loop1", Ino: 3197981, Mode: 060660, UID: 0, GID: 0, NLink: 1, MTime: 1485152330, FileSize: 0, Major: 252, Minor: 0, Rmajor: 7, Rminor: 1}},
   326  		{Info: Info{Name: "dev/loop5", Ino: 3197982, Mode: 060660, UID: 0, GID: 0, NLink: 1, MTime: 1485152330, FileSize: 0, Major: 252, Minor: 0, Rmajor: 7, Rminor: 5}},
   327  		{Info: Info{Name: "dev/null", Ino: 3197988, Mode: 020644, UID: 0, GID: 0, NLink: 1, MTime: 1485152330, FileSize: 0, Major: 252, Minor: 0, Rmajor: 1, Rminor: 3}},
   328  		{Info: Info{Name: "dev/loop0", Ino: 3197976, Mode: 060660, UID: 0, GID: 0, NLink: 1, MTime: 1485152330, FileSize: 0, Major: 252, Minor: 0, Rmajor: 7, Rminor: 0}},
   329  		{Info: Info{Name: "dev/loop3", Ino: 3197980, Mode: 060660, UID: 0, GID: 0, NLink: 1, MTime: 1485152330, FileSize: 0, Major: 252, Minor: 0, Rmajor: 7, Rminor: 3}},
   330  		{Info: Info{Name: "usr", Ino: 3204041, Mode: 040755, UID: 0, GID: 0, NLink: 3, MTime: 1485152330, FileSize: 0, Major: 252, Minor: 0, Rmajor: 0, Rminor: 0}},
   331  		{Info: Info{Name: "usr/lib", Ino: 3204042, Mode: 040755, UID: 0, GID: 0, NLink: 2, MTime: 1485152330, FileSize: 0, Major: 252, Minor: 0, Rmajor: 0, Rminor: 0}},
   332  	}
   333  )
   334  
   335  func TestBad(t *testing.T) {
   336  	r := Newc.Reader(bytes.NewReader(badCPIO))
   337  	if _, err := r.ReadRecord(); err != io.EOF {
   338  		t.Errorf("ReadRecord(badCPIO) got %v, want %v", err, io.EOF)
   339  	}
   340  
   341  	r = Newc.Reader(bytes.NewReader(badMagicCPIO))
   342  	if _, err := r.ReadRecord(); err == nil {
   343  		t.Errorf("Wanted bad magic err, got nil")
   344  	}
   345  }
   346  
   347  func TestSimple(t *testing.T) {
   348  	r := Newc.Reader(bytes.NewReader(testCPIO))
   349  	files, err := ReadAllRecords(r)
   350  	if err != nil {
   351  		t.Fatal(err)
   352  	}
   353  
   354  	for i, f := range files {
   355  		if reflect.DeepEqual(f, testResult[i]) {
   356  			t.Errorf("failed on value %d: got \n%s, want \n%s", i, f.String(), testResult[i])
   357  		}
   358  	}
   359  }
   360  
   361  func TestWriteRead(t *testing.T) {
   362  	contents := []byte("LANAAAAAAAAAA")
   363  	rec := StaticRecord(contents, Info{
   364  		Ino:      1,
   365  		Mode:     syscall.S_IFREG | 2,
   366  		UID:      3,
   367  		GID:      4,
   368  		NLink:    5,
   369  		MTime:    6,
   370  		FileSize: 7,
   371  		Major:    8,
   372  		Minor:    9,
   373  		Rmajor:   10,
   374  		Rminor:   11,
   375  		Name:     "foobar",
   376  	})
   377  
   378  	buf := &bytes.Buffer{}
   379  	w := Newc.Writer(buf)
   380  	if err := w.WriteRecord(rec); err != nil {
   381  		t.Errorf("Could not write record %q: %v", rec.Name, err)
   382  	}
   383  
   384  	if err := WriteTrailer(w); err != nil {
   385  		t.Errorf("Could not write trailer: %v", err)
   386  	}
   387  
   388  	r := Newc.Reader(bytes.NewReader(buf.Bytes()))
   389  	rec2, err := r.ReadRecord()
   390  	if err != nil {
   391  		t.Errorf("Could not read record: %v", err)
   392  	}
   393  
   394  	if rec2.Info != rec.Info {
   395  		t.Errorf("Records not equal:\n%#v\n%#v", rec.Info, rec2.Info)
   396  	}
   397  
   398  	contents2, err := io.ReadAll(uio.Reader(rec2))
   399  	if err != nil {
   400  		t.Errorf("Could not read %q: %v", rec2.Name, err)
   401  	}
   402  
   403  	if !bytes.Equal(contents2, contents) {
   404  		t.Errorf("Read(%q) = %s, want %s", rec2.Name, string(contents2), contents)
   405  	}
   406  }
   407  
   408  func TestPipeWriteRead(t *testing.T) {
   409  	contents := []byte("ABCDEFG")
   410  	// N.B. It is important to have two records,
   411  	// it caught a problem with the first discard
   412  	// implementation.
   413  	records := []Record{
   414  		StaticRecord(contents, Info{
   415  			Ino:      1,
   416  			Mode:     syscall.S_IFREG | 2,
   417  			UID:      3,
   418  			GID:      4,
   419  			NLink:    5,
   420  			MTime:    6,
   421  			FileSize: 7,
   422  			Major:    8,
   423  			Minor:    9,
   424  			Rmajor:   10,
   425  			Rminor:   11,
   426  			Name:     "foobar",
   427  		}),
   428  		StaticRecord(contents[:5], Info{
   429  			Ino:      1,
   430  			Mode:     syscall.S_IFREG | 2,
   431  			UID:      3,
   432  			GID:      4,
   433  			NLink:    5,
   434  			MTime:    6,
   435  			FileSize: 5,
   436  			Major:    8,
   437  			Minor:    9,
   438  			Rmajor:   10,
   439  			Rminor:   11,
   440  			Name:     "farba",
   441  		}),
   442  	}
   443  
   444  	rp, wp, err := os.Pipe()
   445  	if err != nil {
   446  		t.Fatal(err)
   447  	}
   448  	w := Newc.Writer(wp)
   449  	// We need a func here in case the pipe blocks the write.
   450  
   451  	go func() {
   452  		for _, rec := range records {
   453  			if err := w.WriteRecord(rec); err != nil {
   454  				t.Errorf("Could not write record %q: %v", rec.Name, err)
   455  			}
   456  		}
   457  
   458  		if err := WriteTrailer(w); err != nil {
   459  			t.Errorf("Could not write trailer: %v", err)
   460  		}
   461  	}()
   462  
   463  	Debug = t.Logf
   464  
   465  	rdr, err := Newc.NewFileReader(rp)
   466  	if err != nil {
   467  		t.Fatal(err)
   468  	}
   469  	for _, r := range records {
   470  		rec, err := rdr.ReadRecord()
   471  		if err != nil {
   472  			t.Errorf("Could not read record: %v", err)
   473  		}
   474  
   475  		t.Logf("Check Info")
   476  		if rec.Info != r.Info {
   477  			t.Errorf("Records not equal:\n%#v\n%#v", r.Info, rec.Info)
   478  		}
   479  
   480  		t.Logf("Check Data")
   481  		dat, err := io.ReadAll(uio.Reader(rec))
   482  		if err != nil {
   483  			t.Errorf("Could not read %q: %v", rec.Name, err)
   484  		}
   485  
   486  		if !bytes.Equal(dat, contents[:r.Info.FileSize]) {
   487  			t.Errorf("Read(%q) = %s, want %s", rec.Name, string(dat), contents[:r.Info.FileSize])
   488  		}
   489  	}
   490  }
   491  
   492  func TestReadWrite(t *testing.T) {
   493  	r := Newc.Reader(bytes.NewReader(testCPIO))
   494  	files, err := ReadAllRecords(r)
   495  	if err != nil {
   496  		t.Fatalf("Reading testCPIO reader: %v", err)
   497  	}
   498  
   499  	buf := &bytes.Buffer{}
   500  	w := Newc.Writer(buf)
   501  	if err := WriteRecords(w, files); err != nil {
   502  		t.Fatalf("WriteRecords: %v", err)
   503  	}
   504  
   505  	if err := WriteTrailer(w); err != nil {
   506  		t.Fatalf("WriteTrailer: %v", err)
   507  	}
   508  
   509  	r = Newc.Reader(bytes.NewReader(buf.Bytes()))
   510  	filesReadBack, err := ReadAllRecords(r)
   511  	if err != nil {
   512  		t.Fatalf("TestReadWrite: reading generated data: %v", err)
   513  	}
   514  
   515  	// Now check a few things: arrays should be same length, Headers should match,
   516  	// names should be the same, and data should be the same. If this all works,
   517  	// it means we read in serialized data, wrote it out, read it in, and the
   518  	// structs all matched.
   519  	if len(files) != len(filesReadBack) {
   520  		t.Fatalf("[]file len from testCPIO %v and generated %v are not the same and should be", len(files), len(filesReadBack))
   521  	}
   522  	for i := range files {
   523  		f1 := files[i]
   524  		f2 := filesReadBack[i]
   525  
   526  		if f1.Info != f2.Info {
   527  			t.Errorf("index %d: testCPIO Info\n%v\ngenerated Info\n%v\n", i, f1.Info, f2.Info)
   528  		}
   529  
   530  		contents1, err := io.ReadAll(uio.Reader(f1))
   531  		if err != nil {
   532  			t.Errorf("index %d(%q): can't read from the source: %v", i, f1.Name, err)
   533  		}
   534  		contents2, err := io.ReadAll(uio.Reader(f2))
   535  		if err != nil {
   536  			t.Errorf("index %d(%q): can't read from the dest: %v", i, f2.Name, err)
   537  		}
   538  		if !bytes.Equal(contents1, contents2) {
   539  			t.Errorf("index %d content: file 1 (%q) is %v, file 2 (%q) wanted %v", i, f1.Name, contents1, f2.Name, contents2)
   540  		}
   541  	}
   542  }
   543  
   544  // testReproducible verifies that we can produce reproducible cpio archives for newc format.
   545  func TestReproducible(t *testing.T) {
   546  	contents := []byte("LANAAAAAAAAAA")
   547  	rec := []Record{
   548  		StaticRecord(contents, Info{
   549  			Ino:      1,
   550  			Mode:     syscall.S_IFREG | 2,
   551  			UID:      3,
   552  			GID:      4,
   553  			NLink:    5,
   554  			MTime:    6,
   555  			FileSize: 7,
   556  			Major:    8,
   557  			Minor:    9,
   558  			Rmajor:   10,
   559  			Rminor:   11,
   560  			Name:     "foobar",
   561  		}),
   562  	}
   563  
   564  	// First test that it fails unless we make it reproducible
   565  
   566  	b1 := &bytes.Buffer{}
   567  	w := Newc.Writer(b1)
   568  	if err := WriteRecords(w, rec); err != nil {
   569  		t.Errorf("Could not write record %q: %v", rec[0].Name, err)
   570  	}
   571  	rec[0].ReaderAt = bytes.NewReader(contents)
   572  	b2 := &bytes.Buffer{}
   573  	w = Newc.Writer(b2)
   574  	rec[0].MTime++
   575  	if err := WriteRecords(w, rec); err != nil {
   576  		t.Errorf("Could not write record %q: %v", rec[0].Name, err)
   577  	}
   578  
   579  	if reflect.DeepEqual(b1.Bytes()[:], b2.Bytes()[:]) {
   580  		t.Error("Reproducible: compared as same, wanted different")
   581  	}
   582  
   583  	// Second test that it works if we make it reproducible
   584  	// It does indeed fail without the second call.
   585  
   586  	b1 = &bytes.Buffer{}
   587  	w = Newc.Writer(b1)
   588  	rec[0].ReaderAt = bytes.NewReader([]byte(contents))
   589  	MakeAllReproducible(rec)
   590  	if err := WriteRecords(w, rec); err != nil {
   591  		t.Errorf("Could not write record %q: %v", rec[0].Name, err)
   592  	}
   593  
   594  	b2 = &bytes.Buffer{}
   595  	w = Newc.Writer(b2)
   596  	rec[0].MTime++
   597  	rec[0].ReaderAt = bytes.NewReader([]byte(contents))
   598  	MakeAllReproducible(rec)
   599  	if err := WriteRecords(w, rec); err != nil {
   600  		t.Errorf("Could not write record %q: %v", rec[0].Name, err)
   601  	}
   602  
   603  	if len(b1.Bytes()) != len(b2.Bytes()) {
   604  		t.Fatalf("Reproducible \n%v,\n%v: len is different, wanted same", b1.Bytes()[:], b2.Bytes()[:])
   605  	}
   606  	if !reflect.DeepEqual(b1.Bytes()[:], b2.Bytes()[:]) {
   607  		t.Error("Reproducible: compared different, wanted same")
   608  		for i := range b1.Bytes() {
   609  			a := b1.Bytes()[i]
   610  			b := b2.Bytes()[i]
   611  			if a != b {
   612  				t.Errorf("\tb1[%d] is %v, b2[%d] is %v", i, a, i, b)
   613  			}
   614  		}
   615  	}
   616  }
   617  
   618  func FuzzReadWriteNewc(f *testing.F) {
   619  
   620  	f.Add(testCPIO)
   621  	f.Add([]byte("070701000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"))
   622  	f.Add([]byte("07070100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000//000"))
   623  	seeds, err := filepath.Glob("testdata/fuzz/corpora/*")
   624  	if err != nil {
   625  		f.Fatalf("failed to find seed corpora data %v", err)
   626  	}
   627  
   628  	for _, seed := range seeds {
   629  		seedBytes, err := os.ReadFile(seed)
   630  		if err != nil {
   631  			f.Fatalf("failed to read seed corpora from file %v: %v", seed, err)
   632  		}
   633  		f.Add(seedBytes)
   634  	}
   635  
   636  	// Cannot log when fuzzing
   637  	Debug = func(s string, i ...interface{}) {}
   638  	log.SetOutput(io.Discard)
   639  	log.SetFlags(0)
   640  
   641  	f.Fuzz(func(t *testing.T, cpio []byte) {
   642  		// Unneccessary big inputs will only slow down the fuzzing
   643  		if len(cpio) > 64 {
   644  			return
   645  		}
   646  
   647  		// Try to parse the generated fuzzing input. If the input is not parseable skip to next input
   648  		r := Newc.Reader(bytes.NewReader(cpio))
   649  		files, err := ReadAllRecords(r)
   650  		if err != nil {
   651  			return
   652  		}
   653  
   654  		buf := &bytes.Buffer{}
   655  		w := Newc.Writer(buf)
   656  		// The headers filesize vs actual filesize of records is not compared when reading.
   657  		// Hence writing the filecontent back can results in an error. Ignoring this for now.
   658  		if err := WriteRecords(w, files); err != nil {
   659  			return
   660  		}
   661  
   662  		if err := WriteTrailer(w); err != nil {
   663  			t.Fatalf("WriteTrailer: %v", err)
   664  		}
   665  
   666  		r = Newc.Reader(bytes.NewReader(buf.Bytes()))
   667  		filesReadBack, err := ReadAllRecords(r)
   668  		if err != nil {
   669  			t.Fatalf("TestReadWrite: reading generated data: %v", err)
   670  		}
   671  
   672  		// Now check a few things: arrays should be same length, Headers should match,
   673  		// names should be the same, and data should be the same. If this all works,
   674  		// it means we read in serialized data, wrote it out, read it in, and the
   675  		// structs all matched.
   676  		if len(files) != len(filesReadBack) {
   677  			t.Errorf("[]file len from cpio %v and generated %v are not the same and should be", len(files), len(filesReadBack))
   678  		}
   679  		for i := range files {
   680  			f1 := files[i]
   681  			f2 := filesReadBack[i]
   682  
   683  			if f1.Info != f2.Info {
   684  				t.Errorf("index %d: cpio Info\n%v\ngenerated Info\n%v\n", i, f1.Info, f2.Info)
   685  			}
   686  
   687  			contents1, err := io.ReadAll(uio.Reader(f1))
   688  			if err != nil {
   689  				t.Errorf("index %d(%q): can't read from the source: %v", i, f1.Name, err)
   690  			}
   691  			contents2, err := io.ReadAll(uio.Reader(f2))
   692  			if err != nil {
   693  				t.Errorf("index %d(%q): can't read from the dest: %v", i, f2.Name, err)
   694  			}
   695  			if !bytes.Equal(contents1, contents2) {
   696  				t.Errorf("index %d content: file 1 (%q) is %v, file 2 (%q) wanted %v", i, f1.Info, contents1, f2.Info, contents2)
   697  			}
   698  		}
   699  	})
   700  }