Drop main() prototype. Syncs with NetBSD-8
[minix.git] / distrib / common / sunbootcd.sh
blob26d68ef94d114575638ecafffd5eed1df9d4de53
1 #! /bin/sh
3 # $NetBSD: sunbootcd.sh,v 1.6 2012/02/22 16:12:34 martin Exp $
5 # Copyright (c) 2003 The NetBSD Foundation, Inc.
6 # All rights reserved.
8 # This code is derived from software contributed to The NetBSD Foundation
9 # by Luke Mewburn.
11 # Redistribution and use in source and binary forms, with or without
12 # modification, are permitted provided that the following conditions
13 # are met:
14 # 1. Redistributions of source code must retain the above copyright
15 # notice, this list of conditions and the following disclaimer.
16 # 2. Redistributions in binary form must reproduce the above copyright
17 # notice, this list of conditions and the following disclaimer in the
18 # documentation and/or other materials provided with the distribution.
20 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 # POSSIBILITY OF SUCH DAMAGE.
33 : ${SUNLABEL:=sunlabel} # sunlabel(8)
34 : ${CYLSIZE:=640} # Cylinder size, in 512byte blocks
36 PROGNAME=${0##*/}
37 FORMAT="%-8s offset %4d, size %4d, file %s\n"
40 usage()
42 cat 1>&2 << _USAGE_
43 Usage: ${PROGNAME} fsimage sun4 [sun4c [sun4m [sun3|sun4d [sun3x|sun4u]]]]
44 Combine file system partitions for Sun Microsystems, Inc. computers
45 into a CD-ROM file system image suitable for booting on the
46 following platforms:
47 NetBSD/sun3: sun3, sun3x
48 NetBSD/sparc: sun4, sun4c, sun4d, sun4m
49 NetBSD/sparc64: sun4u
50 The architecture arguments must be bootable file system image
51 for that architecture, or \`-' if no entry is desired.
52 \`fsimage' is typically an iso9660 file system image, although
53 any type of file system can be used as long as the first 512
54 bytes of the image are not used. \`fsimage' is modified, and
55 the additional partitions are added in order. If the same
56 filename is used more than once for different architectures,
57 it will only be copied once.
58 _USAGE_
59 exit 1
62 if [ $# -lt 2 -o $# -gt 6 ]; then
63 usage
66 for curfile in $*; do
67 [ "$curfile" = "-" ] && continue
68 if [ ! -f "$curfile" ]; then
69 echo 1>&2 "${PROGNAME}: ${curfile}: No such file."
70 exit 1
72 done
74 ISOIMAGE="$1"; shift
76 ISOSIZE=$( ls -l "${ISOIMAGE}" | awk '{print $5}' )
77 ISOBLKS=$(( (${ISOSIZE} + 511) / 512 ))
78 ISOCYLS=$(( (${ISOBLKS} + (${CYLSIZE} - 1)) / ${CYLSIZE} ))
80 printf "${FORMAT}" "fsimage:" 0 ${ISOCYLS} "${ISOIMAGE}"
82 ENDCYL=${ISOCYLS}
83 curpart=0
84 for curfile in $*; do
85 curpart=$(( ${curpart} + 1 ))
86 [ "$curfile" = "-" ] && continue
88 tpart=1
89 curoff=${ENDCYL}
90 while [ ${tpart} -lt ${curpart} ]; do
91 tfile=$(eval echo \$PART${tpart}FILE)
92 if [ "${curfile}" = "${tfile}" ]; then
93 curoff=$(eval echo \$PART${tpart}OFF)
94 break
96 tpart=$(( ${tpart} + 1 ))
97 done
99 cursize=$( ls -l "${curfile}" | awk '{print $5}' )
100 curblks=$(( (${cursize} + 511) / 512 ))
101 curcyls=$(( (${curblks} + (${CYLSIZE} - 1)) / ${CYLSIZE} ))
102 printf "${FORMAT}" "Image ${curpart}:" ${curoff} ${curcyls} "${curfile}"
104 eval PART${curpart}SIZE=${cursize} \
105 PART${curpart}BLKS=${curblks} \
106 PART${curpart}CYLS=${curcyls} \
107 PART${curpart}OFF=${curoff} \
108 PART${curpart}FILE="${curfile}"
110 if [ $curoff -eq $ENDCYL ]; then # append ${curfile}
111 echo " (appending ${curfile} to ${ISOIMAGE})"
112 dd if="${curfile}" of="${ISOIMAGE}" bs=${CYLSIZE}b \
113 seek=${ENDCYL} conv=notrunc,sync 2>/dev/null
114 ENDCYL=$(( $ENDCYL + $curcyls ))
117 done
119 printf "${FORMAT}" "Final:" 0 ${ENDCYL} "${ISOIMAGE}"
121 ${SUNLABEL} -nq "${ISOIMAGE}" << _partinfo_
122 V nsect ${CYLSIZE}
123 V nhead 1
124 V rpm 300
125 V pcyl ${ENDCYL}
126 V ncyl ${ENDCYL}
127 a 0 $(( ${ISOCYLS} * ${CYLSIZE} ))
128 b ${PART1OFF:-0} $(( ${PART1CYLS:-0} * ${CYLSIZE} ))
129 c ${PART2OFF:-0} $(( ${PART2CYLS:-0} * ${CYLSIZE} ))
130 d ${PART3OFF:-0} $(( ${PART3CYLS:-0} * ${CYLSIZE} ))
131 e ${PART4OFF:-0} $(( ${PART4CYLS:-0} * ${CYLSIZE} ))
132 f ${PART5OFF:-0} $(( ${PART5CYLS:-0} * ${CYLSIZE} ))
134 _partinfo_