From 99a43e9240395e10e2b365bd35bdecad717bca37 Mon Sep 17 00:00:00 2001 From: ewt Date: Fri, 5 Jan 1996 18:15:57 +0000 Subject: [PATCH] began to add faFree(), though it doesn't work yet CVS patchset: 135 CVS date: 1996/01/05 18:15:57 --- lib/falloc.c | 16 +++++++++++++++- lib/falloc.h | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/falloc.c b/lib/falloc.c index ad524df..119641e 100644 --- a/lib/falloc.c +++ b/lib/falloc.c @@ -205,7 +205,21 @@ unsigned int faAlloc(faFile fa, unsigned int size) { /* returns 0 on failure */ return newBlock + sizeof(block); } -void faFree(faFile fa, unsigned int offset); +int faFree(faFile fa, unsigned int offset) { + struct faBlock block; + + /* this is *really* bad ****/ + + offset -= sizeof(block); + if (lseek(fa->fd, offset, SEEK_SET) < 0) return 0; + if (read(fa->fd, &block, sizeof(block)) != sizeof(block)) return 0; + + block.isFree = 1; + if (lseek(fa->fd, offset, SEEK_SET) < 0) return 0; + if (write(fa->fd, &block, sizeof(block)) != sizeof(block)) return 0; + + return 1; +} void faClose(faFile fa) { close(fa->fd); diff --git a/lib/falloc.h b/lib/falloc.h index 49c2add..1e5adf6 100644 --- a/lib/falloc.h +++ b/lib/falloc.h @@ -18,7 +18,7 @@ typedef struct FaPlace * faPlace; /* flags here is the same as for open(2) - NULL returned on error */ faFile faOpen(char * path, int flags, int perms); unsigned int faAlloc(faFile fa, unsigned int size); /* returns 0 on failure */ -void faFree(faFile fa, unsigned int offset); +int faFree(faFile fa, unsigned int offset); void faClose(faFile fa); unsigned int faFirstOffset(faFile fa); -- 2.7.4