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 # Assume an in-tree build.
13 ../imagex $@ > /dev/null
17 if ! fusermount -u $1; then
18 error "Failed to unmount \"$1\""
23 if mountpoint $1 &> /dev/null; then
30 if ! ntfs-3g ${options:+-o $options} $1 $2; then
31 error "Could not mount NTFS volume \"$1\" on \"$2\". Make sure ntfs-3g is installed."
41 if ! mkntfs --force --fast $1 &> /dev/null; then
42 error "Could not create NTFS volume on \"$1\". Make sure ntfs-3g / ntfsprogs are installed"
47 echo "Creating NTFS volumes and empty directories to use as mountpoints"
48 dd if=/dev/zero of=in.ntfs bs=4096 count=500 &> /dev/null
49 dd if=/dev/zero of=out.ntfs bs=4096 count=500 &> /dev/null
53 do_mount in.ntfs in.mnt
59 rm -rf in.ntfs out.ntfs in.mnt out.mnt in.xattr out.xattr
65 echo "****************************************************************"
68 echo "****************************************************************"
77 if ! imagex capture in.ntfs ntfs.wim; then
78 error "Failed to capture NTFS volume into a WIM"
80 if ! imagex apply ntfs.wim 1 out.ntfs; then
81 error "Failed to apply WIM to NTFS volume"
83 __do_mount in.ntfs in.mnt noatime
84 __do_mount out.ntfs out.mnt noatime
85 if [ -x /usr/bin/tree ]; then
86 tree in.mnt --inodes -F -s --noreport
88 if ! ./ntfs-cmp in.mnt out.mnt; then
89 if [ -x /usr/bin/tree ]; then
90 echo "Dumping tree of applied image"
91 tree out.mnt --inodes -F -s --noreport
92 error 'Information was lost or corrupted while capturing
93 and then applying a NTFS volume'
96 rm -rf out.mnt/* in.mnt/*
100 echo "Testing image capture and application of $1"
106 msg "Empty NTFS volume"
109 msg "NTFS volume containing a single file"
110 do_test "echo 1 > file"
112 msg "NTFS volume containing a single directory"
115 msg "NTFS volume containing subdirectory with file"
116 do_test "mkdir dir; echo 1 > dir/file"
118 msg "NTFS volume containing empty file"
119 do_test "echo -n > empty_file"
121 msg "NTFS volume containing two empty files"
122 do_test "echo -n > empty_file_1; echo -n > empty_file_2"
124 msg "NTFS volume containing hard link in same directory"
125 do_test "echo 1 > file; ln file link"
127 msg "NTFS volume containing hard link between empty files"
128 do_test "echo -n > empty_file; ln empty_file link"
130 msg "NTFS volume containing relative symbolic link"
131 do_test "echo 1 > file; ln -s file symlink"
133 msg "NTFS volume containing absolute symbolic link"
134 do_test "echo 1 > file; ln -s /some/absolute/target symlink"
136 msg "NTFS volume containing large file"
137 do_test "dd if=/dev/zero of=file bs=4096 count=10 &> /dev/null"
139 msg "NTFS volume containing file with DOS name"
140 do_test "echo 1 > file; setfattr -v file -n system.ntfs_dos_name file"
142 msg "NTFS volume containing file with DOS name with alphabetically smaller hardlink in same directory"
143 do_test "echo 1 > file; setfattr -v file -n system.ntfs_dos_name file; ln file aaa_link"
145 msg "NTFS volume containing file with DOS name with alphabetically larger hardlink in same directory"
146 do_test "echo 1 > file; setfattr -v file -n system.ntfs_dos_name file; ln file zzz_link"
148 msg "NTFS volume containing file with long name and with DOS name with alphabetically smaller hardlink in same directory"
149 do_test 'echo 1 > file_with_a_long_name;
150 setfattr -v "file~1" -n system.ntfs_dos_name file_with_a_long_name;
151 ln file_with_a_long_name aaa_link'
153 msg "NTFS volume containing many nested directories"
154 do_test 'mkdir dir; mkdir dir/subdir; mkdir dir/subdir/subdir2; mkdir dir/subdir/subdir3'
156 msg "NTFS volume containing identical files and symlinks in subdirectory"
159 echo 888 > dir/idfile2;
160 ln -s ../dir dir/circle; ln -s file dir/filelink'
162 msg "NTFS volume containing hard link group and identical files not hard linked"
163 do_test 'echo 888 > file;
169 msg "NTFS volume containing file with named data stream"
170 do_test 'echo 1 > file;
171 setfattr -n user.ads -v 2 file'
173 msg "NTFS volume containing file with multiple named data streams"
174 do_test 'echo 1 > file;
175 setfattr -n user.a -v 1 file;
176 setfattr -n user.aa -v 11 file;
177 setfattr -n user.aaa -v 111 file;
178 setfattr -n user.aaaa -v 1111 file'
180 msg "NTFS volume containing file with multiple named data streams with same contents"
181 do_test 'echo 1 > file;
182 setfattr -n user.a -v 1111 file;
183 setfattr -n user.aa -v 1111 file;
184 setfattr -n user.aaa -v 1111 file;
185 setfattr -n user.aaaa -v 1111 file;'
187 msg "NTFS volume containing file with named data streams with same contents as other file"
188 do_test 'echo -n > file;
189 setfattr -n user.a -v 1111 file;
190 echo -n 1111 > otherfile;'
192 msg "NTFS volume containing file with empty named data stream and non-empty unnamed data stream"
193 do_test 'echo 1 > file;
194 setfattr -n user.ads -v "" file;'
196 msg "NTFS volume containing file with empty named data stream and empty unnamed data stream"
197 do_test 'echo -n > file;
198 setfattr -n user.ads -v "" file;'
200 msg "NTFS volume containing file with named data stream with hardlink"
201 do_test 'echo 999 > file;
202 setfattr -n user.ads -v "888" file;
205 msg "NTFS volume containing file with named data stream with hardlink and DOS name"
206 do_test 'echo 999 > file;
207 setfattr -n user.ads -v "888" file;
209 setfattr -v DOSNAME -n system.ntfs_dos_name file;'
211 msg "NTFS volume containing C source code of wimlib"
212 do_test 'cp ../../src/*.c ../../src/*.h .'
214 msg "NTFS volume containing file with security descriptor"
216 setfattr -n system.ntfs_acl -v 0s`cat ../security_descriptor_1.base64` file'
218 msg "NTFS volume containing files with different security descriptors"
221 setfattr -n system.ntfs_acl -v 0s`cat ../security_descriptor_1.base64` file
222 setfattr -n system.ntfs_acl -v 0s`cat ../security_descriptor_2.base64` file'
224 msg "NTFS volume containing files with different security descriptors and some with the same security descriptor"
229 setfattr -n system.ntfs_acl -v 0s`cat ../security_descriptor_1.base64` file
230 setfattr -n system.ntfs_acl -v 0s`cat ../security_descriptor_2.base64` file
231 setfattr -n system.ntfs_acl -v 0s`cat ../security_descriptor_1.base64` dir
232 setfattr -n system.ntfs_acl -v 0s`cat ../security_descriptor_1.base64` file3'
234 msg "NTFS volume containing tons of random stuff"
235 do_test 'echo -n 8 > file;
237 ln -s hardlink symlink;
238 echo -n 8 > identical file;
239 dd if=/dev/urandom of=randomfile bs=4096 count=10 &>/dev/null;
241 setfattr -n system.ntfs_dos_name -v DOSNAME dir;
242 setfattr -n system.ntfs_acl -v 0s`cat ../security_descriptor_1.base64` dir
245 ln file anotherdir/anotherhardlink;
246 ln -s .. anotherdir/anothersymlink;
247 ln -s anothersymlink anotherdir/symlinktosymlink;
248 echo -n 33 > anotherfile;
249 setfattr -n user.ads anotherfile -v 33;
250 setfattr -n user.ads2 anotherfile -v 8;
251 setfattr -n user.ads3 anotherfile -v 33;
253 setfattr -n user.ads emptyfile -v 8;
254 setfattr -n user.ads5 emptyfile -v"`cat ../../src/hardlink.c`"
256 ln file dir/subdir/file;
257 echo -n 8 > dir/subdir/file2;
258 ln dir/subdir/file dir/subdir/link;
259 setfattr -n system.ntfs_dos_name -v 123 dir/subdir/link;
260 setfattr -n system.ntfs_acl -v 0s`cat ../security_descriptor_1.base64` dir/subdir/link;
261 setfattr -n user.yet_another_ads -v "" dir/subdir/link;
262 setfattr -n user.yet_another_ads2 -v "" dir/subdir/link;
263 setfattr -n user.yet_another_ads3 -v "abc" dir/subdir/link;
264 setfattr -n user.yet_another_ads4 -v "" dir/subdir/link;'
266 echo "**********************************************************"
267 echo " NTFS capture/apply tests passed "
268 echo "**********************************************************"