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="${srcdir:-.}/.."
14 srcdir="$(cd $srcdir; pwd)"
15 . "$srcdir/tests/tests-common.sh"
17 TEST_SUBDIR=tmpdir_test-imagex-ntfs
20 for ((i = 0; i < 10; i++)); do
21 if fusermount -z -u $1; then
27 error "Failed to unmount \"$1\""
31 if mountpoint $1 &> /dev/null; then
43 if ! ntfs-3g -o "no_def_opts,silent" $1 $2; then
44 if [ $UID -ne 0 ] && [ "$3" = "nofail" ]; then
45 echo "WARNING: skipping NTFS tests because we aren't able to "
46 echo "mount an NTFS volume (perhaps ntfs-3g is not installed setuid root?)"
49 error "Could not mount NTFS volume \"$1\" on \"$2\"! Make sure ntfs-3g is "\
50 "installed, and that you are either running the tests as root or have ntfs-3g "\
51 "installed setuid root, so that we can mount an NTFS volume."
62 if ! mkntfs --force --fast $1 > /dev/null; then
63 error "Could not create NTFS volume \"$1\"! Make sure ntfsprogs are installed."
68 echo "Creating NTFS volumes and empty directories to use as mountpoints"
69 dd if=/dev/zero of=in.ntfs bs=4096 count=1000 &> /dev/null
70 dd if=/dev/zero of=out.ntfs bs=4096 count=1000 &> /dev/null
74 do_mount in.ntfs in.mnt nofail
78 do_unmount $TEST_SUBDIR/in.mnt
79 do_unmount $TEST_SUBDIR/out.mnt
88 if ! imagex capture in.ntfs ntfs.wim; then
89 error "Failed to capture NTFS volume into a WIM"
91 if ! imagex apply ntfs.wim 1 out.ntfs; then
92 error "Failed to apply WIM to NTFS volume"
94 __do_mount in.ntfs in.mnt noatime
95 __do_mount out.ntfs out.mnt noatime
96 if [ -x /usr/bin/tree ]; then
97 tree in.mnt --inodes -F -s --noreport
99 if ! ../tree-cmp in.mnt out.mnt NTFS; then
100 if [ -x /usr/bin/tree ]; then
101 echo "Dumping tree of applied image"
102 tree out.mnt --inodes -F -s --noreport
103 error 'Information was lost or corrupted while capturing
104 and then applying an NTFS volume'
107 rm -rf out.mnt/* in.mnt/*
111 echo "--------------------------------------------------------------------"
112 echo "Testing image capture and application of NTFS volume containing $1"
113 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 # To be replaced/removed: files with DOS names can no longer be hard linked as
158 # of NTFS-3g 2013.1.13.
160 #msg "file with DOS name with alphabetically smaller hardlink in same directory"
161 #do_test "echo 1 > file; setfattr -v file -n system.ntfs_dos_name file; ln file aaa_link"
163 #msg "file with DOS name with alphabetically larger hardlink in same directory"
164 #do_test "echo 1 > file; setfattr -v file -n system.ntfs_dos_name file; ln file zzz_link"
166 #msg "file with long name and with DOS name with alphabetically smaller hardlink in same directory"
167 #do_test 'echo 1 > file_with_a_long_name;
168 #setfattr -v "file~1" -n system.ntfs_dos_name file_with_a_long_name;
169 #ln file_with_a_long_name aaa_link'
171 msg "many nested directories"
172 do_test 'mkdir dir; mkdir dir/subdir; mkdir dir/subdir/subdir2; mkdir dir/subdir/subdir3'
174 msg "identical files and symlinks in subdirectory"
177 echo 888 > dir/idfile2;
178 ln -s ../dir dir/circle; ln -s file dir/filelink'
180 msg "hard link group and identical files not hard linked"
181 do_test 'echo 888 > file;
187 msg "file with named data stream"
188 do_test 'echo 1 > file;
189 setfattr -n user.ads -v 2 file'
191 msg "file with multiple named data streams"
192 do_test 'echo 1 > file;
193 setfattr -n user.a -v 1 file;
194 setfattr -n user.aa -v 11 file;
195 setfattr -n user.aaa -v 111 file;
196 setfattr -n user.aaaa -v 1111 file'
198 msg "file with multiple named data streams with same contents"
199 do_test 'echo 1 > file;
200 setfattr -n user.a -v 1111 file;
201 setfattr -n user.aa -v 1111 file;
202 setfattr -n user.aaa -v 1111 file;
203 setfattr -n user.aaaa -v 1111 file;'
205 msg "file with named data streams with same contents as other file"
206 do_test 'echo -n > file;
207 setfattr -n user.a -v 1111 file;
208 echo -n 1111 > otherfile;'
210 msg "file with empty named data stream and non-empty unnamed data stream"
211 do_test 'echo 1 > file;
212 setfattr -n user.ads -v "" file;'
214 msg "file with empty named data stream and empty unnamed data stream"
215 do_test 'echo -n > file;
216 setfattr -n user.ads -v "" file;'
218 msg "file with named data stream with hardlink"
219 do_test 'echo 999 > file;
220 setfattr -n user.ads -v "888" file;
223 # To be replaced/removed: files with DOS names can no longer be hard linked as
224 # of NTFS-3g 2013.1.13.
226 #msg "file with named data stream with hardlink and DOS name"
227 #do_test 'echo 999 > file;
228 #setfattr -n user.ads -v "888" file;
230 #setfattr -v DOSNAME -n system.ntfs_dos_name file;'
232 msg "C source code of wimlib"
233 do_test 'cp $srcdir/src/*.c .'
235 msg "file with security descriptor"
237 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` file'
239 msg "files with different security descriptors"
242 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` file
243 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_2.base64` file'
245 msg "files with different security descriptors and some with the same security descriptor"
250 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` file
251 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_2.base64` file
252 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` dir
253 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` file3'
255 msg "tons of random stuff"
256 do_test 'echo -n 8 > file;
258 ln -s hardlink symlink;
259 echo -n 8 > identical file;
260 dd if=/dev/urandom of=randomfile bs=4096 count=10 &>/dev/null;
262 setfattr -n system.ntfs_dos_name -v DOSNAME dir;
263 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` dir
266 ln file anotherdir/anotherhardlink;
267 ln -s .. anotherdir/anothersymlink;
268 ln -s anothersymlink anotherdir/symlinktosymlink;
269 echo -n 33 > anotherfile;
270 setfattr -n user.ads anotherfile -v 33;
271 setfattr -n user.ads2 anotherfile -v 8;
272 setfattr -n user.ads3 anotherfile -v 33;
274 setfattr -n user.ads emptyfile -v 8;
275 setfattr -n user.ads5 emptyfile -v"`cat $srcdir/src/sha1.c`"
277 ln file dir/subdir/file;
278 echo -n 8 > dir/subdir/file2;
279 ln dir/subdir/file dir/subdir/link;
280 echo -n > dir/subdir/empty;
281 setfattr -n system.ntfs_dos_name -v 123 dir/subdir/empty;
282 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` dir/subdir/link;
283 setfattr -n user.yet_another_ads -v "" dir/subdir/link;
284 setfattr -n user.yet_another_ads2 -v "" dir/subdir/link;
285 setfattr -n user.yet_another_ads3 -v "abc" dir/subdir/link;
286 setfattr -n user.yet_another_ads4 -v "" dir/subdir/link;'
288 echo "**********************************************************"
289 echo " NTFS capture/apply tests passed "
290 echo "**********************************************************"