3 # This script does some sanity testing of the 'imagex' program, specifically
4 # checking the NTFS capture and apply features.
6 # This test will fail if wimlib was compiled with --without-ntfs-3g.
8 # Please note that cleanup is not done if a test fails, and NTFS volumes may
13 srcdir=`realpath $srcdir`
17 ../imagex $@ > /dev/null
21 if ! fusermount -u $1; then
22 error "Failed to unmount \"$1\""
27 if mountpoint $1 &> /dev/null; then
34 if [ -z "$options" ]; then
35 options="no_def_opts,silent"
37 options="$options,no_def_opts,silent"
39 if ! ntfs-3g -o $options $1 $2; then
40 error "Could not mount NTFS volume \"$1\" on \"$2\". Make sure ntfs-3g is installed."
50 if ! mkntfs --force --fast $1 &> /dev/null; then
51 error "Could not create NTFS volume on \"$1\". Make sure ntfs-3g / ntfsprogs are installed"
56 echo "Creating NTFS volumes and empty directories to use as mountpoints"
57 dd if=/dev/zero of=in.ntfs bs=4096 count=500 &> /dev/null
58 dd if=/dev/zero of=out.ntfs bs=4096 count=500 &> /dev/null
62 do_mount in.ntfs in.mnt
68 rm -rf in.ntfs out.ntfs in.mnt out.mnt in.xattr out.xattr ntfs.wim
74 echo "****************************************************************"
77 echo "****************************************************************"
86 if ! imagex capture in.ntfs ntfs.wim; then
87 error "Failed to capture NTFS volume into a WIM"
89 if ! imagex apply ntfs.wim 1 out.ntfs; then
90 error "Failed to apply WIM to NTFS volume"
92 __do_mount in.ntfs in.mnt noatime
93 __do_mount out.ntfs out.mnt noatime
94 if [ -x /usr/bin/tree ]; then
95 tree in.mnt --inodes -F -s --noreport
97 if ! ./tree-cmp in.mnt out.mnt NTFS; then
98 if [ -x /usr/bin/tree ]; then
99 echo "Dumping tree of applied image"
100 tree out.mnt --inodes -F -s --noreport
101 error 'Information was lost or corrupted while capturing
102 and then applying a NTFS volume'
105 rm -rf out.mnt/* in.mnt/*
109 echo "--------------------------------------------------------------------"
110 echo "Testing image capture and application of NTFS volume containing $1"
111 echo "--------------------------------------------------------------------"
117 msg "Empty NTFS volume"
121 do_test "echo 1 > file"
123 msg "a single directory"
126 msg "subdirectory with file"
127 do_test "mkdir dir; echo 1 > dir/file"
130 do_test "echo -n > empty_file"
132 msg "two empty files"
133 do_test "echo -n > empty_file_1; echo -n > empty_file_2"
135 msg "hard link in same directory"
136 do_test "echo 1 > file; ln file link"
138 msg "hard link between empty files"
139 do_test "echo -n > empty_file; ln empty_file link"
141 msg "relative symbolic link"
142 do_test "echo 1 > file; ln -s file symlink"
144 msg "absolute symbolic link"
145 do_test "echo 1 > file; ln -s /some/absolute/target symlink"
148 do_test "dd if=/dev/zero of=file bs=4096 count=10 &> /dev/null"
150 msg "file with DOS name"
151 do_test "echo 1 > file; setfattr -v file -n system.ntfs_dos_name file"
153 msg "file with DOS name with alphabetically smaller hardlink in same directory"
154 do_test "echo 1 > file; setfattr -v file -n system.ntfs_dos_name file; ln file aaa_link"
156 msg "file with DOS name with alphabetically larger hardlink in same directory"
157 do_test "echo 1 > file; setfattr -v file -n system.ntfs_dos_name file; ln file zzz_link"
159 msg "file with long name and with DOS name with alphabetically smaller hardlink in same directory"
160 do_test 'echo 1 > file_with_a_long_name;
161 setfattr -v "file~1" -n system.ntfs_dos_name file_with_a_long_name;
162 ln file_with_a_long_name aaa_link'
164 msg "many nested directories"
165 do_test 'mkdir dir; mkdir dir/subdir; mkdir dir/subdir/subdir2; mkdir dir/subdir/subdir3'
167 msg "identical files and symlinks in subdirectory"
170 echo 888 > dir/idfile2;
171 ln -s ../dir dir/circle; ln -s file dir/filelink'
173 msg "hard link group and identical files not hard linked"
174 do_test 'echo 888 > file;
180 msg "file with named data stream"
181 do_test 'echo 1 > file;
182 setfattr -n user.ads -v 2 file'
184 msg "file with multiple named data streams"
185 do_test 'echo 1 > file;
186 setfattr -n user.a -v 1 file;
187 setfattr -n user.aa -v 11 file;
188 setfattr -n user.aaa -v 111 file;
189 setfattr -n user.aaaa -v 1111 file'
191 msg "file with multiple named data streams with same contents"
192 do_test 'echo 1 > file;
193 setfattr -n user.a -v 1111 file;
194 setfattr -n user.aa -v 1111 file;
195 setfattr -n user.aaa -v 1111 file;
196 setfattr -n user.aaaa -v 1111 file;'
198 msg "file with named data streams with same contents as other file"
199 do_test 'echo -n > file;
200 setfattr -n user.a -v 1111 file;
201 echo -n 1111 > otherfile;'
203 msg "file with empty named data stream and non-empty unnamed data stream"
204 do_test 'echo 1 > file;
205 setfattr -n user.ads -v "" file;'
207 msg "file with empty named data stream and empty unnamed data stream"
208 do_test 'echo -n > file;
209 setfattr -n user.ads -v "" file;'
211 msg "file with named data stream with hardlink"
212 do_test 'echo 999 > file;
213 setfattr -n user.ads -v "888" file;
216 msg "file with named data stream with hardlink and DOS name"
217 do_test 'echo 999 > file;
218 setfattr -n user.ads -v "888" file;
220 setfattr -v DOSNAME -n system.ntfs_dos_name file;'
222 msg "C source code of wimlib"
223 do_test 'cp $srcdir/src/*.{c,h} .'
225 msg "file with security descriptor"
227 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` file'
229 msg "files with different security descriptors"
232 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` file
233 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_2.base64` file'
235 msg "files with different security descriptors and some with the same security descriptor"
240 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` file
241 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_2.base64` file
242 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` dir
243 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` file3'
245 msg "tons of random stuff"
246 do_test 'echo -n 8 > file;
248 ln -s hardlink symlink;
249 echo -n 8 > identical file;
250 dd if=/dev/urandom of=randomfile bs=4096 count=10 &>/dev/null;
252 setfattr -n system.ntfs_dos_name -v DOSNAME dir;
253 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` dir
256 ln file anotherdir/anotherhardlink;
257 ln -s .. anotherdir/anothersymlink;
258 ln -s anothersymlink anotherdir/symlinktosymlink;
259 echo -n 33 > anotherfile;
260 setfattr -n user.ads anotherfile -v 33;
261 setfattr -n user.ads2 anotherfile -v 8;
262 setfattr -n user.ads3 anotherfile -v 33;
264 setfattr -n user.ads emptyfile -v 8;
265 setfattr -n user.ads5 emptyfile -v"`cat $srcdir/src/hardlink.c`"
267 ln file dir/subdir/file;
268 echo -n 8 > dir/subdir/file2;
269 ln dir/subdir/file dir/subdir/link;
270 setfattr -n system.ntfs_dos_name -v 123 dir/subdir/link;
271 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` dir/subdir/link;
272 setfattr -n user.yet_another_ads -v "" dir/subdir/link;
273 setfattr -n user.yet_another_ads2 -v "" dir/subdir/link;
274 setfattr -n user.yet_another_ads3 -v "abc" dir/subdir/link;
275 setfattr -n user.yet_another_ads4 -v "" dir/subdir/link;'
279 echo "**********************************************************"
280 echo " NTFS capture/apply tests passed "
281 echo "**********************************************************"