/*-
* Copyright (c) 2005 Izumi Tsutsui. 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.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 THE AUTHOR 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.
*/
if ((params->fsfd = open(params->filesystem, O_RDWR, 0600)) == -1)
err(1, "Opening file system `%s' read", params->filesystem);
if (fstat(params->fsfd, ¶ms->fsstat) == -1)
err(1, "Examining file system `%s'", params->filesystem);
if (!params->fstype->match(params))
errx(1, "File system `%s' is not of type %s",
params->filesystem, params->fstype->name);
/*
* Find space for primary boot from the second (NetBSD_BootBlock)
* partition.
*/
if (pread(params->fsfd, &pme, sizeof pme, BSIZE * 2) != sizeof(pme))
err(1, "read pme from file system `%s'", params->filesystem);
if (strcmp((char *)pme.pmPartName, "NetBSD_BootBlock"))
err(1, "invalid partition map in file system `%s'",
params->filesystem);
/* pmPyPartStart is written by mkisofs */
partoff = BSIZE * be32toh(pme.pmPyPartStart);
if ((params->s1fd = open(params->stage1, O_RDONLY, 0600)) == -1)
err(1, "Opening primary bootstrap `%s'", params->stage1);
if (fstat(params->s1fd, ¶ms->s1stat) == -1)
err(1, "Examining primary bootstrap `%s'", params->stage1);
if (!S_ISREG(params->s1stat.st_mode))
err(1, "`%s' must be a regular file", params->stage1);
if (params->s1stat.st_size > MACPPC_BOOT_BLOCK_MAX_SIZE)
err(1, "primary bootrap `%s' too large (%ld bytes)",
params->stage1, (long)params->s1stat.st_size);