summaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2008-01-06 17:27:12 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2008-01-06 17:27:12 +0000
commit7d5438866d9aec7ee161d470f35342cb9695a95a (patch)
tree997257409ead4ec27fe5e6bc3d4e62d23dc70274 /sbin
parenta1314ba315db397dafaaf87f9ed7d16db5f29e4f (diff)
Calculate amount of free space by adding up space in free chunks, rather
than hand rolling another partition walking loop. No functional change.
Diffstat (limited to 'sbin')
-rw-r--r--sbin/disklabel/editor.c29
1 files changed, 7 insertions, 22 deletions
diff --git a/sbin/disklabel/editor.c b/sbin/disklabel/editor.c
index 2384f774058..32b11db5edc 100644
--- a/sbin/disklabel/editor.c
+++ b/sbin/disklabel/editor.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: editor.c,v 1.140 2008/01/06 16:44:54 krw Exp $ */
+/* $OpenBSD: editor.c,v 1.141 2008/01/06 17:27:11 krw 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.140 2008/01/06 16:44:54 krw Exp $";
+static char rcsid[] = "$OpenBSD: editor.c,v 1.141 2008/01/06 17:27:11 krw Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -1608,30 +1608,15 @@ find_bounds(struct disklabel *lp)
void
editor_countfree(struct disklabel *lp, u_int64_t *freep)
{
+ struct diskchunk *chunks;
struct partition *pp;
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) {
- 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;
+ *freep = 0;
+ chunks = free_chunks(lp);
- if (s < starting_sector)
- sz -= starting_sector - s;
- if (e > ending_sector)
- sz -= e - ending_sector;
- *freep -= sz;
- }
- }
+ for (i = 0; chunks[i].start != 0 || chunks[i].stop != 0; i++)
+ *freep += chunks[i].stop - chunks[i].start;
}
void