Fix 'gpt boot' to work on disk devices and not just plain files. Writes to
disk devices have to consist of a block of sectors. Thus, when writing gptboot to the boot partition, round the size of the gptboot file up to a sector boundary, pre-zero it, and write out the full buffer to disk.
This commit is contained in:
parent
31a1fa7932
commit
990847f475
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=173262
@ -169,7 +169,6 @@ boot(int fd)
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/* Fourth step: find an existing boot partition or create one. */
|
||||
if (gpt_find(&boot_uuid, &gptboot) != 0)
|
||||
return;
|
||||
@ -191,8 +190,14 @@ boot(int fd)
|
||||
return;
|
||||
}
|
||||
|
||||
/* Fourth step, write out the gptboot binary to the boot partition. */
|
||||
buf = malloc(sb.st_size);
|
||||
/*
|
||||
* Fourth step, write out the gptboot binary to the boot partition.
|
||||
* When writing to a disk device, the write must be sector aligned
|
||||
* and not write to any partial sectors, so round up the buffer size
|
||||
* to the next sector and zero it.
|
||||
*/
|
||||
bsize = (sb.st_size + secsz - 1) / secsz * secsz;
|
||||
buf = calloc(1, bsize);
|
||||
nbytes = read(bfd, buf, sb.st_size);
|
||||
if (nbytes < 0) {
|
||||
warn("unable to read GPT boot loader");
|
||||
@ -209,12 +214,12 @@ boot(int fd)
|
||||
device_name);
|
||||
return;
|
||||
}
|
||||
nbytes = write(fd, buf, sb.st_size);
|
||||
nbytes = write(fd, buf, bsize);
|
||||
if (nbytes < 0) {
|
||||
warn("unable to write GPT boot loader");
|
||||
return;
|
||||
}
|
||||
if (nbytes != sb.st_size) {
|
||||
if (nbytes != bsize) {
|
||||
warnx("short write of GPT boot loader");
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user