Subject: disklabel -Rr sd0 protofile, disklabel -wr sd0 disktype
To: None <port-i386@NetBSD.ORG>
From: Hiroyuki Ito <hiroy@netcom.com>
List: port-i386
Date: 04/26/1996 08:00:34
"disklabel -Rr sd0 protofile" trashes existing boot or MBR.
"disklabel -wr sd0 disktype"  trashes existing boot or MBR.

----------------- from /usr/src/sbin/disklabel.c ----------------------
/*	$NetBSD: disklabel.c,v 1.30 1996/03/14 19:49:24 ghudson Exp $   */

....
....

char	bootarea[BBSIZE];

....
....

int
main(argc, argv)
	int argc;
	char *argv[];
{
	struct disklabel *lp;
	....
	....

#ifdef i386
	/*
	 * Check for presence of DOS partition table in
	 * master boot record. Return pointer to NetBSD/i386
	 * partition, if present. If no valid partition table,
	 * return 0. If valid partition table present, but no
	 * partition to use, return a pointer to a non-386bsd
	 * partition.
	 */
	dosdp = readmbr(f);
#endif

	....
	....

		lp = makebootarea(bootarea, &lab, f);

	....
	....
}

....
....

struct disklabel *
makebootarea(boot, dp, f)
	char *boot;
	struct disklabel *dp;
	int f;
{
	struct disklabel *lp;
	....
	....

	/*
	 * If we are not installing a boot program but we are installing a
	 * label on disk then we must read the current bootarea so we don't
	 * clobber the existing boot.
	 */
	if (!installboot) {
		if (rflag) {
			if (read(f, boot, BBSIZE) < BBSIZE)
				err(4, "%s", specname);
			memset(lp, 0, sizeof *lp);
		}
		return (lp);
	}

	....
	....
}

....
....

-----------------------------------------------------------------------

0. f=open(/dev/rsd0d).
1. readmbr(f) reads sector#0 of sd0.
2. read(f, boot, BBSIZE) reads sector#1-sector#16 into bootarea.

Hiroyuki Ito