summaryrefslogtreecommitdiff
path: root/minix/tests/testisofs.sh
blob: f1ab021ebddefc739313150de2e309612765492a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# Create and verify a simple ISO filesystem
#
#!/bin/sh

set -e

echo -n "isofs test "

# Somehow timezones mess up the timestamp comparison, so unset the timezone for
# now.  TODO: sort out if this is actually a bug or simply expected behavior.
unset TZ

# testing ISO 9660 Level 3 compliance isn't possible for the time being
# (not possible to store a >4GB ISO file into a ramdisk)
testLevel3=0
testRockRidge=1

ramdev=/dev/ram
mp=/mnt
testdir=isofstest
fsimage=isofsimage
contents=CONTENTS
out1=v1
out2=v2
excludes=excludes

create_contents_level3() {
	# >4GB file
	seq 1 1000000000 > $testdir/HUGEFILE
}

create_contents_rockridge() {
	# long filenames
	mkdir -p $testdir/rockridge/longnames
	echo "this is a test" > $testdir/rockridge/longnames/azertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopaz
	echo "this is a test" > $testdir/rockridge/longnames/azertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopaze
	echo "this is a test" > $testdir/rockridge/longnames/azertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazer

	# devices
	mkdir -p $testdir/rockridge/devices
	CURLOC=$(pwd)
	cd $testdir/rockridge/devices && MAKEDEV -s
	cd $CURLOC

	# symbolic links
	mkdir -p $testdir/rockridge/symlinks
	ln -s . $testdir/rockridge/symlinks/cur_dir
	ln -s .. $testdir/rockridge/symlinks/parent_dir
	ln -s / $testdir/rockridge/symlinks/root_dir
	ln -s /mnt $testdir/rockridge/symlinks/root_mnt_dir
	ln -s ../../rockridge $testdir/rockridge/symlinks/rockridge_dir
	ln -s ../../rockridge/symlinks $testdir/rockridge/symlinks/symlinks_dir
	ln -s ../../rockridge/symlinks/../symlinks $testdir/rockridge/symlinks/symlinks_dir_bis
	ln -s cur_dir $testdir/rockridge/symlinks/to_cur_dir
	ln -s rockridge_dir $testdir/rockridge/symlinks/to_rockridge_dir

	# deep directory tree
	mkdir -p $testdir/rockridge/deep_dirs/this/is/a/ridiculously/deep/directory/hierarchy/dont/you/think
	mkdir -p $testdir/rockridge/deep_dirs/this/is/a/ridiculously/deep/directory/hierarchy/dont/you/think/yes
	mkdir -p $testdir/rockridge/deep_dirs/this/is/a/ridiculously/deep/directory/hierarchy/dont/you/think/no
	echo "I agree." > $testdir/rockridge/deep_dirs/this/is/a/ridiculously/deep/directory/hierarchy/dont/you/think/yes/awnser1
	echo "Yes, totally." > $testdir/rockridge/deep_dirs/this/is/a/ridiculously/deep/directory/hierarchy/dont/you/think/yes/awnser2
	echo "Nah." > $testdir/rockridge/deep_dirs/this/is/a/ridiculously/deep/directory/hierarchy/dont/you/think/no/awnser1
	echo "Meh." > $testdir/rockridge/deep_dirs/this/is/a/ridiculously/deep/directory/hierarchy/dont/you/think/no/awnser2

	# permissions
	mkdir -p $testdir/rockridge/permissions
	for u in $(seq 0 7); do
		for g in $(seq 0 7); do
			for o in $(seq 0 7); do
				echo "$u$g$o" > $testdir/rockridge/permissions/mode-$u$g$o
				chmod $u$g$o $testdir/rockridge/permissions/mode-$u$g$o
			done
		done
	done
	echo "uid-gid test" > $testdir/rockridge/permissions/uid-1-gid-2
	chown 1:2 $testdir/rockridge/permissions/uid-1-gid-2
	echo "uid-gid test" > $testdir/rockridge/permissions/uid-128-gid-256
	chown 128:256 $testdir/rockridge/permissions/uid-128-gid-256
	echo "uid-gid test" > $testdir/rockridge/permissions/uid-12345-gid-23456
	chown 12345:23456 $testdir/rockridge/permissions/uid-12345-gid-23456
}

create_contents_base() {
	# simple file
	echo $(date) > $testdir/DATE

	# big file
	seq 1 100000 > $testdir/BIGFILE

	# lots of files in a directory
	mkdir $testdir/BIGDIR
	for i in $(seq 1 250); do
		HASH=$(cksum -a SHA1 <<EOF
$i
EOF
)
		FILE=$(echo $HASH | cut -c 1-30 | sed -e "y/abcdef/ABCDEF/")
		echo $HASH > $testdir/BIGDIR/$FILE
	done

	# lots of directories
	mkdir $testdir/SUBDIRS
	for i in $(seq 1 1000); do
		HASH=$(cksum -a SHA1 <<EOF
$i
EOF
)
		DIR1=$(echo $HASH | cut -c 1-2 | sed -e "y/abcdef/ABCDEF/")
		DIR2=$(echo $HASH | cut -c 3-4 | sed -e "y/abcdef/ABCDEF/")
		FILE=$(echo $HASH | cut -c 5-12 | sed -e "y/abcdef/ABCDEF/")
		mkdir -p $testdir/SUBDIRS/$DIR1/$DIR2
		echo $HASH > $testdir/SUBDIRS/$DIR1/$DIR2/$FILE
	done
}

rm -rf $testdir $fsimage $out1 $out2 $excludes

if [ -d $testdir ]
then
	echo "dir?"
	exit 1
fi

mkdir -p $testdir

if [ ! -d $testdir ]
then
	echo "no dir?"
	exit 1
fi

# make some small & big & bigger files
OPTIONS=
create_contents_base
if [ "$testLevel3" -eq 1 ]
then
	create_contents_level3
fi
if [ "$testRockRidge" -eq 1 ]
then
	create_contents_rockridge
	OPTIONS="-o rockridge"
else
	# fixups for the fact that bare ISO 9660 isn't POSIX enough
	# for mtree
	# fix permissions
	find $testdir -exec chmod 555 {} ";"
fi

# make image
/usr/sbin/makefs -t cd9660 $OPTIONS $fsimage $testdir

# umount previous things
umount $ramdev >/dev/null 2>&1 || true
umount $mp >/dev/null 2>&1 || true

# mount it on a RAM disk
ramdisk $(expr $(wc -c < $fsimage) / 1024) $ramdev >/dev/null 2>&1
cat < $fsimage > $ramdev
mount -t isofs $ramdev $mp >/dev/null 2>&1

# compare contents
if [ "$testRockRidge" -eq 1 ]
then
	# get rid of root directory time
	echo 'RR_MOVED' >$excludes
	/usr/sbin/mtree -c -p $testdir | sed -e "s/\. *type=dir.*/\. type=dir/" | /usr/sbin/mtree -p $mp -X $excludes
else
	# fixups for the fact that bare ISO 9660 isn't POSIX enough
	# for mtree
	# get rid of time
	/usr/sbin/mtree -c -p $testdir | sed -e "s/time=[0-9]*.[0-9]*//" | /usr/sbin/mtree -p $mp
fi

umount $ramdev >/dev/null 2>&1

# cleanup
rm -rf $testdir $fsimage $out1 $out2 $excludes

echo ok

exit 0