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
12 srcdir=`realpath $srcdir`
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 ! ntfs-3g ${options:+-o $options} $1 $2; then
34 error "Could not mount NTFS volume \"$1\" on \"$2\". Make sure ntfs-3g is installed."
44 if ! mkntfs --force --fast $1 &> /dev/null; then
45 error "Could not create NTFS volume on \"$1\". Make sure ntfs-3g / ntfsprogs are installed"
50 echo "Creating NTFS volumes and empty directories to use as mountpoints"
51 dd if=/dev/zero of=in.ntfs bs=4096 count=500 &> /dev/null
52 dd if=/dev/zero of=out.ntfs bs=4096 count=500 &> /dev/null
56 do_mount in.ntfs in.mnt
62 rm -rf in.ntfs out.ntfs in.mnt out.mnt in.xattr out.xattr ntfs.wim
68 echo "****************************************************************"
71 echo "****************************************************************"
80 if ! imagex capture in.ntfs ntfs.wim; then
81 error "Failed to capture NTFS volume into a WIM"
83 if ! imagex apply ntfs.wim 1 out.ntfs; then
84 error "Failed to apply WIM to NTFS volume"
86 __do_mount in.ntfs in.mnt noatime
87 __do_mount out.ntfs out.mnt noatime
88 if [ -x /usr/bin/tree ]; then
89 tree in.mnt --inodes -F -s --noreport
91 if ! ./ntfs-cmp in.mnt out.mnt; then
92 if [ -x /usr/bin/tree ]; then
93 echo "Dumping tree of applied image"
94 tree out.mnt --inodes -F -s --noreport
95 error 'Information was lost or corrupted while capturing
96 and then applying a NTFS volume'
99 rm -rf out.mnt/* in.mnt/*
103 echo "Testing image capture and application of $1"
109 msg "Empty NTFS volume"
112 msg "NTFS volume containing a single file"
113 do_test "echo 1 > file"
115 msg "NTFS volume containing a single directory"
118 msg "NTFS volume containing subdirectory with file"
119 do_test "mkdir dir; echo 1 > dir/file"
121 msg "NTFS volume containing empty file"
122 do_test "echo -n > empty_file"
124 msg "NTFS volume containing two empty files"
125 do_test "echo -n > empty_file_1; echo -n > empty_file_2"
127 msg "NTFS volume containing hard link in same directory"
128 do_test "echo 1 > file; ln file link"
130 msg "NTFS volume containing hard link between empty files"
131 do_test "echo -n > empty_file; ln empty_file link"
133 msg "NTFS volume containing relative symbolic link"
134 do_test "echo 1 > file; ln -s file symlink"
136 msg "NTFS volume containing absolute symbolic link"
137 do_test "echo 1 > file; ln -s /some/absolute/target symlink"
139 msg "NTFS volume containing large file"
140 do_test "dd if=/dev/zero of=file bs=4096 count=10 &> /dev/null"
142 msg "NTFS volume containing file with DOS name"
143 do_test "echo 1 > file; setfattr -v file -n system.ntfs_dos_name file"
145 msg "NTFS volume containing file with DOS name with alphabetically smaller hardlink in same directory"
146 do_test "echo 1 > file; setfattr -v file -n system.ntfs_dos_name file; ln file aaa_link"
148 msg "NTFS volume containing file with DOS name with alphabetically larger hardlink in same directory"
149 do_test "echo 1 > file; setfattr -v file -n system.ntfs_dos_name file; ln file zzz_link"
151 msg "NTFS volume containing file with long name and with DOS name with alphabetically smaller hardlink in same directory"
152 do_test 'echo 1 > file_with_a_long_name;
153 setfattr -v "file~1" -n system.ntfs_dos_name file_with_a_long_name;
154 ln file_with_a_long_name aaa_link'
156 msg "NTFS volume containing many nested directories"
157 do_test 'mkdir dir; mkdir dir/subdir; mkdir dir/subdir/subdir2; mkdir dir/subdir/subdir3'
159 msg "NTFS volume containing identical files and symlinks in subdirectory"
162 echo 888 > dir/idfile2;
163 ln -s ../dir dir/circle; ln -s file dir/filelink'
165 msg "NTFS volume containing hard link group and identical files not hard linked"
166 do_test 'echo 888 > file;
172 msg "NTFS volume containing file with named data stream"
173 do_test 'echo 1 > file;
174 setfattr -n user.ads -v 2 file'
176 msg "NTFS volume containing file with multiple named data streams"
177 do_test 'echo 1 > file;
178 setfattr -n user.a -v 1 file;
179 setfattr -n user.aa -v 11 file;
180 setfattr -n user.aaa -v 111 file;
181 setfattr -n user.aaaa -v 1111 file'
183 msg "NTFS volume containing file with multiple named data streams with same contents"
184 do_test 'echo 1 > file;
185 setfattr -n user.a -v 1111 file;
186 setfattr -n user.aa -v 1111 file;
187 setfattr -n user.aaa -v 1111 file;
188 setfattr -n user.aaaa -v 1111 file;'
190 msg "NTFS volume containing file with named data streams with same contents as other file"
191 do_test 'echo -n > file;
192 setfattr -n user.a -v 1111 file;
193 echo -n 1111 > otherfile;'
195 msg "NTFS volume containing file with empty named data stream and non-empty unnamed data stream"
196 do_test 'echo 1 > file;
197 setfattr -n user.ads -v "" file;'
199 msg "NTFS volume containing file with empty named data stream and empty unnamed data stream"
200 do_test 'echo -n > file;
201 setfattr -n user.ads -v "" file;'
203 msg "NTFS volume containing file with named data stream with hardlink"
204 do_test 'echo 999 > file;
205 setfattr -n user.ads -v "888" file;
208 msg "NTFS volume containing file with named data stream with hardlink and DOS name"
209 do_test 'echo 999 > file;
210 setfattr -n user.ads -v "888" file;
212 setfattr -v DOSNAME -n system.ntfs_dos_name file;'
214 msg "NTFS volume containing C source code of wimlib"
215 do_test 'cp $srcdir/src/*.{c,h} .'
217 msg "NTFS volume containing file with security descriptor"
219 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` file'
221 msg "NTFS volume containing files with different security descriptors"
224 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` file
225 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_2.base64` file'
227 msg "NTFS volume containing files with different security descriptors and some with the same security descriptor"
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
234 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` dir
235 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` file3'
237 msg "NTFS volume containing tons of random stuff"
238 do_test 'echo -n 8 > file;
240 ln -s hardlink symlink;
241 echo -n 8 > identical file;
242 dd if=/dev/urandom of=randomfile bs=4096 count=10 &>/dev/null;
244 setfattr -n system.ntfs_dos_name -v DOSNAME dir;
245 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` dir
248 ln file anotherdir/anotherhardlink;
249 ln -s .. anotherdir/anothersymlink;
250 ln -s anothersymlink anotherdir/symlinktosymlink;
251 echo -n 33 > anotherfile;
252 setfattr -n user.ads anotherfile -v 33;
253 setfattr -n user.ads2 anotherfile -v 8;
254 setfattr -n user.ads3 anotherfile -v 33;
256 setfattr -n user.ads emptyfile -v 8;
257 setfattr -n user.ads5 emptyfile -v"`cat $srcdir/src/hardlink.c`"
259 ln file dir/subdir/file;
260 echo -n 8 > dir/subdir/file2;
261 ln dir/subdir/file dir/subdir/link;
262 setfattr -n system.ntfs_dos_name -v 123 dir/subdir/link;
263 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` dir/subdir/link;
264 setfattr -n user.yet_another_ads -v "" dir/subdir/link;
265 setfattr -n user.yet_another_ads2 -v "" dir/subdir/link;
266 setfattr -n user.yet_another_ads3 -v "abc" dir/subdir/link;
267 setfattr -n user.yet_another_ads4 -v "" dir/subdir/link;'
271 echo "**********************************************************"
272 echo " NTFS capture/apply tests passed "
273 echo "**********************************************************"