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