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