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/test_utils.sh"
17 TEST_SUBDIR=tmpdir_test-imagex-ntfs
19 # In Debian, mkntfs is at /sbin/mkntfs but /sbin is not on the $PATH by default.
23 for ((i = 0; i < 10; i++)); do
24 if fusermount -z -u $1; then
30 error "Failed to unmount \"$1\""
34 if mountpoint $1 &> /dev/null; then
46 if ! ntfs-3g -o "no_def_opts,silent" $1 $2; then
47 if [ $UID -ne 0 ] && [ "$3" = "nofail" ]; then
48 echo "WARNING: skipping NTFS tests because we aren't able to "
49 echo "mount an NTFS volume (perhaps ntfs-3g is not installed setuid root?)"
52 error "Could not mount NTFS volume \"$1\" on \"$2\"! Make sure ntfs-3g is "\
53 "installed, and that you are either running the tests as root or have ntfs-3g "\
54 "installed setuid root, so that we can mount an NTFS volume."
65 if ! mkntfs --force --fast $1 >/dev/null; then
66 error "Could not create NTFS volume \"$1\"! Make sure ntfsprogs are installed."
71 echo "Creating NTFS volumes and empty directories to use as mountpoints"
72 dd if=/dev/zero of=in.ntfs bs=4096 count=1000 &> /dev/null
73 dd if=/dev/zero of=out.ntfs bs=4096 count=1000 &> /dev/null
77 do_mount in.ntfs in.mnt nofail
81 do_unmount $TEST_SUBDIR/in.mnt
82 do_unmount $TEST_SUBDIR/out.mnt
91 if ! wimcapture in.ntfs ntfs.wim; then
92 error "Failed to capture NTFS volume into a WIM"
94 if ! wimapply 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 an 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 "--------------------------------------------------------------------"
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 msg "many nested directories"
161 do_test 'mkdir dir; mkdir dir/subdir; mkdir dir/subdir/subdir2; mkdir dir/subdir/subdir3'
163 msg "identical files and symlinks in subdirectory"
166 echo 888 > dir/idfile2;
167 ln -s ../dir dir/circle; ln -s file dir/filelink'
169 msg "hard link group and identical files not hard linked"
170 do_test 'echo 888 > file;
176 msg "file with named data stream"
177 do_test 'echo 1 > file;
178 setfattr -n user.ads -v 2 file'
180 msg "file with multiple named data streams"
181 do_test 'echo 1 > file;
182 setfattr -n user.a -v 1 file;
183 setfattr -n user.aa -v 11 file;
184 setfattr -n user.aaa -v 111 file;
185 setfattr -n user.aaaa -v 1111 file'
187 msg "file with multiple named data streams with same contents"
188 do_test 'echo 1 > file;
189 setfattr -n user.a -v 1111 file;
190 setfattr -n user.aa -v 1111 file;
191 setfattr -n user.aaa -v 1111 file;
192 setfattr -n user.aaaa -v 1111 file;'
194 msg "file with named data streams with same contents as other file"
195 do_test 'echo -n > file;
196 setfattr -n user.a -v 1111 file;
197 echo -n 1111 > otherfile;'
199 msg "file with empty named data stream and non-empty unnamed data stream"
200 do_test 'echo 1 > file;
201 setfattr -n user.ads -v 0x file;'
203 msg "file with empty named data stream and empty unnamed data stream"
204 do_test 'echo -n > file;
205 setfattr -n user.ads -v 0x file;'
207 msg "file with named data stream with hardlink"
208 do_test 'echo 999 > file;
209 setfattr -n user.ads -v 0x123456 file;
212 msg "C source code of wimlib"
213 do_test 'cp $srcdir/src/*.c .'
215 msg "file with security descriptor"
217 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` file'
219 msg "file with object ID"
222 setfattr -n system.ntfs_object_id -v 0x15ac83a36dc6cf8ec459b8017dd8626f file
223 setfattr -n system.ntfs_object_id -v 0xf67394c12b17608e1d050d181ba8ffd27df80cbdf620f4c82c79b9e6799147b697621aff72915ade05abb96b15dea1a3e0bda4caa9e33cfd461c92c16be9713d file2'
225 msg "files with different security descriptors"
228 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` file
229 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_2.base64` file'
231 msg "files with different security descriptors and some with the same security descriptor"
236 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` file
237 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_2.base64` file
238 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` dir
239 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` file3'
241 msg "tons of random stuff"
242 do_test 'echo -n 8 > file;
244 ln -s hardlink symlink;
245 echo -n 8 > identical file;
246 dd if=/dev/urandom of=randomfile bs=4096 count=10 &>/dev/null;
248 setfattr -n system.ntfs_dos_name -v DOSNAME dir;
249 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` dir
252 ln file anotherdir/anotherhardlink;
253 ln -s .. anotherdir/anothersymlink;
254 ln -s anothersymlink anotherdir/symlinktosymlink;
255 echo -n 33 > anotherfile;
256 setfattr -n user.ads anotherfile -v 33;
257 setfattr -n user.ads2 anotherfile -v 8;
258 setfattr -n user.ads3 anotherfile -v 33;
260 setfattr -n user.ads emptyfile -v 8;
261 setfattr -n user.ads5 emptyfile -v"`cat $srcdir/src/sha1.c`"
263 ln file dir/subdir/file;
264 echo -n 8 > dir/subdir/file2;
265 ln dir/subdir/file dir/subdir/link;
266 echo -n > dir/subdir/empty;
267 setfattr -n system.ntfs_dos_name -v 123 dir/subdir/empty;
268 setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` dir/subdir/link;
269 setfattr -n user.yet_another_ads -v "" dir/subdir/link;
270 setfattr -n user.yet_another_ads2 -v "" dir/subdir/link;
271 setfattr -n user.yet_another_ads3 -v "abc" dir/subdir/link;
272 setfattr -n user.yet_another_ads4 -v "" dir/subdir/link;'
274 echo "**********************************************************"
275 echo " NTFS capture/apply tests passed "
276 echo "**********************************************************"