/*-
* Copyright (c) 1999 Minoura Makoto
* 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.
*/
/*
* Create the disk mark for x68k SCSI IPL.
* It used to be a shell/awk script, but is rewritten in order to be fit with
* the install kernel.
*
* Usage: /usr/mdec/newdisk [-vnfc] [-m /usr/mdec/mboot] /dev/rsd?c
*/
if (read(fd, buf, 512) < 0)
err(1, "reading %s", dev);
if (strncmp(buf, "X68SCSI1", 8) == 0 && !force)
errx(1, "%s is already marked. "
"Use -f to overwrite the existing mark.", dev);
if (check_only)
return 0;
if (verbose)
fprintf(stderr, "Inspecting %s... ", dev);
if (ioctl(fd, DIOCGDINFO, &label) < 0)
err(1, "inspecting %s", dev);
close(fd);
if (label.d_secsize != 512)
errx(1, "This type of disk is not supported by NetBSD.");
if (verbose)
fprintf(stderr, "total number of sector is %d.\n",
label.d_secperunit);
if (verbose)
fprintf(stderr, "Building disk mark... ");
memset(buf, 0, 3072);
#define n label.d_secperunit
snprintf(buf, sizeof(buf), "X68SCSI1%c%c%c%c%c%c%c%c%s",
2, 0,
(n/16777216)%256, (n/65536)%256, (n/256)%256, n%256,
1, 0, copyright);
#undef n
if (verbose)
fprintf(stderr, "done.\n");
if (verbose)
fprintf(stderr, "Merging %s... ", mboot);
fd = open(mboot, O_RDONLY);
if (fd < 0)
err(1, "opening %s", mboot);
if (read(fd, buf+1024, 1024) < 0)
err(1, "reading %s", mboot);
close(fd);
if (verbose)
fprintf(stderr, "done.\n");
if (!mark_only) {
if (verbose)
fprintf(stderr,
"Creating an empty partition table... ");
#define n (label.d_secperunit/2)
snprintf(buf + 2048, sizeof(buf) - 2048,
"X68K%c%c%c%c%c%c%c%c%c%c%c%c",
0, 0, 0, 32,
(n/16777215)%256, (n/65536)%256, (n/256)%256, n%256,
(n/16777215)%256, (n/65536)%256, (n/256)%256, n%256);
#undef n
if (verbose)
fprintf(stderr, "done.\n");
}
if (dry_run) {
char filename[MAXPATHLEN] = "/tmp/diskmarkXXXXX";
fd = mkstemp(filename);
if (fd < 0)
err(1, "opening %s", filename);
if (write(fd, buf, 4096) < 0)
err(1, "writing %s", filename);
close(fd);
fprintf(stderr, "Disk mark is kept in %s.\n", filename);
} else {
int mode = 1;