hjfs: merge start of hjfs check implementation
This commit is contained in:
commit
3edac80327
7 changed files with 112 additions and 4 deletions
70
sys/src/cmd/hjfs/check.c
Normal file
70
sys/src/cmd/hjfs/check.c
Normal file
|
@ -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;
|
||||||
|
}
|
|
@ -103,6 +103,38 @@ cmdchatty(int, char **)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
int
|
||||||
cmddisallow(int, char **)
|
cmddisallow(int, char **)
|
||||||
{
|
{
|
||||||
|
|
|
@ -79,6 +79,11 @@ struct Dentry {
|
||||||
enum {
|
enum {
|
||||||
DENTRYSIZ = NAMELEN + 4 * sizeof(ushort) + 13 + (3 + NDIRECT + NINDIRECT) * sizeof(uvlong),
|
DENTRYSIZ = NAMELEN + 4 * sizeof(ushort) + 13 + (3 + NDIRECT + NINDIRECT) * sizeof(uvlong),
|
||||||
DEPERBLK = RBLOCK / DENTRYSIZ,
|
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,
|
OFFPERBLK = RBLOCK / 12,
|
||||||
REFSIZ = 3,
|
REFSIZ = 3,
|
||||||
REFPERBLK = RBLOCK / REFSIZ,
|
REFPERBLK = RBLOCK / REFSIZ,
|
||||||
|
@ -185,8 +190,8 @@ enum {
|
||||||
CHREAD = 1,
|
CHREAD = 1,
|
||||||
CHWRITE = 2,
|
CHWRITE = 2,
|
||||||
CHRCLOSE = 4,
|
CHRCLOSE = 4,
|
||||||
CHFDUMP = 1,
|
|
||||||
|
|
||||||
|
CHFDUMP = 1,
|
||||||
CHFNOLOCK = 2,
|
CHFNOLOCK = 2,
|
||||||
CHFRO = 4,
|
CHFRO = 4,
|
||||||
CHFNOPERM = 8,
|
CHFNOPERM = 8,
|
||||||
|
|
|
@ -54,3 +54,4 @@ int ingroup(Fs *, short, short, int);
|
||||||
void workerinit(void);
|
void workerinit(void);
|
||||||
void writeusers(Fs *);
|
void writeusers(Fs *);
|
||||||
void readusers(Fs *);
|
void readusers(Fs *);
|
||||||
|
int checkblk(uvlong);
|
||||||
|
|
|
@ -211,7 +211,7 @@ writeusers(Fs *fs)
|
||||||
error:
|
error:
|
||||||
if(ch != nil)
|
if(ch != nil)
|
||||||
chanclunk(ch);
|
chanclunk(ch);
|
||||||
dprint("writeusers: %r\n");
|
dprint("hjfs: writeusers: %r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -449,7 +449,7 @@ freeit:
|
||||||
if((l->flags & LGONE) != 0){
|
if((l->flags & LGONE) != 0){
|
||||||
/*
|
/*
|
||||||
* safe to unlock here, the file is gone and
|
* safe to unlock here, the file is gone and
|
||||||
* we'r the last reference.
|
* we're the last reference.
|
||||||
*/
|
*/
|
||||||
qunlock(&fs->loctree);
|
qunlock(&fs->loctree);
|
||||||
b = getbuf(fs->d, l->blk, TDENTRY, 0);
|
b = getbuf(fs->d, l->blk, TDENTRY, 0);
|
||||||
|
|
|
@ -100,7 +100,6 @@ namevalid(char *name)
|
||||||
return p - name < NAMELEN;
|
return p - name < NAMELEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
chancreat(Chan *ch, char *name, int perm, int mode)
|
chancreat(Chan *ch, char *name, int perm, int mode)
|
||||||
{
|
{
|
||||||
|
|
|
@ -13,6 +13,7 @@ OFILES=\
|
||||||
9p.$O\
|
9p.$O\
|
||||||
dump.$O\
|
dump.$O\
|
||||||
cons.$O\
|
cons.$O\
|
||||||
|
check.$O\
|
||||||
|
|
||||||
HFILES=\
|
HFILES=\
|
||||||
dat.h\
|
dat.h\
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue