]> wimlib.net Git - wimlib/blob - tests/test-imagex-ntfs
dist files and test fixes
[wimlib] / tests / test-imagex-ntfs
1 #!/bin/bash
2
3 # This script does some sanity testing of the 'imagex' program, specifically
4 # checking the NTFS capture and apply features.
5 #
6 # This test will fail if wimlib was compiled with --without-ntfs-3g.
7 #
8 # Please note that cleanup is not done if a test fails, and NTFS volumes may
9 # remain mounted.
10
11 set -e
12 srcdir=${srcdir:-.}
13 srcdir=`realpath $srcdir`
14 cd tests
15
16 imagex() {
17         ../imagex $@ > /dev/null
18 }
19
20 __do_unmount() {
21         if !  fusermount -u $1; then
22                 error "Failed to unmount \"$1\""
23         fi
24
25 }
26 do_unmount() {
27         if mountpoint $1 &> /dev/null; then
28                 __do_unmount $1
29         fi
30 }
31
32 __do_mount() {
33         options="$3"
34         if ! ntfs-3g ${options:+-o $options} $1 $2; then
35                 error "Could not mount NTFS volume \"$1\" on \"$2\".  Make sure ntfs-3g is installed."
36         fi
37 }
38
39 do_mount() {
40         do_unmount $2
41         __do_mount $1 $2 $3
42 }
43
44 do_mkntfs() {
45         if ! mkntfs --force --fast $1 &> /dev/null; then
46                 error "Could not create NTFS volume on \"$1\".  Make sure ntfs-3g / ntfsprogs are installed"
47         fi
48 }
49
50 init() {
51         echo "Creating NTFS volumes and empty directories to use as mountpoints"
52         dd if=/dev/zero of=in.ntfs bs=4096 count=500 &> /dev/null
53         dd if=/dev/zero of=out.ntfs bs=4096 count=500 &> /dev/null
54         mkdir in.mnt out.mnt
55         do_mkntfs in.ntfs
56         do_mkntfs out.ntfs
57         do_mount in.ntfs in.mnt
58 }
59
60 cleanup() {
61         do_unmount in.mnt
62         do_unmount out.mnt
63         rm -rf in.ntfs out.ntfs in.mnt out.mnt in.xattr out.xattr ntfs.wim
64 }
65 #trap cleanup exit
66
67
68 error() {
69         echo "****************************************************************"
70         echo "                         Test failure                           "
71         echo $*
72         echo "****************************************************************"
73         exit 1
74 }
75
76 do_test() {
77         cd in.mnt
78         eval "$1"
79         cd ..
80         __do_unmount in.mnt
81         if ! imagex capture in.ntfs ntfs.wim; then
82                 error "Failed to capture NTFS volume into a WIM"
83         fi
84         if ! imagex apply ntfs.wim 1 out.ntfs; then
85                 error "Failed to apply WIM to NTFS volume"
86         fi
87         __do_mount in.ntfs in.mnt noatime
88         __do_mount out.ntfs out.mnt noatime
89         if [ -x /usr/bin/tree ]; then
90                 tree in.mnt --inodes -F -s --noreport
91         fi
92         if ! ./tree-cmp in.mnt out.mnt NTFS; then
93                 if [ -x /usr/bin/tree ]; then
94                         echo "Dumping tree of applied image"
95                         tree out.mnt --inodes -F -s --noreport
96                         error 'Information was lost or corrupted while capturing
97                                 and then applying a NTFS volume'
98                 fi
99         fi
100         rm -rf out.mnt/* in.mnt/*
101         __do_unmount out.mnt
102 }
103 msg() {
104         echo "--------------------------------------------------------------------"
105         echo "Testing image capture and application of NTFS volume containing $1"
106         echo "--------------------------------------------------------------------"
107 }
108
109 cleanup
110 init
111
112 msg "Empty NTFS volume"
113 do_test ""
114
115 msg "NTFS volume containing a single file"
116 do_test "echo 1 > file"
117
118 msg "NTFS volume containing a single directory"
119 do_test "mkdir dir"
120
121 msg "NTFS volume containing subdirectory with file"
122 do_test "mkdir dir; echo 1 > dir/file"
123
124 msg "NTFS volume containing empty file"
125 do_test "echo -n > empty_file"
126
127 msg "NTFS volume containing two empty files"
128 do_test "echo -n > empty_file_1; echo -n > empty_file_2"
129
130 msg "NTFS volume containing hard link in same directory"
131 do_test "echo 1 > file; ln file link"
132
133 msg "NTFS volume containing hard link between empty files"
134 do_test "echo -n > empty_file; ln empty_file link"
135
136 msg "NTFS volume containing relative symbolic link"
137 do_test "echo 1 > file; ln -s file symlink"
138
139 msg "NTFS volume containing absolute symbolic link"
140 do_test "echo 1 > file; ln -s /some/absolute/target symlink"
141
142 msg "NTFS volume containing large file"
143 do_test "dd if=/dev/zero of=file bs=4096 count=10 &> /dev/null"
144
145 msg "NTFS volume containing file with DOS name"
146 do_test "echo 1 > file; setfattr -v file -n system.ntfs_dos_name file"
147
148 msg "NTFS volume containing file with DOS name with alphabetically smaller hardlink in same directory"
149 do_test "echo 1 > file; setfattr -v file -n system.ntfs_dos_name file; ln file aaa_link"
150
151 msg "NTFS volume containing file with DOS name with alphabetically larger hardlink in same directory"
152 do_test "echo 1 > file; setfattr -v file -n system.ntfs_dos_name file; ln file zzz_link"
153
154 msg "NTFS volume containing file with long name and with DOS name with alphabetically smaller hardlink in same directory"
155 do_test 'echo 1 > file_with_a_long_name;
156          setfattr -v "file~1" -n system.ntfs_dos_name file_with_a_long_name;
157          ln file_with_a_long_name aaa_link'
158
159 msg "NTFS volume containing many nested directories"
160 do_test 'mkdir dir; mkdir dir/subdir; mkdir dir/subdir/subdir2; mkdir dir/subdir/subdir3'
161
162 msg "NTFS volume containing identical files and symlinks in subdirectory"
163 do_test 'mkdir dir;
164          echo 888 > dir/file;
165          echo 888 > dir/idfile2;
166          ln -s ../dir dir/circle; ln -s file dir/filelink'
167
168 msg "NTFS volume containing hard link group and identical files not hard linked"
169 do_test 'echo 888 > file;
170          echo 888 > file2;
171          ln file link;
172          ln file link2;
173          echo 888 > file3'
174
175 msg "NTFS volume containing file with named data stream"
176 do_test 'echo 1 > file;
177          setfattr -n user.ads -v 2 file'
178
179 msg "NTFS volume containing file with multiple named data streams"
180 do_test 'echo 1 > file;
181          setfattr -n user.a -v 1 file;
182          setfattr -n user.aa -v 11 file;
183          setfattr -n user.aaa -v 111 file;
184          setfattr -n user.aaaa -v 1111 file'
185
186 msg "NTFS volume containing file with multiple named data streams with same contents"
187 do_test 'echo 1 > file;
188          setfattr -n user.a -v 1111 file;
189          setfattr -n user.aa -v 1111 file;
190          setfattr -n user.aaa -v 1111 file;
191          setfattr -n user.aaaa -v 1111 file;'
192         
193 msg "NTFS volume containing file with named data streams with same contents as other file"
194 do_test 'echo -n > file;
195          setfattr -n user.a -v 1111 file;
196          echo -n 1111 > otherfile;'
197
198 msg "NTFS volume containing file with empty named data stream and non-empty unnamed data stream"
199 do_test 'echo 1 > file;
200          setfattr -n user.ads -v "" file;'
201
202 msg "NTFS volume containing file with empty named data stream and empty unnamed data stream"
203 do_test 'echo -n > file;
204          setfattr -n user.ads -v "" file;'
205
206 msg "NTFS volume containing file with named data stream with hardlink"
207 do_test 'echo 999 > file;
208          setfattr -n user.ads -v "888" file;
209          ln file link;'
210
211 msg "NTFS volume containing file with named data stream with hardlink and DOS name"
212 do_test 'echo 999 > file;
213          setfattr -n user.ads -v "888" file;
214          ln file link;
215          setfattr -v DOSNAME -n system.ntfs_dos_name file;'
216
217 msg "NTFS volume containing C source code of wimlib"
218 do_test 'cp $srcdir/src/*.{c,h} .'
219
220 msg "NTFS volume containing file with security descriptor"
221 do_test 'touch file;
222          setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` file'
223
224 msg "NTFS volume containing files with different security descriptors"
225 do_test 'touch file;
226          touch file2;
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         
230 msg "NTFS volume containing files with different security descriptors and some with the same security descriptor"
231 do_test 'touch file;
232          touch file2;
233          touch file3;
234          mkdir dir;
235          setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` file
236          setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_2.base64` file
237          setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` dir
238          setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` file3'
239
240 msg "NTFS volume containing tons of random stuff"
241 do_test 'echo -n 8 > file;
242          ln file hardlink;
243          ln -s hardlink symlink;
244          echo -n 8 > identical file;
245          dd if=/dev/urandom of=randomfile bs=4096 count=10 &>/dev/null;
246          mkdir dir;
247          setfattr -n system.ntfs_dos_name -v DOSNAME dir;
248          setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` dir
249          mkdir anotherdir;
250          cp file anotherdir;
251          ln file anotherdir/anotherhardlink;
252          ln -s .. anotherdir/anothersymlink;
253          ln -s anothersymlink anotherdir/symlinktosymlink;
254          echo -n 33 > anotherfile;
255          setfattr -n user.ads anotherfile -v 33;
256          setfattr -n user.ads2 anotherfile -v 8;
257          setfattr -n user.ads3 anotherfile -v 33;
258          echo -n > emptyfile;
259          setfattr -n user.ads emptyfile -v 8;
260          setfattr -n user.ads5 emptyfile -v"`cat $srcdir/src/hardlink.c`"
261          mkdir dir/subdir;
262          ln file dir/subdir/file;
263          echo -n 8 > dir/subdir/file2;
264          ln dir/subdir/file dir/subdir/link;
265          setfattr -n system.ntfs_dos_name -v 123 dir/subdir/link;
266          setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` dir/subdir/link;
267          setfattr -n user.yet_another_ads -v "" dir/subdir/link;
268          setfattr -n user.yet_another_ads2 -v "" dir/subdir/link;
269          setfattr -n user.yet_another_ads3 -v "abc" dir/subdir/link;
270          setfattr -n user.yet_another_ads4 -v "" dir/subdir/link;'
271
272 cleanup
273
274 echo "**********************************************************"
275 echo "           NTFS capture/apply tests passed                "
276 echo "**********************************************************"