shithub: gefs

Download patch

ref: b3e1a9e2057a7f30200d4f70a5779546898b22f6
parent: 20adcc7d9b12ff6b4f42275c5a10aff8d2d80db7
author: Michael Forney <[email protected]>
date: Wed Feb 9 18:21:52 EST 2022

ream: don't reserve space for extinct superblock

--- a/ream.c
+++ b/ream.c
@@ -146,7 +146,9 @@
 		sysfatal("open %s: %r", dev);
 	if((d = dirfstat(fs->fd)) == nil)
 		sysfatal("ream: %r");
-	if(d->length < 64*MiB)
+	sz = d->length;
+	free(d);
+	if(sz < 64*MiB)
 		sysfatal("ream: disk too small");
 	if((mnt = mallocz(sizeof(Mount), 1)) == nil)
 		sysfatal("ream: alloc mount: %r");
@@ -153,9 +155,7 @@
 	if((mnt->root = mallocz(sizeof(Tree), 1)) == nil)
 		sysfatal("ream: alloc tree: %r");
 
-	sz = d->length;
-	sz = sz - (sz % Blksz) - Blksz;
-	fs->narena = (d->length + 64ULL*GiB - 1) / (64ULL*GiB);
+	fs->narena = (sz + 64ULL*GiB - 1) / (64ULL*GiB);
 	if(fs->narena < 8)
 		fs->narena = 8;
 	if(fs->narena >= 128)
@@ -162,7 +162,6 @@
 		fs->narena = 128;
 	if((fs->arenas = calloc(fs->narena, sizeof(Arena))) == nil)
 		sysfatal("malloc: %r");
-	free(d);
 
 	asz = sz/fs->narena;
 	asz = asz - (asz % Blksz) - Blksz;