}  if (!installboot) { struct disklabel tlab;  if (lseek(f, sectoffset, SEEK_SET) < 0) { perror("lseek"); return (1); } tlab = *lp; if (read(f, boot, tlab.d_bbsize) != tlab.d_bbsize) { perror("read"); return (1); } *lp =tlab;
writelabel(f, boot, lp)	int f;	char *boot;	struct disklabel *lp;{	int writeable;	off_t sectoffset = 0;#if NUMBOOT > 0	setbootflag(lp);#endif	lp->d_magic = DISKMAGIC;	lp->d_magic2 = DISKMAGIC;	lp->d_checksum = 0;	lp->d_checksum = dkcksum(lp);	if (rflag) {#ifdef DOSLABEL		struct partition *pp = &lp->d_partitions[2];		/*		 * If NetBSD/i386 DOS partition is missing, or if 		 * the label to be written is not within partition,		 * prompt first. Need to allow this in case operator		 * wants to convert the drive for dedicated use.		 * In this case, partition 'a' had better start at 0,		 * otherwise we reject the request as meaningless. -wfj		 */		if (dosdp && dosdp->dp_typ == DOSPTYP_386BSD && pp->p_size &&			dosdp->dp_start == pp->p_offset) {		        sectoffset = pp->p_offset * lp->d_secsize;		} else {			if (dosdp) {				int first, ch;				printf("Erase the previous contents of the disk? [n]: ");				fflush(stdout);				first = ch = getchar();				while (ch != '\n' && ch != EOF)					ch = getchar();				if (first != 'y' && first != 'Y')					exit(0);			}			sectoffset = 0;		}#endif		/*		 * First set the kernel disk label,		 * then write a label to the raw disk.		 * If the SDINFO ioctl fails because it is unimplemented,		 * keep going; otherwise, the kernel consistency checks		 * may prevent us from changing the current (in-core)		 * label.		 */		if (ioctl(f, DIOCSDINFO, lp) < 0 &&		    errno != ENODEV && errno != ENOTTY) {			l_perror("ioctl DIOCSDINFO");			return (1);		}		if (lseek(f, sectoffset, SEEK_SET) < 0) {			perror("lseek");			return (1);		}		/*		 * write enable label sector before write (if necessary),		 * disable after writing.		 */		writeable = 1;		if (ioctl(f, DIOCWLABEL, &writeable) < 0)			perror("ioctl DIOCWLABEL");#ifdef __alpha__		/*		 * The Alpha requires that the boot block be checksummed.		 * The first 63 8-byte quantites are summed into the 64th.		 */		{			int i;			u_int64_t *dp, sum;			dp = (u_int64_t *)boot;			sum = 0;			for (i = 0; i < 63; i++)				sum += dp[i];			dp[63] = sum;		}#endif		if (write(f, boot, lp->d_bbsize) != lp->d_bbsize) {			perror("write");			return (1);		}#if NUMBOOT > 0		/*		 * Output the remainder of the disklabel		 */		if (bootbuf && write(f, bootbuf, bootsize) != bootsize) {			perror("write");			return(1);		}#endif		writeable = 0;		if (ioctl(f, DIOCWLABEL, &writeable) < 0)			perror("ioctl DIOCWLABEL");	} else {		if (ioctl(f, DIOCWDINFO, lp) < 0) {			l_perror("ioctl DIOCWDINFO");			return (1);		}	}#ifdef vax	if (lp->d_type == DTYPE_SMD && lp->d_flags & D_BADSECT) {		daddr_t alt;		int i;		alt = lp->d_ncylinders * lp->d_secpercyl - lp->d_nsectors;		for (i = 1; i < 11 && i < lp->d_nsectors; i += 2) {			(void)lseek(f, (off_t)((alt + i) * lp->d_secsize),			    SEEK_SET);			if (write(f, boot, lp->d_secsize) < lp->d_secsize)				warn("alternate label %d write", i/2);		}	}#endif	return (0);}