7 srcdir="${srcdir:-.}/.."
8 srcdir="$(cd $srcdir; pwd)"
9 . "$srcdir/tests/tests-common.sh"
11 if [ ! -r /dev/fuse ]; then
12 echo "WARNING: /dev/fuse is not readable."
13 echo "Skipping WIM mounting checks"
19 ../imagex $@ > /dev/null
28 echo "imagex mountrw $@"
29 ../imagex mountrw "$@"
33 fusermount -u tmp &> /dev/null || true
34 fusermount -u tmp.mnt &> /dev/null || true
35 rm -rf dir* tmp* *.wim *.swm empty.wim tmp.orig tmp.mnt \
36 tmp.apply mount.log test.tar wimlib-staging*
40 cp $srcdir/src/*.c $srcdir/src/*.h dir
42 echo 'hello' > dir/subdir/hello
43 echo 'hello' > dir/subdir/hello2
44 ln dir/subdir/hello dir/subdir/hellolink
45 echo -n > dir/subdir/empty_file
46 ln -s hello dir/subdir/rel_symlink
49 echo 'testing' > dir2/file
50 dd if=/dev/zero of=dir2/zeroes bs=4096 count=5
51 mkdir tmp.empty tmp.mnt tmp.apply tmp.orig
52 imagex capture tmp.empty empty.wim
56 echo "****************************************************************"
58 while [ $# -gt 0 ]; do
62 echo "****************************************************************"
71 for flag in "--compress=none" "--compress=maximum" "--compress=fast"; do
72 echo "Using flag $flag"
73 echo "Testing mounting WIM read-only"
74 if ! imagex capture dir dir.wim $flag; then
75 error "Failed to capture WIM"
78 if ! imagex mount dir.wim dir tmp; then
79 error "Failed to mount test WIM read-only" \
80 "Please read any error messages above before reporting this test failure."\
81 "Perhaps you don't have FUSE installed, or the FUSE kernel module isn't" \
82 "loaded, or you aren't a member of the FUSE group?"
84 echo "Testing extracting file from mounted read-only WIM"
85 if ! cp tmp/lz77.c lz77.c; then
86 error "Failed to extract file from read-only mounted WIM"
88 if ! diff -q dir/lz77.c lz77.c; then
89 error "Extracted file does not match copy in mounted WIM"
91 if ! diff -q tmp/lz77.c dir/lz77.c; then
92 error "Extractef file does not match original"
95 echo "Testing modifying mounted read-only WIM (should fail)"
96 if rm tmp/lz77.c; then
97 error "Removing file from read-only mounted WIM didn't fail"
99 if touch tmp/newfile; then
100 error "Creating file on read-only mounted WIM didn't fail"
102 if echo 3 > tmp/lz77.c; then
103 error "Writing to file on read-only mounted WIM didn't fail"
105 echo "Testing diff of mounted read-only WIM with original directory"
106 if ! diff -q -r tmp dir; then
107 error "Recursive diff of read-only mounted WIM with original directory failed"
109 echo "Testing unmount of read-only filesystem"
110 if ! imagex unmount tmp; then
111 error "Unmounting read-only WIM failed"
113 echo "Testing unmount of read-only filesystem with --commit given"
114 if ! imagex mount dir.wim dir tmp; then
115 error "Failed to re-mount WIM read-only"
117 if ! imagex unmount tmp --commit; then
118 error "Failed to unmount read-only WIM with --commit flag (should be ignored)"
124 echo "Testing mounting WIM read-write"
125 if ! imagex capture dir dir.wim; then
126 error "Failed to capture WIM"
129 if ! imagex mountrw dir.wim dir tmp; then
130 error "Failed to mount test WIM read-write"
132 echo "Testing unmounting WIM unmodified"
133 if ! imagex unmount tmp; then
134 error "Failed to unmount test WIM unmodified"
136 echo "Testing unmounting WIM unmodified with --commit and --check"
137 if ! imagex mountrw dir.wim dir tmp; then
138 error "Failed to re-mount test WIM read-write"
140 if ! imagex unmount tmp --commit --check; then
141 error "Failed to unmount read-write mounted WIM with changes commited (no changes made)"
143 echo "Testing removing file from mounted WIM"
144 if ! imagex mountrw dir.wim dir tmp; then
145 error "Failed to re-mount test WIM read-write"
147 if ! rm tmp/lz77.c; then
148 error "Failed to remove file from read-write mounted WIM"
150 if test -f tmp/lz77.c; then
151 error "Removing file from read-write mounted WIM failed"
153 echo "Testing making directory in mounted WIM"
154 if ! mkdir tmp/newdir; then
155 error "Failed to make directory in read-write mounted WIM"
157 if ! test -d tmp/newdir; then
158 error "Making directory in read-write mounted WIM failed"
160 echo "Testing making new empty file in mounted WIM"
161 if ! touch tmp/newdir/empty_file; then
162 error "Could not create new empty file in read-write mounted WIM"
164 if ! test -f tmp/newdir/empty_file; then
165 error "New empty file not created correctly in read-write mounted WIM"
167 if ! test "`get_file_size tmp/newdir/empty_file`" = 0; then
168 error "New empty file in read-write mounted WIM is not empty"
170 echo "Testing making new non-empty file in mounted WIM"
171 if ! dd if=/dev/zero of=tmp/newdir/zeroes1 bs=1 count=4096; then
172 error "Failed to make new non-empty file in mounted WIM"
174 if ! dd if=/dev/zero of=tmp/newdir/zeroes2 bs=4096 count=1; then
175 error "Failed to make new non-empty file in mounted WIM"
177 if ! diff -q tmp/newdir/zeroes1 tmp/newdir/zeroes2; then
178 error "New files in mounted WIM not made correctly"
180 echo "Unmounting WIM with changes committed and --check"
181 if ! imagex unmount tmp --commit --check; then
182 error "Failed to unmount read-write mounted WIM"
184 if test "`imagex_info dir.wim | grep Integrity | awk '{print $3}'`" != "yes"; then
185 error "Integrity information was not included"
188 if ! imagex apply dir.wim tmp; then
189 error "Failed to apply WIM we had previously mounted read-write"
191 if ! diff -q tmp/newdir/zeroes1 tmp/newdir/zeroes2; then
192 error "The new non-empty files we made in the read-write mounted WIM were not extracted correctly"
194 if test `get_file_size tmp/newdir/empty_file` != 0; then
195 error "The new empty file we made in the read-write mounted WIM was not extracted correctly"
197 if test `get_file_size tmp/newdir/zeroes1` != 4096; then
198 error "The new non-empty files we made in the read-write mounted WIM were not extracted correctly"
201 # Now do some tests using tar.
203 if ! ./tree-cmp $1 $2; then
204 if [ -x /usr/bin/tree ]; then
205 echo "Dumping tree of applied image"
206 tree $2 --inodes -F -s --noreport
207 error 'Information was lost or corrupted while capturing
208 and then applying a directory tree'
214 echo "--------------------------------------------------------------------"
215 echo "Testing making $1 on read-write mounted WIM"
216 echo "--------------------------------------------------------------------"
221 # Create tree, tar it up, and untar it on an empty WIM image mounted
224 cp empty.wim test.wim
228 if [ -x /usr/bin/tree ]; then
229 tree . --inodes -F -s --noreport
234 if ! imagex_mountrw test.wim tmp.mnt; then
235 error "Failed to mount WIM read-write"
239 if ! tar xf ../test.tar --no-same-owner; then
240 error "Failed to untar archive on read-write mounted WIM"
244 # Diff the original tree with the mounted WIM
245 do_tree_cmp tmp.orig tmp.mnt
247 # Clear the mounted WIM and do it again! (We need to test deleting
248 # stuff as well as creating stuff.)
249 if ! rm -rf tmp.mnt/*; then
250 error "Failed to clear mounted WIM"
254 if ! tar xf ../test.tar --no-same-owner; then
255 error "Failed to untar archive on read-write mounted WIM"
259 # Diff the original tree with the mounted WIM
260 do_tree_cmp tmp.orig tmp.mnt
262 # Unmount the WIM, apply it, and diff the original tree with the applied
264 if ! imagex unmount tmp.mnt --commit; then
265 error "Failed to unmount WIM mounted read-write"
267 if ! imagex apply test.wim tmp.apply; then
268 error "Failed to apply WIM we previously had mounted read-write"
270 do_tree_cmp tmp.orig tmp.apply
271 rm -rf tmp.orig/* tmp.apply/*
274 . $srcdir/tests/common_tests.sh
278 echo "**********************************************************"
279 echo " WIM mount tests passed "
280 echo "**********************************************************"