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 for ((i = 0; i < 10; i++)); do
21 if fusermount -z -u $1; then
27 error "Failed to unmount \"$1\""
31 if mountpoint $1 &> /dev/null; then
43 if ! ntfs-3g -o "no_def_opts,silent" $1 $2; then
44 if [ $UID -ne 0 ] && [ "$3" = "nofail" ]; then
45 echo "WARNING: skipping NTFS tests because we aren't able to "
46 echo "mount an NTFS volume (perhaps ntfs-3g is not installed setuid root?)"
49 error "Could not mount NTFS volume \"$1\" on \"$2\"! Make sure ntfs-3g is "\
50 "installed, and that you are either running the tests as root or have ntfs-3g "\
51 "installed setuid root, so that we can mount an NTFS volume."
62 if ! mkntfs --force --fast $1 > /dev/null; then
63 error "Could not create NTFS volume \"$1\"! Make sure ntfsprogs are installed."
68 echo "Creating NTFS volumes and empty directories to use as mountpoints"
69 dd if=/dev/zero of=in.ntfs bs=4096 count=1000 &> /dev/null
70 dd if=/dev/zero of=out.ntfs bs=4096 count=1000 &> /dev/null
74 do_mount in.ntfs in.mnt nofail
78 do_unmount $TEST_SUBDIR/in.mnt
79 do_unmount $TEST_SUBDIR/out.mnt
88 if ! wimcapture in.ntfs ntfs.wim; then
89 error "Failed to capture NTFS volume into a WIM"
91 if ! wimapply ntfs.wim 1 out.ntfs; then
92 error "Failed to apply WIM to NTFS volume"
94 __do_mount in.ntfs in.mnt noatime
95 __do_mount out.ntfs out.mnt noatime
96 if [ -x /usr/bin/tree ]; then
97 tree in.mnt --inodes -F -s --noreport
99 if ! ../tree-cmp in.mnt out.mnt NTFS; then
100 if [ -x /usr/bin/tree ]; then
101 echo "Dumping tree of applied image"
102 tree out.mnt --inodes -F -s --noreport
103 error 'Information was lost or corrupted while capturing
104 and then applying an NTFS volume'
107 rm -rf out.mnt/* in.mnt/*
111 echo "--------------------------------------------------------------------"
112 echo "Testing image capture and application of NTFS volume containing $1"
113 echo "--------------------------------------------------------------------"
121 msg "Empty NTFS volume"
125 do_test "echo 1 > file"
127 msg "a single directory"
130 msg "subdirectory with file"
131 do_test "mkdir dir; echo 1 > dir/file"
134 do_test "echo -n > empty_file"
136 msg "two empty files"
137 do_test "echo -n > empty_file_1; echo -n > empty_file_2"
139 msg "hard link in same directory"
140 do_test "echo 1 > file; ln file link"
142 msg "hard link between empty files"
143 do_test "echo -n > empty_file; ln empty_file link"
145 msg "relative symbolic link"
146 do_test "echo 1 > file; ln -s file symlink"
148 msg "absolute symbolic link"
149 do_test "echo 1 > file; ln -s /some/absolute/target symlink"
152 do_test "dd if=/dev/zero of=file bs=4096 count=10 &> /dev/null"
154 msg "file with DOS name"
155 do_test "echo 1 > file; setfattr -v file -n system.ntfs_dos_name file"
157 msg "many nested directories"
158 do_test 'mkdir dir; mkdir dir/subdir; mkdir dir/subdir/subdir2; mkdir dir/subdir/subdir3'
160 msg "identical files and symlinks in subdirectory"
163 echo 888 > dir/idfile2;
164 ln -s ../dir dir/circle; ln -s file dir/filelink'
166 msg "hard link group and identical files not hard linked"
167 do_test 'echo 888 > file;
173 msg "file with named data stream"
174 do_test 'echo 1 > file;
175 setfattr -n user.ads -v 2 file'
177 msg "file with multiple named data streams"
178 do_test 'echo 1 > file;
179 setfattr -n user.a -v 1 file;
180 setfattr -n user.aa -v 11 file;
181 setfattr -n user.aaa -v 111 file;
182 setfattr -n user.aaaa -v 1111 file'
184 msg "file with multiple named data streams with same contents"
185 do_test 'echo 1 > file;
186 setfattr -n user.a -v 1111 file;
187 setfattr -n user.aa -v 1111 file;
188 setfattr -n user.aaa -v 1111 file;
189 setfattr -n user.aaaa -v 1111 file;'
191 msg "file with named data streams with same contents as other file"
192 do_test 'echo -n > file;
193 setfattr -n user.a -v 1111 file;
194 echo -n 1111 > otherfile;'
196 msg "file with empty named data stream and non-empty unnamed data stream"
197 do_test 'echo 1 > file;
198 setfattr -n user.ads -v 0x file;'
200 msg "file with empty named data stream and empty unnamed data stream"
201 do_test 'echo -n > file;
202 setfattr -n user.ads -v 0x file;'
204 msg "file with named data stream with hardlink"
205 do_test 'echo 999 > file;
206 setfattr -n user.ads -v 0x123456 file;
209 msg "C source code of wimlib"
210 do_test 'cp $srcdir/src/*.c .'
212 msg "file with security descriptor"
214 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` file'
216 msg "files with different security descriptors"
219 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` file
220 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_2.base64` file'
222 msg "files with different security descriptors and some with the same security descriptor"
227 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` file
228 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_2.base64` file
229 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` dir
230 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` file3'
232 msg "tons of random stuff"
233 do_test 'echo -n 8 > file;
235 ln -s hardlink symlink;
236 echo -n 8 > identical file;
237 dd if=/dev/urandom of=randomfile bs=4096 count=10 &>/dev/null;
239 setfattr -n system.ntfs_dos_name -v DOSNAME dir;
240 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` dir
243 ln file anotherdir/anotherhardlink;
244 ln -s .. anotherdir/anothersymlink;
245 ln -s anothersymlink anotherdir/symlinktosymlink;
246 echo -n 33 > anotherfile;
247 setfattr -n user.ads anotherfile -v 33;
248 setfattr -n user.ads2 anotherfile -v 8;
249 setfattr -n user.ads3 anotherfile -v 33;
251 setfattr -n user.ads emptyfile -v 8;
252 setfattr -n user.ads5 emptyfile -v"`cat $srcdir/src/sha1.c`"
254 ln file dir/subdir/file;
255 echo -n 8 > dir/subdir/file2;
256 ln dir/subdir/file dir/subdir/link;
257 echo -n > dir/subdir/empty;
258 setfattr -n system.ntfs_dos_name -v 123 dir/subdir/empty;
259 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` dir/subdir/link;
260 setfattr -n user.yet_another_ads -v "" dir/subdir/link;
261 setfattr -n user.yet_another_ads2 -v "" dir/subdir/link;
262 setfattr -n user.yet_another_ads3 -v "abc" dir/subdir/link;
263 setfattr -n user.yet_another_ads4 -v "" dir/subdir/link;'
265 echo "**********************************************************"
266 echo " NTFS capture/apply tests passed "
267 echo "**********************************************************"