diff options
author | Otto Moerbeek <otto@cvs.openbsd.org> | 2007-03-13 19:25:32 +0000 |
---|---|---|
committer | Otto Moerbeek <otto@cvs.openbsd.org> | 2007-03-13 19:25:32 +0000 |
commit | 48978070767dbaf6c1891550bbae64de84c799b6 (patch) | |
tree | ff734949b964617f4859f1e15c7d302bd7eda706 /sbin | |
parent | b497d68cd34dd59a1766a1353c9ef896585a56ca (diff) |
Refactor & fix computation of offset for next partition. Now the
code is almost readable. Keep in mind that the starting offset is
inclusive, but the ending offset is exclusive. I heard rumors that
disklabel was misbehaving in some cases before, but espie@ was the
only one to provide me with enough details to actually find the
problem.
ok millert@ tom@
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/disklabel/editor.c | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/sbin/disklabel/editor.c b/sbin/disklabel/editor.c index b9a1b7918ca..00f85c74a54 100644 --- a/sbin/disklabel/editor.c +++ b/sbin/disklabel/editor.c @@ -1,4 +1,4 @@ -/* $OpenBSD: editor.c,v 1.107 2007/03/02 02:29:13 krw Exp $ */ +/* $OpenBSD: editor.c,v 1.108 2007/03/13 19:25:31 otto Exp $ */ /* * Copyright (c) 1997-2000 Todd C. Miller <Todd.Miller@courtesan.com> @@ -17,7 +17,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: editor.c,v 1.107 2007/03/02 02:29:13 krw Exp $"; +static char rcsid[] = "$OpenBSD: editor.c,v 1.108 2007/03/13 19:25:31 otto Exp $"; #endif /* not lint */ #include <sys/types.h> @@ -810,22 +810,27 @@ next_offset(struct disklabel *lp, u_int32_t *sizep) new_offset = starting_sector; for (i = 0; i < npartitions; i++ ) { + u_int32_t pstart = spp[i]->p_offset; + u_int32_t pend = pstart + spp[i]->p_size; + u_int32_t newend = new_offset + *sizep; + /* * Is new_offset inside this partition? If so, * make it the next sector after the partition ends. */ - if (spp[i]->p_offset + spp[i]->p_size < ending_sector && - ((new_offset >= spp[i]->p_offset && - new_offset < spp[i]->p_offset + spp[i]->p_size) || - (new_offset + *sizep >= spp[i]->p_offset && new_offset - + *sizep <= spp[i]->p_offset + spp[i]->p_size))) - new_offset = spp[i]->p_offset + spp[i]->p_size; + if (pend < ending_sector && + ((new_offset >= pstart && new_offset < pend) || + (newend > pstart && newend <= pend))) + new_offset = pend; } /* Did we find a suitable offset? */ for (good_offset = 1, i = 0; i < npartitions; i++ ) { - if (new_offset + *sizep >= spp[i]->p_offset && - new_offset + *sizep <= spp[i]->p_offset + spp[i]->p_size) { + u_int32_t pstart = spp[i]->p_offset; + u_int32_t pend = pstart + spp[i]->p_size; + u_int32_t newend = new_offset + *sizep; + + if (newend > pstart && newend <= pend) { /* Nope */ good_offset = 0; break; |