void write_bootblocks(int devfd, struct disklabel *dl) { struct stat sb; u_int8_t *secbuf; u_int start = 0; /* Write patched proto bootblock(s) into the superblock. */ if (fstat(devfd, &sb) < 0) err(1, "stat: %s", realdev); if (!S_ISCHR(sb.st_mode)) errx(1, "%s: not a character device", realdev); /* Patch the parameters into the proto bootstrap sector. */ pbr_set_symbols(proto, protostore, pbr_symbols); if (!nowrite) { /* Sync filesystems (to clean in-memory superblock?). */ sync(); sleep(1); } /* * Find OpenBSD partition. Floppies are special, getting an * everything-in-one biosboot starting at sector 0. */ if (dl->d_type != DTYPE_FLOPPY) { start = findopenbsd(devfd, dl); if (start == (u_int)-1) errx(1, "no Bitrig partition"); } if (verbose) fprintf(stderr, "%s will be written at sector %u\n", proto, start); if (start + (protosize / dl->d_secsize) > BOOTBIOS_MAXSEC) warnx("%s extends beyond sector %u. Bitrig might not boot.", proto, BOOTBIOS_MAXSEC); if (!nowrite) { if (lseek(devfd, (off_t)start * dl->d_secsize, SEEK_SET) < 0) err(1, "seek bootstrap"); secbuf = calloc(1, dl->d_secsize); bcopy(protostore, secbuf, protosize); if (write(devfd, secbuf, dl->d_secsize) != dl->d_secsize) err(1, "write bootstrap"); free(secbuf); } }
void write_bootblocks(int devfd, struct disklabel *dl) { struct stat sb; u_int start = 0; /* Write patched proto bootblock(s) into the superblock. */ if (fstat(devfd, &sb) < 0) err(1, "stat: %s", realdev); if (!S_ISCHR(sb.st_mode)) errx(1, "%s: not a character device", realdev); /* Patch the parameters into the proto bootstrap sector. */ pbr_set_symbols(proto, protostore, pbr_symbols); if (!nowrite) { /* Sync filesystems (to clean in-memory superblock?). */ sync(); sleep(1); } if (dl->d_type != 0 && dl->d_type != DTYPE_FLOPPY && dl->d_type != DTYPE_VND) { /* Find OpenBSD partition. */ start = findopenbsd(devfd, dl); if (start == (u_int)-1) errx(1, "no OpenBSD partition"); } if (start + (protosize / DEV_BSIZE) > BOOTBIOS_MAXSEC) errx(1, "invalid location: all of /boot must be < sector %u.", BOOTBIOS_MAXSEC); if (verbose) fprintf(stderr, "/boot will be written at sector %u\n", start); if (!nowrite) { if (lseek(devfd, (off_t)start * dl->d_secsize, SEEK_SET) < 0 || write(devfd, protostore, protosize) != protosize) err(1, "write bootstrap"); } }