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