1#!/bin/bash
2
3[ -f testing.sh ] && . testing.sh
4
5# We need to test name and file padding.
6# This means all possible values of strlen(name)+1 % 4,
7# plus file sizes of at least 0-4.
8
9touch a bb ccc dddd
10testing "cpio name padding" "cpio -o -H newc|cpio -it" "a\nbb\nccc\ndddd\n" "" "a\nbb\nccc\ndddd\n"
11rm a bb ccc dddd
12
13touch a
14printf '1' >b
15printf '22' >c
16printf '333' >d
17testing "cpio file padding" "cpio -o -H newc|cpio -it" "a\nb\nc\nd\n" "" "a\nb\nc\nd\n"
18rm a b c d
19
20touch a
21printf '1' >bb
22printf '22' >ccc
23printf '333' >dddd
24# With the proper padding, header length, and file length,
25# the relevant bit should be here:
26# 110*5 + 4*3 + 2 + 6*3 = 550 + 12 + 20 = 582
27# files are padded to n*4, names are padded to 2 + n*4 due to the header length
28testing "cpio archive length" "cpio -o -H newc|dd ibs=2 skip=291 count=5 2>/dev/null" "TRAILER!!!" "" "a\nbb\nccc\ndddd\n"
29testing "cpio archive magic" "cpio -o -H newc|dd ibs=2 count=3 2>/dev/null" "070701" "" "a\n"
30# check name length (8 bytes before the empty "crc")
31testing "cpio name length" "cpio -o -H newc|dd ibs=2 skip=47 count=4 2>/dev/null" "00000002" "" "a\n"
32rm a bb ccc dddd
33
34# archive dangling symlinks and empty files even if we cannot open them
35touch a; chmod a-rwx a; ln -s a/cant b
36testing "cpio archives unreadable empty files" "cpio -o -H newc|cpio -it" "a\nb\n" "" "a\nb\n"
37chmod u+rw a; rm -f a b
38
39
40