]> wimlib.net Git - wimlib/blob - tests/test-imagex-ntfs
wimlib_mount_image(): Send final status after fuse_main() returns
[wimlib] / tests / test-imagex-ntfs
1 #!/usr/bin/env 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 cd tests
13 srcdir="${srcdir:-.}/.."
14 srcdir="$(cd $srcdir; pwd)"
15 . "$srcdir/tests/tests-common.sh"
16
17 TEST_SUBDIR=tmpdir_test-imagex-ntfs
18
19 __do_unmount() {
20         if ! fusermount -z -u $1; then
21                 error "Failed to unmount \"$1\""
22         fi
23
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 "\
41                       "installed, and that you are either running the tests as root or have ntfs-3g "\
42                       "installed setuid root, so that we can mount a NTFS volume."
43         fi
44 }
45
46 do_mount() {
47         do_unmount $2
48         __do_mount $1 $2 $3
49 }
50
51 do_mkntfs() {
52         if ! mkntfs --force --fast $1 > /dev/null; then
53                 error "Could not create NTFS volume \"$1\"!  Make sure ntfsprogs are installed."
54         fi
55 }
56
57 init() {
58         echo "Creating NTFS volumes and empty directories to use as mountpoints"
59         dd if=/dev/zero of=in.ntfs bs=4096 count=500 &> /dev/null
60         dd if=/dev/zero of=out.ntfs bs=4096 count=500 &> /dev/null
61         mkdir in.mnt out.mnt
62         do_mkntfs in.ntfs
63         do_mkntfs out.ntfs
64         do_mount in.ntfs in.mnt
65 }
66
67 cleanup() {
68         do_unmount $TEST_SUBDIR/in.mnt
69         do_unmount $TEST_SUBDIR/out.mnt
70         rm -rf $TEST_SUBDIR
71 }
72
73 do_test() {
74         cd in.mnt
75         eval "$1"
76         cd ..
77         __do_unmount in.mnt
78         if ! imagex capture in.ntfs ntfs.wim; then
79                 error "Failed to capture NTFS volume into a WIM"
80         fi
81         if ! imagex apply ntfs.wim 1 out.ntfs; then
82                 error "Failed to apply WIM to NTFS volume"
83         fi
84         __do_mount in.ntfs in.mnt noatime
85         __do_mount out.ntfs out.mnt noatime
86         if [ -x /usr/bin/tree ]; then
87                 tree in.mnt --inodes -F -s --noreport
88         fi
89         if ! ../tree-cmp in.mnt out.mnt NTFS; then
90                 if [ -x /usr/bin/tree ]; then
91                         echo "Dumping tree of applied image"
92                         tree out.mnt --inodes -F -s --noreport
93                         error 'Information was lost or corrupted while capturing
94                                 and then applying a NTFS volume'
95                 fi
96         fi
97         rm -rf out.mnt/* in.mnt/*
98         __do_unmount out.mnt
99 }
100 msg() {
101         echo "--------------------------------------------------------------------"
102         echo "Testing image capture and application of NTFS volume containing $1"
103         echo "--------------------------------------------------------------------"
104 }
105
106 cleanup
107 mkdir $TEST_SUBDIR
108 cd $TEST_SUBDIR
109 init
110
111 msg "Empty NTFS volume"
112 do_test ""
113
114 msg "a single file"
115 do_test "echo 1 > file"
116
117 msg "a single directory"
118 do_test "mkdir dir"
119
120 msg "subdirectory with file"
121 do_test "mkdir dir; echo 1 > dir/file"
122
123 msg "empty file"
124 do_test "echo -n > empty_file"
125
126 msg "two empty files"
127 do_test "echo -n > empty_file_1; echo -n > empty_file_2"
128
129 msg "hard link in same directory"
130 do_test "echo 1 > file; ln file link"
131
132 msg "hard link between empty files"
133 do_test "echo -n > empty_file; ln empty_file link"
134
135 msg "relative symbolic link"
136 do_test "echo 1 > file; ln -s file symlink"
137
138 msg "absolute symbolic link"
139 do_test "echo 1 > file; ln -s /some/absolute/target symlink"
140
141 msg "large file"
142 do_test "dd if=/dev/zero of=file bs=4096 count=10 &> /dev/null"
143
144 msg "file with DOS name"
145 do_test "echo 1 > file; setfattr -v file -n system.ntfs_dos_name file"
146
147 # To be replaced/removed: files with DOS names can no longer be hard linked as
148 # of NTFS-3g 2013.1.13.
149
150 #msg "file with DOS name with alphabetically smaller hardlink in same directory"
151 #do_test "echo 1 > file; setfattr -v file -n system.ntfs_dos_name file; ln file aaa_link"
152
153 #msg "file with DOS name with alphabetically larger hardlink in same directory"
154 #do_test "echo 1 > file; setfattr -v file -n system.ntfs_dos_name file; ln file zzz_link"
155
156 #msg "file with long name and with DOS name with alphabetically smaller hardlink in same directory"
157 #do_test 'echo 1 > file_with_a_long_name;
158          #setfattr -v "file~1" -n system.ntfs_dos_name file_with_a_long_name;
159          #ln file_with_a_long_name aaa_link'
160
161 msg "many nested directories"
162 do_test 'mkdir dir; mkdir dir/subdir; mkdir dir/subdir/subdir2; mkdir dir/subdir/subdir3'
163
164 msg "identical files and symlinks in subdirectory"
165 do_test 'mkdir dir;
166          echo 888 > dir/file;
167          echo 888 > dir/idfile2;
168          ln -s ../dir dir/circle; ln -s file dir/filelink'
169
170 msg "hard link group and identical files not hard linked"
171 do_test 'echo 888 > file;
172          echo 888 > file2;
173          ln file link;
174          ln file link2;
175          echo 888 > file3'
176
177 msg "file with named data stream"
178 do_test 'echo 1 > file;
179          setfattr -n user.ads -v 2 file'
180
181 msg "file with multiple named data streams"
182 do_test 'echo 1 > file;
183          setfattr -n user.a -v 1 file;
184          setfattr -n user.aa -v 11 file;
185          setfattr -n user.aaa -v 111 file;
186          setfattr -n user.aaaa -v 1111 file'
187
188 msg "file with multiple named data streams with same contents"
189 do_test 'echo 1 > file;
190          setfattr -n user.a -v 1111 file;
191          setfattr -n user.aa -v 1111 file;
192          setfattr -n user.aaa -v 1111 file;
193          setfattr -n user.aaaa -v 1111 file;'
194
195 msg "file with named data streams with same contents as other file"
196 do_test 'echo -n > file;
197          setfattr -n user.a -v 1111 file;
198          echo -n 1111 > otherfile;'
199
200 msg "file with empty named data stream and non-empty unnamed data stream"
201 do_test 'echo 1 > file;
202          setfattr -n user.ads -v "" file;'
203
204 msg "file with empty named data stream and empty unnamed data stream"
205 do_test 'echo -n > file;
206          setfattr -n user.ads -v "" file;'
207
208 msg "file with named data stream with hardlink"
209 do_test 'echo 999 > file;
210          setfattr -n user.ads -v "888" file;
211          ln file link;'
212
213 # To be replaced/removed: files with DOS names can no longer be hard linked as
214 # of NTFS-3g 2013.1.13.
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          echo -n > dir/subdir/empty;
271          setfattr -n system.ntfs_dos_name -v 123 dir/subdir/empty;
272          setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` dir/subdir/link;
273          setfattr -n user.yet_another_ads -v "" dir/subdir/link;
274          setfattr -n user.yet_another_ads2 -v "" dir/subdir/link;
275          setfattr -n user.yet_another_ads3 -v "abc" dir/subdir/link;
276          setfattr -n user.yet_another_ads4 -v "" dir/subdir/link;'
277
278 echo "**********************************************************"
279 echo "           NTFS capture/apply tests passed                "
280 echo "**********************************************************"
281
282 cd ..
283 cleanup
284