ref: 00a0ac11f923a87301a22b2bca8311a1a493ad4e
parent: 89bdceb722cd18eeddddcf884e845f561459b49d
author: Noam Preil <noam@pixelhero.dev>
date: Sat Jan 4 22:02:26 EST 2025
disk: read all arena fields
--- a/cache.c
+++ b/cache.c
@@ -212,5 +212,4 @@
fprint(2, "impossible\n");
// DO NOT PROCEED if the cache might be corrupt!
abort();
- return 0;
}
--- a/disk.c
+++ b/disk.c
@@ -15,12 +15,8 @@
u32int div;
u32int namap;
MapEntry *amap;
- struct {- // The active arena, which is currently being appended to.
- VtArena *arena;
- // Next offset within the current arena.
- u32int offset;
- } active;
+ // The active arena, which is currently being appended to.
+ VtArena *arena;
} index;
int
@@ -186,6 +182,19 @@
}
int
+vtwritearenaclump(VtArena *arena, char *buf, u16int len)
+{+ USED(len, buf);
+ wlock(arena);
+ if(arena->arenastats.sealed){+ wunlock(arena);
+ return 0;
+ }
+ wunlock(arena);
+ return 0;
+}
+
+int
vtwriteclump(char *buf, u16int len)
{USED(len, buf);
@@ -194,7 +203,10 @@
// - Write metadata to arena
// - Add entry to index
wlock(&index);
-
+ if(!vtwritearenaclump(index.arena, buf, len)){+ werrstr("TODO: advance arena");+ return 0;
+ }
wunlock(&index);
werrstr("TODO: write clump");return 0;
@@ -235,12 +247,26 @@
sysfatal("failed to pread");magic = U32GET(p);
version = U32GET(p + 4);
- arena->indexstats.clumps = U32GET(p+8+NameSize);
- arena->indexstats.cclumps = U32GET(p+8+NameSize+4);
- arena->ctime = U32GET(p+8+NameSize+8);
- arena->wtime = U32GET(p+8+NameSize+12);
- arena->clumpmagic = U32GET(p+8+NameSize+16);
- arena->indexstats.used = U64GET(p+8+NameSize+20);
+ p += 8+NameSize;
+ arena->indexstats.clumps = U32GET(p);
+ arena->indexstats.cclumps = U32GET(p+4);
+ arena->ctime = U32GET(p+8);
+ arena->wtime = U32GET(p+12);
+ arena->clumpmagic = U32GET(p+16);
+ arena->indexstats.used = U64GET(p+20);
+ arena->indexstats.uncsize = U64GET(p+28);
+ arena->indexstats.sealed = U8GET(p+36);
+ if(U8GET(p+37) == 1){+ arena->arenastats.clumps = U32GET(p+38);
+ arena->arenastats.cclumps = U32GET(p+42);
+ arena->arenastats.used = U64GET(p+46);
+ arena->arenastats.uncsize = U64GET(p+54);
+ // OR with indexstats: a bug from 2008 could leave arenastats out of date,
+ // and venti worked around it for ages so now I have to too.
+ arena->arenastats.sealed = U8GET(p+62) || arena->indexstats.sealed;
+ } else {+ arena->arenastats = arena->indexstats;
+ }
// We _can_ read the values in even if the arena is invalid, and the code looks
// cleaner with all the parsing and validation grouped, so meh, going to keep it
// like this.
@@ -250,7 +276,8 @@
sysfatal("unsupported arena version %d\n", version);if(strncmp(arena->name, buf + 8, strlen(arena->name)) != 0)
sysfatal("arena name mismatch: %s vs %s", arena->name, buf + 8);-
+ if(arena->indexstats.sealed && index.arena == nil)
+ index.arena = arena;
}
static void
--- a/neoventi.h
+++ b/neoventi.h
@@ -50,6 +50,7 @@
} VtConn;
typedef struct {+ RWLock;
char name[NameSize];
u32int clumpmagic;
u32int clumpmax;
@@ -64,13 +65,11 @@
u64int base;
int fd;
struct {- u32int clumps;
- } arenastats;
- struct {// Total clump count, and compressed clump count, respectively
u32int clumps, cclumps;
- u64int used;
- } indexstats;
+ u64int used, uncsize;
+ int sealed;
+ } indexstats, arenastats;
} VtArena;
typedef struct {--- a/notebook
+++ b/notebook
@@ -2639,5 +2639,5 @@
Rename it from badcheck.c, commit this, add the sealed detection, and then determine live arena...
% mv badcheck.c checkarena.c
-% git/add badcheck.c check.c
+% git/add badcheck.c checkarena.c
% git/commit -m 'fix check tool!!' .
--
⑨