/*
* Copyright (C) 1995, 1996 Wolfgang Solfrank.
* Copyright (C) 1995, 1996 TooLs GmbH.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by TooLs GmbH.
* 4. The name of TooLs GmbH may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Device I/O routines using Open Firmware
*/
/*
* Check if this APM partition is a suitable root partition and return
* its file system type or zero.
*/
static u_int8_t
check_apm_root(struct part_map_entry *part, int *clust)
{
struct blockzeroblock *bzb;
char typestr[32], *s;
u_int8_t fstype;
*clust = 0; /* may become 1 for A/UX partitions */
fstype = 0;
bzb = (struct blockzeroblock *)(&part->pmBootArgs);
/* convert partition type name to upper case */
strncpy(typestr, (char *)part->pmPartType, sizeof(typestr));
typestr[sizeof(typestr) - 1] = '\0';
for (s = typestr; *s; s++)
if ((*s >= 'a') && (*s <= 'z'))
*s = (*s - 'a' + 'A');
/*
* Build a disklabel from APM partitions.
* We will just look for a suitable root partition and insert it into
* the 'a' slot. Should be sufficient to boot a kernel from it.
*/
static int
search_mac_label(struct of_dev *devp, char *buf, struct disklabel *lp)
{
struct part_map_entry *pme;
struct partition *a_part;
size_t nread;
int blkno, clust, lastblk, lastclust;
u_int8_t fstype;
if (devname != NULL)
devname[0] = '\0';
if (fname != NULL)
fname[0] = '\0';
if (ppart != NULL)
*ppart = 0;
strlcpy(str, path, sizeof(str));
lp = str;
for (cp = str; *cp != '\0'; lp = cp) {
/* For each component of the path name... */
while (*++cp != '\0' && *cp != '/')
continue;
savec = *cp;
*cp = '\0';
/* ...look whether there is a device with this name */
dhandle = OF_finddevice(str);
DPRINTF("%s: Checking %s: dhandle = %d\n",
__func__, str, dhandle);
*cp = savec;
if (dhandle != -1) {
/*
* If it's a valid device, lp is a delimiter
* in the OF device path.
*/
if (OF_getprop(dhandle, "device_type", devtype,
sizeof devtype) < 0)
devtype[0] = '\0';
continue;
}
/*
* If not, lp is the delimiter between OF device path
* and the specified filename.
*/
/* Check if the last component was a block device... */
if (strcmp(devtype, "block") == 0) {
/* search for arguments */
for (cp = lp;
--cp >= str && *cp != '/' && *cp != ':';)
continue;
if (cp >= str && *cp == ':') {
/* found arguments */
for (cp = lp;
*--cp != ':' && *cp != ',';)
continue;
if (*++cp >= 'a' &&
*cp <= 'a' + MAXPARTITIONS &&
ppart != NULL)
*ppart = *cp;
}
}
if (*lp != '\0') {
/* set filename */
DPRINTF("%s: filename = %s\n", __func__, lp);
if (fname != NULL)
strcpy(fname, lp);
if (str != lp) {
/* set device path */
*lp = '\0';
DPRINTF("%s: device path = %s\n",
__func__, str);
if (devname != NULL)
strcpy(devname, str);
}
}
return true;
}
if (error == ERDLAB) {
if (partition)
/*
* User specified a partition,
* but there is none
*/
goto bad;
/* No label, just use complete disk */
ofdev.partoff = 0;
} else {
part = partition ? partition - 'a' : 0;
ofdev.partoff = label.d_partitions[part].p_offset;
}