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)"
17 ../imagex $@ > /dev/null
21 if ! fusermount -z -u $1; then
22 error "Failed to unmount \"$1\""
27 if mountpoint $1 &> /dev/null; then
34 if [ -z "$options" ]; then
35 options="no_def_opts,silent"
37 options="$options,no_def_opts,silent"
39 if ! ntfs-3g -o $options $1 $2; then
40 error "Could not mount NTFS volume \"$1\" on \"$2\"! Make sure ntfs-3g is "\
41 "installed, and that you are either running the tests as root or have ntfs-3g "\
42 "installed setuid root, so that we can mount a NTFS volume."
52 if ! mkntfs --force --fast $1 &> /dev/null; then
53 error "Could not create NTFS volume \"$1\"! Make sure ntfsprogs are installed."
58 echo "Creating NTFS volumes and empty directories to use as mountpoints"
59 dd if=/dev/zero of=in.ntfs bs=4096 count=500 &> /dev/null
60 dd if=/dev/zero of=out.ntfs bs=4096 count=500 &> /dev/null
64 do_mount in.ntfs in.mnt
70 rm -rf in.ntfs out.ntfs in.mnt out.mnt in.xattr out.xattr ntfs.wim
76 echo "****************************************************************"
78 while [ $# -gt 0 ]; do
82 echo "****************************************************************"
91 if ! imagex capture in.ntfs ntfs.wim; then
92 error "Failed to capture NTFS volume into a WIM"
94 if ! imagex apply ntfs.wim 1 out.ntfs; then
95 error "Failed to apply WIM to NTFS volume"
97 __do_mount in.ntfs in.mnt noatime
98 __do_mount out.ntfs out.mnt noatime
99 if [ -x /usr/bin/tree ]; then
100 tree in.mnt --inodes -F -s --noreport
102 if ! ./tree-cmp in.mnt out.mnt NTFS; then
103 if [ -x /usr/bin/tree ]; then
104 echo "Dumping tree of applied image"
105 tree out.mnt --inodes -F -s --noreport
106 error 'Information was lost or corrupted while capturing
107 and then applying a NTFS volume'
110 rm -rf out.mnt/* in.mnt/*
114 echo "--------------------------------------------------------------------"
115 echo "Testing image capture and application of NTFS volume containing $1"
116 echo "--------------------------------------------------------------------"
122 msg "Empty NTFS volume"
126 do_test "echo 1 > file"
128 msg "a single directory"
131 msg "subdirectory with file"
132 do_test "mkdir dir; echo 1 > dir/file"
135 do_test "echo -n > empty_file"
137 msg "two empty files"
138 do_test "echo -n > empty_file_1; echo -n > empty_file_2"
140 msg "hard link in same directory"
141 do_test "echo 1 > file; ln file link"
143 msg "hard link between empty files"
144 do_test "echo -n > empty_file; ln empty_file link"
146 msg "relative symbolic link"
147 do_test "echo 1 > file; ln -s file symlink"
149 msg "absolute symbolic link"
150 do_test "echo 1 > file; ln -s /some/absolute/target symlink"
153 do_test "dd if=/dev/zero of=file bs=4096 count=10 &> /dev/null"
155 msg "file with DOS name"
156 do_test "echo 1 > file; setfattr -v file -n system.ntfs_dos_name file"
158 msg "file with DOS name with alphabetically smaller hardlink in same directory"
159 do_test "echo 1 > file; setfattr -v file -n system.ntfs_dos_name file; ln file aaa_link"
161 msg "file with DOS name with alphabetically larger hardlink in same directory"
162 do_test "echo 1 > file; setfattr -v file -n system.ntfs_dos_name file; ln file zzz_link"
164 msg "file with long name and with DOS name with alphabetically smaller hardlink in same directory"
165 do_test 'echo 1 > file_with_a_long_name;
166 setfattr -v "file~1" -n system.ntfs_dos_name file_with_a_long_name;
167 ln file_with_a_long_name aaa_link'
169 msg "many nested directories"
170 do_test 'mkdir dir; mkdir dir/subdir; mkdir dir/subdir/subdir2; mkdir dir/subdir/subdir3'
172 msg "identical files and symlinks in subdirectory"
175 echo 888 > dir/idfile2;
176 ln -s ../dir dir/circle; ln -s file dir/filelink'
178 msg "hard link group and identical files not hard linked"
179 do_test 'echo 888 > file;
185 msg "file with named data stream"
186 do_test 'echo 1 > file;
187 setfattr -n user.ads -v 2 file'
189 msg "file with multiple named data streams"
190 do_test 'echo 1 > file;
191 setfattr -n user.a -v 1 file;
192 setfattr -n user.aa -v 11 file;
193 setfattr -n user.aaa -v 111 file;
194 setfattr -n user.aaaa -v 1111 file'
196 msg "file with multiple named data streams with same contents"
197 do_test 'echo 1 > file;
198 setfattr -n user.a -v 1111 file;
199 setfattr -n user.aa -v 1111 file;
200 setfattr -n user.aaa -v 1111 file;
201 setfattr -n user.aaaa -v 1111 file;'
203 msg "file with named data streams with same contents as other file"
204 do_test 'echo -n > file;
205 setfattr -n user.a -v 1111 file;
206 echo -n 1111 > otherfile;'
208 msg "file with empty named data stream and non-empty unnamed data stream"
209 do_test 'echo 1 > file;
210 setfattr -n user.ads -v "" file;'
212 msg "file with empty named data stream and empty unnamed data stream"
213 do_test 'echo -n > file;
214 setfattr -n user.ads -v "" file;'
216 msg "file with named data stream with hardlink"
217 do_test 'echo 999 > file;
218 setfattr -n user.ads -v "888" file;
221 msg "file with named data stream with hardlink and DOS name"
222 do_test 'echo 999 > file;
223 setfattr -n user.ads -v "888" file;
225 setfattr -v DOSNAME -n system.ntfs_dos_name file;'
227 msg "C source code of wimlib"
228 do_test 'cp $srcdir/src/*.{c,h} .'
230 msg "file with security descriptor"
232 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` file'
234 msg "files with different security descriptors"
237 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` file
238 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_2.base64` file'
240 msg "files with different security descriptors and some with the same security descriptor"
245 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` file
246 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_2.base64` file
247 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` dir
248 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` file3'
250 msg "tons of random stuff"
251 do_test 'echo -n 8 > file;
253 ln -s hardlink symlink;
254 echo -n 8 > identical file;
255 dd if=/dev/urandom of=randomfile bs=4096 count=10 &>/dev/null;
257 setfattr -n system.ntfs_dos_name -v DOSNAME dir;
258 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` dir
261 ln file anotherdir/anotherhardlink;
262 ln -s .. anotherdir/anothersymlink;
263 ln -s anothersymlink anotherdir/symlinktosymlink;
264 echo -n 33 > anotherfile;
265 setfattr -n user.ads anotherfile -v 33;
266 setfattr -n user.ads2 anotherfile -v 8;
267 setfattr -n user.ads3 anotherfile -v 33;
269 setfattr -n user.ads emptyfile -v 8;
270 setfattr -n user.ads5 emptyfile -v"`cat $srcdir/src/hardlink.c`"
272 ln file dir/subdir/file;
273 echo -n 8 > dir/subdir/file2;
274 ln dir/subdir/file dir/subdir/link;
275 setfattr -n system.ntfs_dos_name -v 123 dir/subdir/link;
276 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` dir/subdir/link;
277 setfattr -n user.yet_another_ads -v "" dir/subdir/link;
278 setfattr -n user.yet_another_ads2 -v "" dir/subdir/link;
279 setfattr -n user.yet_another_ads3 -v "abc" dir/subdir/link;
280 setfattr -n user.yet_another_ads4 -v "" dir/subdir/link;'
284 echo "**********************************************************"
285 echo " NTFS capture/apply tests passed "
286 echo "**********************************************************"