]> git.ipfire.org Git - thirdparty/e2fsprogs.git/blame - tests/m_rootgnutar/script
mke2fs: the -d option can now handle tarball input
[thirdparty/e2fsprogs.git] / tests / m_rootgnutar / script
CommitLineData
7e3a4f0a
JSMR
1# vim: filetype=sh
2
3test_description="create fs image from GNU tarball"
4if ! test -x "$DEBUGFS_EXE"; then
5 echo "$test_name: $test_description: skipped (no debugfs)"
6 return 0
7fi
8if [ "$(grep -c 'define HAVE_ARCHIVE_H' ../lib/config.h)" -eq 0 ]; then
9 echo "$test_name: $test_description: skipped (no libarchive)"
10 exit 0
11fi
12
13MKFS_TAR="$TMPFILE.tar"
14MKFS_DIR="$TMPFILE.dir"
15OUT="$test_name.log"
16EXP="$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
20rm -rf "$MKFS_DIR"
21mkdir -p "$MKFS_DIR/test"
22touch "$MKFS_DIR/test/emptyfile"
23dd if=/dev/zero bs=1024 count=32 2> /dev/null | tr '\0' 'a' > "$MKFS_DIR/test/bigfile"
24dd if=/dev/zero of="$MKFS_DIR/test/zerofile" bs=1 count=1 seek=1024 2> /dev/null
25ln -s /silly_bs_link "$MKFS_DIR/test/silly_bs_link"
26mkdir "$MKFS_DIR/test/emptydir"
27mkdir "$MKFS_DIR/test/dir"
28echo "will be overwritten" > "$MKFS_DIR/test/dir/file"
29
30if 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
45else
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"
56fi
57
58rm -r "$MKFS_DIR"
59
60cat > "$TMPFILE.cmd1" << ENDL
61stat /test/emptyfile
62stat /test/bigfile
63stat /test/zerofile
64stat /test/silly_bs_link
65stat /test/emptydir
66stat /test/dir
67stat /test/dir/file
68ENDL
69
70cat > "$TMPFILE.cmd2" << ENDL
71ex /test/emptyfile
72ex /test/bigfile
73ex /test/zerofile
74ex /test/silly_bs_link
75ex /test/emptydir
76ex /test/dir
77ex /test/dir/file
78ENDL
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#
83for 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"
128done
129
130# Do the verification
131cmp -s "$OUT" "$EXP"
132status=$?
133
134if [ "$status" = 0 ] ; then
135 echo "$test_name: $test_description: ok"
136 touch "$test_name.ok"
137else
138 echo "$test_name: $test_description: failed"
139 diff $DIFF_OPTS "$EXP" "$OUT" > "$test_name.failed"
140fi
141
142rm -rf "$MKFS_TAR.dupl" "$MKFS_TAR.uniq" "$TMPFILE.cmd1" "$TMPFILE.cmd2" "$TMPFILE.log"
143unset MKFS_TAR MKFS_DIR OUT EXP