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
16 ../imagex $@ > /dev/null
20 if ! fusermount -u $1; then
21 error "Failed to unmount \"$1\""
26 if mountpoint $1 &> /dev/null; then
33 if [ -z "$options" ]; then
34 options="no_def_opts,silent"
36 options="$options,no_def_opts,silent"
38 if ! ntfs-3g -o $options $1 $2; then
39 error "Could not mount NTFS volume \"$1\" on \"$2\"! Make sure ntfs-3g is "\
40 "installed, and that you are either running the tests as root or have ntfs-3g "\
41 "installed setuid root, so that we can mount a NTFS volume."
51 if ! mkntfs --force --fast $1 &> /dev/null; then
52 error "Could not create NTFS volume \"$1\"! Make sure ntfsprogs are installed."
57 echo "Creating NTFS volumes and empty directories to use as mountpoints"
58 dd if=/dev/zero of=in.ntfs bs=4096 count=500 &> /dev/null
59 dd if=/dev/zero of=out.ntfs bs=4096 count=500 &> /dev/null
63 do_mount in.ntfs in.mnt
69 rm -rf in.ntfs out.ntfs in.mnt out.mnt in.xattr out.xattr ntfs.wim
75 echo "****************************************************************"
77 while [ $# -gt 0 ]; do
81 echo "****************************************************************"
90 if ! imagex capture in.ntfs ntfs.wim; then
91 error "Failed to capture NTFS volume into a WIM"
93 if ! imagex apply ntfs.wim 1 out.ntfs; then
94 error "Failed to apply WIM to NTFS volume"
96 __do_mount in.ntfs in.mnt noatime
97 __do_mount out.ntfs out.mnt noatime
98 if [ -x /usr/bin/tree ]; then
99 tree in.mnt --inodes -F -s --noreport
101 if ! ./tree-cmp in.mnt out.mnt NTFS; then
102 if [ -x /usr/bin/tree ]; then
103 echo "Dumping tree of applied image"
104 tree out.mnt --inodes -F -s --noreport
105 error 'Information was lost or corrupted while capturing
106 and then applying a NTFS volume'
109 rm -rf out.mnt/* in.mnt/*
113 echo "--------------------------------------------------------------------"
114 echo "Testing image capture and application of NTFS volume containing $1"
115 echo "--------------------------------------------------------------------"
121 msg "Empty NTFS volume"
125 do_test "echo 1 > file"
127 msg "a single directory"
130 msg "subdirectory with file"
131 do_test "mkdir dir; echo 1 > dir/file"
134 do_test "echo -n > empty_file"
136 msg "two empty files"
137 do_test "echo -n > empty_file_1; echo -n > empty_file_2"
139 msg "hard link in same directory"
140 do_test "echo 1 > file; ln file link"
142 msg "hard link between empty files"
143 do_test "echo -n > empty_file; ln empty_file link"
145 msg "relative symbolic link"
146 do_test "echo 1 > file; ln -s file symlink"
148 msg "absolute symbolic link"
149 do_test "echo 1 > file; ln -s /some/absolute/target symlink"
152 do_test "dd if=/dev/zero of=file bs=4096 count=10 &> /dev/null"
154 msg "file with DOS name"
155 do_test "echo 1 > file; setfattr -v file -n system.ntfs_dos_name file"
157 msg "file with DOS name with alphabetically smaller hardlink in same directory"
158 do_test "echo 1 > file; setfattr -v file -n system.ntfs_dos_name file; ln file aaa_link"
160 msg "file with DOS name with alphabetically larger hardlink in same directory"
161 do_test "echo 1 > file; setfattr -v file -n system.ntfs_dos_name file; ln file zzz_link"
163 msg "file with long name and with DOS name with alphabetically smaller hardlink in same directory"
164 do_test 'echo 1 > file_with_a_long_name;
165 setfattr -v "file~1" -n system.ntfs_dos_name file_with_a_long_name;
166 ln file_with_a_long_name aaa_link'
168 msg "many nested directories"
169 do_test 'mkdir dir; mkdir dir/subdir; mkdir dir/subdir/subdir2; mkdir dir/subdir/subdir3'
171 msg "identical files and symlinks in subdirectory"
174 echo 888 > dir/idfile2;
175 ln -s ../dir dir/circle; ln -s file dir/filelink'
177 msg "hard link group and identical files not hard linked"
178 do_test 'echo 888 > file;
184 msg "file with named data stream"
185 do_test 'echo 1 > file;
186 setfattr -n user.ads -v 2 file'
188 msg "file with multiple named data streams"
189 do_test 'echo 1 > file;
190 setfattr -n user.a -v 1 file;
191 setfattr -n user.aa -v 11 file;
192 setfattr -n user.aaa -v 111 file;
193 setfattr -n user.aaaa -v 1111 file'
195 msg "file with multiple named data streams with same contents"
196 do_test 'echo 1 > file;
197 setfattr -n user.a -v 1111 file;
198 setfattr -n user.aa -v 1111 file;
199 setfattr -n user.aaa -v 1111 file;
200 setfattr -n user.aaaa -v 1111 file;'
202 msg "file with named data streams with same contents as other file"
203 do_test 'echo -n > file;
204 setfattr -n user.a -v 1111 file;
205 echo -n 1111 > otherfile;'
207 msg "file with empty named data stream and non-empty unnamed data stream"
208 do_test 'echo 1 > file;
209 setfattr -n user.ads -v "" file;'
211 msg "file with empty named data stream and empty unnamed data stream"
212 do_test 'echo -n > file;
213 setfattr -n user.ads -v "" file;'
215 msg "file with named data stream with hardlink"
216 do_test 'echo 999 > file;
217 setfattr -n user.ads -v "888" file;
220 msg "file with named data stream with hardlink and DOS name"
221 do_test 'echo 999 > file;
222 setfattr -n user.ads -v "888" file;
224 setfattr -v DOSNAME -n system.ntfs_dos_name file;'
226 msg "C source code of wimlib"
227 do_test 'cp $srcdir/src/*.{c,h} .'
229 msg "file with security descriptor"
231 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` file'
233 msg "files with different security descriptors"
236 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` file
237 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_2.base64` file'
239 msg "files with different security descriptors and some with the same security descriptor"
244 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` file
245 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_2.base64` file
246 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` dir
247 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` file3'
249 msg "tons of random stuff"
250 do_test 'echo -n 8 > file;
252 ln -s hardlink symlink;
253 echo -n 8 > identical file;
254 dd if=/dev/urandom of=randomfile bs=4096 count=10 &>/dev/null;
256 setfattr -n system.ntfs_dos_name -v DOSNAME dir;
257 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` dir
260 ln file anotherdir/anotherhardlink;
261 ln -s .. anotherdir/anothersymlink;
262 ln -s anothersymlink anotherdir/symlinktosymlink;
263 echo -n 33 > anotherfile;
264 setfattr -n user.ads anotherfile -v 33;
265 setfattr -n user.ads2 anotherfile -v 8;
266 setfattr -n user.ads3 anotherfile -v 33;
268 setfattr -n user.ads emptyfile -v 8;
269 setfattr -n user.ads5 emptyfile -v"`cat $srcdir/src/hardlink.c`"
271 ln file dir/subdir/file;
272 echo -n 8 > dir/subdir/file2;
273 ln dir/subdir/file dir/subdir/link;
274 setfattr -n system.ntfs_dos_name -v 123 dir/subdir/link;
275 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` dir/subdir/link;
276 setfattr -n user.yet_another_ads -v "" dir/subdir/link;
277 setfattr -n user.yet_another_ads2 -v "" dir/subdir/link;
278 setfattr -n user.yet_another_ads3 -v "abc" dir/subdir/link;
279 setfattr -n user.yet_another_ads4 -v "" dir/subdir/link;'
283 echo "**********************************************************"
284 echo " NTFS capture/apply tests passed "
285 echo "**********************************************************"