began to add faFree(), though it doesn't work yet
authorewt <devnull@localhost>
Fri, 5 Jan 1996 18:15:57 +0000 (18:15 +0000)
committerewt <devnull@localhost>
Fri, 5 Jan 1996 18:15:57 +0000 (18:15 +0000)
CVS patchset: 135
CVS date: 1996/01/05 18:15:57

lib/falloc.c
lib/falloc.h

index ad524df..119641e 100644 (file)
@@ -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);
index 49c2add..1e5adf6 100644 (file)
@@ -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);