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
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
68 do_unmount $TEST_SUBDIR/in.mnt
69 do_unmount $TEST_SUBDIR/out.mnt
78 if ! imagex capture in.ntfs ntfs.wim; then
79 error "Failed to capture NTFS volume into a WIM"
81 if ! imagex apply ntfs.wim 1 out.ntfs; then
82 error "Failed to apply WIM to NTFS volume"
84 __do_mount in.ntfs in.mnt noatime
85 __do_mount out.ntfs out.mnt noatime
86 if [ -x /usr/bin/tree ]; then
87 tree in.mnt --inodes -F -s --noreport
89 if ! ../tree-cmp in.mnt out.mnt NTFS; then
90 if [ -x /usr/bin/tree ]; then
91 echo "Dumping tree of applied image"
92 tree out.mnt --inodes -F -s --noreport
93 error 'Information was lost or corrupted while capturing
94 and then applying a NTFS volume'
97 rm -rf out.mnt/* in.mnt/*
101 echo "--------------------------------------------------------------------"
102 echo "Testing image capture and application of NTFS volume containing $1"
103 echo "--------------------------------------------------------------------"
111 msg "Empty NTFS volume"
115 do_test "echo 1 > file"
117 msg "a single directory"
120 msg "subdirectory with file"
121 do_test "mkdir dir; echo 1 > dir/file"
124 do_test "echo -n > empty_file"
126 msg "two empty files"
127 do_test "echo -n > empty_file_1; echo -n > empty_file_2"
129 msg "hard link in same directory"
130 do_test "echo 1 > file; ln file link"
132 msg "hard link between empty files"
133 do_test "echo -n > empty_file; ln empty_file link"
135 msg "relative symbolic link"
136 do_test "echo 1 > file; ln -s file symlink"
138 msg "absolute symbolic link"
139 do_test "echo 1 > file; ln -s /some/absolute/target symlink"
142 do_test "dd if=/dev/zero of=file bs=4096 count=10 &> /dev/null"
144 msg "file with DOS name"
145 do_test "echo 1 > file; setfattr -v file -n system.ntfs_dos_name file"
147 # To be replaced/removed: files with DOS names can no longer be hard linked as
148 # of NTFS-3g 2013.1.13.
150 #msg "file with DOS name with alphabetically smaller hardlink in same directory"
151 #do_test "echo 1 > file; setfattr -v file -n system.ntfs_dos_name file; ln file aaa_link"
153 #msg "file with DOS name with alphabetically larger hardlink in same directory"
154 #do_test "echo 1 > file; setfattr -v file -n system.ntfs_dos_name file; ln file zzz_link"
156 #msg "file with long name and with DOS name with alphabetically smaller hardlink in same directory"
157 #do_test 'echo 1 > file_with_a_long_name;
158 #setfattr -v "file~1" -n system.ntfs_dos_name file_with_a_long_name;
159 #ln file_with_a_long_name aaa_link'
161 msg "many nested directories"
162 do_test 'mkdir dir; mkdir dir/subdir; mkdir dir/subdir/subdir2; mkdir dir/subdir/subdir3'
164 msg "identical files and symlinks in subdirectory"
167 echo 888 > dir/idfile2;
168 ln -s ../dir dir/circle; ln -s file dir/filelink'
170 msg "hard link group and identical files not hard linked"
171 do_test 'echo 888 > file;
177 msg "file with named data stream"
178 do_test 'echo 1 > file;
179 setfattr -n user.ads -v 2 file'
181 msg "file with multiple named data streams"
182 do_test 'echo 1 > file;
183 setfattr -n user.a -v 1 file;
184 setfattr -n user.aa -v 11 file;
185 setfattr -n user.aaa -v 111 file;
186 setfattr -n user.aaaa -v 1111 file'
188 msg "file with multiple named data streams with same contents"
189 do_test 'echo 1 > file;
190 setfattr -n user.a -v 1111 file;
191 setfattr -n user.aa -v 1111 file;
192 setfattr -n user.aaa -v 1111 file;
193 setfattr -n user.aaaa -v 1111 file;'
195 msg "file with named data streams with same contents as other file"
196 do_test 'echo -n > file;
197 setfattr -n user.a -v 1111 file;
198 echo -n 1111 > otherfile;'
200 msg "file with empty named data stream and non-empty unnamed data stream"
201 do_test 'echo 1 > file;
202 setfattr -n user.ads -v "" file;'
204 msg "file with empty named data stream and empty unnamed data stream"
205 do_test 'echo -n > file;
206 setfattr -n user.ads -v "" file;'
208 msg "file with named data stream with hardlink"
209 do_test 'echo 999 > file;
210 setfattr -n user.ads -v "888" file;
213 # To be replaced/removed: files with DOS names can no longer be hard linked as
214 # of NTFS-3g 2013.1.13.
216 #msg "file with named data stream with hardlink and DOS name"
217 #do_test 'echo 999 > file;
218 #setfattr -n user.ads -v "888" file;
220 #setfattr -v DOSNAME -n system.ntfs_dos_name file;'
222 msg "C source code of wimlib"
223 do_test 'cp $srcdir/src/*.{c,h} .'
225 msg "file with security descriptor"
227 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` file'
229 msg "files with different security descriptors"
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'
235 msg "files with different security descriptors and some with the same security descriptor"
240 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` file
241 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_2.base64` file
242 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` dir
243 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` file3'
245 msg "tons of random stuff"
246 do_test 'echo -n 8 > file;
248 ln -s hardlink symlink;
249 echo -n 8 > identical file;
250 dd if=/dev/urandom of=randomfile bs=4096 count=10 &>/dev/null;
252 setfattr -n system.ntfs_dos_name -v DOSNAME dir;
253 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` dir
256 ln file anotherdir/anotherhardlink;
257 ln -s .. anotherdir/anothersymlink;
258 ln -s anothersymlink anotherdir/symlinktosymlink;
259 echo -n 33 > anotherfile;
260 setfattr -n user.ads anotherfile -v 33;
261 setfattr -n user.ads2 anotherfile -v 8;
262 setfattr -n user.ads3 anotherfile -v 33;
264 setfattr -n user.ads emptyfile -v 8;
265 setfattr -n user.ads5 emptyfile -v"`cat $srcdir/src/hardlink.c`"
267 ln file dir/subdir/file;
268 echo -n 8 > dir/subdir/file2;
269 ln dir/subdir/file dir/subdir/link;
270 echo -n > dir/subdir/empty;
271 setfattr -n system.ntfs_dos_name -v 123 dir/subdir/empty;
272 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` dir/subdir/link;
273 setfattr -n user.yet_another_ads -v "" dir/subdir/link;
274 setfattr -n user.yet_another_ads2 -v "" dir/subdir/link;
275 setfattr -n user.yet_another_ads3 -v "abc" dir/subdir/link;
276 setfattr -n user.yet_another_ads4 -v "" dir/subdir/link;'
278 echo "**********************************************************"
279 echo " NTFS capture/apply tests passed "
280 echo "**********************************************************"