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"
18 ../imagex $@ > /dev/null
22 if ! fusermount -z -u $1; then
23 error "Failed to unmount \"$1\""
29 if mountpoint $1 &> /dev/null; then
36 if [ -z "$options" ]; then
37 options="no_def_opts,silent"
39 options="$options,no_def_opts,silent"
41 if ! ntfs-3g -o $options $1 $2; then
42 error "Could not mount NTFS volume \"$1\" on \"$2\"! Make sure ntfs-3g is "\
43 "installed, and that you are either running the tests as root or have ntfs-3g "\
44 "installed setuid root, so that we can mount a NTFS volume."
54 if ! mkntfs --force --fast $1 &> /dev/null; then
55 error "Could not create NTFS volume \"$1\"! Make sure ntfsprogs are installed."
60 echo "Creating NTFS volumes and empty directories to use as mountpoints"
61 dd if=/dev/zero of=in.ntfs bs=4096 count=500 &> /dev/null
62 dd if=/dev/zero of=out.ntfs bs=4096 count=500 &> /dev/null
66 do_mount in.ntfs in.mnt
72 rm -rf in.ntfs out.ntfs in.mnt out.mnt in.xattr out.xattr ntfs.wim
78 echo "****************************************************************"
80 while [ $# -gt 0 ]; do
84 echo "****************************************************************"
93 if ! imagex capture in.ntfs ntfs.wim; then
94 error "Failed to capture NTFS volume into a WIM"
96 if ! imagex apply ntfs.wim 1 out.ntfs; then
97 error "Failed to apply WIM to NTFS volume"
99 __do_mount in.ntfs in.mnt noatime
100 __do_mount out.ntfs out.mnt noatime
101 if [ -x /usr/bin/tree ]; then
102 tree in.mnt --inodes -F -s --noreport
104 if ! ./tree-cmp in.mnt out.mnt NTFS; then
105 if [ -x /usr/bin/tree ]; then
106 echo "Dumping tree of applied image"
107 tree out.mnt --inodes -F -s --noreport
108 error 'Information was lost or corrupted while capturing
109 and then applying a NTFS volume'
112 rm -rf out.mnt/* in.mnt/*
116 echo "--------------------------------------------------------------------"
117 echo "Testing image capture and application of NTFS volume containing $1"
118 echo "--------------------------------------------------------------------"
124 msg "Empty NTFS volume"
128 do_test "echo 1 > file"
130 msg "a single directory"
133 msg "subdirectory with file"
134 do_test "mkdir dir; echo 1 > dir/file"
137 do_test "echo -n > empty_file"
139 msg "two empty files"
140 do_test "echo -n > empty_file_1; echo -n > empty_file_2"
142 msg "hard link in same directory"
143 do_test "echo 1 > file; ln file link"
145 msg "hard link between empty files"
146 do_test "echo -n > empty_file; ln empty_file link"
148 msg "relative symbolic link"
149 do_test "echo 1 > file; ln -s file symlink"
151 msg "absolute symbolic link"
152 do_test "echo 1 > file; ln -s /some/absolute/target symlink"
155 do_test "dd if=/dev/zero of=file bs=4096 count=10 &> /dev/null"
157 msg "file with DOS name"
158 do_test "echo 1 > file; setfattr -v file -n system.ntfs_dos_name file"
160 # To be replaced/removed: files with DOS names can no longer be hard linked as
161 # of NTFS-3g 2013.1.13.
163 #msg "file with DOS name with alphabetically smaller hardlink in same directory"
164 #do_test "echo 1 > file; setfattr -v file -n system.ntfs_dos_name file; ln file aaa_link"
166 #msg "file with DOS name with alphabetically larger hardlink in same directory"
167 #do_test "echo 1 > file; setfattr -v file -n system.ntfs_dos_name file; ln file zzz_link"
169 #msg "file with long name and with DOS name with alphabetically smaller hardlink in same directory"
170 #do_test 'echo 1 > file_with_a_long_name;
171 #setfattr -v "file~1" -n system.ntfs_dos_name file_with_a_long_name;
172 #ln file_with_a_long_name aaa_link'
174 msg "many nested directories"
175 do_test 'mkdir dir; mkdir dir/subdir; mkdir dir/subdir/subdir2; mkdir dir/subdir/subdir3'
177 msg "identical files and symlinks in subdirectory"
180 echo 888 > dir/idfile2;
181 ln -s ../dir dir/circle; ln -s file dir/filelink'
183 msg "hard link group and identical files not hard linked"
184 do_test 'echo 888 > file;
190 msg "file with named data stream"
191 do_test 'echo 1 > file;
192 setfattr -n user.ads -v 2 file'
194 msg "file with multiple named data streams"
195 do_test 'echo 1 > file;
196 setfattr -n user.a -v 1 file;
197 setfattr -n user.aa -v 11 file;
198 setfattr -n user.aaa -v 111 file;
199 setfattr -n user.aaaa -v 1111 file'
201 msg "file with multiple named data streams with same contents"
202 do_test 'echo 1 > file;
203 setfattr -n user.a -v 1111 file;
204 setfattr -n user.aa -v 1111 file;
205 setfattr -n user.aaa -v 1111 file;
206 setfattr -n user.aaaa -v 1111 file;'
208 msg "file with named data streams with same contents as other file"
209 do_test 'echo -n > file;
210 setfattr -n user.a -v 1111 file;
211 echo -n 1111 > otherfile;'
213 msg "file with empty named data stream and non-empty unnamed data stream"
214 do_test 'echo 1 > file;
215 setfattr -n user.ads -v "" file;'
217 msg "file with empty named data stream and empty unnamed data stream"
218 do_test 'echo -n > file;
219 setfattr -n user.ads -v "" file;'
221 msg "file with named data stream with hardlink"
222 do_test 'echo 999 > file;
223 setfattr -n user.ads -v "888" file;
226 # To be replaced/removed: files with DOS names can no longer be hard linked as
227 # of NTFS-3g 2013.1.13.
229 #msg "file with named data stream with hardlink and DOS name"
230 #do_test 'echo 999 > file;
231 #setfattr -n user.ads -v "888" file;
233 #setfattr -v DOSNAME -n system.ntfs_dos_name file;'
235 msg "C source code of wimlib"
236 do_test 'cp $srcdir/src/*.{c,h} .'
238 msg "file with security descriptor"
240 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` file'
242 msg "files with different security descriptors"
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'
248 msg "files with different security descriptors and some with the same security descriptor"
253 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` file
254 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_2.base64` file
255 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` dir
256 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` file3'
258 msg "tons of random stuff"
259 do_test 'echo -n 8 > file;
261 ln -s hardlink symlink;
262 echo -n 8 > identical file;
263 dd if=/dev/urandom of=randomfile bs=4096 count=10 &>/dev/null;
265 setfattr -n system.ntfs_dos_name -v DOSNAME dir;
266 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` dir
269 ln file anotherdir/anotherhardlink;
270 ln -s .. anotherdir/anothersymlink;
271 ln -s anothersymlink anotherdir/symlinktosymlink;
272 echo -n 33 > anotherfile;
273 setfattr -n user.ads anotherfile -v 33;
274 setfattr -n user.ads2 anotherfile -v 8;
275 setfattr -n user.ads3 anotherfile -v 33;
277 setfattr -n user.ads emptyfile -v 8;
278 setfattr -n user.ads5 emptyfile -v"`cat $srcdir/src/hardlink.c`"
280 ln file dir/subdir/file;
281 echo -n 8 > dir/subdir/file2;
282 ln dir/subdir/file dir/subdir/link;
283 echo -n > dir/subdir/empty;
284 setfattr -n system.ntfs_dos_name -v 123 dir/subdir/empty;
285 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` dir/subdir/link;
286 setfattr -n user.yet_another_ads -v "" dir/subdir/link;
287 setfattr -n user.yet_another_ads2 -v "" dir/subdir/link;
288 setfattr -n user.yet_another_ads3 -v "abc" dir/subdir/link;
289 setfattr -n user.yet_another_ads4 -v "" dir/subdir/link;'
293 echo "**********************************************************"
294 echo " NTFS capture/apply tests passed "
295 echo "**********************************************************"