Various small interface changes.

This commit is contained in:
rsc 2004-03-15 01:57:29 +00:00
parent 3d77c87e81
commit d23a617a83
6 changed files with 64 additions and 53 deletions

View file

@ -22,9 +22,9 @@ int packetconsume(Packet*, uchar *buf, int n);
int packettrim(Packet*, int offset, int n); int packettrim(Packet*, int offset, int n);
uchar *packetheader(Packet*, int n); uchar *packetheader(Packet*, int n);
uchar *packettrailer(Packet*, int n); uchar *packettrailer(Packet*, int n);
int packetprefix(Packet*, uchar *buf, int n); void packetprefix(Packet*, uchar *buf, int n);
int packetappend(Packet*, uchar *buf, int n); void packetappend(Packet*, uchar *buf, int n);
int packetconcat(Packet*, Packet*); void packetconcat(Packet*, Packet*);
uchar *packetpeek(Packet*, uchar *buf, int offset, int n); uchar *packetpeek(Packet*, uchar *buf, int offset, int n);
int packetcopy(Packet*, uchar *buf, int offset, int n); int packetcopy(Packet*, uchar *buf, int offset, int n);
int packetfragments(Packet*, IOchunk*, int nio, int offset); int packetfragments(Packet*, IOchunk*, int nio, int offset);
@ -43,7 +43,6 @@ void packetsha1(Packet*, uchar sha1[20]);
*/ */
typedef struct VtFcall VtFcall; typedef struct VtFcall VtFcall;
typedef struct VtSha1 VtSha1;
typedef struct VtConn VtConn; typedef struct VtConn VtConn;
typedef struct VtEntry VtEntry; typedef struct VtEntry VtEntry;
typedef struct VtRoot VtRoot; typedef struct VtRoot VtRoot;
@ -85,6 +84,7 @@ enum
VtMaxType, VtMaxType,
VtTypeDepthMask = 7, VtTypeDepthMask = 7,
VtTypeBaseMask = ~VtTypeDepthMask,
}; };
/* convert to/from on-disk type numbers */ /* convert to/from on-disk type numbers */
@ -97,9 +97,9 @@ uint vtfromdisktype(uint);
enum enum
{ {
VtEntryActive = 1<<0, /* entry is in use */ VtEntryActive = 1<<0, /* entry is in use */
VtEntryDir = 1<<1, /* a directory */ _VtEntryDir = 1<<1, /* a directory */
VtEntryDepthShift = 2, /* shift for pointer depth */ _VtEntryDepthShift = 2, /* shift for pointer depth */
VtEntryDepthMask = 7<<2, /* mask for pointer depth */ _VtEntryDepthMask = 7<<2, /* mask for pointer depth */
VtEntryLocal = 1<<5, /* for local storage only */ VtEntryLocal = 1<<5, /* for local storage only */
}; };
enum enum
@ -152,7 +152,7 @@ uint vtzerotruncate(int type, uchar *buf, uint n);
/* /*
* parse score: mungs s * parse score: mungs s
*/ */
int vtparsescore(char *s, uint len, char **prefix, uchar[VtScoreSize]); int vtparsescore(char *s, char **prefix, uchar[VtScoreSize]);
/* /*
* formatting * formatting
@ -384,11 +384,30 @@ u32int vtcacheblocksize(VtCache*);
int vtblockwrite(VtBlock*); int vtblockwrite(VtBlock*);
VtBlock *vtblockcopy(VtBlock*); VtBlock *vtblockcopy(VtBlock*);
void vtblockduplock(VtBlock*); void vtblockduplock(VtBlock*);
int vtblockdirty(VtBlock*);
/* /*
* Hash tree file tree. * Hash tree file tree.
*/ */
typedef struct VtFile VtFile; typedef struct VtFile VtFile;
struct VtFile
{
QLock lk;
int ref;
int local;
VtBlock *b; /* block containing this file */
uchar score[VtScoreSize]; /* score of block containing this file */
/* immutable */
VtCache *c;
int mode;
u32int gen;
int dsize;
int dir;
VtFile *parent;
int epb; /* entries per block in parent */
u32int offset; /* entry offset in parent */
};
enum enum
{ {
@ -403,13 +422,13 @@ VtFile *vtfilecreateroot(VtCache*, int psize, int dsize, int type);
VtFile *vtfileopen(VtFile*, u32int, int); VtFile *vtfileopen(VtFile*, u32int, int);
VtFile *vtfilecreate(VtFile*, int psize, int dsize, int dir); VtFile *vtfilecreate(VtFile*, int psize, int dsize, int dir);
VtBlock *vtfileblock(VtFile*, u32int, int mode); VtBlock *vtfileblock(VtFile*, u32int, int mode);
int vtfileblockhash(VtFile*, u32int, uchar[VtScoreSize]);
long vtfileread(VtFile*, void*, long, vlong); long vtfileread(VtFile*, void*, long, vlong);
long vtfilewrite(VtFile*, void*, long, vlong); long vtfilewrite(VtFile*, void*, long, vlong);
int vtfileflush(VtFile*); int vtfileflush(VtFile*);
void vtfileincref(VtFile*); void vtfileincref(VtFile*);
void vtfileclose(VtFile*); void vtfileclose(VtFile*);
int vtfilegetentry(VtFile*, VtEntry*); int vtfilegetentry(VtFile*, VtEntry*);
int vtfilesetentry(VtFile*, VtEntry*);
int vtfileblockscore(VtFile*, u32int, uchar[VtScoreSize]); int vtfileblockscore(VtFile*, u32int, uchar[VtScoreSize]);
u32int vtfilegetdirsize(VtFile*); u32int vtfilegetdirsize(VtFile*);
int vtfilesetdirsize(VtFile*, u32int); int vtfilesetdirsize(VtFile*, u32int);
@ -417,6 +436,10 @@ void vtfileunlock(VtFile*);
int vtfilelock(VtFile*, int); int vtfilelock(VtFile*, int);
int vtfilelock2(VtFile*, VtFile*, int); int vtfilelock2(VtFile*, VtFile*, int);
int vtfileflushbefore(VtFile*, u64int); int vtfileflushbefore(VtFile*, u64int);
int vtfiletruncate(VtFile*);
uvlong vtfilegetsize(VtFile*);
int vtfilesetsize(VtFile*, uvlong);
int vtfileremove(VtFile*);
#if defined(__cplusplus) #if defined(__cplusplus)
} }

View file

@ -558,3 +558,10 @@ vtglobaltolocal(uchar score[VtScoreSize])
return NilBlock; return NilBlock;
return (score[16]<<24)|(score[17]<<16)|(score[18]<<8)|score[19]; return (score[16]<<24)|(score[17]<<16)|(score[18]<<8)|score[19];
} }
int
vtblockdirty(VtBlock *b)
{
return 0;
}

View file

@ -31,10 +31,10 @@ vtentrypack(VtEntry *e, uchar *p, int index)
U16PUT(p, e->dsize); U16PUT(p, e->dsize);
p += 2; p += 2;
depth = e->type&VtTypeDepthMask; depth = e->type&VtTypeDepthMask;
flags = (e->flags&~(VtEntryDir|VtEntryDepthShift)); flags = (e->flags&~(_VtEntryDir|_VtEntryDepthMask));
flags |= depth << VtEntryDepthShift; flags |= depth << _VtEntryDepthShift;
if(e->type - depth == VtEntryDir) if(e->type - depth == VtDirType)
flags |= VtEntryDir; flags |= _VtEntryDir;
U8PUT(p, flags); U8PUT(p, flags);
p++; p++;
memset(p, 0, 5); memset(p, 0, 5);
@ -62,9 +62,9 @@ vtentryunpack(VtEntry *e, uchar *p, int index)
e->dsize = U16GET(p); e->dsize = U16GET(p);
p += 2; p += 2;
e->flags = U8GET(p); e->flags = U8GET(p);
e->type = (e->flags&VtEntryDir) ? VtDirType : VtDataType; e->type = (e->flags&_VtEntryDir) ? VtDirType : VtDataType;
e->type += (e->flags & VtEntryDepthMask) >> VtEntryDepthShift; e->type += (e->flags & _VtEntryDepthMask) >> _VtEntryDepthShift;
e->flags &= ~(VtEntryDir|VtEntryDepthMask); e->flags &= ~(_VtEntryDir|_VtEntryDepthMask);
p++; p++;
p += 5; p += 5;
e->size = U48GET(p); e->size = U48GET(p);

View file

@ -21,25 +21,6 @@ enum
MaxBlock = (1UL<<31), MaxBlock = (1UL<<31),
}; };
struct VtFile
{
QLock lk;
int ref;
int local;
VtBlock *b; /* block containing this file */
uchar score[VtScoreSize]; /* score of block containing this file */
/* immutable */
VtCache *c;
int mode;
u32int gen;
int dsize;
int dir;
VtFile *parent;
int epb; /* entries per block in parent */
u32int offset; /* entry offset in parent */
};
static char EBadEntry[] = "bad VtEntry"; static char EBadEntry[] = "bad VtEntry";
static char ENotDir[] = "walk in non-directory"; static char ENotDir[] = "walk in non-directory";
static char ETooBig[] = "file too big"; static char ETooBig[] = "file too big";
@ -109,7 +90,7 @@ vtfilealloc(VtCache *c, VtBlock *b, VtFile *p, u32int offset, int mode)
r->mode = mode; r->mode = mode;
r->dsize = e.dsize; r->dsize = e.dsize;
r->gen = e.gen; r->gen = e.gen;
r->dir = (e.flags & VtEntryDir) != 0; r->dir = (e.type & VtTypeBaseMask) == VtDirType;
r->ref = 1; r->ref = 1;
r->parent = p; r->parent = p;
if(p){ if(p){
@ -169,8 +150,7 @@ vtfilecreateroot(VtCache *c, int psize, int dsize, int type)
e.flags = VtEntryActive; e.flags = VtEntryActive;
e.psize = psize; e.psize = psize;
e.dsize = dsize; e.dsize = dsize;
if(type == VtDirType) e.type = type;
e.flags |= VtEntryDir;
memmove(e.score, vtzeroscore, VtScoreSize); memmove(e.score, vtzeroscore, VtScoreSize);
return vtfileopenroot(c, &e); return vtfileopenroot(c, &e);
@ -679,13 +659,15 @@ static int
mkindices(VtEntry *e, u32int bn, int *index) mkindices(VtEntry *e, u32int bn, int *index)
{ {
int i, np; int i, np;
u32int obn;
obn = bn;
memset(index, 0, VtPointerDepth*sizeof(int)); memset(index, 0, VtPointerDepth*sizeof(int));
np = e->psize/VtScoreSize; np = e->psize/VtScoreSize;
for(i=0; bn > 0; i++){ for(i=0; bn > 0; i++){
if(i >= VtPointerDepth){ if(i >= VtPointerDepth){
werrstr(EBadAddr); werrstr("bad address 0x%lux", (ulong)bn);
return -1; return -1;
} }
index[i] = bn % np; index[i] = bn % np;
@ -715,7 +697,7 @@ vtfileblock(VtFile *r, u32int bn, int mode)
return nil; return nil;
if(i > DEPTH(e.type)){ if(i > DEPTH(e.type)){
if(mode == VtOREAD){ if(mode == VtOREAD){
werrstr(EBadAddr); werrstr("bad address 0x%lux", (ulong)bn);
goto Err; goto Err;
} }
index[i] = 0; index[i] = 0;
@ -746,7 +728,7 @@ Err:
} }
int int
vtfileblockhash(VtFile *r, u32int bn, uchar score[VtScoreSize]) vtfileblockscore(VtFile *r, u32int bn, uchar score[VtScoreSize])
{ {
VtBlock *b, *bb; VtBlock *b, *bb;
int index[VtPointerDepth+1]; int index[VtPointerDepth+1];

View file

@ -17,6 +17,7 @@ OFILES=\
hangup.$O\ hangup.$O\
mem.$O\ mem.$O\
packet.$O\ packet.$O\
parsescore.$O\
queue.$O\ queue.$O\
root.$O\ root.$O\
rpc.$O\ rpc.$O\

View file

@ -113,7 +113,7 @@ packetalloc(void)
p->last = nil; p->last = nil;
p->next = nil; p->next = nil;
if(1)fprint(2, "packetalloc %p from %08lux %08lux %08lux\n", p, *((uint*)&p+2), *((uint*)&p+3), *((uint*)&p+4)); if(0)fprint(2, "packetalloc %p from %08lux %08lux %08lux\n", p, *((uint*)&p+2), *((uint*)&p+3), *((uint*)&p+4));
return p; return p;
} }
@ -123,7 +123,7 @@ packetfree(Packet *p)
{ {
Frag *f, *ff; Frag *f, *ff;
if(1)fprint(2, "packetfree %p from %08lux\n", p, getcallerpc(&p)); if(0)fprint(2, "packetfree %p from %08lux\n", p, getcallerpc(&p));
if(p == nil) if(p == nil)
return; return;
@ -237,7 +237,7 @@ packetconsume(Packet *p, uchar *buf, int n)
{ {
NOTFREE(p); NOTFREE(p);
if(buf && packetcopy(p, buf, 0, n) < 0) if(buf && packetcopy(p, buf, 0, n) < 0)
return 0; return -1;
return packettrim(p, n, p->size-n); return packettrim(p, n, p->size-n);
} }
@ -371,7 +371,7 @@ packettrailer(Packet *p, int n)
return f->rp; return f->rp;
} }
int void
packetprefix(Packet *p, uchar *buf, int n) packetprefix(Packet *p, uchar *buf, int n)
{ {
Frag *f; Frag *f;
@ -380,7 +380,7 @@ packetprefix(Packet *p, uchar *buf, int n)
NOTFREE(p); NOTFREE(p);
if(n <= 0) if(n <= 0)
return 0; return;
p->size += n; p->size += n;
@ -410,10 +410,9 @@ packetprefix(Packet *p, uchar *buf, int n)
n -= nn; n -= nn;
memmove(f->rp, buf+n, nn); memmove(f->rp, buf+n, nn);
} }
return 0;
} }
int void
packetappend(Packet *p, uchar *buf, int n) packetappend(Packet *p, uchar *buf, int n)
{ {
Frag *f; Frag *f;
@ -422,7 +421,7 @@ packetappend(Packet *p, uchar *buf, int n)
NOTFREE(p); NOTFREE(p);
if(n <= 0) if(n <= 0)
return 0; return;
p->size += n; p->size += n;
/* try and fix in current frag */ /* try and fix in current frag */
@ -455,16 +454,16 @@ packetappend(Packet *p, uchar *buf, int n)
buf += nn; buf += nn;
n -= nn; n -= nn;
} }
return 0; return;
} }
int void
packetconcat(Packet *p, Packet *pp) packetconcat(Packet *p, Packet *pp)
{ {
NOTFREE(p); NOTFREE(p);
NOTFREE(pp); NOTFREE(pp);
if(pp->size == 0) if(pp->size == 0)
return 0; return;
p->size += pp->size; p->size += pp->size;
p->asize += pp->asize; p->asize += pp->asize;
@ -477,7 +476,6 @@ packetconcat(Packet *p, Packet *pp)
pp->asize = 0; pp->asize = 0;
pp->first = nil; pp->first = nil;
pp->last = nil; pp->last = nil;
return 0;
} }
uchar * uchar *