xref: /minix/minix/tests/testisofs.sh (revision 045e0ed3)
1# Create and verify a simple ISO filesystem
2#
3#!/bin/sh
4
5set -e
6
7echo -n "isofs test "
8
9# Somehow timezones mess up the timestamp comparison, so unset the timezone for
10# now.  TODO: sort out if this is actually a bug or simply expected behavior.
11unset TZ
12
13# testing ISO 9660 Level 3 compliance isn't possible for the time being
14# (not possible to store a >4GB ISO file into a ramdisk)
15testLevel3=0
16testRockRidge=1
17
18ramdev=/dev/ram
19mp=/mnt
20testdir=isofstest
21fsimage=isofsimage
22contents=CONTENTS
23out1=v1
24out2=v2
25excludes=excludes
26
27create_contents_level3() {
28	# >4GB file
29	seq 1 1000000000 > $testdir/HUGEFILE
30}
31
32create_contents_rockridge() {
33	# long filenames
34	mkdir -p $testdir/rockridge/longnames
35	echo "this is a test" > $testdir/rockridge/longnames/azertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopaz
36	echo "this is a test" > $testdir/rockridge/longnames/azertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopaze
37	echo "this is a test" > $testdir/rockridge/longnames/azertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazer
38
39	# devices
40	mkdir -p $testdir/rockridge/devices
41	CURLOC=$(pwd)
42	cd $testdir/rockridge/devices && MAKEDEV -s
43	cd $CURLOC
44
45	# symbolic links
46	mkdir -p $testdir/rockridge/symlinks
47	ln -s . $testdir/rockridge/symlinks/cur_dir
48	ln -s .. $testdir/rockridge/symlinks/parent_dir
49	ln -s / $testdir/rockridge/symlinks/root_dir
50	ln -s /mnt $testdir/rockridge/symlinks/root_mnt_dir
51	ln -s ../../rockridge $testdir/rockridge/symlinks/rockridge_dir
52	ln -s ../../rockridge/symlinks $testdir/rockridge/symlinks/symlinks_dir
53	ln -s ../../rockridge/symlinks/../symlinks $testdir/rockridge/symlinks/symlinks_dir_bis
54	ln -s cur_dir $testdir/rockridge/symlinks/to_cur_dir
55	ln -s rockridge_dir $testdir/rockridge/symlinks/to_rockridge_dir
56
57	# deep directory tree
58	mkdir -p $testdir/rockridge/deep_dirs/this/is/a/ridiculously/deep/directory/hierarchy/dont/you/think
59	mkdir -p $testdir/rockridge/deep_dirs/this/is/a/ridiculously/deep/directory/hierarchy/dont/you/think/yes
60	mkdir -p $testdir/rockridge/deep_dirs/this/is/a/ridiculously/deep/directory/hierarchy/dont/you/think/no
61	echo "I agree." > $testdir/rockridge/deep_dirs/this/is/a/ridiculously/deep/directory/hierarchy/dont/you/think/yes/awnser1
62	echo "Yes, totally." > $testdir/rockridge/deep_dirs/this/is/a/ridiculously/deep/directory/hierarchy/dont/you/think/yes/awnser2
63	echo "Nah." > $testdir/rockridge/deep_dirs/this/is/a/ridiculously/deep/directory/hierarchy/dont/you/think/no/awnser1
64	echo "Meh." > $testdir/rockridge/deep_dirs/this/is/a/ridiculously/deep/directory/hierarchy/dont/you/think/no/awnser2
65
66	# permissions
67	mkdir -p $testdir/rockridge/permissions
68	for u in $(seq 0 7); do
69		for g in $(seq 0 7); do
70			for o in $(seq 0 7); do
71				echo "$u$g$o" > $testdir/rockridge/permissions/mode-$u$g$o
72				chmod $u$g$o $testdir/rockridge/permissions/mode-$u$g$o
73			done
74		done
75	done
76	echo "uid-gid test" > $testdir/rockridge/permissions/uid-1-gid-2
77	chown 1:2 $testdir/rockridge/permissions/uid-1-gid-2
78	echo "uid-gid test" > $testdir/rockridge/permissions/uid-128-gid-256
79	chown 128:256 $testdir/rockridge/permissions/uid-128-gid-256
80	echo "uid-gid test" > $testdir/rockridge/permissions/uid-12345-gid-23456
81	chown 12345:23456 $testdir/rockridge/permissions/uid-12345-gid-23456
82}
83
84create_contents_base() {
85	# simple file
86	echo $(date) > $testdir/DATE
87
88	# big file
89	seq 1 100000 > $testdir/BIGFILE
90
91	# lots of files in a directory
92	mkdir $testdir/BIGDIR
93	for i in $(seq 1 250); do
94		HASH=$(cksum -a SHA1 <<EOF
95$i
96EOF
97)
98		FILE=$(echo $HASH | cut -c 1-30 | sed -e "y/abcdef/ABCDEF/")
99		echo $HASH > $testdir/BIGDIR/$FILE
100	done
101
102	# lots of directories
103	mkdir $testdir/SUBDIRS
104	for i in $(seq 1 1000); do
105		HASH=$(cksum -a SHA1 <<EOF
106$i
107EOF
108)
109		DIR1=$(echo $HASH | cut -c 1-2 | sed -e "y/abcdef/ABCDEF/")
110		DIR2=$(echo $HASH | cut -c 3-4 | sed -e "y/abcdef/ABCDEF/")
111		FILE=$(echo $HASH | cut -c 5-12 | sed -e "y/abcdef/ABCDEF/")
112		mkdir -p $testdir/SUBDIRS/$DIR1/$DIR2
113		echo $HASH > $testdir/SUBDIRS/$DIR1/$DIR2/$FILE
114	done
115}
116
117rm -rf $testdir $fsimage $out1 $out2 $excludes
118
119if [ -d $testdir ]
120then
121	echo "dir?"
122	exit 1
123fi
124
125mkdir -p $testdir
126
127if [ ! -d $testdir ]
128then
129	echo "no dir?"
130	exit 1
131fi
132
133# make some small & big & bigger files
134OPTIONS=
135create_contents_base
136if [ "$testLevel3" -eq 1 ]
137then
138	create_contents_level3
139fi
140if [ "$testRockRidge" -eq 1 ]
141then
142	create_contents_rockridge
143	OPTIONS="-o rockridge"
144else
145	# fixups for the fact that bare ISO 9660 isn't POSIX enough
146	# for mtree
147	# fix permissions
148	find $testdir -exec chmod 555 {} ";"
149fi
150
151# make image
152/usr/sbin/makefs -t cd9660 $OPTIONS $fsimage $testdir
153
154# umount previous things
155umount $ramdev >/dev/null 2>&1 || true
156umount $mp >/dev/null 2>&1 || true
157
158# mount it on a RAM disk
159ramdisk $(expr $(wc -c < $fsimage) / 1024) $ramdev >/dev/null 2>&1
160cat < $fsimage > $ramdev
161mount -t isofs $ramdev $mp >/dev/null 2>&1
162
163# compare contents
164if [ "$testRockRidge" -eq 1 ]
165then
166	# get rid of root directory time
167	echo 'RR_MOVED' >$excludes
168	/usr/sbin/mtree -c -p $testdir | sed -e "s/\. *type=dir.*/\. type=dir/" | /usr/sbin/mtree -p $mp -X $excludes
169else
170	# fixups for the fact that bare ISO 9660 isn't POSIX enough
171	# for mtree
172	# get rid of time
173	/usr/sbin/mtree -c -p $testdir | sed -e "s/time=[0-9]*.[0-9]*//" | /usr/sbin/mtree -p $mp
174fi
175
176umount $ramdev >/dev/null 2>&1
177
178# cleanup
179rm -rf $testdir $fsimage $out1 $out2 $excludes
180
181echo ok
182
183exit 0
184