summaryrefslogtreecommitdiffstats
path: root/sbin/geom/class
diff options
context:
space:
mode:
authorae <ae@FreeBSD.org>2015-07-21 06:18:42 +0000
committerae <ae@FreeBSD.org>2015-07-21 06:18:42 +0000
commitd0ec2bec825b04f11645ffa035f506283a15bbee (patch)
treed09d236d256aecca29953eda8037c94128e6177c /sbin/geom/class
parentf137e0726b5a82a8cf998a522716bd66f5c6f083 (diff)
downloadFreeBSD-src-d0ec2bec825b04f11645ffa035f506283a15bbee.zip
FreeBSD-src-d0ec2bec825b04f11645ffa035f506283a15bbee.tar.gz
lseek() allows an offset to be set beyond the end of file. Using
it to check that partition has enough space to write bootcode doesn't work. Use the known size of provider instead. PR: 201504 MFC after: 1 week
Diffstat (limited to 'sbin/geom/class')
-rw-r--r--sbin/geom/class/part/geom_part.c11
1 files changed, 4 insertions, 7 deletions
diff --git a/sbin/geom/class/part/geom_part.c b/sbin/geom/class/part/geom_part.c
index 133e8f8..44309f9 100644
--- a/sbin/geom/class/part/geom_part.c
+++ b/sbin/geom/class/part/geom_part.c
@@ -1106,14 +1106,11 @@ gpart_write_partcode(struct ggeom *gp, int idx, void *code, ssize_t size)
if (pp != NULL) {
snprintf(dsf, sizeof(dsf), "/dev/%s", pp->lg_name);
+ if (pp->lg_mediasize < size)
+ errx(EXIT_FAILURE, "%s: not enough space", dsf);
fd = open(dsf, O_WRONLY);
if (fd == -1)
err(EXIT_FAILURE, "%s", dsf);
- if (lseek(fd, size, SEEK_SET) != size)
- errx(EXIT_FAILURE, "%s: not enough space", dsf);
- if (lseek(fd, 0, SEEK_SET) != 0)
- err(EXIT_FAILURE, "%s", dsf);
-
/*
* When writing to a disk device, the write must be
* sector aligned and not write to any partial sectors,
@@ -1152,11 +1149,11 @@ gpart_write_partcode_vtoc8(struct ggeom *gp, int idx, void *code)
if (pp->lg_sectorsize != sizeof(struct vtoc8))
errx(EXIT_FAILURE, "%s: unexpected sector "
"size (%d)\n", dsf, pp->lg_sectorsize);
+ if (pp->lg_mediasize < VTOC_BOOTSIZE)
+ continue;
fd = open(dsf, O_WRONLY);
if (fd == -1)
err(EXIT_FAILURE, "%s", dsf);
- if (lseek(fd, VTOC_BOOTSIZE, SEEK_SET) != VTOC_BOOTSIZE)
- continue;
/*
* We ignore the first VTOC_BOOTSIZE bytes of boot code in
* order to avoid overwriting the label.
OpenPOWER on IntegriCloud