From owner-freebsd-bugs Wed Oct 10 9:40:12 2001 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id E668637B40A for ; Wed, 10 Oct 2001 09:40:00 -0700 (PDT) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.4/8.11.4) id f9AGe0H05104; Wed, 10 Oct 2001 09:40:00 -0700 (PDT) (envelope-from gnats) Received: from tomts12-srv.bellnexxia.net (tomts12.bellnexxia.net [209.226.175.56]) by hub.freebsd.org (Postfix) with ESMTP id 8B63937B406 for ; Wed, 10 Oct 2001 09:31:59 -0700 (PDT) Received: from khan.anarcat.dyndns.org ([65.94.128.156]) by tomts12-srv.bellnexxia.net (InterMail vM.4.01.03.16 201-229-121-116-20010115) with ESMTP id <20011010163158.CJOP10438.tomts12-srv.bellnexxia.net@khan.anarcat.dyndns.org> for ; Wed, 10 Oct 2001 12:31:58 -0400 Received: from shall.anarcat.dyndns.org (shall.anarcat.dyndns.org [192.168.0.1]) by khan.anarcat.dyndns.org (Postfix) with ESMTP id CC9DC1893 for ; Wed, 10 Oct 2001 12:31:54 -0400 (EDT) Received: by shall.anarcat.dyndns.org (Postfix, from userid 1000) id 3258220B50; Wed, 10 Oct 2001 12:32:06 -0400 (EDT) Message-Id: <20011010163206.3258220B50@shall.anarcat.dyndns.org> Date: Wed, 10 Oct 2001 12:32:06 -0400 (EDT) From: The Anarcat Reply-To: The Anarcat To: FreeBSD-gnats-submit@freebsd.org X-Send-Pr-Version: 3.113 Subject: bin/31201: [patch] add free_space(chunk) to libdisk Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org >Number: 31201 >Category: bin >Synopsis: [patch] add free_space(chunk) to libdisk >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Wed Oct 10 09:40:00 PDT 2001 >Closed-Date: >Last-Modified: >Originator: The Anarcat >Release: FreeBSD 4.4-STABLE i386 >Organization: Nada, Inc >Environment: System: FreeBSD shall.anarcat.dyndns.org 4.4-STABLE FreeBSD 4.4-STABLE #7: Sat Sep 15 00:41:38 EDT 2001 anarcat@shall.anarcat.dyndns.org:/usr/obj/usr/src/sys/SHALL i386 >Description: There is no function available to see the "free space" available on a given slice, where free space is defined as per src/release/sysinstall/label.c:255 (free = size - sum of used parts) >How-To-Repeat: n/a >Fix: patch libdisk to include sysinstall' space_free. note that this makes use of errno to signal an error, this might not be proper style since size args are usually u_long and we're using plain long here to signal the error (-1). diff -c /usr/src/lib/libdisk/chunk.c.orig /usr/src/lib/libdisk/chunk.c *** /usr/src/lib/libdisk/chunk.c.orig Wed Oct 10 12:29:42 2001 --- /usr/src/lib/libdisk/chunk.c Wed Oct 10 12:29:42 2001 *************** *** 16,21 **** --- 16,22 ---- #include #include #include + #include #include "libdisk.h" #define new_chunk() memset(malloc(sizeof(struct chunk)), 0, sizeof(struct chunk)) *************** *** 327,332 **** --- 328,350 ---- if (c->flags & CHUNK_IS_ROOT) ret[i++] = 'R'; ret[i++] = '\0'; return ret; + } + + /* return free space of that chunk */ + long + free_space(struct chunk *c) + { + struct chunk *c1; + int sz = c->size; + if (!c) { + errno = EFAULT; + return -1; + } + for (c1 = c->part; c1; c1 = c1->next) { + if (c1->type != unused) + sz -= c1->size; + } + return sz; } void diff -c /usr/src/lib/libdisk/libdisk.h.orig /usr/src/lib/libdisk/libdisk.h *** /usr/src/lib/libdisk/libdisk.h.orig Wed Oct 10 12:30:42 2001 --- /usr/src/lib/libdisk/libdisk.h Wed Oct 10 12:30:43 2001 *************** *** 156,161 **** --- 156,173 ---- /* Create a chunk with the specified paramters */ + long + free_space(struct chunk *c); + /* + * return the free space available in this chunk + * + * free = total - sum "not unused" partitions + * + * returns the space or -1 if an error occured + * + * EFAULT: bad chunk pointer given + */ + void All_FreeBSD(struct disk *d, int force_all); /* Make one FreeBSD chunk covering the entire disk; >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message