]>
Commit | Line | Data |
---|---|---|
7e3a4f0a JSMR |
1 | # vim: filetype=sh |
2 | ||
3 | test_description="create fs image from GNU tarball" | |
4 | if ! test -x "$DEBUGFS_EXE"; then | |
5 | echo "$test_name: $test_description: skipped (no debugfs)" | |
6 | return 0 | |
7 | fi | |
8 | if [ "$(grep -c 'define HAVE_ARCHIVE_H' ../lib/config.h)" -eq 0 ]; then | |
9 | echo "$test_name: $test_description: skipped (no libarchive)" | |
10 | exit 0 | |
11 | fi | |
12 | ||
13 | MKFS_TAR="$TMPFILE.tar" | |
14 | MKFS_DIR="$TMPFILE.dir" | |
15 | OUT="$test_name.log" | |
16 | EXP="$test_dir/expect" | |
17 | ||
18 | # we put everything in a subdir because we cannot rdump the root as that would | |
19 | # require permissions to changing ownership of /lost+found | |
20 | rm -rf "$MKFS_DIR" | |
21 | mkdir -p "$MKFS_DIR/test" | |
22 | touch "$MKFS_DIR/test/emptyfile" | |
23 | dd if=/dev/zero bs=1024 count=32 2> /dev/null | tr '\0' 'a' > "$MKFS_DIR/test/bigfile" | |
24 | dd if=/dev/zero of="$MKFS_DIR/test/zerofile" bs=1 count=1 seek=1024 2> /dev/null | |
25 | ln -s /silly_bs_link "$MKFS_DIR/test/silly_bs_link" | |
26 | mkdir "$MKFS_DIR/test/emptydir" | |
27 | mkdir "$MKFS_DIR/test/dir" | |
28 | echo "will be overwritten" > "$MKFS_DIR/test/dir/file" | |
29 | ||
30 | if false; then | |
31 | # debugfs rdump does not preserve the timestamps when it extracts the | |
32 | # files so we ignore them by using tar --clamp-mtime | |
33 | # first write a partial tar | |
34 | tar --sort=name -C "$MKFS_DIR" --mtime="$DEBUGFS_EXE" --clamp-mtime --format=gnu -cf "$MKFS_TAR.dupl" test | |
35 | # now overwrite the contents of a file | |
36 | echo "Test me" > "$MKFS_DIR/test/dir/file" | |
37 | # and update the tar so that it contains two entries for the same file | |
38 | # we need this to test the code path that first unlinks and then overwrites an | |
39 | # existing file | |
40 | tar -C "$MKFS_DIR" --mtime="$DEBUGFS_EXE" --clamp-mtime --format=gnu -rf "$MKFS_TAR.dupl" test/dir/file | |
41 | # also add a duplicate directory entry because those must not be unlinked | |
42 | echo test | tar -C "$MKFS_DIR" --mtime="$DEBUGFS_EXE" --clamp-mtime --format=gnu -rf "$MKFS_TAR.dupl" --no-recursion --verbatim-files-from --files-from=- | |
43 | # also create a tarball of the directory with only one entry per file | |
44 | tar --sort=name -C "$MKFS_DIR" --mtime="$DEBUGFS_EXE" --clamp-mtime --format=gnu -cf "$MKFS_TAR.uniq" test | |
45 | else | |
46 | # same as above but without using GNU tar | |
47 | perl $test_dir/mkgnutar.pl --nopadding --directory="$MKFS_DIR" --mtime "$(stat -c %Y $DEBUGFS_EXE)" test > "$MKFS_TAR.dupl" | |
48 | echo "Test me" > "$MKFS_DIR/test/dir/file" | |
49 | perl $test_dir/mkgnutar.pl --nopadding --directory="$MKFS_DIR" --mtime "$(stat -c %Y $DEBUGFS_EXE)" test/dir/file >> "$MKFS_TAR.dupl" | |
50 | perl $test_dir/mkgnutar.pl --nopadding --directory="$MKFS_DIR" --mtime "$(stat -c %Y $DEBUGFS_EXE)" --no-recursion test/ >> "$MKFS_TAR.dupl" | |
51 | # add end-of-archive entry | |
52 | truncate -s +1024 "$MKFS_TAR.dupl" | |
53 | # pad to a multiple of the record size | |
54 | truncate -s %10240 "$MKFS_TAR.dupl" | |
55 | perl $test_dir/mkgnutar.pl --directory="$MKFS_DIR" --mtime "$(stat -c %Y $DEBUGFS_EXE)" test > "$MKFS_TAR.uniq" | |
56 | fi | |
57 | ||
58 | rm -r "$MKFS_DIR" | |
59 | ||
60 | cat > "$TMPFILE.cmd1" << ENDL | |
61 | stat /test/emptyfile | |
62 | stat /test/bigfile | |
63 | stat /test/zerofile | |
64 | stat /test/silly_bs_link | |
65 | stat /test/emptydir | |
66 | stat /test/dir | |
67 | stat /test/dir/file | |
68 | ENDL | |
69 | ||
70 | cat > "$TMPFILE.cmd2" << ENDL | |
71 | ex /test/emptyfile | |
72 | ex /test/bigfile | |
73 | ex /test/zerofile | |
74 | ex /test/silly_bs_link | |
75 | ex /test/emptydir | |
76 | ex /test/dir | |
77 | ex /test/dir/file | |
78 | ENDL | |
79 | ||
80 | # Create two file systems, one for each tar that was created above. The | |
81 | # tarballs differ but should result in the same filesystem contents | |
82 | # | |
83 | for ext in uniq dupl; do | |
84 | mkdir "$MKFS_DIR" | |
85 | { | |
86 | $MKE2FS -q -F -o Linux -T ext4 -O metadata_csum,64bit -E lazy_itable_init=1 -b 1024 -d "$MKFS_TAR.$ext" "$TMPFILE.$ext" 16384 2>&1; | |
87 | echo Exit status is $?; | |
88 | $DUMPE2FS "$TMPFILE.$ext" 2>&1; | |
89 | echo Exit status is $?; | |
90 | $DEBUGFS -f "$TMPFILE.cmd1" "$TMPFILE.$ext" 2>&1 | grep -E "(stat|Size:|Type:|Links:|Blockcount:)" | |
91 | echo Exit status is $?; | |
92 | $DEBUGFS -f "$TMPFILE.cmd2" "$TMPFILE.$ext" 2>&1; | |
93 | echo Exit status is $?; | |
94 | $DEBUGFS -R "dump /test/dir/file $TMPFILE.testme" "$TMPFILE.$ext" 2>&1; | |
95 | echo Exit status is $?; | |
96 | # extract the files and directories from the image and tar them | |
97 | # again to make sure that a tarball from the image contents is | |
98 | # bit-by-bit identical to the tarball the image was created | |
99 | # from -- essentially this checks whether a roundtrip from tar | |
100 | # to ext4 to tar remains identical | |
101 | $DEBUGFS -R "rdump /test $MKFS_DIR" "$TMPFILE.$ext" 2>&1; | |
102 | echo Exit status is $?; | |
103 | # debugfs rdump does not preserve the timestamps when it extracts the | |
104 | # files so we ignore them by using tar --clamp-mtime | |
105 | if false; then | |
106 | tar --sort=name -C "$MKFS_DIR" --mtime="$DEBUGFS_EXE" --clamp-mtime --format=gnu -cvf "$TMPFILE.new.tar" test 2>&1; | |
107 | else | |
108 | perl $test_dir/mkgnutar.pl --verbose --directory="$MKFS_DIR" --mtime "$(stat -c %Y $DEBUGFS_EXE)" test 2>&1 > "$TMPFILE.new.tar"; | |
109 | fi; | |
110 | echo Exit status is $?; | |
111 | $FSCK -f -n "$TMPFILE.$ext" 2>&1; | |
112 | echo Exit status is $?; | |
113 | # independent from which tarball the ext4 image was created, | |
114 | # the tarball created from the files in it should be bit-by-bit | |
115 | # identical to the tarball without duplicate entries | |
116 | cmp "$MKFS_TAR.uniq" "$TMPFILE.new.tar" 2>&1; | |
117 | echo Exit status is $?; | |
118 | } | sed -f "$cmd_dir/filter.sed" -f "$test_dir/output.sed" -e "s;$TMPFILE.$ext;test.img;" | { | |
119 | # In the first pass, store the output and append to the log | |
120 | # file. In the second pass, compare the output to the output | |
121 | # to the one from the first. | |
122 | case $ext in | |
123 | uniq) tee "$TMPFILE.log" >> "$OUT";; | |
124 | dupl) cmp - "$TMPFILE.log" >> "$OUT" 2>&1 || echo "cmp failed" >> "$OUT";; | |
125 | esac | |
126 | } | |
127 | rm -r "$MKFS_DIR" "$TMPFILE.new.tar" | |
128 | done | |
129 | ||
130 | # Do the verification | |
131 | cmp -s "$OUT" "$EXP" | |
132 | status=$? | |
133 | ||
134 | if [ "$status" = 0 ] ; then | |
135 | echo "$test_name: $test_description: ok" | |
136 | touch "$test_name.ok" | |
137 | else | |
138 | echo "$test_name: $test_description: failed" | |
139 | diff $DIFF_OPTS "$EXP" "$OUT" > "$test_name.failed" | |
140 | fi | |
141 | ||
142 | rm -rf "$MKFS_TAR.dupl" "$MKFS_TAR.uniq" "$TMPFILE.cmd1" "$TMPFILE.cmd2" "$TMPFILE.log" | |
143 | unset MKFS_TAR MKFS_DIR OUT EXP |