Date: Wed, 10 Oct 2001 12:32:06 -0400 (EDT) From: The Anarcat <anarcat@anarcat.dyndns.org> To: FreeBSD-gnats-submit@freebsd.org Subject: bin/31201: [patch] add free_space(chunk) to libdisk Message-ID: <20011010163206.3258220B50@shall.anarcat.dyndns.org>
next in thread | raw e-mail | index | archive | help
>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 <string.h> #include <sys/types.h> #include <err.h> + #include <errno.h> #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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20011010163206.3258220B50>