diff options
author | Otto Moerbeek <otto@cvs.openbsd.org> | 2007-06-20 19:16:54 +0000 |
---|---|---|
committer | Otto Moerbeek <otto@cvs.openbsd.org> | 2007-06-20 19:16:54 +0000 |
commit | 6766d4ec05d843d13b7654d87957286ec0d69aeb (patch) | |
tree | 3bc01e3fc03ea2df63093235e53806501728a773 /sbin/disklabel | |
parent | bd1c32f85cafff792a3c3ceb7eea9d3dafbe1706 (diff) |
if a 4.2BSD partition falls partly within the area defined by the
'b' command, subtract the overlapping space from the free space.
fixes weird free space calculation on hppa, where converted lif
labels start at sector 1, but the 'b' area skips the first cylinder.
ok millert@
Diffstat (limited to 'sbin/disklabel')
-rw-r--r-- | sbin/disklabel/editor.c | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/sbin/disklabel/editor.c b/sbin/disklabel/editor.c index a4087326a45..c5bdcc8a2c4 100644 --- a/sbin/disklabel/editor.c +++ b/sbin/disklabel/editor.c @@ -1,4 +1,4 @@ -/* $OpenBSD: editor.c,v 1.122 2007/06/17 00:32:21 deraadt Exp $ */ +/* $OpenBSD: editor.c,v 1.123 2007/06/20 19:16:53 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.122 2007/06/17 00:32:21 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: editor.c,v 1.123 2007/06/20 19:16:53 otto Exp $"; #endif /* not lint */ #include <sys/types.h> @@ -1693,13 +1693,25 @@ editor_countfree(struct disklabel *lp, u_int64_t *freep) int i; *freep = ending_sector - starting_sector; + for (i = 0; i < lp->d_npartitions; i++) { - pp = &lp->d_partitions[i]; - if (pp->p_fstype != FS_UNUSED && pp->p_fstype != FS_BOOT && - DL_GETPSIZE(pp) > 0 && - DL_GETPOFFSET(pp) + DL_GETPSIZE(pp) <= ending_sector && - DL_GETPOFFSET(pp) >= starting_sector) - *freep -= DL_GETPSIZE(pp); + pp = &lp->d_partitions[i]; + if (pp->p_fstype != FS_UNUSED && pp->p_fstype != FS_BOOT && + DL_GETPSIZE(pp) > 0) { + u_int64_t s = DL_GETPOFFSET(pp); + u_int64_t sz = DL_GETPSIZE(pp); + u_int64_t e = s + sz; + + /* do not count if completely out of 'b' area */ + if (e < starting_sector || s >= ending_sector) + continue; + + if (s < starting_sector) + sz -= starting_sector - s; + if (e > ending_sector) + sz -= e - ending_sector; + *freep -= sz; + } } } |