summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorspew <devnull@localhost>2017-03-27 09:57:08 -0500
committerspew <devnull@localhost>2017-03-27 09:57:08 -0500
commit3edac8032702e5fb30dd78591ec0d104f83cfa33 (patch)
tree0e2d66a55ed0d0cb8d26e8098af052be117f70cb
parentf59ef5e8e7661dc06924bf8fea625ae69d59e40e (diff)
parent347bb2a7a7110e55debd5ebe57ba03bbe315c5ba (diff)
downloadplan9front-3edac8032702e5fb30dd78591ec0d104f83cfa33.tar.xz
hjfs: merge start of hjfs check implementation
-rw-r--r--sys/src/cmd/hjfs/check.c70
-rw-r--r--sys/src/cmd/hjfs/cons.c32
-rw-r--r--sys/src/cmd/hjfs/dat.h7
-rw-r--r--sys/src/cmd/hjfs/fns.h1
-rw-r--r--sys/src/cmd/hjfs/fs1.c4
-rw-r--r--sys/src/cmd/hjfs/fs2.c1
-rw-r--r--sys/src/cmd/hjfs/mkfile1
7 files changed, 112 insertions, 4 deletions
diff --git a/sys/src/cmd/hjfs/check.c b/sys/src/cmd/hjfs/check.c
new file mode 100644
index 000000000..edb11b75e
--- /dev/null
+++ b/sys/src/cmd/hjfs/check.c
@@ -0,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;
+}
diff --git a/sys/src/cmd/hjfs/cons.c b/sys/src/cmd/hjfs/cons.c
index bfe6bf938..e2bff60ba 100644
--- a/sys/src/cmd/hjfs/cons.c
+++ b/sys/src/cmd/hjfs/cons.c
@@ -104,6 +104,38 @@ cmdchatty(int, char **)
}
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);
diff --git a/sys/src/cmd/hjfs/dat.h b/sys/src/cmd/hjfs/dat.h
index f05229a29..bc336a7b2 100644
--- a/sys/src/cmd/hjfs/dat.h
+++ b/sys/src/cmd/hjfs/dat.h
@@ -79,6 +79,11 @@ struct Dentry {
enum {
DENTRYSIZ = NAMELEN + 4 * sizeof(ushort) + 13 + (3 + NDIRECT + NINDIRECT) * sizeof(uvlong),
DEPERBLK = RBLOCK / DENTRYSIZ,
+ /* Given any opportunity to make a breaking change to hjfs,
+ * make this 12 an 8. Indirect offsets to blocks used to
+ * hold an incrementing 4 byte generation number. That
+ * design has changed.
+ */
OFFPERBLK = RBLOCK / 12,
REFSIZ = 3,
REFPERBLK = RBLOCK / REFSIZ,
@@ -185,8 +190,8 @@ enum {
CHREAD = 1,
CHWRITE = 2,
CHRCLOSE = 4,
- CHFDUMP = 1,
+ CHFDUMP = 1,
CHFNOLOCK = 2,
CHFRO = 4,
CHFNOPERM = 8,
diff --git a/sys/src/cmd/hjfs/fns.h b/sys/src/cmd/hjfs/fns.h
index 0a2cb8667..788440993 100644
--- a/sys/src/cmd/hjfs/fns.h
+++ b/sys/src/cmd/hjfs/fns.h
@@ -54,3 +54,4 @@ int ingroup(Fs *, short, short, int);
void workerinit(void);
void writeusers(Fs *);
void readusers(Fs *);
+int checkblk(uvlong);
diff --git a/sys/src/cmd/hjfs/fs1.c b/sys/src/cmd/hjfs/fs1.c
index 5331d34f3..f543f8810 100644
--- a/sys/src/cmd/hjfs/fs1.c
+++ b/sys/src/cmd/hjfs/fs1.c
@@ -211,7 +211,7 @@ writeusers(Fs *fs)
error:
if(ch != nil)
chanclunk(ch);
- dprint("writeusers: %r\n");
+ dprint("hjfs: writeusers: %r\n");
}
void
@@ -449,7 +449,7 @@ freeit:
if((l->flags & LGONE) != 0){
/*
* safe to unlock here, the file is gone and
- * we'r the last reference.
+ * we're the last reference.
*/
qunlock(&fs->loctree);
b = getbuf(fs->d, l->blk, TDENTRY, 0);
diff --git a/sys/src/cmd/hjfs/fs2.c b/sys/src/cmd/hjfs/fs2.c
index 4390404f1..8befb2426 100644
--- a/sys/src/cmd/hjfs/fs2.c
+++ b/sys/src/cmd/hjfs/fs2.c
@@ -100,7 +100,6 @@ namevalid(char *name)
return p - name < NAMELEN;
}
-
int
chancreat(Chan *ch, char *name, int perm, int mode)
{
diff --git a/sys/src/cmd/hjfs/mkfile b/sys/src/cmd/hjfs/mkfile
index b7064affc..ab13b8619 100644
--- a/sys/src/cmd/hjfs/mkfile
+++ b/sys/src/cmd/hjfs/mkfile
@@ -13,6 +13,7 @@ OFILES=\
9p.$O\
dump.$O\
cons.$O\
+ check.$O\
HFILES=\
dat.h\