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 ! ntfs-3g ${options:+-o $options} $1 $2; then
35 error "Could not mount NTFS volume \"$1\" on \"$2\". Make sure ntfs-3g is installed."
45 if ! mkntfs --force --fast $1 &> /dev/null; then
46 error "Could not create NTFS volume on \"$1\". Make sure ntfs-3g / ntfsprogs are installed"
51 echo "Creating NTFS volumes and empty directories to use as mountpoints"
52 dd if=/dev/zero of=in.ntfs bs=4096 count=500 &> /dev/null
53 dd if=/dev/zero of=out.ntfs bs=4096 count=500 &> /dev/null
57 do_mount in.ntfs in.mnt
63 rm -rf in.ntfs out.ntfs in.mnt out.mnt in.xattr out.xattr ntfs.wim
69 echo "****************************************************************"
72 echo "****************************************************************"
81 if ! imagex capture in.ntfs ntfs.wim; then
82 error "Failed to capture NTFS volume into a WIM"
84 if ! imagex apply ntfs.wim 1 out.ntfs; then
85 error "Failed to apply WIM to NTFS volume"
87 __do_mount in.ntfs in.mnt noatime
88 __do_mount out.ntfs out.mnt noatime
89 if [ -x /usr/bin/tree ]; then
90 tree in.mnt --inodes -F -s --noreport
92 if ! ./tree-cmp in.mnt out.mnt NTFS; then
93 if [ -x /usr/bin/tree ]; then
94 echo "Dumping tree of applied image"
95 tree out.mnt --inodes -F -s --noreport
96 error 'Information was lost or corrupted while capturing
97 and then applying a NTFS volume'
100 rm -rf out.mnt/* in.mnt/*
104 echo "--------------------------------------------------------------------"
105 echo "Testing image capture and application of NTFS volume containing $1"
106 echo "--------------------------------------------------------------------"
112 msg "Empty NTFS volume"
115 msg "NTFS volume containing a single file"
116 do_test "echo 1 > file"
118 msg "NTFS volume containing a single directory"
121 msg "NTFS volume containing subdirectory with file"
122 do_test "mkdir dir; echo 1 > dir/file"
124 msg "NTFS volume containing empty file"
125 do_test "echo -n > empty_file"
127 msg "NTFS volume containing two empty files"
128 do_test "echo -n > empty_file_1; echo -n > empty_file_2"
130 msg "NTFS volume containing hard link in same directory"
131 do_test "echo 1 > file; ln file link"
133 msg "NTFS volume containing hard link between empty files"
134 do_test "echo -n > empty_file; ln empty_file link"
136 msg "NTFS volume containing relative symbolic link"
137 do_test "echo 1 > file; ln -s file symlink"
139 msg "NTFS volume containing absolute symbolic link"
140 do_test "echo 1 > file; ln -s /some/absolute/target symlink"
142 msg "NTFS volume containing large file"
143 do_test "dd if=/dev/zero of=file bs=4096 count=10 &> /dev/null"
145 msg "NTFS volume containing file with DOS name"
146 do_test "echo 1 > file; setfattr -v file -n system.ntfs_dos_name file"
148 msg "NTFS volume containing file with DOS name with alphabetically smaller hardlink in same directory"
149 do_test "echo 1 > file; setfattr -v file -n system.ntfs_dos_name file; ln file aaa_link"
151 msg "NTFS volume containing file with DOS name with alphabetically larger hardlink in same directory"
152 do_test "echo 1 > file; setfattr -v file -n system.ntfs_dos_name file; ln file zzz_link"
154 msg "NTFS volume containing file with long name and with DOS name with alphabetically smaller hardlink in same directory"
155 do_test 'echo 1 > file_with_a_long_name;
156 setfattr -v "file~1" -n system.ntfs_dos_name file_with_a_long_name;
157 ln file_with_a_long_name aaa_link'
159 msg "NTFS volume containing many nested directories"
160 do_test 'mkdir dir; mkdir dir/subdir; mkdir dir/subdir/subdir2; mkdir dir/subdir/subdir3'
162 msg "NTFS volume containing identical files and symlinks in subdirectory"
165 echo 888 > dir/idfile2;
166 ln -s ../dir dir/circle; ln -s file dir/filelink'
168 msg "NTFS volume containing hard link group and identical files not hard linked"
169 do_test 'echo 888 > file;
175 msg "NTFS volume containing file with named data stream"
176 do_test 'echo 1 > file;
177 setfattr -n user.ads -v 2 file'
179 msg "NTFS volume containing file with multiple named data streams"
180 do_test 'echo 1 > file;
181 setfattr -n user.a -v 1 file;
182 setfattr -n user.aa -v 11 file;
183 setfattr -n user.aaa -v 111 file;
184 setfattr -n user.aaaa -v 1111 file'
186 msg "NTFS volume containing file with multiple named data streams with same contents"
187 do_test 'echo 1 > file;
188 setfattr -n user.a -v 1111 file;
189 setfattr -n user.aa -v 1111 file;
190 setfattr -n user.aaa -v 1111 file;
191 setfattr -n user.aaaa -v 1111 file;'
193 msg "NTFS volume containing file with named data streams with same contents as other file"
194 do_test 'echo -n > file;
195 setfattr -n user.a -v 1111 file;
196 echo -n 1111 > otherfile;'
198 msg "NTFS volume containing file with empty named data stream and non-empty unnamed data stream"
199 do_test 'echo 1 > file;
200 setfattr -n user.ads -v "" file;'
202 msg "NTFS volume containing file with empty named data stream and empty unnamed data stream"
203 do_test 'echo -n > file;
204 setfattr -n user.ads -v "" file;'
206 msg "NTFS volume containing file with named data stream with hardlink"
207 do_test 'echo 999 > file;
208 setfattr -n user.ads -v "888" file;
211 msg "NTFS volume containing file with named data stream with hardlink and DOS name"
212 do_test 'echo 999 > file;
213 setfattr -n user.ads -v "888" file;
215 setfattr -v DOSNAME -n system.ntfs_dos_name file;'
217 msg "NTFS volume containing C source code of wimlib"
218 do_test 'cp $srcdir/src/*.{c,h} .'
220 msg "NTFS volume containing file with security descriptor"
222 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` file'
224 msg "NTFS volume containing files with different security descriptors"
227 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` file
228 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_2.base64` file'
230 msg "NTFS volume containing files with different security descriptors and some with the same security descriptor"
235 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` file
236 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_2.base64` file
237 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` dir
238 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` file3'
240 msg "NTFS volume containing tons of random stuff"
241 do_test 'echo -n 8 > file;
243 ln -s hardlink symlink;
244 echo -n 8 > identical file;
245 dd if=/dev/urandom of=randomfile bs=4096 count=10 &>/dev/null;
247 setfattr -n system.ntfs_dos_name -v DOSNAME dir;
248 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` dir
251 ln file anotherdir/anotherhardlink;
252 ln -s .. anotherdir/anothersymlink;
253 ln -s anothersymlink anotherdir/symlinktosymlink;
254 echo -n 33 > anotherfile;
255 setfattr -n user.ads anotherfile -v 33;
256 setfattr -n user.ads2 anotherfile -v 8;
257 setfattr -n user.ads3 anotherfile -v 33;
259 setfattr -n user.ads emptyfile -v 8;
260 setfattr -n user.ads5 emptyfile -v"`cat $srcdir/src/hardlink.c`"
262 ln file dir/subdir/file;
263 echo -n 8 > dir/subdir/file2;
264 ln dir/subdir/file dir/subdir/link;
265 setfattr -n system.ntfs_dos_name -v 123 dir/subdir/link;
266 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` dir/subdir/link;
267 setfattr -n user.yet_another_ads -v "" dir/subdir/link;
268 setfattr -n user.yet_another_ads2 -v "" dir/subdir/link;
269 setfattr -n user.yet_another_ads3 -v "abc" dir/subdir/link;
270 setfattr -n user.yet_another_ads4 -v "" dir/subdir/link;'
274 echo "**********************************************************"
275 echo " NTFS capture/apply tests passed "
276 echo "**********************************************************"