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