7 srcdir="${srcdir:-.}/.."
8 srcdir="$(cd $srcdir; pwd)"
9 . "$srcdir/tests/tests-common.sh"
11 TEST_SUBDIR=tmpdir_test-imagex-mount
13 if [ ! -r /dev/fuse ]; then
14 echo "WARNING: /dev/fuse is not readable."
15 echo "Skipping WIM mounting checks"
20 fusermount -u $TEST_SUBDIR/tmp &> /dev/null || true
21 fusermount -u $TEST_SUBDIR/tmp.mnt &> /dev/null || true
27 cp $srcdir/src/*.c dir
29 echo 'hello' > dir/subdir/hello
30 echo 'hello' > dir/subdir/hello2
31 ln dir/subdir/hello dir/subdir/hellolink
32 echo -n > dir/subdir/empty_file
33 ln -s hello dir/subdir/rel_symlink
36 echo 'testing' > dir2/file
37 dd if=/dev/zero of=dir2/zeroes bs=4096 count=5
38 mkdir tmp.empty tmp.mnt tmp.apply tmp.orig
39 imagex capture tmp.empty empty.wim --norpfix
49 for flag in "--compress=none" "--compress=maximum" "--compress=fast"; do
50 echo "Using flag $flag"
51 echo "Testing mounting WIM read-only"
52 if ! imagex capture dir dir.wim $flag; then
53 error "Failed to capture WIM"
56 if ! imagex mount dir.wim dir tmp; then
57 error "Failed to mount test WIM read-only. " \
58 "Please read any error messages above before reporting this test failure. "\
59 "Perhaps you don't have FUSE installed, or the FUSE kernel module isn't" \
60 "loaded, or you aren't a member of the FUSE group?"
62 echo "Testing extracting file from mounted read-only WIM"
63 if ! cp tmp/lz77.c lz77.c; then
64 error "Failed to extract file from read-only mounted WIM"
66 if ! diff -q dir/lz77.c lz77.c; then
67 error "Extracted file does not match copy in mounted WIM"
69 if ! diff -q tmp/lz77.c dir/lz77.c; then
70 error "Extractef file does not match original"
73 echo "Testing modifying mounted read-only WIM (should fail)"
74 if rm tmp/lz77.c; then
75 error "Removing file from read-only mounted WIM didn't fail"
77 if touch tmp/newfile; then
78 error "Creating file on read-only mounted WIM didn't fail"
80 if echo 3 > tmp/lz77.c; then
81 error "Writing to file on read-only mounted WIM didn't fail"
83 echo "Testing diff of mounted read-only WIM with original directory"
84 if ! diff -q -r tmp dir; then
85 error "Recursive diff of read-only mounted WIM with original directory failed"
87 echo "Testing unmount of read-only filesystem"
88 if ! imagex unmount tmp; then
89 error "Unmounting read-only WIM failed"
91 echo "Testing unmount of read-only filesystem with --commit given"
92 if ! imagex mount dir.wim dir tmp; then
93 error "Failed to re-mount WIM read-only"
95 if ! imagex unmount tmp --commit; then
96 error "Failed to unmount read-only WIM with --commit flag (should be ignored)"
102 echo "Testing mounting WIM read-write"
103 if ! imagex capture dir dir.wim; then
104 error "Failed to capture WIM"
107 if ! imagex mountrw dir.wim dir tmp; then
108 error "Failed to mount test WIM read-write"
110 echo "Testing unmounting WIM unmodified"
111 if ! imagex unmount tmp; then
112 error "Failed to unmount test WIM unmodified"
114 echo "Testing unmounting WIM unmodified with --commit and --check"
115 if ! imagex mountrw dir.wim dir tmp; then
116 error "Failed to re-mount test WIM read-write"
118 if ! imagex unmount tmp --commit --check; then
119 error "Failed to unmount read-write mounted WIM with changes commited (no changes made)"
121 echo "Testing removing file from mounted WIM"
122 if ! imagex mountrw dir.wim dir tmp; then
123 error "Failed to re-mount test WIM read-write"
125 if ! rm tmp/lz77.c; then
126 error "Failed to remove file from read-write mounted WIM"
128 if test -f tmp/lz77.c; then
129 error "Removing file from read-write mounted WIM failed"
131 echo "Testing making directory in mounted WIM"
132 if ! mkdir tmp/newdir; then
133 error "Failed to make directory in read-write mounted WIM"
135 if ! test -d tmp/newdir; then
136 error "Making directory in read-write mounted WIM failed"
138 echo "Testing making new empty file in mounted WIM"
139 if ! touch tmp/newdir/empty_file; then
140 error "Could not create new empty file in read-write mounted WIM"
142 if ! test -f tmp/newdir/empty_file; then
143 error "New empty file not created correctly in read-write mounted WIM"
145 if ! test "`get_file_size tmp/newdir/empty_file`" = 0; then
146 error "New empty file in read-write mounted WIM is not empty"
148 echo "Testing making new non-empty file in mounted WIM"
149 if ! dd if=/dev/zero of=tmp/newdir/zeroes1 bs=1 count=4096; then
150 error "Failed to make new non-empty file in mounted WIM"
152 if ! dd if=/dev/zero of=tmp/newdir/zeroes2 bs=4096 count=1; then
153 error "Failed to make new non-empty file in mounted WIM"
155 if ! diff -q tmp/newdir/zeroes1 tmp/newdir/zeroes2; then
156 error "New files in mounted WIM not made correctly"
158 echo "Unmounting WIM with changes committed and --check"
159 if ! imagex unmount tmp --commit --check; then
160 error "Failed to unmount read-write mounted WIM"
162 if test "`imagex info dir.wim | grep Integrity | awk '{print $3}'`" != "yes"; then
163 error "Integrity information was not included"
166 if ! imagex apply dir.wim tmp; then
167 error "Failed to apply WIM we had previously mounted read-write"
169 if ! diff -q tmp/newdir/zeroes1 tmp/newdir/zeroes2; then
170 error "The new non-empty files we made in the read-write mounted WIM were not extracted correctly"
172 if test `get_file_size tmp/newdir/empty_file` != 0; then
173 error "The new empty file we made in the read-write mounted WIM was not extracted correctly"
175 if test `get_file_size tmp/newdir/zeroes1` != 4096; then
176 error "The new non-empty files we made in the read-write mounted WIM were not extracted correctly"
179 # Now do some tests using tar.
181 if ! ../tree-cmp $1 $2; then
182 if [ -x /usr/bin/tree ]; then
183 echo "Dumping tree of applied image"
184 tree $2 --inodes -F -s --noreport
185 error 'Information was lost or corrupted while capturing
186 and then applying a directory tree'
192 echo "--------------------------------------------------------------------"
193 echo "Testing making $1 on read-write mounted WIM"
194 echo "--------------------------------------------------------------------"
199 # Create tree, tar it up, and untar it on an empty WIM image mounted
202 cp empty.wim test.wim
206 if [ -x /usr/bin/tree ]; then
207 tree . --inodes -F -s --noreport
212 if ! imagex mountrw test.wim tmp.mnt --unix-data; then
213 error "Failed to mount WIM read-write"
217 if ! tar xf ../test.tar; then
218 error "Failed to untar archive on read-write mounted WIM"
222 # Diff the original tree with the mounted WIM
223 do_tree_cmp tmp.orig tmp.mnt
225 # Clear the mounted WIM and do it again! (We need to test deleting
226 # stuff as well as creating stuff.)
227 if ! rm -rf tmp.mnt/*; then
228 error "Failed to clear mounted WIM"
232 if ! tar xf ../test.tar; then
233 error "Failed to untar archive on read-write mounted WIM"
237 # Diff the original tree with the mounted WIM
238 do_tree_cmp tmp.orig tmp.mnt
240 # Unmount the WIM, apply it, and diff the original tree with the applied
242 if ! imagex unmount tmp.mnt --commit; then
243 error "Failed to unmount WIM mounted read-write"
245 if ! imagex apply test.wim tmp.apply; then
246 error "Failed to apply WIM we previously had mounted read-write"
248 do_tree_cmp tmp.orig tmp.apply
249 rm -rf tmp.orig/* tmp.apply/*
252 . $srcdir/tests/common_tests.sh
255 echo "**********************************************************"
256 echo " WIM mount tests passed "
257 echo "**********************************************************"