ref: 347bb2a7a7110e55debd5ebe57ba03bbe315c5ba
parent: 5aa501870b9aa8095ae3bff7d39f55225a7b46b1
author: spew <devnull@localhost>
date: Mon Mar 27 05:55:56 EDT 2017
hjfs: start implementation of checking a directory
--- /dev/null
+++ b/sys/src/cmd/hjfs/check.c
@@ -1,0 +1,70 @@
+#include <u.h>
+#include <libc.h>
+#include <thread.h>
+#include "dat.h"
+#include "fns.h"
+
+extern Fs *fsmain;
+
+static void
+checkdir(FLoc *l, Buf *b)
+{
+ Buf *c;
+ Dentry *d;
+ uvlong i, r;
+
+ d = getdent(l, b);
+ for(i = 0; i < d->size; i++){
+ if(getblk(fsmain, l, b, i, &r, GBREAD) <= 0) {
+ dprint("hjfs: directory %s in block %ulld at index %d has a bad block reference at %ulld\n", d->name, l->blk, l->deind, i);
+ continue;
+ }
+ c = getbuf(fsmain->d, r, TDENTRY, 0);
+ if(c == nil) {
+ dprint("hjfs: directory %s in block %ulld at index %d has a block %ulld that is not a directory entry\n", d->name, l->blk, l->deind, i);
+ continue;
+ }
+ }
+}
+
+static void
+checkfile(FLoc*, Buf*)
+{}
+
+int
+checkblk(uvlong blk)
+{
+ Dentry *d;
+ Buf *b;
+ FLoc l;
+ int i, type;
+
+ b = getbuf(fsmain->d, blk, TDONTCARE, 0);
+ if(b == nil)
+ return -1;
+ switch(type = b->type){
+ case TRAW:
+ break;
+ case TSUPERBLOCK:
+ dprint("hjfs: checkblk: should not have found superblock at %ulld\n", blk);
+ break;
+ case TDENTRY:
+ l.blk = blk;
+ for(i = 0; i < DEPERBLK; i++){
+ d = &b->de[i];
+ l.deind = i;
+ l.Qid = d->Qid;
+ if((d->type & QTDIR) != 0)
+ checkdir(&l, b);
+ else
+ checkfile(&l, b);
+ }
+ break;
+ case TINDIR:
+ break;
+ case TREF:
+ break;
+ }
+ putbuf(b);
+ return type;
+}
--- a/sys/src/cmd/hjfs/cons.c
+++ b/sys/src/cmd/hjfs/cons.c
@@ -104,6 +104,38 @@
}
int
+cmdcheck(int, char**)
+{
+ uvlong fblk, fend, blk;
+ int j;
+ Buf *b, *sb;
+
+ wlock(fsmain);
+ sb = getbuf(fsmain->d, SUPERBLK, TSUPERBLOCK, 0);
+ if(sb == nil){
+ wunlock(fsmain);
+ return -1;
+ }
+ fblk = sb->sb.fstart;
+ fend = sb->sb.fend;
+ putbuf(sb);
+
+ for(blk = 0; fblk < fend; fblk++){
+ b = getbuf(fsmain->d, fblk, TREF, 0);
+ if(b == nil){
+ blk += REFPERBLK;
+ continue;
+ }
+ for(j = 0; j < REFPERBLK; j++, blk++)
+ if(b->refs[j] == 0)
+ checkblk(blk);
+ putbuf(b);
+ }
+ wunlock(fsmain);
+ return 1;
+}
+
+int
cmddisallow(int, char **)
{
fsmain->flags &= ~(FSNOPERM | FSCHOWN);
--- a/sys/src/cmd/hjfs/fns.h
+++ b/sys/src/cmd/hjfs/fns.h
@@ -54,3 +54,4 @@
void workerinit(void);
void writeusers(Fs *);
void readusers(Fs *);
+int checkblk(uvlong);
--- a/sys/src/cmd/hjfs/fs1.c
+++ b/sys/src/cmd/hjfs/fs1.c
@@ -211,7 +211,7 @@
error:
if(ch != nil)
chanclunk(ch);
- dprint("writeusers: %r\n");
+ dprint("hjfs: writeusers: %r\n");
}
void
--- a/sys/src/cmd/hjfs/mkfile
+++ b/sys/src/cmd/hjfs/mkfile
@@ -13,6 +13,7 @@
9p.$O\
dump.$O\
cons.$O\
+ check.$O\
HFILES=\
dat.h\