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 if ! fusermount -z -u $1; then
21 error "Failed to unmount \"$1\""
27 if mountpoint $1 &> /dev/null; then
39 if ! ntfs-3g -o "no_def_opts,silent" $1 $2; then
40 if [ $UID -ne 0 ] && [ "$3" = "nofail" ]; then
41 echo "WARNING: skipping NTFS tests because we aren't able to "
42 echo "mount a NTFS volume (perhaps ntfs-3g is not installed setuid root?)"
45 error "Could not mount NTFS volume \"$1\" on \"$2\"! Make sure ntfs-3g is "\
46 "installed, and that you are either running the tests as root or have ntfs-3g "\
47 "installed setuid root, so that we can mount a NTFS volume."
58 if ! mkntfs --force --fast $1 > /dev/null; then
59 error "Could not create NTFS volume \"$1\"! Make sure ntfsprogs are installed."
64 echo "Creating NTFS volumes and empty directories to use as mountpoints"
65 dd if=/dev/zero of=in.ntfs bs=4096 count=1000 &> /dev/null
66 dd if=/dev/zero of=out.ntfs bs=4096 count=1000 &> /dev/null
70 do_mount in.ntfs in.mnt nofail
74 do_unmount $TEST_SUBDIR/in.mnt
75 do_unmount $TEST_SUBDIR/out.mnt
84 if ! imagex capture in.ntfs ntfs.wim; then
85 error "Failed to capture NTFS volume into a WIM"
87 if ! imagex apply ntfs.wim 1 out.ntfs; then
88 error "Failed to apply WIM to NTFS volume"
90 __do_mount in.ntfs in.mnt noatime
91 __do_mount out.ntfs out.mnt noatime
92 if [ -x /usr/bin/tree ]; then
93 tree in.mnt --inodes -F -s --noreport
95 if ! ../tree-cmp in.mnt out.mnt NTFS; then
96 if [ -x /usr/bin/tree ]; then
97 echo "Dumping tree of applied image"
98 tree out.mnt --inodes -F -s --noreport
99 error 'Information was lost or corrupted while capturing
100 and then applying a NTFS volume'
103 rm -rf out.mnt/* in.mnt/*
107 echo "--------------------------------------------------------------------"
108 echo "Testing image capture and application of NTFS volume containing $1"
109 echo "--------------------------------------------------------------------"
117 msg "Empty NTFS volume"
121 do_test "echo 1 > file"
123 msg "a single directory"
126 msg "subdirectory with file"
127 do_test "mkdir dir; echo 1 > dir/file"
130 do_test "echo -n > empty_file"
132 msg "two empty files"
133 do_test "echo -n > empty_file_1; echo -n > empty_file_2"
135 msg "hard link in same directory"
136 do_test "echo 1 > file; ln file link"
138 msg "hard link between empty files"
139 do_test "echo -n > empty_file; ln empty_file link"
141 msg "relative symbolic link"
142 do_test "echo 1 > file; ln -s file symlink"
144 msg "absolute symbolic link"
145 do_test "echo 1 > file; ln -s /some/absolute/target symlink"
148 do_test "dd if=/dev/zero of=file bs=4096 count=10 &> /dev/null"
150 msg "file with DOS name"
151 do_test "echo 1 > file; setfattr -v file -n system.ntfs_dos_name file"
153 # To be replaced/removed: files with DOS names can no longer be hard linked as
154 # of NTFS-3g 2013.1.13.
156 #msg "file with DOS name with alphabetically smaller hardlink in same directory"
157 #do_test "echo 1 > file; setfattr -v file -n system.ntfs_dos_name file; ln file aaa_link"
159 #msg "file with DOS name with alphabetically larger hardlink in same directory"
160 #do_test "echo 1 > file; setfattr -v file -n system.ntfs_dos_name file; ln file zzz_link"
162 #msg "file with long name and with DOS name with alphabetically smaller hardlink in same directory"
163 #do_test 'echo 1 > file_with_a_long_name;
164 #setfattr -v "file~1" -n system.ntfs_dos_name file_with_a_long_name;
165 #ln file_with_a_long_name aaa_link'
167 msg "many nested directories"
168 do_test 'mkdir dir; mkdir dir/subdir; mkdir dir/subdir/subdir2; mkdir dir/subdir/subdir3'
170 msg "identical files and symlinks in subdirectory"
173 echo 888 > dir/idfile2;
174 ln -s ../dir dir/circle; ln -s file dir/filelink'
176 msg "hard link group and identical files not hard linked"
177 do_test 'echo 888 > file;
183 msg "file with named data stream"
184 do_test 'echo 1 > file;
185 setfattr -n user.ads -v 2 file'
187 msg "file with multiple named data streams"
188 do_test 'echo 1 > file;
189 setfattr -n user.a -v 1 file;
190 setfattr -n user.aa -v 11 file;
191 setfattr -n user.aaa -v 111 file;
192 setfattr -n user.aaaa -v 1111 file'
194 msg "file with multiple named data streams with same contents"
195 do_test 'echo 1 > file;
196 setfattr -n user.a -v 1111 file;
197 setfattr -n user.aa -v 1111 file;
198 setfattr -n user.aaa -v 1111 file;
199 setfattr -n user.aaaa -v 1111 file;'
201 msg "file with named data streams with same contents as other file"
202 do_test 'echo -n > file;
203 setfattr -n user.a -v 1111 file;
204 echo -n 1111 > otherfile;'
206 msg "file with empty named data stream and non-empty unnamed data stream"
207 do_test 'echo 1 > file;
208 setfattr -n user.ads -v "" file;'
210 msg "file with empty named data stream and empty unnamed data stream"
211 do_test 'echo -n > file;
212 setfattr -n user.ads -v "" file;'
214 msg "file with named data stream with hardlink"
215 do_test 'echo 999 > file;
216 setfattr -n user.ads -v "888" file;
219 # To be replaced/removed: files with DOS names can no longer be hard linked as
220 # of NTFS-3g 2013.1.13.
222 #msg "file with named data stream with hardlink and DOS name"
223 #do_test 'echo 999 > file;
224 #setfattr -n user.ads -v "888" file;
226 #setfattr -v DOSNAME -n system.ntfs_dos_name file;'
228 msg "C source code of wimlib"
229 do_test 'cp $srcdir/src/*.c .'
231 msg "file with security descriptor"
233 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` file'
235 msg "files with different security descriptors"
238 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` file
239 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_2.base64` file'
241 msg "files with different security descriptors and some with the same security descriptor"
246 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` file
247 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_2.base64` file
248 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` dir
249 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` file3'
251 msg "tons of random stuff"
252 do_test 'echo -n 8 > file;
254 ln -s hardlink symlink;
255 echo -n 8 > identical file;
256 dd if=/dev/urandom of=randomfile bs=4096 count=10 &>/dev/null;
258 setfattr -n system.ntfs_dos_name -v DOSNAME dir;
259 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` dir
262 ln file anotherdir/anotherhardlink;
263 ln -s .. anotherdir/anothersymlink;
264 ln -s anothersymlink anotherdir/symlinktosymlink;
265 echo -n 33 > anotherfile;
266 setfattr -n user.ads anotherfile -v 33;
267 setfattr -n user.ads2 anotherfile -v 8;
268 setfattr -n user.ads3 anotherfile -v 33;
270 setfattr -n user.ads emptyfile -v 8;
271 setfattr -n user.ads5 emptyfile -v"`cat $srcdir/src/hardlink.c`"
273 ln file dir/subdir/file;
274 echo -n 8 > dir/subdir/file2;
275 ln dir/subdir/file dir/subdir/link;
276 echo -n > dir/subdir/empty;
277 setfattr -n system.ntfs_dos_name -v 123 dir/subdir/empty;
278 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` dir/subdir/link;
279 setfattr -n user.yet_another_ads -v "" dir/subdir/link;
280 setfattr -n user.yet_another_ads2 -v "" dir/subdir/link;
281 setfattr -n user.yet_another_ads3 -v "abc" dir/subdir/link;
282 setfattr -n user.yet_another_ads4 -v "" dir/subdir/link;'
284 echo "**********************************************************"
285 echo " NTFS capture/apply tests passed "
286 echo "**********************************************************"