fossil: move from liboventi to libthread and libventi
R=rsc https://codereview.appspot.com/13504049
This commit is contained in:
parent
6f4d00ee45
commit
4b57665805
@ -57,31 +57,31 @@ struct Con {
|
|||||||
int isconsole; /* immutable */
|
int isconsole; /* immutable */
|
||||||
int flags; /* immutable */
|
int flags; /* immutable */
|
||||||
char remote[128]; /* immutable */
|
char remote[128]; /* immutable */
|
||||||
VtLock* lock;
|
QLock lock;
|
||||||
int state;
|
int state;
|
||||||
int fd;
|
int fd;
|
||||||
Msg* version;
|
Msg* version;
|
||||||
u32int msize; /* negotiated with Tversion */
|
u32int msize; /* negotiated with Tversion */
|
||||||
VtRendez* rendez;
|
Rendez rendez;
|
||||||
|
|
||||||
Con* anext; /* alloc */
|
Con* anext; /* alloc */
|
||||||
Con* cnext; /* in use */
|
Con* cnext; /* in use */
|
||||||
Con* cprev;
|
Con* cprev;
|
||||||
|
|
||||||
VtLock* alock;
|
RWLock alock;
|
||||||
int aok; /* authentication done */
|
int aok; /* authentication done */
|
||||||
|
|
||||||
VtLock* mlock;
|
QLock mlock;
|
||||||
Msg* mhead; /* all Msgs on this connection */
|
Msg* mhead; /* all Msgs on this connection */
|
||||||
Msg* mtail;
|
Msg* mtail;
|
||||||
VtRendez* mrendez;
|
Rendez mrendez;
|
||||||
|
|
||||||
VtLock* wlock;
|
QLock wlock;
|
||||||
Msg* whead; /* write queue */
|
Msg* whead; /* write queue */
|
||||||
Msg* wtail;
|
Msg* wtail;
|
||||||
VtRendez* wrendez;
|
Rendez wrendez;
|
||||||
|
|
||||||
VtLock* fidlock; /* */
|
QLock fidlock; /* */
|
||||||
Fid* fidhash[NFidHash];
|
Fid* fidhash[NFidHash];
|
||||||
Fid* fhead;
|
Fid* fhead;
|
||||||
Fid* ftail;
|
Fid* ftail;
|
||||||
@ -98,7 +98,7 @@ enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct Fid {
|
struct Fid {
|
||||||
VtLock* lock;
|
RWLock lock;
|
||||||
Con* con;
|
Con* con;
|
||||||
u32int fidno;
|
u32int fidno;
|
||||||
int ref; /* inc/dec under Con.fidlock */
|
int ref; /* inc/dec under Con.fidlock */
|
||||||
@ -113,7 +113,7 @@ struct Fid {
|
|||||||
DirBuf* db;
|
DirBuf* db;
|
||||||
Excl* excl;
|
Excl* excl;
|
||||||
|
|
||||||
VtLock* alock; /* Tauth/Tattach */
|
QLock alock; /* Tauth/Tattach */
|
||||||
AuthRpc* rpc;
|
AuthRpc* rpc;
|
||||||
char* cuname;
|
char* cuname;
|
||||||
|
|
||||||
|
|||||||
@ -8,44 +8,44 @@ authRead(Fid* afid, void* data, int count)
|
|||||||
AuthRpc *rpc;
|
AuthRpc *rpc;
|
||||||
|
|
||||||
if((rpc = afid->rpc) == nil){
|
if((rpc = afid->rpc) == nil){
|
||||||
vtSetError("not an auth fid");
|
werrstr("not an auth fid");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(auth_rpc(rpc, "read", nil, 0)){
|
switch(auth_rpc(rpc, "read", nil, 0)){
|
||||||
default:
|
default:
|
||||||
vtSetError("fossil authRead: auth protocol not finished");
|
werrstr("fossil authRead: auth protocol not finished");
|
||||||
return -1;
|
return -1;
|
||||||
case ARdone:
|
case ARdone:
|
||||||
if((ai = auth_getinfo(rpc)) == nil){
|
if((ai = auth_getinfo(rpc)) == nil){
|
||||||
vtSetError("%r");
|
werrstr("%r");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(ai->cuid == nil || *ai->cuid == '\0'){
|
if(ai->cuid == nil || *ai->cuid == '\0'){
|
||||||
vtSetError("auth with no cuid");
|
werrstr("auth with no cuid");
|
||||||
auth_freeAI(ai);
|
auth_freeAI(ai);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
assert(afid->cuname == nil);
|
assert(afid->cuname == nil);
|
||||||
afid->cuname = vtStrDup(ai->cuid);
|
afid->cuname = vtstrdup(ai->cuid);
|
||||||
auth_freeAI(ai);
|
auth_freeAI(ai);
|
||||||
if(Dflag)
|
if(Dflag)
|
||||||
fprint(2, "authRead cuname %s\n", afid->cuname);
|
fprint(2, "authRead cuname %s\n", afid->cuname);
|
||||||
assert(afid->uid == nil);
|
assert(afid->uid == nil);
|
||||||
if((afid->uid = uidByUname(afid->cuname)) == nil){
|
if((afid->uid = uidByUname(afid->cuname)) == nil){
|
||||||
vtSetError("unknown user %#q", afid->cuname);
|
werrstr("unknown user %#q", afid->cuname);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
case ARok:
|
case ARok:
|
||||||
if(count < rpc->narg){
|
if(count < rpc->narg){
|
||||||
vtSetError("not enough data in auth read");
|
werrstr("not enough data in auth read");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
memmove(data, rpc->arg, rpc->narg);
|
memmove(data, rpc->arg, rpc->narg);
|
||||||
return rpc->narg;
|
return rpc->narg;
|
||||||
case ARphase:
|
case ARphase:
|
||||||
vtSetError("%r");
|
werrstr("%r");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
@ -82,7 +82,7 @@ authCheck(Fcall* t, Fid* fid, Fsys* fsys)
|
|||||||
* The console is allowed to attach without
|
* The console is allowed to attach without
|
||||||
* authentication.
|
* authentication.
|
||||||
*/
|
*/
|
||||||
vtRLock(con->alock);
|
rlock(&con->alock);
|
||||||
if(con->isconsole){
|
if(con->isconsole){
|
||||||
/* anything goes */
|
/* anything goes */
|
||||||
}else if((con->flags&ConNoneAllow) || con->aok){
|
}else if((con->flags&ConNoneAllow) || con->aok){
|
||||||
@ -91,21 +91,21 @@ authCheck(Fcall* t, Fid* fid, Fsys* fsys)
|
|||||||
if(noneprint++ < 10)
|
if(noneprint++ < 10)
|
||||||
consPrint("attach %s as %s: allowing as none\n",
|
consPrint("attach %s as %s: allowing as none\n",
|
||||||
fsysGetName(fsys), fid->uname);
|
fsysGetName(fsys), fid->uname);
|
||||||
vtMemFree(fid->uname);
|
vtfree(fid->uname);
|
||||||
fid->uname = vtStrDup(unamenone);
|
fid->uname = vtstrdup(unamenone);
|
||||||
}else{
|
}else{
|
||||||
vtRUnlock(con->alock);
|
runlock(&con->alock);
|
||||||
consPrint("attach %s as %s: connection not authenticated, not console\n",
|
consPrint("attach %s as %s: connection not authenticated, not console\n",
|
||||||
fsysGetName(fsys), fid->uname);
|
fsysGetName(fsys), fid->uname);
|
||||||
vtSetError("cannot attach as none before authentication");
|
werrstr("cannot attach as none before authentication");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
vtRUnlock(con->alock);
|
runlock(&con->alock);
|
||||||
|
|
||||||
if((fid->uid = uidByUname(fid->uname)) == nil){
|
if((fid->uid = uidByUname(fid->uname)) == nil){
|
||||||
consPrint("attach %s as %s: unknown uname\n",
|
consPrint("attach %s as %s: unknown uname\n",
|
||||||
fsysGetName(fsys), fid->uname);
|
fsysGetName(fsys), fid->uname);
|
||||||
vtSetError("unknown user");
|
werrstr("unknown user");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
@ -114,7 +114,7 @@ authCheck(Fcall* t, Fid* fid, Fsys* fsys)
|
|||||||
if((afid = fidGet(con, t->afid, 0)) == nil){
|
if((afid = fidGet(con, t->afid, 0)) == nil){
|
||||||
consPrint("attach %s as %s: bad afid\n",
|
consPrint("attach %s as %s: bad afid\n",
|
||||||
fsysGetName(fsys), fid->uname);
|
fsysGetName(fsys), fid->uname);
|
||||||
vtSetError("bad authentication fid");
|
werrstr("bad authentication fid");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,7 +126,7 @@ authCheck(Fcall* t, Fid* fid, Fsys* fsys)
|
|||||||
consPrint("attach %s as %s: afid not an auth file\n",
|
consPrint("attach %s as %s: afid not an auth file\n",
|
||||||
fsysGetName(fsys), fid->uname);
|
fsysGetName(fsys), fid->uname);
|
||||||
fidPut(afid);
|
fidPut(afid);
|
||||||
vtSetError("bad authentication fid");
|
werrstr("bad authentication fid");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(strcmp(afid->uname, fid->uname) != 0 || afid->fsys != fsys){
|
if(strcmp(afid->uname, fid->uname) != 0 || afid->fsys != fsys){
|
||||||
@ -134,42 +134,42 @@ authCheck(Fcall* t, Fid* fid, Fsys* fsys)
|
|||||||
fsysGetName(fsys), fid->uname,
|
fsysGetName(fsys), fid->uname,
|
||||||
fsysGetName(afid->fsys), afid->uname);
|
fsysGetName(afid->fsys), afid->uname);
|
||||||
fidPut(afid);
|
fidPut(afid);
|
||||||
vtSetError("attach/auth mismatch");
|
werrstr("attach/auth mismatch");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
vtLock(afid->alock);
|
qlock(&afid->alock);
|
||||||
if(afid->cuname == nil){
|
if(afid->cuname == nil){
|
||||||
if(authRead(afid, buf, 0) != 0 || afid->cuname == nil){
|
if(authRead(afid, buf, 0) != 0 || afid->cuname == nil){
|
||||||
vtUnlock(afid->alock);
|
qunlock(&afid->alock);
|
||||||
consPrint("attach %s as %s: %R\n",
|
consPrint("attach %s as %s: %r\n",
|
||||||
fsysGetName(fsys), fid->uname);
|
fsysGetName(fsys), fid->uname);
|
||||||
fidPut(afid);
|
fidPut(afid);
|
||||||
vtSetError("fossil authCheck: auth protocol not finished");
|
werrstr("fossil authCheck: auth protocol not finished");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
vtUnlock(afid->alock);
|
qunlock(&afid->alock);
|
||||||
|
|
||||||
assert(fid->uid == nil);
|
assert(fid->uid == nil);
|
||||||
if((fid->uid = uidByUname(afid->cuname)) == nil){
|
if((fid->uid = uidByUname(afid->cuname)) == nil){
|
||||||
consPrint("attach %s as %s: unknown cuname %s\n",
|
consPrint("attach %s as %s: unknown cuname %s\n",
|
||||||
fsysGetName(fsys), fid->uname, afid->cuname);
|
fsysGetName(fsys), fid->uname, afid->cuname);
|
||||||
fidPut(afid);
|
fidPut(afid);
|
||||||
vtSetError("unknown user");
|
werrstr("unknown user");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
vtMemFree(fid->uname);
|
vtfree(fid->uname);
|
||||||
fid->uname = vtStrDup(afid->cuname);
|
fid->uname = vtstrdup(afid->cuname);
|
||||||
fidPut(afid);
|
fidPut(afid);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Allow "none" once the connection has been authenticated.
|
* Allow "none" once the connection has been authenticated.
|
||||||
*/
|
*/
|
||||||
vtLock(con->alock);
|
wlock(&con->alock);
|
||||||
con->aok = 1;
|
con->aok = 1;
|
||||||
vtUnlock(con->alock);
|
wunlock(&con->alock);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,11 +14,11 @@ dirBufAlloc(File* file)
|
|||||||
{
|
{
|
||||||
DirBuf *db;
|
DirBuf *db;
|
||||||
|
|
||||||
db = vtMemAllocZ(sizeof(DirBuf));
|
db = vtmallocz(sizeof(DirBuf));
|
||||||
db->dee = deeOpen(file);
|
db->dee = deeOpen(file);
|
||||||
if(db->dee == nil){
|
if(db->dee == nil){
|
||||||
/* can happen if dir is removed from under us */
|
/* can happen if dir is removed from under us */
|
||||||
vtMemFree(db);
|
vtfree(db);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
return db;
|
return db;
|
||||||
@ -33,7 +33,7 @@ dirBufFree(DirBuf* db)
|
|||||||
if(db->valid)
|
if(db->valid)
|
||||||
deCleanup(&db->de);
|
deCleanup(&db->de);
|
||||||
deeClose(db->dee);
|
deeClose(db->dee);
|
||||||
vtMemFree(db);
|
vtfree(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -82,9 +82,9 @@ dirDe2M(DirEntry* de, uchar* p, int np)
|
|||||||
|
|
||||||
n = convD2M(&dir, p, np);
|
n = convD2M(&dir, p, np);
|
||||||
|
|
||||||
vtMemFree(dir.muid);
|
vtfree(dir.muid);
|
||||||
vtMemFree(dir.gid);
|
vtfree(dir.gid);
|
||||||
vtMemFree(dir.uid);
|
vtfree(dir.uid);
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
#include "9.h"
|
#include "9.h"
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
VtLock* lock;
|
QLock lock;
|
||||||
|
|
||||||
Excl* head;
|
Excl* head;
|
||||||
Excl* tail;
|
Excl* tail;
|
||||||
@ -31,7 +31,7 @@ exclAlloc(Fid* fid)
|
|||||||
assert(fid->excl == nil);
|
assert(fid->excl == nil);
|
||||||
|
|
||||||
t = time(0L);
|
t = time(0L);
|
||||||
vtLock(ebox.lock);
|
qlock(&ebox.lock);
|
||||||
for(excl = ebox.head; excl != nil; excl = excl->next){
|
for(excl = ebox.head; excl != nil; excl = excl->next){
|
||||||
if(excl->fsys != fid->fsys || excl->path != fid->qid.path)
|
if(excl->fsys != fid->fsys || excl->path != fid->qid.path)
|
||||||
continue;
|
continue;
|
||||||
@ -44,8 +44,8 @@ exclAlloc(Fid* fid)
|
|||||||
* a new one.
|
* a new one.
|
||||||
*/
|
*/
|
||||||
if(excl->time >= t){
|
if(excl->time >= t){
|
||||||
vtUnlock(ebox.lock);
|
qunlock(&ebox.lock);
|
||||||
vtSetError("exclusive lock");
|
werrstr("exclusive lock");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
excl->fsys = nil;
|
excl->fsys = nil;
|
||||||
@ -55,7 +55,7 @@ exclAlloc(Fid* fid)
|
|||||||
* Not found or timed-out.
|
* Not found or timed-out.
|
||||||
* Alloc a new one and initialise.
|
* Alloc a new one and initialise.
|
||||||
*/
|
*/
|
||||||
excl = vtMemAllocZ(sizeof(Excl));
|
excl = vtmallocz(sizeof(Excl));
|
||||||
excl->fsys = fid->fsys;
|
excl->fsys = fid->fsys;
|
||||||
excl->path = fid->qid.path;
|
excl->path = fid->qid.path;
|
||||||
excl->time = t+LifeTime;
|
excl->time = t+LifeTime;
|
||||||
@ -69,7 +69,7 @@ exclAlloc(Fid* fid)
|
|||||||
}
|
}
|
||||||
ebox.tail = excl;
|
ebox.tail = excl;
|
||||||
excl->next = nil;
|
excl->next = nil;
|
||||||
vtUnlock(ebox.lock);
|
qunlock(&ebox.lock);
|
||||||
|
|
||||||
fid->excl = excl;
|
fid->excl = excl;
|
||||||
return 1;
|
return 1;
|
||||||
@ -84,14 +84,14 @@ exclUpdate(Fid* fid)
|
|||||||
excl = fid->excl;
|
excl = fid->excl;
|
||||||
|
|
||||||
t = time(0L);
|
t = time(0L);
|
||||||
vtLock(ebox.lock);
|
qlock(&ebox.lock);
|
||||||
if(excl->time < t || excl->fsys != fid->fsys){
|
if(excl->time < t || excl->fsys != fid->fsys){
|
||||||
vtUnlock(ebox.lock);
|
qunlock(&ebox.lock);
|
||||||
vtSetError("exclusive lock broken");
|
werrstr("exclusive lock broken");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
excl->time = t+LifeTime;
|
excl->time = t+LifeTime;
|
||||||
vtUnlock(ebox.lock);
|
qunlock(&ebox.lock);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -105,7 +105,7 @@ exclFree(Fid* fid)
|
|||||||
return;
|
return;
|
||||||
fid->excl = nil;
|
fid->excl = nil;
|
||||||
|
|
||||||
vtLock(ebox.lock);
|
qlock(&ebox.lock);
|
||||||
if(excl->prev != nil)
|
if(excl->prev != nil)
|
||||||
excl->prev->next = excl->next;
|
excl->prev->next = excl->next;
|
||||||
else
|
else
|
||||||
@ -114,13 +114,12 @@ exclFree(Fid* fid)
|
|||||||
excl->next->prev = excl->prev;
|
excl->next->prev = excl->prev;
|
||||||
else
|
else
|
||||||
ebox.tail = excl->prev;
|
ebox.tail = excl->prev;
|
||||||
vtUnlock(ebox.lock);
|
qunlock(&ebox.lock);
|
||||||
|
|
||||||
vtMemFree(excl);
|
vtfree(excl);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
exclInit(void)
|
exclInit(void)
|
||||||
{
|
{
|
||||||
ebox.lock = vtLockAlloc();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
#include "9.h"
|
#include "9.h"
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
VtLock* lock;
|
QLock lock;
|
||||||
|
|
||||||
Fid* free;
|
Fid* free;
|
||||||
int nfree;
|
int nfree;
|
||||||
@ -14,11 +14,11 @@ static void
|
|||||||
fidLock(Fid* fid, int flags)
|
fidLock(Fid* fid, int flags)
|
||||||
{
|
{
|
||||||
if(flags & FidFWlock){
|
if(flags & FidFWlock){
|
||||||
vtLock(fid->lock);
|
wlock(&fid->lock);
|
||||||
fid->flags = flags;
|
fid->flags = flags;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
vtRLock(fid->lock);
|
rlock(&fid->lock);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Callers of file* routines are expected to lock fsys->fs->elk
|
* Callers of file* routines are expected to lock fsys->fs->elk
|
||||||
@ -47,10 +47,10 @@ fidUnlock(Fid* fid)
|
|||||||
fsysFsRUnlock(fid->fsys);
|
fsysFsRUnlock(fid->fsys);
|
||||||
if(fid->flags & FidFWlock){
|
if(fid->flags & FidFWlock){
|
||||||
fid->flags = 0;
|
fid->flags = 0;
|
||||||
vtUnlock(fid->lock);
|
wunlock(&fid->lock);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
vtRUnlock(fid->lock);
|
runlock(&fid->lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Fid*
|
static Fid*
|
||||||
@ -58,19 +58,17 @@ fidAlloc(void)
|
|||||||
{
|
{
|
||||||
Fid *fid;
|
Fid *fid;
|
||||||
|
|
||||||
vtLock(fbox.lock);
|
qlock(&fbox.lock);
|
||||||
if(fbox.nfree > 0){
|
if(fbox.nfree > 0){
|
||||||
fid = fbox.free;
|
fid = fbox.free;
|
||||||
fbox.free = fid->hash;
|
fbox.free = fid->hash;
|
||||||
fbox.nfree--;
|
fbox.nfree--;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
fid = vtMemAllocZ(sizeof(Fid));
|
fid = vtmallocz(sizeof(Fid));
|
||||||
fid->lock = vtLockAlloc();
|
|
||||||
fid->alock = vtLockAlloc();
|
|
||||||
}
|
}
|
||||||
fbox.inuse++;
|
fbox.inuse++;
|
||||||
vtUnlock(fbox.lock);
|
qunlock(&fbox.lock);
|
||||||
|
|
||||||
fid->con = nil;
|
fid->con = nil;
|
||||||
fid->fidno = NOFID;
|
fid->fidno = NOFID;
|
||||||
@ -105,11 +103,11 @@ fidFree(Fid* fid)
|
|||||||
fidUnlock(fid);
|
fidUnlock(fid);
|
||||||
|
|
||||||
if(fid->uid != nil){
|
if(fid->uid != nil){
|
||||||
vtMemFree(fid->uid);
|
vtfree(fid->uid);
|
||||||
fid->uid = nil;
|
fid->uid = nil;
|
||||||
}
|
}
|
||||||
if(fid->uname != nil){
|
if(fid->uname != nil){
|
||||||
vtMemFree(fid->uname);
|
vtfree(fid->uname);
|
||||||
fid->uname = nil;
|
fid->uname = nil;
|
||||||
}
|
}
|
||||||
if(fid->excl != nil)
|
if(fid->excl != nil)
|
||||||
@ -124,11 +122,11 @@ fidFree(Fid* fid)
|
|||||||
fid->fsys = nil;
|
fid->fsys = nil;
|
||||||
}
|
}
|
||||||
if(fid->cuname != nil){
|
if(fid->cuname != nil){
|
||||||
vtMemFree(fid->cuname);
|
vtfree(fid->cuname);
|
||||||
fid->cuname = nil;
|
fid->cuname = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
vtLock(fbox.lock);
|
qlock(&fbox.lock);
|
||||||
fbox.inuse--;
|
fbox.inuse--;
|
||||||
if(fbox.nfree < 10){
|
if(fbox.nfree < 10){
|
||||||
fid->hash = fbox.free;
|
fid->hash = fbox.free;
|
||||||
@ -136,11 +134,9 @@ fidFree(Fid* fid)
|
|||||||
fbox.nfree++;
|
fbox.nfree++;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
vtLockFree(fid->alock);
|
vtfree(fid);
|
||||||
vtLockFree(fid->lock);
|
|
||||||
vtMemFree(fid);
|
|
||||||
}
|
}
|
||||||
vtUnlock(fbox.lock);
|
qunlock(&fbox.lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -182,7 +178,7 @@ fidGet(Con* con, u32int fidno, int flags)
|
|||||||
return nil;
|
return nil;
|
||||||
|
|
||||||
hash = &con->fidhash[fidno % NFidHash];
|
hash = &con->fidhash[fidno % NFidHash];
|
||||||
vtLock(con->fidlock);
|
qlock(&con->fidlock);
|
||||||
for(fid = *hash; fid != nil; fid = fid->hash){
|
for(fid = *hash; fid != nil; fid = fid->hash){
|
||||||
if(fid->fidno != fidno)
|
if(fid->fidno != fidno)
|
||||||
continue;
|
continue;
|
||||||
@ -192,17 +188,17 @@ fidGet(Con* con, u32int fidno, int flags)
|
|||||||
* when called from attach, clone or walk.
|
* when called from attach, clone or walk.
|
||||||
*/
|
*/
|
||||||
if(flags & FidFCreate){
|
if(flags & FidFCreate){
|
||||||
vtUnlock(con->fidlock);
|
qunlock(&con->fidlock);
|
||||||
vtSetError("%s: fid 0x%ud in use", argv0, fidno);
|
werrstr("%s: fid 0x%ud in use", argv0, fidno);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
fid->ref++;
|
fid->ref++;
|
||||||
vtUnlock(con->fidlock);
|
qunlock(&con->fidlock);
|
||||||
|
|
||||||
fidLock(fid, flags);
|
fidLock(fid, flags);
|
||||||
if((fid->open & FidOCreate) || fid->fidno == NOFID){
|
if((fid->open & FidOCreate) || fid->fidno == NOFID){
|
||||||
fidPut(fid);
|
fidPut(fid);
|
||||||
vtSetError("%s: fid invalid", argv0);
|
werrstr("%s: fid invalid", argv0);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
return fid;
|
return fid;
|
||||||
@ -228,7 +224,7 @@ fidGet(Con* con, u32int fidno, int flags)
|
|||||||
fid->next = nil;
|
fid->next = nil;
|
||||||
|
|
||||||
con->nfid++;
|
con->nfid++;
|
||||||
vtUnlock(con->fidlock);
|
qunlock(&con->fidlock);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The FidOCreate flag is used to prevent any
|
* The FidOCreate flag is used to prevent any
|
||||||
@ -239,19 +235,19 @@ fidGet(Con* con, u32int fidno, int flags)
|
|||||||
fid->open &= ~FidOCreate;
|
fid->open &= ~FidOCreate;
|
||||||
return fid;
|
return fid;
|
||||||
}
|
}
|
||||||
vtUnlock(con->fidlock);
|
qunlock(&con->fidlock);
|
||||||
|
|
||||||
vtSetError("%s: fid not found", argv0);
|
werrstr("%s: fid not found", argv0);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
fidPut(Fid* fid)
|
fidPut(Fid* fid)
|
||||||
{
|
{
|
||||||
vtLock(fid->con->fidlock);
|
qlock(&fid->con->fidlock);
|
||||||
assert(fid->ref > 0);
|
assert(fid->ref > 0);
|
||||||
fid->ref--;
|
fid->ref--;
|
||||||
vtUnlock(fid->con->fidlock);
|
qunlock(&fid->con->fidlock);
|
||||||
|
|
||||||
if(fid->ref == 0 && fid->fidno == NOFID){
|
if(fid->ref == 0 && fid->fidno == NOFID){
|
||||||
fidFree(fid);
|
fidFree(fid);
|
||||||
@ -265,12 +261,12 @@ fidClunk(Fid* fid)
|
|||||||
{
|
{
|
||||||
assert(fid->flags & FidFWlock);
|
assert(fid->flags & FidFWlock);
|
||||||
|
|
||||||
vtLock(fid->con->fidlock);
|
qlock(&fid->con->fidlock);
|
||||||
assert(fid->ref > 0);
|
assert(fid->ref > 0);
|
||||||
fid->ref--;
|
fid->ref--;
|
||||||
fidUnHash(fid);
|
fidUnHash(fid);
|
||||||
fid->fidno = NOFID;
|
fid->fidno = NOFID;
|
||||||
vtUnlock(fid->con->fidlock);
|
qunlock(&fid->con->fidlock);
|
||||||
|
|
||||||
if(fid->ref > 0){
|
if(fid->ref > 0){
|
||||||
/* not reached - fidUnHash requires ref == 0 */
|
/* not reached - fidUnHash requires ref == 0 */
|
||||||
@ -286,19 +282,18 @@ fidClunkAll(Con* con)
|
|||||||
Fid *fid;
|
Fid *fid;
|
||||||
u32int fidno;
|
u32int fidno;
|
||||||
|
|
||||||
vtLock(con->fidlock);
|
qlock(&con->fidlock);
|
||||||
while(con->fhead != nil){
|
while(con->fhead != nil){
|
||||||
fidno = con->fhead->fidno;
|
fidno = con->fhead->fidno;
|
||||||
vtUnlock(con->fidlock);
|
qunlock(&con->fidlock);
|
||||||
if((fid = fidGet(con, fidno, FidFWlock)) != nil)
|
if((fid = fidGet(con, fidno, FidFWlock)) != nil)
|
||||||
fidClunk(fid);
|
fidClunk(fid);
|
||||||
vtLock(con->fidlock);
|
qlock(&con->fidlock);
|
||||||
}
|
}
|
||||||
vtUnlock(con->fidlock);
|
qunlock(&con->fidlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
fidInit(void)
|
fidInit(void)
|
||||||
{
|
{
|
||||||
fbox.lock = vtLockAlloc();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,14 +5,14 @@
|
|||||||
#include "9.h"
|
#include "9.h"
|
||||||
|
|
||||||
struct Fsys {
|
struct Fsys {
|
||||||
VtLock* lock;
|
QLock lock;
|
||||||
|
|
||||||
char* name; /* copy here & Fs to ease error reporting */
|
char* name; /* copy here & Fs to ease error reporting */
|
||||||
char* dev;
|
char* dev;
|
||||||
char* venti;
|
char* venti;
|
||||||
|
|
||||||
Fs* fs;
|
Fs* fs;
|
||||||
VtSession* session;
|
VtConn* session;
|
||||||
int ref;
|
int ref;
|
||||||
|
|
||||||
int noauth;
|
int noauth;
|
||||||
@ -27,7 +27,7 @@ int mempcnt; /* from fossil.c */
|
|||||||
int fsGetBlockSize(Fs *fs);
|
int fsGetBlockSize(Fs *fs);
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
VtLock* lock;
|
RWLock lock;
|
||||||
Fsys* head;
|
Fsys* head;
|
||||||
Fsys* tail;
|
Fsys* tail;
|
||||||
|
|
||||||
@ -49,10 +49,10 @@ static char *
|
|||||||
ventihost(char *host)
|
ventihost(char *host)
|
||||||
{
|
{
|
||||||
if(host != nil)
|
if(host != nil)
|
||||||
return vtStrDup(host);
|
return vtstrdup(host);
|
||||||
host = getenv("venti");
|
host = getenv("venti");
|
||||||
if(host == nil)
|
if(host == nil)
|
||||||
host = vtStrDup("$venti");
|
host = vtstrdup("$venti");
|
||||||
return host;
|
return host;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,18 +67,18 @@ prventihost(char *host)
|
|||||||
free(vh);
|
free(vh);
|
||||||
}
|
}
|
||||||
|
|
||||||
static VtSession *
|
static VtConn *
|
||||||
myDial(char *host, int canfail)
|
myDial(char *host)
|
||||||
{
|
{
|
||||||
prventihost(host);
|
prventihost(host);
|
||||||
return vtDial(host, canfail);
|
return vtdial(host);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
myRedial(VtSession *z, char *host)
|
myRedial(VtConn *z, char *host)
|
||||||
{
|
{
|
||||||
prventihost(host);
|
prventihost(host);
|
||||||
return vtRedial(z, host);
|
return vtredial(z, host);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Fsys*
|
static Fsys*
|
||||||
@ -89,16 +89,16 @@ _fsysGet(char* name)
|
|||||||
if(name == nil || name[0] == '\0')
|
if(name == nil || name[0] == '\0')
|
||||||
name = "main";
|
name = "main";
|
||||||
|
|
||||||
vtRLock(sbox.lock);
|
rlock(&sbox.lock);
|
||||||
for(fsys = sbox.head; fsys != nil; fsys = fsys->next){
|
for(fsys = sbox.head; fsys != nil; fsys = fsys->next){
|
||||||
if(strcmp(name, fsys->name) == 0){
|
if(strcmp(name, fsys->name) == 0){
|
||||||
fsys->ref++;
|
fsys->ref++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
vtRUnlock(sbox.lock);
|
runlock(&sbox.lock);
|
||||||
if(fsys == nil)
|
if(fsys == nil)
|
||||||
vtSetError(EFsysNotFound, name);
|
werrstr(EFsysNotFound, name);
|
||||||
return fsys;
|
return fsys;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,14 +116,14 @@ cmdPrintConfig(int argc, char* argv[])
|
|||||||
if(argc)
|
if(argc)
|
||||||
return cliError(usage);
|
return cliError(usage);
|
||||||
|
|
||||||
vtRLock(sbox.lock);
|
rlock(&sbox.lock);
|
||||||
for(fsys = sbox.head; fsys != nil; fsys = fsys->next){
|
for(fsys = sbox.head; fsys != nil; fsys = fsys->next){
|
||||||
consPrint("\tfsys %s config %s\n", fsys->name, fsys->dev);
|
consPrint("\tfsys %s config %s\n", fsys->name, fsys->dev);
|
||||||
if(fsys->venti && fsys->venti[0])
|
if(fsys->venti && fsys->venti[0])
|
||||||
consPrint("\tfsys %s venti %q\n", fsys->name,
|
consPrint("\tfsys %s venti %q\n", fsys->name,
|
||||||
fsys->venti);
|
fsys->venti);
|
||||||
}
|
}
|
||||||
vtRUnlock(sbox.lock);
|
runlock(&sbox.lock);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,14 +135,14 @@ fsysGet(char* name)
|
|||||||
if((fsys = _fsysGet(name)) == nil)
|
if((fsys = _fsysGet(name)) == nil)
|
||||||
return nil;
|
return nil;
|
||||||
|
|
||||||
vtLock(fsys->lock);
|
qlock(&fsys->lock);
|
||||||
if(fsys->fs == nil){
|
if(fsys->fs == nil){
|
||||||
vtSetError(EFsysNotOpen, fsys->name);
|
werrstr(EFsysNotOpen, fsys->name);
|
||||||
vtUnlock(fsys->lock);
|
qunlock(&fsys->lock);
|
||||||
fsysPut(fsys);
|
fsysPut(fsys);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
vtUnlock(fsys->lock);
|
qunlock(&fsys->lock);
|
||||||
|
|
||||||
return fsys;
|
return fsys;
|
||||||
}
|
}
|
||||||
@ -156,9 +156,9 @@ fsysGetName(Fsys* fsys)
|
|||||||
Fsys*
|
Fsys*
|
||||||
fsysIncRef(Fsys* fsys)
|
fsysIncRef(Fsys* fsys)
|
||||||
{
|
{
|
||||||
vtLock(sbox.lock);
|
wlock(&sbox.lock);
|
||||||
fsys->ref++;
|
fsys->ref++;
|
||||||
vtUnlock(sbox.lock);
|
wunlock(&sbox.lock);
|
||||||
|
|
||||||
return fsys;
|
return fsys;
|
||||||
}
|
}
|
||||||
@ -166,10 +166,10 @@ fsysIncRef(Fsys* fsys)
|
|||||||
void
|
void
|
||||||
fsysPut(Fsys* fsys)
|
fsysPut(Fsys* fsys)
|
||||||
{
|
{
|
||||||
vtLock(sbox.lock);
|
wlock(&sbox.lock);
|
||||||
assert(fsys->ref > 0);
|
assert(fsys->ref > 0);
|
||||||
fsys->ref--;
|
fsys->ref--;
|
||||||
vtUnlock(sbox.lock);
|
wunlock(&sbox.lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
Fs*
|
Fs*
|
||||||
@ -183,13 +183,13 @@ fsysGetFs(Fsys* fsys)
|
|||||||
void
|
void
|
||||||
fsysFsRlock(Fsys* fsys)
|
fsysFsRlock(Fsys* fsys)
|
||||||
{
|
{
|
||||||
vtRLock(fsys->fs->elk);
|
rlock(&fsys->fs->elk);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
fsysFsRUnlock(Fsys* fsys)
|
fsysFsRUnlock(Fsys* fsys)
|
||||||
{
|
{
|
||||||
vtRUnlock(fsys->fs->elk);
|
runlock(&fsys->fs->elk);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -285,19 +285,18 @@ fsysAlloc(char* name, char* dev)
|
|||||||
{
|
{
|
||||||
Fsys *fsys;
|
Fsys *fsys;
|
||||||
|
|
||||||
vtLock(sbox.lock);
|
wlock(&sbox.lock);
|
||||||
for(fsys = sbox.head; fsys != nil; fsys = fsys->next){
|
for(fsys = sbox.head; fsys != nil; fsys = fsys->next){
|
||||||
if(strcmp(fsys->name, name) != 0)
|
if(strcmp(fsys->name, name) != 0)
|
||||||
continue;
|
continue;
|
||||||
vtSetError(EFsysExists, name);
|
werrstr(EFsysExists, name);
|
||||||
vtUnlock(sbox.lock);
|
wunlock(&sbox.lock);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
fsys = vtMemAllocZ(sizeof(Fsys));
|
fsys = vtmallocz(sizeof(Fsys));
|
||||||
fsys->lock = vtLockAlloc();
|
fsys->name = vtstrdup(name);
|
||||||
fsys->name = vtStrDup(name);
|
fsys->dev = vtstrdup(dev);
|
||||||
fsys->dev = vtStrDup(dev);
|
|
||||||
|
|
||||||
fsys->ref = 1;
|
fsys->ref = 1;
|
||||||
|
|
||||||
@ -306,7 +305,7 @@ fsysAlloc(char* name, char* dev)
|
|||||||
else
|
else
|
||||||
sbox.head = fsys;
|
sbox.head = fsys;
|
||||||
sbox.tail = fsys;
|
sbox.tail = fsys;
|
||||||
vtUnlock(sbox.lock);
|
wunlock(&sbox.lock);
|
||||||
|
|
||||||
return fsys;
|
return fsys;
|
||||||
}
|
}
|
||||||
@ -334,7 +333,7 @@ fsysClose(Fsys* fsys, int argc, char* argv[])
|
|||||||
* More thought and care needed here.
|
* More thought and care needed here.
|
||||||
fsClose(fsys->fs);
|
fsClose(fsys->fs);
|
||||||
fsys->fs = nil;
|
fsys->fs = nil;
|
||||||
vtClose(fsys->session);
|
vtfreeconn(fsys->session);
|
||||||
fsys->session = nil;
|
fsys->session = nil;
|
||||||
|
|
||||||
if(sbox.curfsys != nil && strcmp(fsys->name, sbox.curfsys) == 0){
|
if(sbox.curfsys != nil && strcmp(fsys->name, sbox.curfsys) == 0){
|
||||||
@ -566,19 +565,19 @@ fsysRemove(Fsys* fsys, int argc, char* argv[])
|
|||||||
if(argc == 0)
|
if(argc == 0)
|
||||||
return cliError(usage);
|
return cliError(usage);
|
||||||
|
|
||||||
vtRLock(fsys->fs->elk);
|
rlock(&fsys->fs->elk);
|
||||||
while(argc > 0){
|
while(argc > 0){
|
||||||
if((file = fileOpen(fsys->fs, argv[0])) == nil)
|
if((file = fileOpen(fsys->fs, argv[0])) == nil)
|
||||||
consPrint("%s: %R\n", argv[0]);
|
consPrint("%s: %r\n", argv[0]);
|
||||||
else{
|
else{
|
||||||
if(!fileRemove(file, uidadm))
|
if(!fileRemove(file, uidadm))
|
||||||
consPrint("%s: %R\n", argv[0]);
|
consPrint("%s: %r\n", argv[0]);
|
||||||
fileDecRef(file);
|
fileDecRef(file);
|
||||||
}
|
}
|
||||||
argc--;
|
argc--;
|
||||||
argv++;
|
argv++;
|
||||||
}
|
}
|
||||||
vtRUnlock(fsys->fs->elk);
|
runlock(&fsys->fs->elk);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -595,14 +594,14 @@ fsysClri(Fsys* fsys, int argc, char* argv[])
|
|||||||
if(argc == 0)
|
if(argc == 0)
|
||||||
return cliError(usage);
|
return cliError(usage);
|
||||||
|
|
||||||
vtRLock(fsys->fs->elk);
|
rlock(&fsys->fs->elk);
|
||||||
while(argc > 0){
|
while(argc > 0){
|
||||||
if(!fileClriPath(fsys->fs, argv[0], uidadm))
|
if(!fileClriPath(fsys->fs, argv[0], uidadm))
|
||||||
consPrint("clri %s: %R\n", argv[0]);
|
consPrint("clri %s: %r\n", argv[0]);
|
||||||
argc--;
|
argc--;
|
||||||
argv++;
|
argv++;
|
||||||
}
|
}
|
||||||
vtRUnlock(fsys->fs->elk);
|
runlock(&fsys->fs->elk);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -628,7 +627,7 @@ fsysLabel(Fsys* fsys, int argc, char* argv[])
|
|||||||
return cliError(usage);
|
return cliError(usage);
|
||||||
|
|
||||||
r = 0;
|
r = 0;
|
||||||
vtRLock(fsys->fs->elk);
|
rlock(&fsys->fs->elk);
|
||||||
|
|
||||||
fs = fsys->fs;
|
fs = fsys->fs;
|
||||||
addr = strtoul(argv[0], 0, 0);
|
addr = strtoul(argv[0], 0, 0);
|
||||||
@ -663,11 +662,11 @@ fsysLabel(Fsys* fsys, int argc, char* argv[])
|
|||||||
if(blockWrite(bb, Waitlock)){
|
if(blockWrite(bb, Waitlock)){
|
||||||
while(bb->iostate != BioClean){
|
while(bb->iostate != BioClean){
|
||||||
assert(bb->iostate == BioWriting);
|
assert(bb->iostate == BioWriting);
|
||||||
vtSleep(bb->ioready);
|
rsleep(&bb->ioready);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
consPrint("blockWrite: %R\n");
|
consPrint("blockWrite: %r\n");
|
||||||
if(n++ >= 5){
|
if(n++ >= 5){
|
||||||
consPrint("giving up\n");
|
consPrint("giving up\n");
|
||||||
break;
|
break;
|
||||||
@ -680,7 +679,7 @@ fsysLabel(Fsys* fsys, int argc, char* argv[])
|
|||||||
Out1:
|
Out1:
|
||||||
blockPut(b);
|
blockPut(b);
|
||||||
Out0:
|
Out0:
|
||||||
vtRUnlock(fs->elk);
|
runlock(&fs->elk);
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
@ -710,7 +709,7 @@ fsysBlock(Fsys* fsys, int argc, char* argv[])
|
|||||||
addr = strtoul(argv[0], 0, 0);
|
addr = strtoul(argv[0], 0, 0);
|
||||||
offset = strtoul(argv[1], 0, 0);
|
offset = strtoul(argv[1], 0, 0);
|
||||||
if(offset < 0 || offset >= fs->blockSize){
|
if(offset < 0 || offset >= fs->blockSize){
|
||||||
vtSetError("bad offset");
|
werrstr("bad offset");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(argc > 2)
|
if(argc > 2)
|
||||||
@ -720,12 +719,12 @@ fsysBlock(Fsys* fsys, int argc, char* argv[])
|
|||||||
if(offset+count > fs->blockSize)
|
if(offset+count > fs->blockSize)
|
||||||
count = fs->blockSize - count;
|
count = fs->blockSize - count;
|
||||||
|
|
||||||
vtRLock(fs->elk);
|
rlock(&fs->elk);
|
||||||
|
|
||||||
b = cacheLocal(fs->cache, PartData, addr, argc==4 ? OReadWrite : OReadOnly);
|
b = cacheLocal(fs->cache, PartData, addr, argc==4 ? OReadWrite : OReadOnly);
|
||||||
if(b == nil){
|
if(b == nil){
|
||||||
vtSetError("cacheLocal %#ux: %R", addr);
|
werrstr("cacheLocal %#ux: %r", addr);
|
||||||
vtRUnlock(fs->elk);
|
runlock(&fs->elk);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -735,10 +734,10 @@ fsysBlock(Fsys* fsys, int argc, char* argv[])
|
|||||||
if(argc == 4){
|
if(argc == 4){
|
||||||
s = argv[3];
|
s = argv[3];
|
||||||
if(strlen(s) != 2*count){
|
if(strlen(s) != 2*count){
|
||||||
vtSetError("bad data count");
|
werrstr("bad data count");
|
||||||
goto Out;
|
goto Out;
|
||||||
}
|
}
|
||||||
buf = vtMemAllocZ(count);
|
buf = vtmallocz(count);
|
||||||
for(i = 0; i < count*2; i++){
|
for(i = 0; i < count*2; i++){
|
||||||
if(s[i] >= '0' && s[i] <= '9')
|
if(s[i] >= '0' && s[i] <= '9')
|
||||||
c = s[i] - '0';
|
c = s[i] - '0';
|
||||||
@ -747,8 +746,8 @@ fsysBlock(Fsys* fsys, int argc, char* argv[])
|
|||||||
else if(s[i] >= 'A' && s[i] <= 'F')
|
else if(s[i] >= 'A' && s[i] <= 'F')
|
||||||
c = s[i] - 'A' + 10;
|
c = s[i] - 'A' + 10;
|
||||||
else{
|
else{
|
||||||
vtSetError("bad hex");
|
werrstr("bad hex");
|
||||||
vtMemFree(buf);
|
vtfree(buf);
|
||||||
goto Out;
|
goto Out;
|
||||||
}
|
}
|
||||||
if((i & 1) == 0)
|
if((i & 1) == 0)
|
||||||
@ -763,7 +762,7 @@ fsysBlock(Fsys* fsys, int argc, char* argv[])
|
|||||||
|
|
||||||
Out:
|
Out:
|
||||||
blockPut(b);
|
blockPut(b);
|
||||||
vtRUnlock(fs->elk);
|
runlock(&fs->elk);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -789,18 +788,18 @@ fsysBfree(Fsys* fsys, int argc, char* argv[])
|
|||||||
return cliError(usage);
|
return cliError(usage);
|
||||||
|
|
||||||
fs = fsys->fs;
|
fs = fsys->fs;
|
||||||
vtRLock(fs->elk);
|
rlock(&fs->elk);
|
||||||
while(argc > 0){
|
while(argc > 0){
|
||||||
addr = strtoul(argv[0], &p, 0);
|
addr = strtoul(argv[0], &p, 0);
|
||||||
if(*p != '\0'){
|
if(*p != '\0'){
|
||||||
consPrint("bad address - '%ud'\n", addr);
|
consPrint("bad address - '%ud'\n", addr);
|
||||||
/* syntax error; let's stop */
|
/* syntax error; let's stop */
|
||||||
vtRUnlock(fs->elk);
|
runlock(&fs->elk);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
b = cacheLocal(fs->cache, PartData, addr, OReadOnly);
|
b = cacheLocal(fs->cache, PartData, addr, OReadOnly);
|
||||||
if(b == nil){
|
if(b == nil){
|
||||||
consPrint("loading %#ux: %R\n", addr);
|
consPrint("loading %#ux: %r\n", addr);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
l = b->l;
|
l = b->l;
|
||||||
@ -815,13 +814,13 @@ fsysBfree(Fsys* fsys, int argc, char* argv[])
|
|||||||
l.epoch = 0;
|
l.epoch = 0;
|
||||||
l.epochClose = 0;
|
l.epochClose = 0;
|
||||||
if(!blockSetLabel(b, &l, 0))
|
if(!blockSetLabel(b, &l, 0))
|
||||||
consPrint("freeing %#ux: %R\n", addr);
|
consPrint("freeing %#ux: %r\n", addr);
|
||||||
}
|
}
|
||||||
blockPut(b);
|
blockPut(b);
|
||||||
argc--;
|
argc--;
|
||||||
argv++;
|
argv++;
|
||||||
}
|
}
|
||||||
vtRUnlock(fs->elk);
|
runlock(&fs->elk);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -870,24 +869,24 @@ fsysClrep(Fsys* fsys, int argc, char* argv[], int ch)
|
|||||||
return cliError(usage, ch);
|
return cliError(usage, ch);
|
||||||
|
|
||||||
fs = fsys->fs;
|
fs = fsys->fs;
|
||||||
vtRLock(fsys->fs->elk);
|
rlock(&fsys->fs->elk);
|
||||||
|
|
||||||
addr = strtoul(argv[0], 0, 0);
|
addr = strtoul(argv[0], 0, 0);
|
||||||
b = cacheLocal(fs->cache, PartData, addr, argc==4 ? OReadWrite : OReadOnly);
|
b = cacheLocal(fs->cache, PartData, addr, argc==4 ? OReadWrite : OReadOnly);
|
||||||
if(b == nil){
|
if(b == nil){
|
||||||
vtSetError("cacheLocal %#ux: %R", addr);
|
werrstr("cacheLocal %#ux: %r", addr);
|
||||||
Err:
|
Err:
|
||||||
vtRUnlock(fsys->fs->elk);
|
runlock(&fsys->fs->elk);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(ch){
|
switch(ch){
|
||||||
default:
|
default:
|
||||||
vtSetError("clrep");
|
werrstr("clrep");
|
||||||
goto Err;
|
goto Err;
|
||||||
case 'e':
|
case 'e':
|
||||||
if(b->l.type != BtDir){
|
if(b->l.type != BtDir){
|
||||||
vtSetError("wrong block type");
|
werrstr("wrong block type");
|
||||||
goto Err;
|
goto Err;
|
||||||
}
|
}
|
||||||
sz = VtEntrySize;
|
sz = VtEntrySize;
|
||||||
@ -896,11 +895,11 @@ fsysClrep(Fsys* fsys, int argc, char* argv[], int ch)
|
|||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
if(b->l.type == BtDir || b->l.type == BtData){
|
if(b->l.type == BtDir || b->l.type == BtData){
|
||||||
vtSetError("wrong block type");
|
werrstr("wrong block type");
|
||||||
goto Err;
|
goto Err;
|
||||||
}
|
}
|
||||||
sz = VtScoreSize;
|
sz = VtScoreSize;
|
||||||
memmove(zero, vtZeroScore, VtScoreSize);
|
memmove(zero, vtzeroscore, VtScoreSize);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
max = fs->blockSize/sz;
|
max = fs->blockSize/sz;
|
||||||
@ -916,7 +915,7 @@ fsysClrep(Fsys* fsys, int argc, char* argv[], int ch)
|
|||||||
}
|
}
|
||||||
blockDirty(b);
|
blockDirty(b);
|
||||||
blockPut(b);
|
blockPut(b);
|
||||||
vtRUnlock(fsys->fs->elk);
|
runlock(&fsys->fs->elk);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -951,17 +950,17 @@ fsysEsearch1(File* f, char* s, u32int elo)
|
|||||||
for(;;){
|
for(;;){
|
||||||
r = deeRead(dee, &de);
|
r = deeRead(dee, &de);
|
||||||
if(r < 0){
|
if(r < 0){
|
||||||
consPrint("\tdeeRead %s/%s: %R\n", s, de.elem);
|
consPrint("\tdeeRead %s/%s: %r\n", s, de.elem);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(r == 0)
|
if(r == 0)
|
||||||
break;
|
break;
|
||||||
if(de.mode & ModeSnapshot){
|
if(de.mode & ModeSnapshot){
|
||||||
if((ff = fileWalk(f, de.elem)) == nil)
|
if((ff = fileWalk(f, de.elem)) == nil)
|
||||||
consPrint("\tcannot walk %s/%s: %R\n", s, de.elem);
|
consPrint("\tcannot walk %s/%s: %r\n", s, de.elem);
|
||||||
else{
|
else{
|
||||||
if(!fileGetSources(ff, &e, &ee))
|
if(!fileGetSources(ff, &e, &ee))
|
||||||
consPrint("\tcannot get sources for %s/%s: %R\n", s, de.elem);
|
consPrint("\tcannot get sources for %s/%s: %r\n", s, de.elem);
|
||||||
else if(e.snap != 0 && e.snap < elo){
|
else if(e.snap != 0 && e.snap < elo){
|
||||||
consPrint("\t%ud\tclri %s/%s\n", e.snap, s, de.elem);
|
consPrint("\t%ud\tclri %s/%s\n", e.snap, s, de.elem);
|
||||||
n++;
|
n++;
|
||||||
@ -971,11 +970,11 @@ fsysEsearch1(File* f, char* s, u32int elo)
|
|||||||
}
|
}
|
||||||
else if(de.mode & ModeDir){
|
else if(de.mode & ModeDir){
|
||||||
if((ff = fileWalk(f, de.elem)) == nil)
|
if((ff = fileWalk(f, de.elem)) == nil)
|
||||||
consPrint("\tcannot walk %s/%s: %R\n", s, de.elem);
|
consPrint("\tcannot walk %s/%s: %r\n", s, de.elem);
|
||||||
else{
|
else{
|
||||||
t = smprint("%s/%s", s, de.elem);
|
t = smprint("%s/%s", s, de.elem);
|
||||||
n += fsysEsearch1(ff, t, elo);
|
n += fsysEsearch1(ff, t, elo);
|
||||||
vtMemFree(t);
|
vtfree(t);
|
||||||
fileDecRef(ff);
|
fileDecRef(ff);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -999,7 +998,7 @@ fsysEsearch(Fs* fs, char* path, u32int elo)
|
|||||||
if(f == nil)
|
if(f == nil)
|
||||||
return 0;
|
return 0;
|
||||||
if(!fileGetDir(f, &de)){
|
if(!fileGetDir(f, &de)){
|
||||||
consPrint("\tfileGetDir %s failed: %R\n", path);
|
consPrint("\tfileGetDir %s failed: %r\n", path);
|
||||||
fileDecRef(f);
|
fileDecRef(f);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1046,16 +1045,16 @@ fsysEpoch(Fsys* fsys, int argc, char* argv[])
|
|||||||
|
|
||||||
fs = fsys->fs;
|
fs = fsys->fs;
|
||||||
|
|
||||||
vtRLock(fs->elk);
|
rlock(&fs->elk);
|
||||||
consPrint("\tlow %ud hi %ud\n", fs->elo, fs->ehi);
|
consPrint("\tlow %ud hi %ud\n", fs->elo, fs->ehi);
|
||||||
if(low == ~(u32int)0){
|
if(low == ~(u32int)0){
|
||||||
vtRUnlock(fs->elk);
|
runlock(&fs->elk);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
n = fsysEsearch(fsys->fs, "/archive", low);
|
n = fsysEsearch(fsys->fs, "/archive", low);
|
||||||
n += fsysEsearch(fsys->fs, "/snapshot", low);
|
n += fsysEsearch(fsys->fs, "/snapshot", low);
|
||||||
consPrint("\t%d snapshot%s found with epoch < %ud\n", n, n==1 ? "" : "s", low);
|
consPrint("\t%d snapshot%s found with epoch < %ud\n", n, n==1 ? "" : "s", low);
|
||||||
vtRUnlock(fs->elk);
|
runlock(&fs->elk);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* There's a small race here -- a new snapshot with epoch < low might
|
* There's a small race here -- a new snapshot with epoch < low might
|
||||||
@ -1070,7 +1069,7 @@ fsysEpoch(Fsys* fsys, int argc, char* argv[])
|
|||||||
}
|
}
|
||||||
old = fs->elo;
|
old = fs->elo;
|
||||||
if(!fsEpochLow(fs, low))
|
if(!fsEpochLow(fs, low))
|
||||||
consPrint("\tfsEpochLow: %R\n");
|
consPrint("\tfsEpochLow: %r\n");
|
||||||
else{
|
else{
|
||||||
consPrint("\told: epoch%s %ud\n", force ? " -y" : "", old);
|
consPrint("\told: epoch%s %ud\n", force ? " -y" : "", old);
|
||||||
consPrint("\tnew: epoch%s %ud\n", force ? " -y" : "", fs->elo);
|
consPrint("\tnew: epoch%s %ud\n", force ? " -y" : "", fs->elo);
|
||||||
@ -1108,8 +1107,8 @@ fsysCreate(Fsys* fsys, int argc, char* argv[])
|
|||||||
if(strcmp(argv[1], uidnoworld) == 0)
|
if(strcmp(argv[1], uidnoworld) == 0)
|
||||||
return cliError("permission denied");
|
return cliError("permission denied");
|
||||||
|
|
||||||
vtRLock(fsys->fs->elk);
|
rlock(&fsys->fs->elk);
|
||||||
path = vtStrDup(argv[0]);
|
path = vtstrdup(argv[0]);
|
||||||
if((p = strrchr(path, '/')) != nil){
|
if((p = strrchr(path, '/')) != nil){
|
||||||
*p++ = '\0';
|
*p++ = '\0';
|
||||||
elem = p;
|
elem = p;
|
||||||
@ -1129,20 +1128,20 @@ fsysCreate(Fsys* fsys, int argc, char* argv[])
|
|||||||
file = fileCreate(parent, elem, mode, argv[1]);
|
file = fileCreate(parent, elem, mode, argv[1]);
|
||||||
fileDecRef(parent);
|
fileDecRef(parent);
|
||||||
if(file == nil){
|
if(file == nil){
|
||||||
vtSetError("create %s/%s: %R", p, elem);
|
werrstr("create %s/%s: %r", p, elem);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!fileGetDir(file, &de)){
|
if(!fileGetDir(file, &de)){
|
||||||
vtSetError("stat failed after create: %R");
|
werrstr("stat failed after create: %r");
|
||||||
goto out1;
|
goto out1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(strcmp(de.gid, argv[2]) != 0){
|
if(strcmp(de.gid, argv[2]) != 0){
|
||||||
vtMemFree(de.gid);
|
vtfree(de.gid);
|
||||||
de.gid = vtStrDup(argv[2]);
|
de.gid = vtstrdup(argv[2]);
|
||||||
if(!fileSetDir(file, &de, argv[1])){
|
if(!fileSetDir(file, &de, argv[1])){
|
||||||
vtSetError("wstat failed after create: %R");
|
werrstr("wstat failed after create: %r");
|
||||||
goto out2;
|
goto out2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1153,8 +1152,8 @@ out2:
|
|||||||
out1:
|
out1:
|
||||||
fileDecRef(file);
|
fileDecRef(file);
|
||||||
out:
|
out:
|
||||||
vtMemFree(path);
|
vtfree(path);
|
||||||
vtRUnlock(fsys->fs->elk);
|
runlock(&fsys->fs->elk);
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
@ -1186,14 +1185,14 @@ fsysStat(Fsys* fsys, int argc, char* argv[])
|
|||||||
if(argc == 0)
|
if(argc == 0)
|
||||||
return cliError(usage);
|
return cliError(usage);
|
||||||
|
|
||||||
vtRLock(fsys->fs->elk);
|
rlock(&fsys->fs->elk);
|
||||||
for(i=0; i<argc; i++){
|
for(i=0; i<argc; i++){
|
||||||
if((f = fileOpen(fsys->fs, argv[i])) == nil){
|
if((f = fileOpen(fsys->fs, argv[i])) == nil){
|
||||||
consPrint("%s: %R\n", argv[i]);
|
consPrint("%s: %r\n", argv[i]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(!fileGetDir(f, &de)){
|
if(!fileGetDir(f, &de)){
|
||||||
consPrint("%s: %R\n", argv[i]);
|
consPrint("%s: %r\n", argv[i]);
|
||||||
fileDecRef(f);
|
fileDecRef(f);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -1201,7 +1200,7 @@ fsysStat(Fsys* fsys, int argc, char* argv[])
|
|||||||
deCleanup(&de);
|
deCleanup(&de);
|
||||||
fileDecRef(f);
|
fileDecRef(f);
|
||||||
}
|
}
|
||||||
vtRUnlock(fsys->fs->elk);
|
runlock(&fsys->fs->elk);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1222,79 +1221,79 @@ fsysWstat(Fsys *fsys, int argc, char* argv[])
|
|||||||
if(argc != 6)
|
if(argc != 6)
|
||||||
return cliError(usage);
|
return cliError(usage);
|
||||||
|
|
||||||
vtRLock(fsys->fs->elk);
|
rlock(&fsys->fs->elk);
|
||||||
if((f = fileOpen(fsys->fs, argv[0])) == nil){
|
if((f = fileOpen(fsys->fs, argv[0])) == nil){
|
||||||
vtSetError("console wstat - walk - %R");
|
werrstr("console wstat - walk - %r");
|
||||||
vtRUnlock(fsys->fs->elk);
|
runlock(&fsys->fs->elk);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(!fileGetDir(f, &de)){
|
if(!fileGetDir(f, &de)){
|
||||||
vtSetError("console wstat - stat - %R");
|
werrstr("console wstat - stat - %r");
|
||||||
fileDecRef(f);
|
fileDecRef(f);
|
||||||
vtRUnlock(fsys->fs->elk);
|
runlock(&fsys->fs->elk);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
fsysPrintStat("\told: w", argv[0], &de);
|
fsysPrintStat("\told: w", argv[0], &de);
|
||||||
|
|
||||||
if(strcmp(argv[1], "-") != 0){
|
if(strcmp(argv[1], "-") != 0){
|
||||||
if(!validFileName(argv[1])){
|
if(!validFileName(argv[1])){
|
||||||
vtSetError("console wstat - bad elem");
|
werrstr("console wstat - bad elem");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
vtMemFree(de.elem);
|
vtfree(de.elem);
|
||||||
de.elem = vtStrDup(argv[1]);
|
de.elem = vtstrdup(argv[1]);
|
||||||
}
|
}
|
||||||
if(strcmp(argv[2], "-") != 0){
|
if(strcmp(argv[2], "-") != 0){
|
||||||
if(!validUserName(argv[2])){
|
if(!validUserName(argv[2])){
|
||||||
vtSetError("console wstat - bad uid");
|
werrstr("console wstat - bad uid");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
vtMemFree(de.uid);
|
vtfree(de.uid);
|
||||||
de.uid = vtStrDup(argv[2]);
|
de.uid = vtstrdup(argv[2]);
|
||||||
}
|
}
|
||||||
if(strcmp(argv[3], "-") != 0){
|
if(strcmp(argv[3], "-") != 0){
|
||||||
if(!validUserName(argv[3])){
|
if(!validUserName(argv[3])){
|
||||||
vtSetError("console wstat - bad gid");
|
werrstr("console wstat - bad gid");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
vtMemFree(de.gid);
|
vtfree(de.gid);
|
||||||
de.gid = vtStrDup(argv[3]);
|
de.gid = vtstrdup(argv[3]);
|
||||||
}
|
}
|
||||||
if(strcmp(argv[4], "-") != 0){
|
if(strcmp(argv[4], "-") != 0){
|
||||||
if(!fsysParseMode(argv[4], &de.mode)){
|
if(!fsysParseMode(argv[4], &de.mode)){
|
||||||
vtSetError("console wstat - bad mode");
|
werrstr("console wstat - bad mode");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(strcmp(argv[5], "-") != 0){
|
if(strcmp(argv[5], "-") != 0){
|
||||||
de.size = strtoull(argv[5], &p, 0);
|
de.size = strtoull(argv[5], &p, 0);
|
||||||
if(argv[5][0] == '\0' || *p != '\0' || (vlong)de.size < 0){
|
if(argv[5][0] == '\0' || *p != '\0' || (vlong)de.size < 0){
|
||||||
vtSetError("console wstat - bad length");
|
werrstr("console wstat - bad length");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!fileSetDir(f, &de, uidadm)){
|
if(!fileSetDir(f, &de, uidadm)){
|
||||||
vtSetError("console wstat - %R");
|
werrstr("console wstat - %r");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
deCleanup(&de);
|
deCleanup(&de);
|
||||||
|
|
||||||
if(!fileGetDir(f, &de)){
|
if(!fileGetDir(f, &de)){
|
||||||
vtSetError("console wstat - stat2 - %R");
|
werrstr("console wstat - stat2 - %r");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
fsysPrintStat("\tnew: w", argv[0], &de);
|
fsysPrintStat("\tnew: w", argv[0], &de);
|
||||||
deCleanup(&de);
|
deCleanup(&de);
|
||||||
fileDecRef(f);
|
fileDecRef(f);
|
||||||
vtRUnlock(fsys->fs->elk);
|
runlock(&fsys->fs->elk);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
deCleanup(&de); /* okay to do this twice */
|
deCleanup(&de); /* okay to do this twice */
|
||||||
fileDecRef(f);
|
fileDecRef(f);
|
||||||
vtRUnlock(fsys->fs->elk);
|
runlock(&fsys->fs->elk);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1330,7 +1329,7 @@ fsckClose(Fsck *fsck, Block *b, u32int epoch)
|
|||||||
l.state = BsFree;
|
l.state = BsFree;
|
||||||
|
|
||||||
if(!blockSetLabel(b, &l, 0))
|
if(!blockSetLabel(b, &l, 0))
|
||||||
consPrint("%#ux setlabel: %R\n", b->addr);
|
consPrint("%#ux setlabel: %r\n", b->addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -1358,7 +1357,7 @@ fsckClrp(Fsck *fsck, Block *b, int offset)
|
|||||||
consPrint("bad clre\n");
|
consPrint("bad clre\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
memmove(b->data+offset*VtScoreSize, vtZeroScore, VtScoreSize);
|
memmove(b->data+offset*VtScoreSize, vtzeroscore, VtScoreSize);
|
||||||
blockDirty(b);
|
blockDirty(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1459,13 +1458,13 @@ fsysVenti(char* name, int argc, char* argv[])
|
|||||||
if((fsys = _fsysGet(name)) == nil)
|
if((fsys = _fsysGet(name)) == nil)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
vtLock(fsys->lock);
|
qlock(&fsys->lock);
|
||||||
if(host == nil)
|
if(host == nil)
|
||||||
host = fsys->venti;
|
host = fsys->venti;
|
||||||
else{
|
else{
|
||||||
vtMemFree(fsys->venti);
|
vtfree(fsys->venti);
|
||||||
if(host[0])
|
if(host[0])
|
||||||
fsys->venti = vtStrDup(host);
|
fsys->venti = vtstrdup(host);
|
||||||
else{
|
else{
|
||||||
host = nil;
|
host = nil;
|
||||||
fsys->venti = nil;
|
fsys->venti = nil;
|
||||||
@ -1475,26 +1474,26 @@ fsysVenti(char* name, int argc, char* argv[])
|
|||||||
/* already open: do a redial */
|
/* already open: do a redial */
|
||||||
if(fsys->fs != nil){
|
if(fsys->fs != nil){
|
||||||
if(fsys->session == nil){
|
if(fsys->session == nil){
|
||||||
vtSetError("file system was opened with -V");
|
werrstr("file system was opened with -V");
|
||||||
r = 0;
|
r = 0;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
r = 1;
|
r = 1;
|
||||||
if(!myRedial(fsys->session, host)
|
if(myRedial(fsys->session, host) < 0
|
||||||
|| !vtConnect(fsys->session, 0))
|
|| vtconnect(fsys->session) < 0)
|
||||||
r = 0;
|
r = 0;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* not yet open: try to dial */
|
/* not yet open: try to dial */
|
||||||
if(fsys->session)
|
if(fsys->session)
|
||||||
vtClose(fsys->session);
|
vtfreeconn(fsys->session);
|
||||||
r = 1;
|
r = 1;
|
||||||
if((fsys->session = myDial(host, 0)) == nil
|
if((fsys->session = myDial(host)) == nil
|
||||||
|| !vtConnect(fsys->session, 0))
|
|| vtconnect(fsys->session) < 0)
|
||||||
r = 0;
|
r = 0;
|
||||||
out:
|
out:
|
||||||
vtUnlock(fsys->lock);
|
qunlock(&fsys->lock);
|
||||||
fsysPut(fsys);
|
fsysPut(fsys);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
@ -1593,17 +1592,17 @@ fsysOpen(char* name, int argc, char* argv[])
|
|||||||
ncache = 100;
|
ncache = 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
vtLock(fsys->lock);
|
qlock(&fsys->lock);
|
||||||
if(fsys->fs != nil){
|
if(fsys->fs != nil){
|
||||||
vtSetError(EFsysBusy, fsys->name);
|
werrstr(EFsysBusy, fsys->name);
|
||||||
vtUnlock(fsys->lock);
|
qunlock(&fsys->lock);
|
||||||
fsysPut(fsys);
|
fsysPut(fsys);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(noventi){
|
if(noventi){
|
||||||
if(fsys->session){
|
if(fsys->session){
|
||||||
vtClose(fsys->session);
|
vtfreeconn(fsys->session);
|
||||||
fsys->session = nil;
|
fsys->session = nil;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1612,13 +1611,14 @@ fsysOpen(char* name, int argc, char* argv[])
|
|||||||
host = fsys->venti;
|
host = fsys->venti;
|
||||||
else
|
else
|
||||||
host = nil;
|
host = nil;
|
||||||
fsys->session = myDial(host, 1);
|
|
||||||
if(!vtConnect(fsys->session, nil) && !noventi)
|
if((fsys->session = myDial(host)) == nil
|
||||||
fprint(2, "warning: connecting to venti: %R\n");
|
|| vtconnect(fsys->session) < 0 && !noventi)
|
||||||
|
fprint(2, "warning: connecting to venti: %r\n");
|
||||||
}
|
}
|
||||||
if((fsys->fs = fsOpen(fsys->dev, fsys->session, ncache, rflag)) == nil){
|
if((fsys->fs = fsOpen(fsys->dev, fsys->session, ncache, rflag)) == nil){
|
||||||
vtSetError("fsOpen: %R");
|
werrstr("fsOpen: %r");
|
||||||
vtUnlock(fsys->lock);
|
qunlock(&fsys->lock);
|
||||||
fsysPut(fsys);
|
fsysPut(fsys);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1627,7 +1627,7 @@ fsysOpen(char* name, int argc, char* argv[])
|
|||||||
fsys->noperm = noperm;
|
fsys->noperm = noperm;
|
||||||
fsys->wstatallow = wstatallow;
|
fsys->wstatallow = wstatallow;
|
||||||
fsys->fs->noatimeupd = noatimeupd;
|
fsys->fs->noatimeupd = noatimeupd;
|
||||||
vtUnlock(fsys->lock);
|
qunlock(&fsys->lock);
|
||||||
fsysPut(fsys);
|
fsysPut(fsys);
|
||||||
|
|
||||||
if(strcmp(name, "main") == 0)
|
if(strcmp(name, "main") == 0)
|
||||||
@ -1649,7 +1649,7 @@ fsysUnconfig(char* name, int argc, char* argv[])
|
|||||||
if(argc)
|
if(argc)
|
||||||
return cliError(usage);
|
return cliError(usage);
|
||||||
|
|
||||||
vtLock(sbox.lock);
|
wlock(&sbox.lock);
|
||||||
fp = &sbox.head;
|
fp = &sbox.head;
|
||||||
for(fsys = *fp; fsys != nil; fsys = fsys->next){
|
for(fsys = *fp; fsys != nil; fsys = fsys->next){
|
||||||
if(strcmp(fsys->name, name) == 0)
|
if(strcmp(fsys->name, name) == 0)
|
||||||
@ -1657,29 +1657,27 @@ fsysUnconfig(char* name, int argc, char* argv[])
|
|||||||
fp = &fsys->next;
|
fp = &fsys->next;
|
||||||
}
|
}
|
||||||
if(fsys == nil){
|
if(fsys == nil){
|
||||||
vtSetError(EFsysNotFound, name);
|
werrstr(EFsysNotFound, name);
|
||||||
vtUnlock(sbox.lock);
|
wunlock(&sbox.lock);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(fsys->ref != 0 || fsys->fs != nil){
|
if(fsys->ref != 0 || fsys->fs != nil){
|
||||||
vtSetError(EFsysBusy, fsys->name);
|
werrstr(EFsysBusy, fsys->name);
|
||||||
vtUnlock(sbox.lock);
|
wunlock(&sbox.lock);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
*fp = fsys->next;
|
*fp = fsys->next;
|
||||||
vtUnlock(sbox.lock);
|
wunlock(&sbox.lock);
|
||||||
|
|
||||||
if(fsys->session != nil){
|
if(fsys->session != nil)
|
||||||
vtClose(fsys->session);
|
vtfreeconn(fsys->session);
|
||||||
vtFree(fsys->session);
|
|
||||||
}
|
|
||||||
if(fsys->venti != nil)
|
if(fsys->venti != nil)
|
||||||
vtMemFree(fsys->venti);
|
vtfree(fsys->venti);
|
||||||
if(fsys->dev != nil)
|
if(fsys->dev != nil)
|
||||||
vtMemFree(fsys->dev);
|
vtfree(fsys->dev);
|
||||||
if(fsys->name != nil)
|
if(fsys->name != nil)
|
||||||
vtMemFree(fsys->name);
|
vtfree(fsys->name);
|
||||||
vtMemFree(fsys);
|
vtfree(fsys);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -1704,16 +1702,16 @@ fsysConfig(char* name, int argc, char* argv[])
|
|||||||
part = argv[0];
|
part = argv[0];
|
||||||
|
|
||||||
if((fsys = _fsysGet(part)) != nil){
|
if((fsys = _fsysGet(part)) != nil){
|
||||||
vtLock(fsys->lock);
|
qlock(&fsys->lock);
|
||||||
if(fsys->fs != nil){
|
if(fsys->fs != nil){
|
||||||
vtSetError(EFsysBusy, fsys->name);
|
werrstr(EFsysBusy, fsys->name);
|
||||||
vtUnlock(fsys->lock);
|
qunlock(&fsys->lock);
|
||||||
fsysPut(fsys);
|
fsysPut(fsys);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
vtMemFree(fsys->dev);
|
vtfree(fsys->dev);
|
||||||
fsys->dev = vtStrDup(part);
|
fsys->dev = vtstrdup(part);
|
||||||
vtUnlock(fsys->lock);
|
qunlock(&fsys->lock);
|
||||||
}
|
}
|
||||||
else if((fsys = fsysAlloc(name, part)) == nil)
|
else if((fsys = fsysAlloc(name, part)) == nil)
|
||||||
return 0;
|
return 0;
|
||||||
@ -1762,22 +1760,22 @@ fsysXXX1(Fsys *fsys, int i, int argc, char* argv[])
|
|||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
vtLock(fsys->lock);
|
qlock(&fsys->lock);
|
||||||
if(fsys->fs == nil){
|
if(fsys->fs == nil){
|
||||||
vtUnlock(fsys->lock);
|
qunlock(&fsys->lock);
|
||||||
vtSetError(EFsysNotOpen, fsys->name);
|
werrstr(EFsysNotOpen, fsys->name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fsys->fs->halted
|
if(fsys->fs->halted
|
||||||
&& fsyscmd[i].f != fsysUnhalt && fsyscmd[i].f != fsysCheck){
|
&& fsyscmd[i].f != fsysUnhalt && fsyscmd[i].f != fsysCheck){
|
||||||
vtSetError("file system %s is halted", fsys->name);
|
werrstr("file system %s is halted", fsys->name);
|
||||||
vtUnlock(fsys->lock);
|
qunlock(&fsys->lock);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = (*fsyscmd[i].f)(fsys, argc, argv);
|
r = (*fsyscmd[i].f)(fsys, argc, argv);
|
||||||
vtUnlock(fsys->lock);
|
qunlock(&fsys->lock);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1793,14 +1791,14 @@ fsysXXX(char* name, int argc, char* argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(fsyscmd[i].cmd == nil){
|
if(fsyscmd[i].cmd == nil){
|
||||||
vtSetError("unknown command - '%s'", argv[0]);
|
werrstr("unknown command - '%s'", argv[0]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* some commands want the name... */
|
/* some commands want the name... */
|
||||||
if(fsyscmd[i].f1 != nil){
|
if(fsyscmd[i].f1 != nil){
|
||||||
if(strcmp(name, FsysAll) == 0){
|
if(strcmp(name, FsysAll) == 0){
|
||||||
vtSetError("cannot use fsys %#q with %#q command", FsysAll, argv[0]);
|
werrstr("cannot use fsys %#q with %#q command", FsysAll, argv[0]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return (*fsyscmd[i].f1)(name, argc, argv);
|
return (*fsyscmd[i].f1)(name, argc, argv);
|
||||||
@ -1809,13 +1807,13 @@ fsysXXX(char* name, int argc, char* argv[])
|
|||||||
/* ... but most commands want the Fsys */
|
/* ... but most commands want the Fsys */
|
||||||
if(strcmp(name, FsysAll) == 0){
|
if(strcmp(name, FsysAll) == 0){
|
||||||
r = 1;
|
r = 1;
|
||||||
vtRLock(sbox.lock);
|
rlock(&sbox.lock);
|
||||||
for(fsys = sbox.head; fsys != nil; fsys = fsys->next){
|
for(fsys = sbox.head; fsys != nil; fsys = fsys->next){
|
||||||
fsys->ref++;
|
fsys->ref++;
|
||||||
r = fsysXXX1(fsys, i, argc, argv) && r;
|
r = fsysXXX1(fsys, i, argc, argv) && r;
|
||||||
fsys->ref--;
|
fsys->ref--;
|
||||||
}
|
}
|
||||||
vtRUnlock(sbox.lock);
|
runlock(&sbox.lock);
|
||||||
}else{
|
}else{
|
||||||
if((fsys = _fsysGet(name)) == nil)
|
if((fsys = _fsysGet(name)) == nil)
|
||||||
return 0;
|
return 0;
|
||||||
@ -1831,7 +1829,7 @@ cmdFsysXXX(int argc, char* argv[])
|
|||||||
char *name;
|
char *name;
|
||||||
|
|
||||||
if((name = sbox.curfsys) == nil){
|
if((name = sbox.curfsys) == nil){
|
||||||
vtSetError(EFsysNoCurrent, argv[0]);
|
werrstr(EFsysNoCurrent, argv[0]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1850,18 +1848,18 @@ cmdFsys(int argc, char* argv[])
|
|||||||
}ARGEND
|
}ARGEND
|
||||||
|
|
||||||
if(argc == 0){
|
if(argc == 0){
|
||||||
vtRLock(sbox.lock);
|
rlock(&sbox.lock);
|
||||||
currfsysname = sbox.head->name;
|
currfsysname = sbox.head->name;
|
||||||
for(fsys = sbox.head; fsys != nil; fsys = fsys->next)
|
for(fsys = sbox.head; fsys != nil; fsys = fsys->next)
|
||||||
consPrint("\t%s\n", fsys->name);
|
consPrint("\t%s\n", fsys->name);
|
||||||
vtRUnlock(sbox.lock);
|
runlock(&sbox.lock);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if(argc == 1){
|
if(argc == 1){
|
||||||
fsys = nil;
|
fsys = nil;
|
||||||
if(strcmp(argv[0], FsysAll) != 0 && (fsys = fsysGet(argv[0])) == nil)
|
if(strcmp(argv[0], FsysAll) != 0 && (fsys = fsysGet(argv[0])) == nil)
|
||||||
return 0;
|
return 0;
|
||||||
sbox.curfsys = vtStrDup(argv[0]);
|
sbox.curfsys = vtstrdup(argv[0]);
|
||||||
consPrompt(sbox.curfsys);
|
consPrompt(sbox.curfsys);
|
||||||
if(fsys)
|
if(fsys)
|
||||||
fsysPut(fsys);
|
fsysPut(fsys);
|
||||||
@ -1878,11 +1876,8 @@ fsysInit(void)
|
|||||||
|
|
||||||
fmtinstall('H', encodefmt);
|
fmtinstall('H', encodefmt);
|
||||||
fmtinstall('V', scoreFmt);
|
fmtinstall('V', scoreFmt);
|
||||||
fmtinstall('R', vtErrFmt);
|
|
||||||
fmtinstall('L', labelFmt);
|
fmtinstall('L', labelFmt);
|
||||||
|
|
||||||
sbox.lock = vtLockAlloc();
|
|
||||||
|
|
||||||
cliAddCmd("fsys", cmdFsys);
|
cliAddCmd("fsys", cmdFsys);
|
||||||
for(i = 0; fsyscmd[i].cmd != nil; i++){
|
for(i = 0; fsyscmd[i].cmd != nil; i++){
|
||||||
if(fsyscmd[i].f != nil)
|
if(fsyscmd[i].f != nil)
|
||||||
|
|||||||
@ -14,7 +14,7 @@ struct Lstn {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
VtLock* lock;
|
RWLock lock;
|
||||||
|
|
||||||
Lstn* head;
|
Lstn* head;
|
||||||
Lstn* tail;
|
Lstn* tail;
|
||||||
@ -23,7 +23,7 @@ static struct {
|
|||||||
static void
|
static void
|
||||||
lstnFree(Lstn* lstn)
|
lstnFree(Lstn* lstn)
|
||||||
{
|
{
|
||||||
vtLock(lbox.lock);
|
wlock(&lbox.lock);
|
||||||
if(lstn->prev != nil)
|
if(lstn->prev != nil)
|
||||||
lstn->prev->next = lstn->next;
|
lstn->prev->next = lstn->next;
|
||||||
else
|
else
|
||||||
@ -32,12 +32,12 @@ lstnFree(Lstn* lstn)
|
|||||||
lstn->next->prev = lstn->prev;
|
lstn->next->prev = lstn->prev;
|
||||||
else
|
else
|
||||||
lbox.tail = lstn->prev;
|
lbox.tail = lstn->prev;
|
||||||
vtUnlock(lbox.lock);
|
wunlock(&lbox.lock);
|
||||||
|
|
||||||
if(lstn->afd != -1)
|
if(lstn->afd != -1)
|
||||||
close(lstn->afd);
|
close(lstn->afd);
|
||||||
vtMemFree(lstn->address);
|
vtfree(lstn->address);
|
||||||
vtMemFree(lstn);
|
vtfree(lstn);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -47,7 +47,7 @@ lstnListen(void* a)
|
|||||||
int dfd, lfd;
|
int dfd, lfd;
|
||||||
char newdir[NETPATHLEN];
|
char newdir[NETPATHLEN];
|
||||||
|
|
||||||
vtThreadSetName("listen");
|
threadsetname("listen");
|
||||||
|
|
||||||
lstn = a;
|
lstn = a;
|
||||||
for(;;){
|
for(;;){
|
||||||
@ -71,24 +71,24 @@ lstnAlloc(char* address, int flags)
|
|||||||
Lstn *lstn;
|
Lstn *lstn;
|
||||||
char dir[NETPATHLEN];
|
char dir[NETPATHLEN];
|
||||||
|
|
||||||
vtLock(lbox.lock);
|
wlock(&lbox.lock);
|
||||||
for(lstn = lbox.head; lstn != nil; lstn = lstn->next){
|
for(lstn = lbox.head; lstn != nil; lstn = lstn->next){
|
||||||
if(strcmp(lstn->address, address) != 0)
|
if(strcmp(lstn->address, address) != 0)
|
||||||
continue;
|
continue;
|
||||||
vtSetError("listen: already serving '%s'", address);
|
werrstr("listen: already serving '%s'", address);
|
||||||
vtUnlock(lbox.lock);
|
wunlock(&lbox.lock);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((afd = announce(address, dir)) < 0){
|
if((afd = announce(address, dir)) < 0){
|
||||||
vtSetError("listen: announce '%s': %r", address);
|
werrstr("listen: announce '%s': %r", address);
|
||||||
vtUnlock(lbox.lock);
|
wunlock(&lbox.lock);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
lstn = vtMemAllocZ(sizeof(Lstn));
|
lstn = vtmallocz(sizeof(Lstn));
|
||||||
lstn->afd = afd;
|
lstn->afd = afd;
|
||||||
lstn->address = vtStrDup(address);
|
lstn->address = vtstrdup(address);
|
||||||
lstn->flags = flags;
|
lstn->flags = flags;
|
||||||
memmove(lstn->dir, dir, NETPATHLEN);
|
memmove(lstn->dir, dir, NETPATHLEN);
|
||||||
|
|
||||||
@ -101,10 +101,10 @@ lstnAlloc(char* address, int flags)
|
|||||||
lstn->prev = nil;
|
lstn->prev = nil;
|
||||||
}
|
}
|
||||||
lbox.tail = lstn;
|
lbox.tail = lstn;
|
||||||
vtUnlock(lbox.lock);
|
wunlock(&lbox.lock);
|
||||||
|
|
||||||
if(vtThread(lstnListen, lstn) < 0){
|
if(proccreate(lstnListen, lstn, STACK) < 0){
|
||||||
vtSetError("listen: thread '%s': %r", lstn->address);
|
werrstr("listen: thread '%s': %r", lstn->address);
|
||||||
lstnFree(lstn);
|
lstnFree(lstn);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
@ -139,10 +139,10 @@ cmdLstn(int argc, char* argv[])
|
|||||||
default:
|
default:
|
||||||
return cliError(usage);
|
return cliError(usage);
|
||||||
case 0:
|
case 0:
|
||||||
vtRLock(lbox.lock);
|
rlock(&lbox.lock);
|
||||||
for(lstn = lbox.head; lstn != nil; lstn = lstn->next)
|
for(lstn = lbox.head; lstn != nil; lstn = lstn->next)
|
||||||
consPrint("\t%s\t%s\n", lstn->address, lstn->dir);
|
consPrint("\t%s\t%s\n", lstn->address, lstn->dir);
|
||||||
vtRUnlock(lbox.lock);
|
runlock(&lbox.lock);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
if(!dflag){
|
if(!dflag){
|
||||||
@ -151,7 +151,7 @@ cmdLstn(int argc, char* argv[])
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
vtLock(lbox.lock);
|
wlock(&lbox.lock);
|
||||||
for(lstn = lbox.head; lstn != nil; lstn = lstn->next){
|
for(lstn = lbox.head; lstn != nil; lstn = lstn->next){
|
||||||
if(strcmp(lstn->address, argv[0]) != 0)
|
if(strcmp(lstn->address, argv[0]) != 0)
|
||||||
continue;
|
continue;
|
||||||
@ -161,10 +161,10 @@ cmdLstn(int argc, char* argv[])
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
vtUnlock(lbox.lock);
|
wunlock(&lbox.lock);
|
||||||
|
|
||||||
if(lstn == nil){
|
if(lstn == nil){
|
||||||
vtSetError("listen: '%s' not found", argv[0]);
|
werrstr("listen: '%s' not found", argv[0]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -176,8 +176,6 @@ cmdLstn(int argc, char* argv[])
|
|||||||
int
|
int
|
||||||
lstnInit(void)
|
lstnInit(void)
|
||||||
{
|
{
|
||||||
lbox.lock = vtLockAlloc();
|
|
||||||
|
|
||||||
cliAddCmd("listen", cmdLstn);
|
cliAddCmd("listen", cmdLstn);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@ -35,11 +35,11 @@ permFile(File* file, Fid* fid, int perm)
|
|||||||
*/
|
*/
|
||||||
if((u = unameByUid(de.uid)) != nil){
|
if((u = unameByUid(de.uid)) != nil){
|
||||||
if(strcmp(fid->uname, u) == 0 && ((perm<<6) & de.mode)){
|
if(strcmp(fid->uname, u) == 0 && ((perm<<6) & de.mode)){
|
||||||
vtMemFree(u);
|
vtfree(u);
|
||||||
deCleanup(&de);
|
deCleanup(&de);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
vtMemFree(u);
|
vtfree(u);
|
||||||
}
|
}
|
||||||
if(groupMember(de.gid, fid->uname) && ((perm<<3) & de.mode)){
|
if(groupMember(de.gid, fid->uname) && ((perm<<3) & de.mode)){
|
||||||
deCleanup(&de);
|
deCleanup(&de);
|
||||||
@ -60,7 +60,7 @@ permFile(File* file, Fid* fid, int perm)
|
|||||||
deCleanup(&de);
|
deCleanup(&de);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
vtSetError(EPermission);
|
werrstr(EPermission);
|
||||||
|
|
||||||
deCleanup(&de);
|
deCleanup(&de);
|
||||||
return 0;
|
return 0;
|
||||||
@ -91,19 +91,19 @@ validFileName(char* name)
|
|||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
if(name == nil || name[0] == '\0'){
|
if(name == nil || name[0] == '\0'){
|
||||||
vtSetError("no file name");
|
werrstr("no file name");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(name[0] == '.'){
|
if(name[0] == '.'){
|
||||||
if(name[1] == '\0' || (name[1] == '.' && name[2] == '\0')){
|
if(name[1] == '\0' || (name[1] == '.' && name[2] == '\0')){
|
||||||
vtSetError(". and .. illegal as file name");
|
werrstr(". and .. illegal as file name");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(p = name; *p != '\0'; p++){
|
for(p = name; *p != '\0'; p++){
|
||||||
if((*p & 0xFF) < 040){
|
if((*p & 0xFF) < 040){
|
||||||
vtSetError("bad character in file name");
|
werrstr("bad character in file name");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -128,20 +128,20 @@ rTwstat(Msg* m)
|
|||||||
retval = 0;
|
retval = 0;
|
||||||
|
|
||||||
if(strcmp(fid->uname, unamenone) == 0 || (fid->qid.type & QTAUTH)){
|
if(strcmp(fid->uname, unamenone) == 0 || (fid->qid.type & QTAUTH)){
|
||||||
vtSetError(EPermission);
|
werrstr(EPermission);
|
||||||
goto error0;
|
goto error0;
|
||||||
}
|
}
|
||||||
if(fileIsRoFs(fid->file) || !groupWriteMember(fid->uname)){
|
if(fileIsRoFs(fid->file) || !groupWriteMember(fid->uname)){
|
||||||
vtSetError("read-only filesystem");
|
werrstr("read-only filesystem");
|
||||||
goto error0;
|
goto error0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!fileGetDir(fid->file, &de))
|
if(!fileGetDir(fid->file, &de))
|
||||||
goto error0;
|
goto error0;
|
||||||
|
|
||||||
strs = vtMemAlloc(m->t.nstat);
|
strs = vtmalloc(m->t.nstat);
|
||||||
if(convM2D(m->t.stat, m->t.nstat, &dir, strs) == 0){
|
if(convM2D(m->t.stat, m->t.nstat, &dir, strs) == 0){
|
||||||
vtSetError("wstat -- protocol botch");
|
werrstr("wstat -- protocol botch");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,28 +160,28 @@ rTwstat(Msg* m)
|
|||||||
tsync = 1;
|
tsync = 1;
|
||||||
if(dir.qid.path != ~0){
|
if(dir.qid.path != ~0){
|
||||||
if(dir.qid.path != de.qid){
|
if(dir.qid.path != de.qid){
|
||||||
vtSetError("wstat -- attempt to change qid.path");
|
werrstr("wstat -- attempt to change qid.path");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
tsync = 0;
|
tsync = 0;
|
||||||
}
|
}
|
||||||
if(dir.qid.vers != ~0){
|
if(dir.qid.vers != ~0){
|
||||||
if(dir.qid.vers != de.mcount){
|
if(dir.qid.vers != de.mcount){
|
||||||
vtSetError("wstat -- attempt to change qid.vers");
|
werrstr("wstat -- attempt to change qid.vers");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
tsync = 0;
|
tsync = 0;
|
||||||
}
|
}
|
||||||
if(dir.muid != nil && *dir.muid != '\0'){
|
if(dir.muid != nil && *dir.muid != '\0'){
|
||||||
if((uid = uidByUname(dir.muid)) == nil){
|
if((uid = uidByUname(dir.muid)) == nil){
|
||||||
vtSetError("wstat -- unknown muid");
|
werrstr("wstat -- unknown muid");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if(strcmp(uid, de.mid) != 0){
|
if(strcmp(uid, de.mid) != 0){
|
||||||
vtSetError("wstat -- attempt to change muid");
|
werrstr("wstat -- attempt to change muid");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
vtMemFree(uid);
|
vtfree(uid);
|
||||||
uid = nil;
|
uid = nil;
|
||||||
tsync = 0;
|
tsync = 0;
|
||||||
}
|
}
|
||||||
@ -191,7 +191,7 @@ rTwstat(Msg* m)
|
|||||||
*/
|
*/
|
||||||
if(dir.qid.type != (uchar)~0 && dir.mode != ~0){
|
if(dir.qid.type != (uchar)~0 && dir.mode != ~0){
|
||||||
if(dir.qid.type != ((dir.mode>>24) & 0xFF)){
|
if(dir.qid.type != ((dir.mode>>24) & 0xFF)){
|
||||||
vtSetError("wstat -- qid.type/mode mismatch");
|
werrstr("wstat -- qid.type/mode mismatch");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -206,7 +206,7 @@ rTwstat(Msg* m)
|
|||||||
if(dir.mode == ~0)
|
if(dir.mode == ~0)
|
||||||
dir.mode = (dir.qid.type<<24)|(de.mode & 0777);
|
dir.mode = (dir.qid.type<<24)|(de.mode & 0777);
|
||||||
if(dir.mode & ~(DMDIR|DMAPPEND|DMEXCL|DMTMP|0777)){
|
if(dir.mode & ~(DMDIR|DMAPPEND|DMEXCL|DMTMP|0777)){
|
||||||
vtSetError("wstat -- unknown bits in qid.type/mode");
|
werrstr("wstat -- unknown bits in qid.type/mode");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -224,7 +224,7 @@ rTwstat(Msg* m)
|
|||||||
mode |= ModeTemporary;
|
mode |= ModeTemporary;
|
||||||
|
|
||||||
if((de.mode^mode) & ModeDir){
|
if((de.mode^mode) & ModeDir){
|
||||||
vtSetError("wstat -- attempt to change directory bit");
|
werrstr("wstat -- attempt to change directory bit");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -251,11 +251,11 @@ rTwstat(Msg* m)
|
|||||||
* If we're changing the append bit, it's okay.
|
* If we're changing the append bit, it's okay.
|
||||||
*/
|
*/
|
||||||
if(de.mode & oldmode & ModeAppend){
|
if(de.mode & oldmode & ModeAppend){
|
||||||
vtSetError("wstat -- attempt to change length of append-only file");
|
werrstr("wstat -- attempt to change length of append-only file");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if(de.mode & ModeDir){
|
if(de.mode & ModeDir){
|
||||||
vtSetError("wstat -- attempt to change length of directory");
|
werrstr("wstat -- attempt to change length of directory");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
de.size = dir.length;
|
de.size = dir.length;
|
||||||
@ -271,13 +271,13 @@ rTwstat(Msg* m)
|
|||||||
*/
|
*/
|
||||||
if(dir.gid != nil && *dir.gid != '\0'){
|
if(dir.gid != nil && *dir.gid != '\0'){
|
||||||
if((gid = uidByUname(dir.gid)) == nil){
|
if((gid = uidByUname(dir.gid)) == nil){
|
||||||
vtSetError("wstat -- unknown gid");
|
werrstr("wstat -- unknown gid");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
tsync = 0;
|
tsync = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
gid = vtStrDup(de.gid);
|
gid = vtstrdup(de.gid);
|
||||||
|
|
||||||
wstatallow = (fsysWstatAllow(fid->fsys) || (m->con->flags&ConWstatAllow));
|
wstatallow = (fsysWstatAllow(fid->fsys) || (m->con->flags&ConWstatAllow));
|
||||||
|
|
||||||
@ -289,7 +289,7 @@ rTwstat(Msg* m)
|
|||||||
|
|
||||||
if(op && !wstatallow){
|
if(op && !wstatallow){
|
||||||
if(strcmp(fid->uid, de.uid) != 0 && !gl){
|
if(strcmp(fid->uid, de.uid) != 0 && !gl){
|
||||||
vtSetError("wstat -- not owner or group leader");
|
werrstr("wstat -- not owner or group leader");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -303,10 +303,10 @@ rTwstat(Msg* m)
|
|||||||
if(!wstatallow
|
if(!wstatallow
|
||||||
&& !(strcmp(fid->uid, de.uid) == 0 && groupMember(gid, fid->uname))
|
&& !(strcmp(fid->uid, de.uid) == 0 && groupMember(gid, fid->uname))
|
||||||
&& !(gl == 2)){
|
&& !(gl == 2)){
|
||||||
vtSetError("wstat -- not owner and not group leaders");
|
werrstr("wstat -- not owner and not group leaders");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
vtMemFree(de.gid);
|
vtfree(de.gid);
|
||||||
de.gid = gid;
|
de.gid = gid;
|
||||||
gid = nil;
|
gid = nil;
|
||||||
op = 1;
|
op = 1;
|
||||||
@ -324,8 +324,8 @@ rTwstat(Msg* m)
|
|||||||
if(strcmp(dir.name, de.elem) != 0){
|
if(strcmp(dir.name, de.elem) != 0){
|
||||||
if(permParent(fid, PermW) <= 0)
|
if(permParent(fid, PermW) <= 0)
|
||||||
goto error;
|
goto error;
|
||||||
vtMemFree(de.elem);
|
vtfree(de.elem);
|
||||||
de.elem = vtStrDup(dir.name);
|
de.elem = vtstrdup(dir.name);
|
||||||
op = 1;
|
op = 1;
|
||||||
}
|
}
|
||||||
tsync = 0;
|
tsync = 0;
|
||||||
@ -336,19 +336,19 @@ rTwstat(Msg* m)
|
|||||||
*/
|
*/
|
||||||
if(dir.uid != nil && *dir.uid != '\0'){
|
if(dir.uid != nil && *dir.uid != '\0'){
|
||||||
if((uid = uidByUname(dir.uid)) == nil){
|
if((uid = uidByUname(dir.uid)) == nil){
|
||||||
vtSetError("wstat -- unknown uid");
|
werrstr("wstat -- unknown uid");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if(strcmp(uid, de.uid) != 0){
|
if(strcmp(uid, de.uid) != 0){
|
||||||
if(!wstatallow){
|
if(!wstatallow){
|
||||||
vtSetError("wstat -- not owner");
|
werrstr("wstat -- not owner");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if(strcmp(uid, uidnoworld) == 0){
|
if(strcmp(uid, uidnoworld) == 0){
|
||||||
vtSetError(EPermission);
|
werrstr(EPermission);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
vtMemFree(de.uid);
|
vtfree(de.uid);
|
||||||
de.uid = uid;
|
de.uid = uid;
|
||||||
uid = nil;
|
uid = nil;
|
||||||
op = 1;
|
op = 1;
|
||||||
@ -372,11 +372,11 @@ rTwstat(Msg* m)
|
|||||||
|
|
||||||
error:
|
error:
|
||||||
deCleanup(&de);
|
deCleanup(&de);
|
||||||
vtMemFree(strs);
|
vtfree(strs);
|
||||||
if(gid != nil)
|
if(gid != nil)
|
||||||
vtMemFree(gid);
|
vtfree(gid);
|
||||||
if(uid != nil)
|
if(uid != nil)
|
||||||
vtMemFree(uid);
|
vtfree(uid);
|
||||||
error0:
|
error0:
|
||||||
fidPut(fid);
|
fidPut(fid);
|
||||||
return retval;
|
return retval;
|
||||||
@ -404,7 +404,7 @@ rTstat(Msg* m)
|
|||||||
dir.muid = fid->uname;
|
dir.muid = fid->uname;
|
||||||
|
|
||||||
if((m->r.nstat = convD2M(&dir, m->data, m->con->msize)) == 0){
|
if((m->r.nstat = convD2M(&dir, m->data, m->con->msize)) == 0){
|
||||||
vtSetError("stat QTAUTH botch");
|
werrstr("stat QTAUTH botch");
|
||||||
fidPut(fid);
|
fidPut(fid);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -479,24 +479,24 @@ rTwrite(Msg* m)
|
|||||||
if((fid = fidGet(m->con, m->t.fid, 0)) == nil)
|
if((fid = fidGet(m->con, m->t.fid, 0)) == nil)
|
||||||
return 0;
|
return 0;
|
||||||
if(!(fid->open & FidOWrite)){
|
if(!(fid->open & FidOWrite)){
|
||||||
vtSetError("fid not open for write");
|
werrstr("fid not open for write");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
count = m->t.count;
|
count = m->t.count;
|
||||||
if(count < 0 || count > m->con->msize-IOHDRSZ){
|
if(count < 0 || count > m->con->msize-IOHDRSZ){
|
||||||
vtSetError("write count too big");
|
werrstr("write count too big");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if(m->t.offset < 0){
|
if(m->t.offset < 0){
|
||||||
vtSetError("write offset negative");
|
werrstr("write offset negative");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if(fid->excl != nil && !exclUpdate(fid))
|
if(fid->excl != nil && !exclUpdate(fid))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if(fid->qid.type & QTDIR){
|
if(fid->qid.type & QTDIR){
|
||||||
vtSetError("is a directory");
|
werrstr("is a directory");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
else if(fid->qid.type & QTAUTH)
|
else if(fid->qid.type & QTAUTH)
|
||||||
@ -527,17 +527,17 @@ rTread(Msg* m)
|
|||||||
if((fid = fidGet(m->con, m->t.fid, 0)) == nil)
|
if((fid = fidGet(m->con, m->t.fid, 0)) == nil)
|
||||||
return 0;
|
return 0;
|
||||||
if(!(fid->open & FidORead)){
|
if(!(fid->open & FidORead)){
|
||||||
vtSetError("fid not open for read");
|
werrstr("fid not open for read");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
count = m->t.count;
|
count = m->t.count;
|
||||||
if(count < 0 || count > m->con->msize-IOHDRSZ){
|
if(count < 0 || count > m->con->msize-IOHDRSZ){
|
||||||
vtSetError("read count too big");
|
werrstr("read count too big");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if(m->t.offset < 0){
|
if(m->t.offset < 0){
|
||||||
vtSetError("read offset negative");
|
werrstr("read offset negative");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if(fid->excl != nil && !exclUpdate(fid))
|
if(fid->excl != nil && !exclUpdate(fid))
|
||||||
@ -579,15 +579,15 @@ rTcreate(Msg* m)
|
|||||||
if((fid = fidGet(m->con, m->t.fid, FidFWlock)) == nil)
|
if((fid = fidGet(m->con, m->t.fid, FidFWlock)) == nil)
|
||||||
return 0;
|
return 0;
|
||||||
if(fid->open){
|
if(fid->open){
|
||||||
vtSetError("fid open for I/O");
|
werrstr("fid open for I/O");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if(fileIsRoFs(fid->file) || !groupWriteMember(fid->uname)){
|
if(fileIsRoFs(fid->file) || !groupWriteMember(fid->uname)){
|
||||||
vtSetError("read-only filesystem");
|
werrstr("read-only filesystem");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if(!fileIsDir(fid->file)){
|
if(!fileIsDir(fid->file)){
|
||||||
vtSetError("not a directory");
|
werrstr("not a directory");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if(permFid(fid, PermW) <= 0)
|
if(permFid(fid, PermW) <= 0)
|
||||||
@ -595,7 +595,7 @@ rTcreate(Msg* m)
|
|||||||
if(!validFileName(m->t.name))
|
if(!validFileName(m->t.name))
|
||||||
goto error;
|
goto error;
|
||||||
if(strcmp(fid->uid, uidnoworld) == 0){
|
if(strcmp(fid->uid, uidnoworld) == 0){
|
||||||
vtSetError(EPermission);
|
werrstr(EPermission);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -607,16 +607,16 @@ rTcreate(Msg* m)
|
|||||||
if(omode == OWRITE || omode == ORDWR)
|
if(omode == OWRITE || omode == ORDWR)
|
||||||
open |= FidOWrite;
|
open |= FidOWrite;
|
||||||
if((open & (FidOWrite|FidORead)) == 0){
|
if((open & (FidOWrite|FidORead)) == 0){
|
||||||
vtSetError("unknown mode");
|
werrstr("unknown mode");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if(m->t.perm & DMDIR){
|
if(m->t.perm & DMDIR){
|
||||||
if((m->t.mode & (ORCLOSE|OTRUNC)) || (open & FidOWrite)){
|
if((m->t.mode & (ORCLOSE|OTRUNC)) || (open & FidOWrite)){
|
||||||
vtSetError("illegal mode");
|
werrstr("illegal mode");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if(m->t.perm & DMAPPEND){
|
if(m->t.perm & DMAPPEND){
|
||||||
vtSetError("illegal perm");
|
werrstr("illegal perm");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -681,7 +681,7 @@ rTopen(Msg* m)
|
|||||||
if((fid = fidGet(m->con, m->t.fid, FidFWlock)) == nil)
|
if((fid = fidGet(m->con, m->t.fid, FidFWlock)) == nil)
|
||||||
return 0;
|
return 0;
|
||||||
if(fid->open){
|
if(fid->open){
|
||||||
vtSetError("fid open for I/O");
|
werrstr("fid open for I/O");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -691,11 +691,11 @@ rTopen(Msg* m)
|
|||||||
|
|
||||||
if(m->t.mode & ORCLOSE){
|
if(m->t.mode & ORCLOSE){
|
||||||
if(isdir){
|
if(isdir){
|
||||||
vtSetError("is a directory");
|
werrstr("is a directory");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if(rofs){
|
if(rofs){
|
||||||
vtSetError("read-only filesystem");
|
werrstr("read-only filesystem");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if(permParent(fid, PermW) <= 0)
|
if(permParent(fid, PermW) <= 0)
|
||||||
@ -712,11 +712,11 @@ rTopen(Msg* m)
|
|||||||
}
|
}
|
||||||
if(omode == OWRITE || omode == ORDWR || (m->t.mode & OTRUNC)){
|
if(omode == OWRITE || omode == ORDWR || (m->t.mode & OTRUNC)){
|
||||||
if(isdir){
|
if(isdir){
|
||||||
vtSetError("is a directory");
|
werrstr("is a directory");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if(rofs){
|
if(rofs){
|
||||||
vtSetError("read-only filesystem");
|
werrstr("read-only filesystem");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if(permFid(fid, PermW) <= 0)
|
if(permFid(fid, PermW) <= 0)
|
||||||
@ -725,7 +725,7 @@ rTopen(Msg* m)
|
|||||||
}
|
}
|
||||||
if(omode == OEXEC){
|
if(omode == OEXEC){
|
||||||
if(isdir){
|
if(isdir){
|
||||||
vtSetError("is a directory");
|
werrstr("is a directory");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if(permFid(fid, PermX) <= 0)
|
if(permFid(fid, PermX) <= 0)
|
||||||
@ -733,7 +733,7 @@ rTopen(Msg* m)
|
|||||||
open |= FidORead;
|
open |= FidORead;
|
||||||
}
|
}
|
||||||
if((open & (FidOWrite|FidORead)) == 0){
|
if((open & (FidOWrite|FidORead)) == 0){
|
||||||
vtSetError("unknown mode");
|
werrstr("unknown mode");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -792,7 +792,7 @@ rTwalk(Msg* m)
|
|||||||
if((ofid = fidGet(m->con, t->fid, wlock)) == nil)
|
if((ofid = fidGet(m->con, t->fid, wlock)) == nil)
|
||||||
return 0;
|
return 0;
|
||||||
if(ofid->open){
|
if(ofid->open){
|
||||||
vtSetError("file open for I/O");
|
werrstr("file open for I/O");
|
||||||
fidPut(ofid);
|
fidPut(ofid);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -808,7 +808,7 @@ rTwalk(Msg* m)
|
|||||||
if(t->fid != t->newfid){
|
if(t->fid != t->newfid){
|
||||||
nfid = fidGet(m->con, t->newfid, FidFWlock|FidFCreate);
|
nfid = fidGet(m->con, t->newfid, FidFWlock|FidFCreate);
|
||||||
if(nfid == nil){
|
if(nfid == nil){
|
||||||
vtSetError("%s: walk: newfid 0x%ud in use",
|
werrstr("%s: walk: newfid 0x%ud in use",
|
||||||
argv0, t->newfid);
|
argv0, t->newfid);
|
||||||
fidPut(ofid);
|
fidPut(ofid);
|
||||||
return 0;
|
return 0;
|
||||||
@ -816,8 +816,8 @@ rTwalk(Msg* m)
|
|||||||
nfid->open = ofid->open & ~FidORclose;
|
nfid->open = ofid->open & ~FidORclose;
|
||||||
nfid->file = fileIncRef(ofid->file);
|
nfid->file = fileIncRef(ofid->file);
|
||||||
nfid->qid = ofid->qid;
|
nfid->qid = ofid->qid;
|
||||||
nfid->uid = vtStrDup(ofid->uid);
|
nfid->uid = vtstrdup(ofid->uid);
|
||||||
nfid->uname = vtStrDup(ofid->uname);
|
nfid->uname = vtstrdup(ofid->uname);
|
||||||
nfid->fsys = fsysIncRef(ofid->fsys);
|
nfid->fsys = fsysIncRef(ofid->fsys);
|
||||||
fid = nfid;
|
fid = nfid;
|
||||||
}
|
}
|
||||||
@ -848,7 +848,7 @@ rTwalk(Msg* m)
|
|||||||
* to walk out of it.
|
* to walk out of it.
|
||||||
*/
|
*/
|
||||||
if(!(qid.type & QTDIR)){
|
if(!(qid.type & QTDIR)){
|
||||||
vtSetError("not a directory");
|
werrstr("not a directory");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
switch(permFile(file, fid, PermX)){
|
switch(permFile(file, fid, PermX)){
|
||||||
@ -925,9 +925,9 @@ parseAname(char *aname, char **fsname, char **path)
|
|||||||
char *s;
|
char *s;
|
||||||
|
|
||||||
if(aname && aname[0])
|
if(aname && aname[0])
|
||||||
s = vtStrDup(aname);
|
s = vtstrdup(aname);
|
||||||
else
|
else
|
||||||
s = vtStrDup("main/active");
|
s = vtstrdup("main/active");
|
||||||
*fsname = s;
|
*fsname = s;
|
||||||
if((*path = strchr(s, '/')) != nil)
|
if((*path = strchr(s, '/')) != nil)
|
||||||
*(*path)++ = '\0';
|
*(*path)++ = '\0';
|
||||||
@ -949,7 +949,7 @@ conIPCheck(Con* con)
|
|||||||
|
|
||||||
if(con->flags&ConIPCheck){
|
if(con->flags&ConIPCheck){
|
||||||
if(con->remote[0] == 0){
|
if(con->remote[0] == 0){
|
||||||
vtSetError("cannot verify unknown remote address");
|
werrstr("cannot verify unknown remote address");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(access("/mnt/ipok/ok", AEXIST) < 0){
|
if(access("/mnt/ipok/ok", AEXIST) < 0){
|
||||||
@ -958,7 +958,7 @@ conIPCheck(Con* con)
|
|||||||
&& mount(fd, -1, "/mnt/ipok", MREPL, "") < 0)
|
&& mount(fd, -1, "/mnt/ipok", MREPL, "") < 0)
|
||||||
close(fd);
|
close(fd);
|
||||||
if(access("/mnt/ipok/ok", AEXIST) < 0){
|
if(access("/mnt/ipok/ok", AEXIST) < 0){
|
||||||
vtSetError("cannot verify remote address");
|
werrstr("cannot verify remote address");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -966,7 +966,7 @@ conIPCheck(Con* con)
|
|||||||
if((p = strchr(ok, '!')) != nil)
|
if((p = strchr(ok, '!')) != nil)
|
||||||
*p = 0;
|
*p = 0;
|
||||||
if(access(ok, AEXIST) < 0){
|
if(access(ok, AEXIST) < 0){
|
||||||
vtSetError("restricted remote address");
|
werrstr("restricted remote address");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -986,29 +986,29 @@ rTattach(Msg* m)
|
|||||||
parseAname(m->t.aname, &fsname, &path);
|
parseAname(m->t.aname, &fsname, &path);
|
||||||
if((fsys = fsysGet(fsname)) == nil){
|
if((fsys = fsysGet(fsname)) == nil){
|
||||||
fidClunk(fid);
|
fidClunk(fid);
|
||||||
vtMemFree(fsname);
|
vtfree(fsname);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
fid->fsys = fsys;
|
fid->fsys = fsys;
|
||||||
|
|
||||||
if(m->t.uname[0] != '\0')
|
if(m->t.uname[0] != '\0')
|
||||||
fid->uname = vtStrDup(m->t.uname);
|
fid->uname = vtstrdup(m->t.uname);
|
||||||
else
|
else
|
||||||
fid->uname = vtStrDup(unamenone);
|
fid->uname = vtstrdup(unamenone);
|
||||||
|
|
||||||
if((fid->con->flags&ConIPCheck) && !conIPCheck(fid->con)){
|
if((fid->con->flags&ConIPCheck) && !conIPCheck(fid->con)){
|
||||||
consPrint("reject %s from %s: %R\n", fid->uname, fid->con->remote);
|
consPrint("reject %s from %s: %r\n", fid->uname, fid->con->remote);
|
||||||
fidClunk(fid);
|
fidClunk(fid);
|
||||||
vtMemFree(fsname);
|
vtfree(fsname);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(fsysNoAuthCheck(fsys) || (m->con->flags&ConNoAuthCheck)){
|
if(fsysNoAuthCheck(fsys) || (m->con->flags&ConNoAuthCheck)){
|
||||||
if((fid->uid = uidByUname(fid->uname)) == nil)
|
if((fid->uid = uidByUname(fid->uname)) == nil)
|
||||||
fid->uid = vtStrDup(unamenone);
|
fid->uid = vtstrdup(unamenone);
|
||||||
}
|
}
|
||||||
else if(!authCheck(&m->t, fid, fsys)){
|
else if(!authCheck(&m->t, fid, fsys)){
|
||||||
fidClunk(fid);
|
fidClunk(fid);
|
||||||
vtMemFree(fsname);
|
vtfree(fsname);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1016,11 +1016,11 @@ rTattach(Msg* m)
|
|||||||
if((fid->file = fsysGetRoot(fsys, path)) == nil){
|
if((fid->file = fsysGetRoot(fsys, path)) == nil){
|
||||||
fsysFsRUnlock(fsys);
|
fsysFsRUnlock(fsys);
|
||||||
fidClunk(fid);
|
fidClunk(fid);
|
||||||
vtMemFree(fsname);
|
vtfree(fsname);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
fsysFsRUnlock(fsys);
|
fsysFsRUnlock(fsys);
|
||||||
vtMemFree(fsname);
|
vtfree(fsname);
|
||||||
|
|
||||||
fid->qid = (Qid){fileGetId(fid->file), 0, QTDIR};
|
fid->qid = (Qid){fileGetId(fid->file), 0, QTDIR};
|
||||||
m->r.qid = fid->qid;
|
m->r.qid = fid->qid;
|
||||||
@ -1040,19 +1040,19 @@ rTauth(Msg* m)
|
|||||||
|
|
||||||
parseAname(m->t.aname, &fsname, &path);
|
parseAname(m->t.aname, &fsname, &path);
|
||||||
if((fsys = fsysGet(fsname)) == nil){
|
if((fsys = fsysGet(fsname)) == nil){
|
||||||
vtMemFree(fsname);
|
vtfree(fsname);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
vtMemFree(fsname);
|
vtfree(fsname);
|
||||||
|
|
||||||
if(fsysNoAuthCheck(fsys) || (m->con->flags&ConNoAuthCheck)){
|
if(fsysNoAuthCheck(fsys) || (m->con->flags&ConNoAuthCheck)){
|
||||||
m->con->aok = 1;
|
m->con->aok = 1;
|
||||||
vtSetError("authentication disabled");
|
werrstr("authentication disabled");
|
||||||
fsysPut(fsys);
|
fsysPut(fsys);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(strcmp(m->t.uname, unamenone) == 0){
|
if(strcmp(m->t.uname, unamenone) == 0){
|
||||||
vtSetError("user 'none' requires no authentication");
|
werrstr("user 'none' requires no authentication");
|
||||||
fsysPut(fsys);
|
fsysPut(fsys);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1065,18 +1065,18 @@ rTauth(Msg* m)
|
|||||||
afid->fsys = fsys;
|
afid->fsys = fsys;
|
||||||
|
|
||||||
if((afd = open("/mnt/factotum/rpc", ORDWR)) < 0){
|
if((afd = open("/mnt/factotum/rpc", ORDWR)) < 0){
|
||||||
vtSetError("can't open \"/mnt/factotum/rpc\"");
|
werrstr("can't open \"/mnt/factotum/rpc\"");
|
||||||
fidClunk(afid);
|
fidClunk(afid);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if((afid->rpc = auth_allocrpc(afd)) == nil){
|
if((afid->rpc = auth_allocrpc(afd)) == nil){
|
||||||
close(afd);
|
close(afd);
|
||||||
vtSetError("can't auth_allocrpc");
|
werrstr("can't auth_allocrpc");
|
||||||
fidClunk(afid);
|
fidClunk(afid);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(auth_rpc(afid->rpc, "start", "proto=p9any role=server", 23) != ARok){
|
if(auth_rpc(afid->rpc, "start", "proto=p9any role=server", 23) != ARok){
|
||||||
vtSetError("can't auth_rpc");
|
werrstr("can't auth_rpc");
|
||||||
fidClunk(afid);
|
fidClunk(afid);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1084,7 +1084,7 @@ rTauth(Msg* m)
|
|||||||
afid->open = FidOWrite|FidORead;
|
afid->open = FidOWrite|FidORead;
|
||||||
afid->qid.type = QTAUTH;
|
afid->qid.type = QTAUTH;
|
||||||
afid->qid.path = m->t.afid;
|
afid->qid.path = m->t.afid;
|
||||||
afid->uname = vtStrDup(m->t.uname);
|
afid->uname = vtstrdup(m->t.uname);
|
||||||
|
|
||||||
m->r.qid = afid->qid;
|
m->r.qid = afid->qid;
|
||||||
|
|
||||||
@ -1103,10 +1103,10 @@ rTversion(Msg* m)
|
|||||||
r = &m->r;
|
r = &m->r;
|
||||||
con = m->con;
|
con = m->con;
|
||||||
|
|
||||||
vtLock(con->lock);
|
qlock(&con->lock);
|
||||||
if(con->state != ConInit){
|
if(con->state != ConInit){
|
||||||
vtUnlock(con->lock);
|
qunlock(&con->lock);
|
||||||
vtSetError("Tversion: down");
|
werrstr("Tversion: down");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
con->state = ConNew;
|
con->state = ConNew;
|
||||||
@ -1119,14 +1119,14 @@ rTversion(Msg* m)
|
|||||||
fidClunkAll(con);
|
fidClunkAll(con);
|
||||||
|
|
||||||
if(t->tag != NOTAG){
|
if(t->tag != NOTAG){
|
||||||
vtUnlock(con->lock);
|
qunlock(&con->lock);
|
||||||
vtSetError("Tversion: invalid tag");
|
werrstr("Tversion: invalid tag");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(t->msize < 256){
|
if(t->msize < 256){
|
||||||
vtUnlock(con->lock);
|
qunlock(&con->lock);
|
||||||
vtSetError("Tversion: message size too small");
|
werrstr("Tversion: message size too small");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(t->msize < con->msize)
|
if(t->msize < con->msize)
|
||||||
@ -1159,7 +1159,7 @@ rTversion(Msg* m)
|
|||||||
m->state = MsgF;
|
m->state = MsgF;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
vtUnlock(con->lock);
|
qunlock(&con->lock);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -106,4 +106,3 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
exits(0);
|
exits(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -12,18 +12,18 @@ enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
VtLock* alock; /* alloc */
|
QLock alock; /* alloc */
|
||||||
Msg* ahead;
|
Msg* ahead;
|
||||||
VtRendez* arendez;
|
Rendez arendez;
|
||||||
|
|
||||||
int maxmsg;
|
int maxmsg;
|
||||||
int nmsg;
|
int nmsg;
|
||||||
int nmsgstarve;
|
int nmsgstarve;
|
||||||
|
|
||||||
VtLock* rlock; /* read */
|
QLock rlock; /* read */
|
||||||
Msg* rhead;
|
Msg* rhead;
|
||||||
Msg* rtail;
|
Msg* rtail;
|
||||||
VtRendez* rrendez;
|
Rendez rrendez;
|
||||||
|
|
||||||
int maxproc;
|
int maxproc;
|
||||||
int nproc;
|
int nproc;
|
||||||
@ -33,11 +33,11 @@ static struct {
|
|||||||
} mbox;
|
} mbox;
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
VtLock* alock; /* alloc */
|
QLock alock; /* alloc */
|
||||||
Con* ahead;
|
Con* ahead;
|
||||||
VtRendez* arendez;
|
Rendez arendez;
|
||||||
|
|
||||||
VtLock* clock;
|
RWLock clock;
|
||||||
Con* chead;
|
Con* chead;
|
||||||
Con* ctail;
|
Con* ctail;
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ conFree(Con* con)
|
|||||||
con->flags = 0;
|
con->flags = 0;
|
||||||
con->isconsole = 0;
|
con->isconsole = 0;
|
||||||
|
|
||||||
vtLock(cbox.alock);
|
qlock(&cbox.alock);
|
||||||
if(con->cprev != nil)
|
if(con->cprev != nil)
|
||||||
con->cprev->cnext = con->cnext;
|
con->cprev->cnext = con->cnext;
|
||||||
else
|
else
|
||||||
@ -79,25 +79,18 @@ conFree(Con* con)
|
|||||||
|
|
||||||
if(cbox.ncon > cbox.maxcon){
|
if(cbox.ncon > cbox.maxcon){
|
||||||
if(con->name != nil)
|
if(con->name != nil)
|
||||||
vtMemFree(con->name);
|
vtfree(con->name);
|
||||||
vtLockFree(con->fidlock);
|
vtfree(con->data);
|
||||||
vtMemFree(con->data);
|
vtfree(con);
|
||||||
vtRendezFree(con->wrendez);
|
|
||||||
vtLockFree(con->wlock);
|
|
||||||
vtRendezFree(con->mrendez);
|
|
||||||
vtLockFree(con->mlock);
|
|
||||||
vtRendezFree(con->rendez);
|
|
||||||
vtLockFree(con->lock);
|
|
||||||
vtMemFree(con);
|
|
||||||
cbox.ncon--;
|
cbox.ncon--;
|
||||||
vtUnlock(cbox.alock);
|
qunlock(&cbox.alock);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
con->anext = cbox.ahead;
|
con->anext = cbox.ahead;
|
||||||
cbox.ahead = con;
|
cbox.ahead = con;
|
||||||
if(con->anext == nil)
|
if(con->anext == nil)
|
||||||
vtWakeup(cbox.arendez);
|
rwakeup(&cbox.arendez);
|
||||||
vtUnlock(cbox.alock);
|
qunlock(&cbox.alock);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -106,19 +99,19 @@ msgFree(Msg* m)
|
|||||||
assert(m->rwnext == nil);
|
assert(m->rwnext == nil);
|
||||||
assert(m->flush == nil);
|
assert(m->flush == nil);
|
||||||
|
|
||||||
vtLock(mbox.alock);
|
qlock(&mbox.alock);
|
||||||
if(mbox.nmsg > mbox.maxmsg){
|
if(mbox.nmsg > mbox.maxmsg){
|
||||||
vtMemFree(m->data);
|
vtfree(m->data);
|
||||||
vtMemFree(m);
|
vtfree(m);
|
||||||
mbox.nmsg--;
|
mbox.nmsg--;
|
||||||
vtUnlock(mbox.alock);
|
qunlock(&mbox.alock);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m->anext = mbox.ahead;
|
m->anext = mbox.ahead;
|
||||||
mbox.ahead = m;
|
mbox.ahead = m;
|
||||||
if(m->anext == nil)
|
if(m->anext == nil)
|
||||||
vtWakeup(mbox.arendez);
|
rwakeup(&mbox.arendez);
|
||||||
vtUnlock(mbox.alock);
|
qunlock(&mbox.alock);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Msg*
|
static Msg*
|
||||||
@ -126,15 +119,15 @@ msgAlloc(Con* con)
|
|||||||
{
|
{
|
||||||
Msg *m;
|
Msg *m;
|
||||||
|
|
||||||
vtLock(mbox.alock);
|
qlock(&mbox.alock);
|
||||||
while(mbox.ahead == nil){
|
while(mbox.ahead == nil){
|
||||||
if(mbox.nmsg >= mbox.maxmsg){
|
if(mbox.nmsg >= mbox.maxmsg){
|
||||||
mbox.nmsgstarve++;
|
mbox.nmsgstarve++;
|
||||||
vtSleep(mbox.arendez);
|
rsleep(&mbox.arendez);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
m = vtMemAllocZ(sizeof(Msg));
|
m = vtmallocz(sizeof(Msg));
|
||||||
m->data = vtMemAlloc(mbox.msize);
|
m->data = vtmalloc(mbox.msize);
|
||||||
m->msize = mbox.msize;
|
m->msize = mbox.msize;
|
||||||
mbox.nmsg++;
|
mbox.nmsg++;
|
||||||
mbox.ahead = m;
|
mbox.ahead = m;
|
||||||
@ -143,7 +136,7 @@ msgAlloc(Con* con)
|
|||||||
m = mbox.ahead;
|
m = mbox.ahead;
|
||||||
mbox.ahead = m->anext;
|
mbox.ahead = m->anext;
|
||||||
m->anext = nil;
|
m->anext = nil;
|
||||||
vtUnlock(mbox.alock);
|
qunlock(&mbox.alock);
|
||||||
|
|
||||||
m->con = con;
|
m->con = con;
|
||||||
m->state = MsgR;
|
m->state = MsgR;
|
||||||
@ -188,9 +181,9 @@ msgFlush(Msg* m)
|
|||||||
* If it's not found must assume Elvis has already
|
* If it's not found must assume Elvis has already
|
||||||
* left the building and reply normally.
|
* left the building and reply normally.
|
||||||
*/
|
*/
|
||||||
vtLock(con->mlock);
|
qlock(&con->mlock);
|
||||||
if(m->state == MsgF){
|
if(m->state == MsgF){
|
||||||
vtUnlock(con->mlock);
|
qunlock(&con->mlock);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for(old = con->mhead; old != nil; old = old->mnext)
|
for(old = con->mhead; old != nil; old = old->mnext)
|
||||||
@ -199,7 +192,7 @@ msgFlush(Msg* m)
|
|||||||
if(old == nil){
|
if(old == nil){
|
||||||
if(Dflag)
|
if(Dflag)
|
||||||
fprint(2, "msgFlush: cannot find %d\n", m->t.oldtag);
|
fprint(2, "msgFlush: cannot find %d\n", m->t.oldtag);
|
||||||
vtUnlock(con->mlock);
|
qunlock(&con->mlock);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,17 +246,17 @@ msgFlush(Msg* m)
|
|||||||
if(Dflag)
|
if(Dflag)
|
||||||
fprint(2, "msgFlush: add %d to %d queue\n",
|
fprint(2, "msgFlush: add %d to %d queue\n",
|
||||||
m->t.tag, old->t.tag);
|
m->t.tag, old->t.tag);
|
||||||
vtUnlock(con->mlock);
|
qunlock(&con->mlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
msgProc(void*)
|
msgProc(void*)
|
||||||
{
|
{
|
||||||
Msg *m;
|
Msg *m;
|
||||||
char *e;
|
char e[ERRMAX];
|
||||||
Con *con;
|
Con *con;
|
||||||
|
|
||||||
vtThreadSetName("msgProc");
|
threadsetname("msgProc");
|
||||||
|
|
||||||
for(;;){
|
for(;;){
|
||||||
/*
|
/*
|
||||||
@ -271,64 +264,64 @@ msgProc(void*)
|
|||||||
* If not, wait for and pull a message off
|
* If not, wait for and pull a message off
|
||||||
* the read queue.
|
* the read queue.
|
||||||
*/
|
*/
|
||||||
vtLock(mbox.rlock);
|
qlock(&mbox.rlock);
|
||||||
if(mbox.nproc > mbox.maxproc){
|
if(mbox.nproc > mbox.maxproc){
|
||||||
mbox.nproc--;
|
mbox.nproc--;
|
||||||
vtUnlock(mbox.rlock);
|
qunlock(&mbox.rlock);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
while(mbox.rhead == nil)
|
while(mbox.rhead == nil)
|
||||||
vtSleep(mbox.rrendez);
|
rsleep(&mbox.rrendez);
|
||||||
m = mbox.rhead;
|
m = mbox.rhead;
|
||||||
mbox.rhead = m->rwnext;
|
mbox.rhead = m->rwnext;
|
||||||
m->rwnext = nil;
|
m->rwnext = nil;
|
||||||
vtUnlock(mbox.rlock);
|
qunlock(&mbox.rlock);
|
||||||
|
|
||||||
con = m->con;
|
con = m->con;
|
||||||
e = nil;
|
*e = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the message has been flushed before
|
* If the message has been flushed before
|
||||||
* any 9P processing has started, mark it so
|
* any 9P processing has started, mark it so
|
||||||
* none will be attempted.
|
* none will be attempted.
|
||||||
*/
|
*/
|
||||||
vtLock(con->mlock);
|
qlock(&con->mlock);
|
||||||
if(m->state == MsgF)
|
if(m->state == MsgF)
|
||||||
e = "flushed";
|
strcpy(e, "flushed");
|
||||||
else
|
else
|
||||||
m->state = Msg9;
|
m->state = Msg9;
|
||||||
vtUnlock(con->mlock);
|
qunlock(&con->mlock);
|
||||||
|
|
||||||
if(e == nil){
|
if(*e == 0){
|
||||||
/*
|
/*
|
||||||
* explain this
|
* explain this
|
||||||
*/
|
*/
|
||||||
vtLock(con->lock);
|
qlock(&con->lock);
|
||||||
if(m->t.type == Tversion){
|
if(m->t.type == Tversion){
|
||||||
con->version = m;
|
con->version = m;
|
||||||
con->state = ConDown;
|
con->state = ConDown;
|
||||||
while(con->mhead != m)
|
while(con->mhead != m)
|
||||||
vtSleep(con->rendez);
|
rsleep(&con->rendez);
|
||||||
assert(con->state == ConDown);
|
assert(con->state == ConDown);
|
||||||
if(con->version == m){
|
if(con->version == m){
|
||||||
con->version = nil;
|
con->version = nil;
|
||||||
con->state = ConInit;
|
con->state = ConInit;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
e = "Tversion aborted";
|
strcpy(e, "Tversion aborted");
|
||||||
}
|
}
|
||||||
else if(con->state != ConUp)
|
else if(con->state != ConUp)
|
||||||
e = "connection not ready";
|
strcpy(e, "connection not ready");
|
||||||
vtUnlock(con->lock);
|
qunlock(&con->lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Dispatch if not error already.
|
* Dispatch if not error already.
|
||||||
*/
|
*/
|
||||||
m->r.tag = m->t.tag;
|
m->r.tag = m->t.tag;
|
||||||
if(e == nil && !(*rFcall[m->t.type])(m))
|
if(*e == 0 && !(*rFcall[m->t.type])(m))
|
||||||
e = vtGetError();
|
rerrstr(e, sizeof e);
|
||||||
if(e != nil){
|
if(*e != 0){
|
||||||
m->r.type = Rerror;
|
m->r.type = Rerror;
|
||||||
m->r.ename = e;
|
m->r.ename = e;
|
||||||
}
|
}
|
||||||
@ -340,14 +333,14 @@ msgProc(void*)
|
|||||||
* write queue and wakeup the write process.
|
* write queue and wakeup the write process.
|
||||||
*/
|
*/
|
||||||
if(!m->nowq){
|
if(!m->nowq){
|
||||||
vtLock(con->wlock);
|
qlock(&con->wlock);
|
||||||
if(con->whead == nil)
|
if(con->whead == nil)
|
||||||
con->whead = m;
|
con->whead = m;
|
||||||
else
|
else
|
||||||
con->wtail->rwnext = m;
|
con->wtail->rwnext = m;
|
||||||
con->wtail = m;
|
con->wtail = m;
|
||||||
vtWakeup(con->wrendez);
|
rwakeup(&con->wrendez);
|
||||||
vtUnlock(con->wlock);
|
qunlock(&con->wlock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -359,7 +352,7 @@ msgRead(void* v)
|
|||||||
Con *con;
|
Con *con;
|
||||||
int eof, fd, n;
|
int eof, fd, n;
|
||||||
|
|
||||||
vtThreadSetName("msgRead");
|
threadsetname("msgRead");
|
||||||
|
|
||||||
con = v;
|
con = v;
|
||||||
fd = con->fd;
|
fd = con->fd;
|
||||||
@ -388,7 +381,7 @@ msgRead(void* v)
|
|||||||
if(Dflag)
|
if(Dflag)
|
||||||
fprint(2, "msgRead %p: t %F\n", con, &m->t);
|
fprint(2, "msgRead %p: t %F\n", con, &m->t);
|
||||||
|
|
||||||
vtLock(con->mlock);
|
qlock(&con->mlock);
|
||||||
if(con->mtail != nil){
|
if(con->mtail != nil){
|
||||||
m->mprev = con->mtail;
|
m->mprev = con->mtail;
|
||||||
con->mtail->mnext = m;
|
con->mtail->mnext = m;
|
||||||
@ -398,14 +391,14 @@ msgRead(void* v)
|
|||||||
m->mprev = nil;
|
m->mprev = nil;
|
||||||
}
|
}
|
||||||
con->mtail = m;
|
con->mtail = m;
|
||||||
vtUnlock(con->mlock);
|
qunlock(&con->mlock);
|
||||||
|
|
||||||
vtLock(mbox.rlock);
|
qlock(&mbox.rlock);
|
||||||
if(mbox.rhead == nil){
|
if(mbox.rhead == nil){
|
||||||
mbox.rhead = m;
|
mbox.rhead = m;
|
||||||
if(!vtWakeup(mbox.rrendez)){
|
if(!rwakeup(&mbox.rrendez)){
|
||||||
if(mbox.nproc < mbox.maxproc){
|
if(mbox.nproc < mbox.maxproc){
|
||||||
if(vtThread(msgProc, nil) > 0)
|
if(proccreate(msgProc, nil, STACK) > 0)
|
||||||
mbox.nproc++;
|
mbox.nproc++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -413,13 +406,13 @@ msgRead(void* v)
|
|||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* don't need this surely?
|
* don't need this surely?
|
||||||
vtWakeup(mbox.rrendez);
|
rwakeup(&mbox.rrendez);
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
mbox.rtail->rwnext = m;
|
mbox.rtail->rwnext = m;
|
||||||
mbox.rtail = m;
|
mbox.rtail = m;
|
||||||
vtUnlock(mbox.rlock);
|
qunlock(&mbox.rlock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -430,10 +423,10 @@ msgWrite(void* v)
|
|||||||
int eof, n;
|
int eof, n;
|
||||||
Msg *flush, *m;
|
Msg *flush, *m;
|
||||||
|
|
||||||
vtThreadSetName("msgWrite");
|
threadsetname("msgWrite");
|
||||||
|
|
||||||
con = v;
|
con = v;
|
||||||
if(vtThread(msgRead, con) < 0){
|
if(proccreate(msgRead, con, STACK) < 0){
|
||||||
conFree(con);
|
conFree(con);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -442,14 +435,14 @@ msgWrite(void* v)
|
|||||||
/*
|
/*
|
||||||
* Wait for and pull a message off the write queue.
|
* Wait for and pull a message off the write queue.
|
||||||
*/
|
*/
|
||||||
vtLock(con->wlock);
|
qlock(&con->wlock);
|
||||||
while(con->whead == nil)
|
while(con->whead == nil)
|
||||||
vtSleep(con->wrendez);
|
rsleep(&con->wrendez);
|
||||||
m = con->whead;
|
m = con->whead;
|
||||||
con->whead = m->rwnext;
|
con->whead = m->rwnext;
|
||||||
m->rwnext = nil;
|
m->rwnext = nil;
|
||||||
assert(!m->nowq);
|
assert(!m->nowq);
|
||||||
vtUnlock(con->wlock);
|
qunlock(&con->wlock);
|
||||||
|
|
||||||
eof = 0;
|
eof = 0;
|
||||||
|
|
||||||
@ -457,7 +450,7 @@ msgWrite(void* v)
|
|||||||
* Write each message (if it hasn't been flushed)
|
* Write each message (if it hasn't been flushed)
|
||||||
* followed by any messages waiting for it to complete.
|
* followed by any messages waiting for it to complete.
|
||||||
*/
|
*/
|
||||||
vtLock(con->mlock);
|
qlock(&con->mlock);
|
||||||
while(m != nil){
|
while(m != nil){
|
||||||
msgMunlink(m);
|
msgMunlink(m);
|
||||||
|
|
||||||
@ -467,13 +460,13 @@ msgWrite(void* v)
|
|||||||
|
|
||||||
if(m->state != MsgF){
|
if(m->state != MsgF){
|
||||||
m->state = MsgW;
|
m->state = MsgW;
|
||||||
vtUnlock(con->mlock);
|
qunlock(&con->mlock);
|
||||||
|
|
||||||
n = convS2M(&m->r, con->data, con->msize);
|
n = convS2M(&m->r, con->data, con->msize);
|
||||||
if(write(con->fd, con->data, n) != n)
|
if(write(con->fd, con->data, n) != n)
|
||||||
eof = 1;
|
eof = 1;
|
||||||
|
|
||||||
vtLock(con->mlock);
|
qlock(&con->mlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
if((flush = m->flush) != nil){
|
if((flush = m->flush) != nil){
|
||||||
@ -483,21 +476,21 @@ msgWrite(void* v)
|
|||||||
msgFree(m);
|
msgFree(m);
|
||||||
m = flush;
|
m = flush;
|
||||||
}
|
}
|
||||||
vtUnlock(con->mlock);
|
qunlock(&con->mlock);
|
||||||
|
|
||||||
vtLock(con->lock);
|
qlock(&con->lock);
|
||||||
if(eof && con->fd >= 0){
|
if(eof && con->fd >= 0){
|
||||||
close(con->fd);
|
close(con->fd);
|
||||||
con->fd = -1;
|
con->fd = -1;
|
||||||
}
|
}
|
||||||
if(con->state == ConDown)
|
if(con->state == ConDown)
|
||||||
vtWakeup(con->rendez);
|
rwakeup(&con->rendez);
|
||||||
if(con->state == ConMoribund && con->mhead == nil){
|
if(con->state == ConMoribund && con->mhead == nil){
|
||||||
vtUnlock(con->lock);
|
qunlock(&con->lock);
|
||||||
conFree(con);
|
conFree(con);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
vtUnlock(con->lock);
|
qunlock(&con->lock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -508,24 +501,19 @@ conAlloc(int fd, char* name, int flags)
|
|||||||
char buf[128], *p;
|
char buf[128], *p;
|
||||||
int rfd, n;
|
int rfd, n;
|
||||||
|
|
||||||
vtLock(cbox.alock);
|
qlock(&cbox.alock);
|
||||||
while(cbox.ahead == nil){
|
while(cbox.ahead == nil){
|
||||||
if(cbox.ncon >= cbox.maxcon){
|
if(cbox.ncon >= cbox.maxcon){
|
||||||
cbox.nconstarve++;
|
cbox.nconstarve++;
|
||||||
vtSleep(cbox.arendez);
|
rsleep(&cbox.arendez);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
con = vtMemAllocZ(sizeof(Con));
|
con = vtmallocz(sizeof(Con));
|
||||||
con->lock = vtLockAlloc();
|
con->rendez.l = &con->lock;
|
||||||
con->rendez = vtRendezAlloc(con->lock);
|
con->data = vtmalloc(cbox.msize);
|
||||||
con->data = vtMemAlloc(cbox.msize);
|
|
||||||
con->msize = cbox.msize;
|
con->msize = cbox.msize;
|
||||||
con->alock = vtLockAlloc();
|
con->mrendez.l = &con->mlock;
|
||||||
con->mlock = vtLockAlloc();
|
con->wrendez.l = &con->wlock;
|
||||||
con->mrendez = vtRendezAlloc(con->mlock);
|
|
||||||
con->wlock = vtLockAlloc();
|
|
||||||
con->wrendez = vtRendezAlloc(con->wlock);
|
|
||||||
con->fidlock = vtLockAlloc();
|
|
||||||
|
|
||||||
cbox.ncon++;
|
cbox.ncon++;
|
||||||
cbox.ahead = con;
|
cbox.ahead = con;
|
||||||
@ -553,13 +541,13 @@ conAlloc(int fd, char* name, int flags)
|
|||||||
con->state = ConNew;
|
con->state = ConNew;
|
||||||
con->fd = fd;
|
con->fd = fd;
|
||||||
if(con->name != nil){
|
if(con->name != nil){
|
||||||
vtMemFree(con->name);
|
vtfree(con->name);
|
||||||
con->name = nil;
|
con->name = nil;
|
||||||
}
|
}
|
||||||
if(name != nil)
|
if(name != nil)
|
||||||
con->name = vtStrDup(name);
|
con->name = vtstrdup(name);
|
||||||
else
|
else
|
||||||
con->name = vtStrDup("unknown");
|
con->name = vtstrdup("unknown");
|
||||||
con->remote[0] = 0;
|
con->remote[0] = 0;
|
||||||
snprint(buf, sizeof buf, "%s/remote", con->name);
|
snprint(buf, sizeof buf, "%s/remote", con->name);
|
||||||
if((rfd = open(buf, OREAD)) >= 0){
|
if((rfd = open(buf, OREAD)) >= 0){
|
||||||
@ -574,9 +562,9 @@ conAlloc(int fd, char* name, int flags)
|
|||||||
}
|
}
|
||||||
con->flags = flags;
|
con->flags = flags;
|
||||||
con->isconsole = 0;
|
con->isconsole = 0;
|
||||||
vtUnlock(cbox.alock);
|
qunlock(&cbox.alock);
|
||||||
|
|
||||||
if(vtThread(msgWrite, con) < 0){
|
if(proccreate(msgWrite, con, STACK) < 0){
|
||||||
conFree(con);
|
conFree(con);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
@ -616,21 +604,21 @@ cmdMsg(int argc, char* argv[])
|
|||||||
if(argc)
|
if(argc)
|
||||||
return cliError(usage);
|
return cliError(usage);
|
||||||
|
|
||||||
vtLock(mbox.alock);
|
qlock(&mbox.alock);
|
||||||
if(maxmsg)
|
if(maxmsg)
|
||||||
mbox.maxmsg = maxmsg;
|
mbox.maxmsg = maxmsg;
|
||||||
maxmsg = mbox.maxmsg;
|
maxmsg = mbox.maxmsg;
|
||||||
nmsg = mbox.nmsg;
|
nmsg = mbox.nmsg;
|
||||||
nmsgstarve = mbox.nmsgstarve;
|
nmsgstarve = mbox.nmsgstarve;
|
||||||
vtUnlock(mbox.alock);
|
qunlock(&mbox.alock);
|
||||||
|
|
||||||
vtLock(mbox.rlock);
|
qlock(&mbox.rlock);
|
||||||
if(maxproc)
|
if(maxproc)
|
||||||
mbox.maxproc = maxproc;
|
mbox.maxproc = maxproc;
|
||||||
maxproc = mbox.maxproc;
|
maxproc = mbox.maxproc;
|
||||||
nproc = mbox.nproc;
|
nproc = mbox.nproc;
|
||||||
nprocstarve = mbox.nprocstarve;
|
nprocstarve = mbox.nprocstarve;
|
||||||
vtUnlock(mbox.rlock);
|
qunlock(&mbox.rlock);
|
||||||
|
|
||||||
consPrint("\tmsg -m %d -p %d\n", maxmsg, maxproc);
|
consPrint("\tmsg -m %d -p %d\n", maxmsg, maxproc);
|
||||||
consPrint("\tnmsg %d nmsgstarve %d nproc %d nprocstarve %d\n",
|
consPrint("\tnmsg %d nmsgstarve %d nproc %d nprocstarve %d\n",
|
||||||
@ -717,7 +705,7 @@ cmdWho(int argc, char* argv[])
|
|||||||
if(argc > 0)
|
if(argc > 0)
|
||||||
return cliError(usage);
|
return cliError(usage);
|
||||||
|
|
||||||
vtRLock(cbox.clock);
|
rlock(&cbox.clock);
|
||||||
l1 = 0;
|
l1 = 0;
|
||||||
l2 = 0;
|
l2 = 0;
|
||||||
for(con=cbox.chead; con; con=con->cnext){
|
for(con=cbox.chead; con; con=con->cnext){
|
||||||
@ -728,7 +716,7 @@ cmdWho(int argc, char* argv[])
|
|||||||
}
|
}
|
||||||
for(con=cbox.chead; con; con=con->cnext){
|
for(con=cbox.chead; con; con=con->cnext){
|
||||||
consPrint("\t%-*s %-*s", l1, con->name, l2, con->remote);
|
consPrint("\t%-*s %-*s", l1, con->name, l2, con->remote);
|
||||||
vtLock(con->fidlock);
|
qlock(&con->fidlock);
|
||||||
last = nil;
|
last = nil;
|
||||||
for(i=0; i<NFidHash; i++)
|
for(i=0; i<NFidHash; i++)
|
||||||
for(fid=con->fidhash[i]; fid; fid=fid->hash)
|
for(fid=con->fidhash[i]; fid; fid=fid->hash)
|
||||||
@ -741,21 +729,19 @@ cmdWho(int argc, char* argv[])
|
|||||||
for(; fid; last=fid, fid=fid->sort)
|
for(; fid; last=fid, fid=fid->sort)
|
||||||
if(last==nil || strcmp(fid->uname, last->uname) != 0)
|
if(last==nil || strcmp(fid->uname, last->uname) != 0)
|
||||||
consPrint(" %q", fid->uname);
|
consPrint(" %q", fid->uname);
|
||||||
vtUnlock(con->fidlock);
|
qunlock(&con->fidlock);
|
||||||
consPrint("\n");
|
consPrint("\n");
|
||||||
}
|
}
|
||||||
vtRUnlock(cbox.clock);
|
runlock(&cbox.clock);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
msgInit(void)
|
msgInit(void)
|
||||||
{
|
{
|
||||||
mbox.alock = vtLockAlloc();
|
mbox.arendez.l = &mbox.alock;
|
||||||
mbox.arendez = vtRendezAlloc(mbox.alock);
|
|
||||||
|
|
||||||
mbox.rlock = vtLockAlloc();
|
mbox.rrendez.l = &mbox.rlock;
|
||||||
mbox.rrendez = vtRendezAlloc(mbox.rlock);
|
|
||||||
|
|
||||||
mbox.maxmsg = NMsgInit;
|
mbox.maxmsg = NMsgInit;
|
||||||
mbox.maxproc = NMsgProcInit;
|
mbox.maxproc = NMsgProcInit;
|
||||||
@ -789,22 +775,22 @@ cmdCon(int argc, char* argv[])
|
|||||||
if(argc)
|
if(argc)
|
||||||
return cliError(usage);
|
return cliError(usage);
|
||||||
|
|
||||||
vtLock(cbox.clock);
|
wlock(&cbox.clock);
|
||||||
if(maxcon)
|
if(maxcon)
|
||||||
cbox.maxcon = maxcon;
|
cbox.maxcon = maxcon;
|
||||||
maxcon = cbox.maxcon;
|
maxcon = cbox.maxcon;
|
||||||
ncon = cbox.ncon;
|
ncon = cbox.ncon;
|
||||||
nconstarve = cbox.nconstarve;
|
nconstarve = cbox.nconstarve;
|
||||||
vtUnlock(cbox.clock);
|
wunlock(&cbox.clock);
|
||||||
|
|
||||||
consPrint("\tcon -m %d\n", maxcon);
|
consPrint("\tcon -m %d\n", maxcon);
|
||||||
consPrint("\tncon %d nconstarve %d\n", ncon, nconstarve);
|
consPrint("\tncon %d nconstarve %d\n", ncon, nconstarve);
|
||||||
|
|
||||||
vtRLock(cbox.clock);
|
rlock(&cbox.clock);
|
||||||
for(con = cbox.chead; con != nil; con = con->cnext){
|
for(con = cbox.chead; con != nil; con = con->cnext){
|
||||||
consPrint("\t%s\n", con->name);
|
consPrint("\t%s\n", con->name);
|
||||||
}
|
}
|
||||||
vtRUnlock(cbox.clock);
|
runlock(&cbox.clock);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -812,10 +798,7 @@ cmdCon(int argc, char* argv[])
|
|||||||
void
|
void
|
||||||
conInit(void)
|
conInit(void)
|
||||||
{
|
{
|
||||||
cbox.alock = vtLockAlloc();
|
cbox.arendez.l = &cbox.alock;
|
||||||
cbox.arendez = vtRendezAlloc(cbox.alock);
|
|
||||||
|
|
||||||
cbox.clock = vtLockAlloc();
|
|
||||||
|
|
||||||
cbox.maxcon = NConInit;
|
cbox.maxcon = NConInit;
|
||||||
cbox.msize = NMsizeInit;
|
cbox.msize = NMsizeInit;
|
||||||
|
|||||||
@ -14,7 +14,7 @@ struct Srv {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
VtLock* lock;
|
RWLock lock;
|
||||||
|
|
||||||
Srv* head;
|
Srv* head;
|
||||||
Srv* tail;
|
Srv* tail;
|
||||||
@ -33,11 +33,11 @@ srvFd(char* name, int mode, int fd, char** mntpnt)
|
|||||||
*/
|
*/
|
||||||
p = smprint("/srv/%s", name);
|
p = smprint("/srv/%s", name);
|
||||||
if((srvfd = create(p, ORCLOSE|OWRITE, mode)) < 0){
|
if((srvfd = create(p, ORCLOSE|OWRITE, mode)) < 0){
|
||||||
vtMemFree(p);
|
vtfree(p);
|
||||||
p = smprint("#s/%s", name);
|
p = smprint("#s/%s", name);
|
||||||
if((srvfd = create(p, ORCLOSE|OWRITE, mode)) < 0){
|
if((srvfd = create(p, ORCLOSE|OWRITE, mode)) < 0){
|
||||||
vtSetError("create %s: %r", p);
|
werrstr("create %s: %r", p);
|
||||||
vtMemFree(p);
|
vtfree(p);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -45,8 +45,8 @@ srvFd(char* name, int mode, int fd, char** mntpnt)
|
|||||||
n = snprint(buf, sizeof(buf), "%d", fd);
|
n = snprint(buf, sizeof(buf), "%d", fd);
|
||||||
if(write(srvfd, buf, n) < 0){
|
if(write(srvfd, buf, n) < 0){
|
||||||
close(srvfd);
|
close(srvfd);
|
||||||
vtSetError("write %s: %r", p);
|
werrstr("write %s: %r", p);
|
||||||
vtMemFree(p);
|
vtfree(p);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,9 +69,9 @@ srvFree(Srv* srv)
|
|||||||
|
|
||||||
if(srv->srvfd != -1)
|
if(srv->srvfd != -1)
|
||||||
close(srv->srvfd);
|
close(srv->srvfd);
|
||||||
vtMemFree(srv->service);
|
vtfree(srv->service);
|
||||||
vtMemFree(srv->mntpnt);
|
vtfree(srv->mntpnt);
|
||||||
vtMemFree(srv);
|
vtfree(srv);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Srv*
|
static Srv*
|
||||||
@ -82,7 +82,7 @@ srvAlloc(char* service, int mode, int fd)
|
|||||||
int srvfd;
|
int srvfd;
|
||||||
char *mntpnt;
|
char *mntpnt;
|
||||||
|
|
||||||
vtLock(sbox.lock);
|
wlock(&sbox.lock);
|
||||||
for(srv = sbox.head; srv != nil; srv = srv->next){
|
for(srv = sbox.head; srv != nil; srv = srv->next){
|
||||||
if(strcmp(srv->service, service) != 0)
|
if(strcmp(srv->service, service) != 0)
|
||||||
continue;
|
continue;
|
||||||
@ -92,8 +92,8 @@ srvAlloc(char* service, int mode, int fd)
|
|||||||
*/
|
*/
|
||||||
if((dir = dirfstat(srv->srvfd)) != nil){
|
if((dir = dirfstat(srv->srvfd)) != nil){
|
||||||
free(dir);
|
free(dir);
|
||||||
vtSetError("srv: already serving '%s'", service);
|
werrstr("srv: already serving '%s'", service);
|
||||||
vtUnlock(sbox.lock);
|
wunlock(&sbox.lock);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
srvFree(srv);
|
srvFree(srv);
|
||||||
@ -101,14 +101,14 @@ srvAlloc(char* service, int mode, int fd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if((srvfd = srvFd(service, mode, fd, &mntpnt)) < 0){
|
if((srvfd = srvFd(service, mode, fd, &mntpnt)) < 0){
|
||||||
vtUnlock(sbox.lock);
|
wunlock(&sbox.lock);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
srv = vtMemAllocZ(sizeof(Srv));
|
srv = vtmallocz(sizeof(Srv));
|
||||||
srv->srvfd = srvfd;
|
srv->srvfd = srvfd;
|
||||||
srv->service = vtStrDup(service);
|
srv->service = vtstrdup(service);
|
||||||
srv->mntpnt = mntpnt;
|
srv->mntpnt = mntpnt;
|
||||||
|
|
||||||
if(sbox.tail != nil){
|
if(sbox.tail != nil){
|
||||||
@ -120,7 +120,7 @@ srvAlloc(char* service, int mode, int fd)
|
|||||||
srv->prev = nil;
|
srv->prev = nil;
|
||||||
}
|
}
|
||||||
sbox.tail = srv;
|
sbox.tail = srv;
|
||||||
vtUnlock(sbox.lock);
|
wunlock(&sbox.lock);
|
||||||
|
|
||||||
return srv;
|
return srv;
|
||||||
}
|
}
|
||||||
@ -168,7 +168,7 @@ cmdSrv(int argc, char* argv[])
|
|||||||
}ARGEND
|
}ARGEND
|
||||||
|
|
||||||
if(pflag && (conflags&ConNoPermCheck)){
|
if(pflag && (conflags&ConNoPermCheck)){
|
||||||
vtSetError("srv: cannot use -P with -p");
|
werrstr("srv: cannot use -P with -p");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,27 +176,27 @@ cmdSrv(int argc, char* argv[])
|
|||||||
default:
|
default:
|
||||||
return cliError(usage);
|
return cliError(usage);
|
||||||
case 0:
|
case 0:
|
||||||
vtRLock(sbox.lock);
|
rlock(&sbox.lock);
|
||||||
for(srv = sbox.head; srv != nil; srv = srv->next)
|
for(srv = sbox.head; srv != nil; srv = srv->next)
|
||||||
consPrint("\t%s\t%d\n", srv->service, srv->srvfd);
|
consPrint("\t%s\t%d\n", srv->service, srv->srvfd);
|
||||||
vtRUnlock(sbox.lock);
|
runlock(&sbox.lock);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
case 1:
|
case 1:
|
||||||
if(!dflag)
|
if(!dflag)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
vtLock(sbox.lock);
|
wlock(&sbox.lock);
|
||||||
for(srv = sbox.head; srv != nil; srv = srv->next){
|
for(srv = sbox.head; srv != nil; srv = srv->next){
|
||||||
if(strcmp(srv->service, argv[0]) != 0)
|
if(strcmp(srv->service, argv[0]) != 0)
|
||||||
continue;
|
continue;
|
||||||
srvFree(srv);
|
srvFree(srv);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
vtUnlock(sbox.lock);
|
wunlock(&sbox.lock);
|
||||||
|
|
||||||
if(srv == nil){
|
if(srv == nil){
|
||||||
vtSetError("srv: '%s' not found", argv[0]);
|
werrstr("srv: '%s' not found", argv[0]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,7 +204,7 @@ cmdSrv(int argc, char* argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(pipe(fd) < 0){
|
if(pipe(fd) < 0){
|
||||||
vtSetError("srv pipe: %r");
|
werrstr("srv pipe: %r");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if((srv = srvAlloc(argv[0], mode, fd[0])) == nil){
|
if((srv = srvAlloc(argv[0], mode, fd[0])) == nil){
|
||||||
@ -223,9 +223,9 @@ cmdSrv(int argc, char* argv[])
|
|||||||
}
|
}
|
||||||
if(r == 0){
|
if(r == 0){
|
||||||
close(fd[1]);
|
close(fd[1]);
|
||||||
vtLock(sbox.lock);
|
wlock(&sbox.lock);
|
||||||
srvFree(srv);
|
srvFree(srv);
|
||||||
vtUnlock(sbox.lock);
|
wunlock(&sbox.lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
@ -234,8 +234,6 @@ cmdSrv(int argc, char* argv[])
|
|||||||
int
|
int
|
||||||
srvInit(void)
|
srvInit(void)
|
||||||
{
|
{
|
||||||
sbox.lock = vtLockAlloc();
|
|
||||||
|
|
||||||
cliAddCmd("srv", cmdSrv);
|
cliAddCmd("srv", cmdSrv);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@ -34,7 +34,7 @@ struct Ubox {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
VtLock* lock;
|
RWLock lock;
|
||||||
|
|
||||||
Ubox* box;
|
Ubox* box;
|
||||||
} ubox;
|
} ubox;
|
||||||
@ -83,7 +83,7 @@ _userByUid(Ubox* box, char* uid)
|
|||||||
return u;
|
return u;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
vtSetError("uname: uid '%s' not found", uid);
|
werrstr("uname: uid '%s' not found", uid);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,13 +93,13 @@ unameByUid(char* uid)
|
|||||||
User *u;
|
User *u;
|
||||||
char *uname;
|
char *uname;
|
||||||
|
|
||||||
vtRLock(ubox.lock);
|
rlock(&ubox.lock);
|
||||||
if((u = _userByUid(ubox.box, uid)) == nil){
|
if((u = _userByUid(ubox.box, uid)) == nil){
|
||||||
vtRUnlock(ubox.lock);
|
runlock(&ubox.lock);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
uname = vtStrDup(u->uname);
|
uname = vtstrdup(u->uname);
|
||||||
vtRUnlock(ubox.lock);
|
runlock(&ubox.lock);
|
||||||
|
|
||||||
return uname;
|
return uname;
|
||||||
}
|
}
|
||||||
@ -115,7 +115,7 @@ _userByUname(Ubox* box, char* uname)
|
|||||||
return u;
|
return u;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
vtSetError("uname: uname '%s' not found", uname);
|
werrstr("uname: uname '%s' not found", uname);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,13 +125,13 @@ uidByUname(char* uname)
|
|||||||
User *u;
|
User *u;
|
||||||
char *uid;
|
char *uid;
|
||||||
|
|
||||||
vtRLock(ubox.lock);
|
rlock(&ubox.lock);
|
||||||
if((u = _userByUname(ubox.box, uname)) == nil){
|
if((u = _userByUname(ubox.box, uname)) == nil){
|
||||||
vtRUnlock(ubox.lock);
|
runlock(&ubox.lock);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
uid = vtStrDup(u->uid);
|
uid = vtstrdup(u->uid);
|
||||||
vtRUnlock(ubox.lock);
|
runlock(&ubox.lock);
|
||||||
|
|
||||||
return uid;
|
return uid;
|
||||||
}
|
}
|
||||||
@ -182,9 +182,9 @@ groupWriteMember(char* uname)
|
|||||||
* use this functionality, we could cache the write group lookup.
|
* use this functionality, we could cache the write group lookup.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
vtRLock(ubox.lock);
|
rlock(&ubox.lock);
|
||||||
ret = _groupMember(ubox.box, "write", uname, 1);
|
ret = _groupMember(ubox.box, "write", uname, 1);
|
||||||
vtRUnlock(ubox.lock);
|
runlock(&ubox.lock);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,14 +202,14 @@ _groupRemMember(Ubox* box, User* g, char* member)
|
|||||||
}
|
}
|
||||||
if(i >= g->ngroup){
|
if(i >= g->ngroup){
|
||||||
if(strcmp(g->uname, member) == 0)
|
if(strcmp(g->uname, member) == 0)
|
||||||
vtSetError("uname: '%s' always in own group", member);
|
werrstr("uname: '%s' always in own group", member);
|
||||||
else
|
else
|
||||||
vtSetError("uname: '%s' not in group '%s'",
|
werrstr("uname: '%s' not in group '%s'",
|
||||||
member, g->uname);
|
member, g->uname);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
vtMemFree(g->group[i]);
|
vtfree(g->group[i]);
|
||||||
|
|
||||||
box->len -= strlen(member);
|
box->len -= strlen(member);
|
||||||
if(g->ngroup > 1)
|
if(g->ngroup > 1)
|
||||||
@ -217,14 +217,14 @@ _groupRemMember(Ubox* box, User* g, char* member)
|
|||||||
g->ngroup--;
|
g->ngroup--;
|
||||||
switch(g->ngroup){
|
switch(g->ngroup){
|
||||||
case 0:
|
case 0:
|
||||||
vtMemFree(g->group);
|
vtfree(g->group);
|
||||||
g->group = nil;
|
g->group = nil;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
for(; i < g->ngroup; i++)
|
for(; i < g->ngroup; i++)
|
||||||
g->group[i] = g->group[i+1];
|
g->group[i] = g->group[i+1];
|
||||||
g->group[i] = nil; /* prevent accidents */
|
g->group[i] = nil; /* prevent accidents */
|
||||||
g->group = vtMemRealloc(g->group, g->ngroup * sizeof(char*));
|
g->group = vtrealloc(g->group, g->ngroup * sizeof(char*));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -240,15 +240,15 @@ _groupAddMember(Ubox* box, User* g, char* member)
|
|||||||
return 0;
|
return 0;
|
||||||
if(_groupMember(box, g->uid, u->uname, 0)){
|
if(_groupMember(box, g->uid, u->uname, 0)){
|
||||||
if(strcmp(g->uname, member) == 0)
|
if(strcmp(g->uname, member) == 0)
|
||||||
vtSetError("uname: '%s' always in own group", member);
|
werrstr("uname: '%s' always in own group", member);
|
||||||
else
|
else
|
||||||
vtSetError("uname: '%s' already in group '%s'",
|
werrstr("uname: '%s' already in group '%s'",
|
||||||
member, g->uname);
|
member, g->uname);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
g->group = vtMemRealloc(g->group, (g->ngroup+1)*sizeof(char*));
|
g->group = vtrealloc(g->group, (g->ngroup+1)*sizeof(char*));
|
||||||
g->group[g->ngroup] = vtStrDup(member);
|
g->group[g->ngroup] = vtstrdup(member);
|
||||||
box->len += strlen(member);
|
box->len += strlen(member);
|
||||||
g->ngroup++;
|
g->ngroup++;
|
||||||
if(g->ngroup > 1)
|
if(g->ngroup > 1)
|
||||||
@ -265,9 +265,9 @@ groupMember(char* group, char* member)
|
|||||||
if(group == nil)
|
if(group == nil)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
vtRLock(ubox.lock);
|
rlock(&ubox.lock);
|
||||||
r = _groupMember(ubox.box, group, member, 0);
|
r = _groupMember(ubox.box, group, member, 0);
|
||||||
vtRUnlock(ubox.lock);
|
runlock(&ubox.lock);
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
@ -286,21 +286,21 @@ groupLeader(char* group, char* member)
|
|||||||
if(strcmp(member, unamenone) == 0 || group == nil)
|
if(strcmp(member, unamenone) == 0 || group == nil)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
vtRLock(ubox.lock);
|
rlock(&ubox.lock);
|
||||||
if((g = _userByUid(ubox.box, group)) == nil){
|
if((g = _userByUid(ubox.box, group)) == nil){
|
||||||
vtRUnlock(ubox.lock);
|
runlock(&ubox.lock);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(g->leader != nil){
|
if(g->leader != nil){
|
||||||
if(strcmp(g->leader, member) == 0){
|
if(strcmp(g->leader, member) == 0){
|
||||||
vtRUnlock(ubox.lock);
|
runlock(&ubox.lock);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
r = 0;
|
r = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
r = _groupMember(ubox.box, group, member, 0);
|
r = _groupMember(ubox.box, group, member, 0);
|
||||||
vtRUnlock(ubox.lock);
|
runlock(&ubox.lock);
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
@ -310,16 +310,16 @@ userFree(User* u)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
vtMemFree(u->uid);
|
vtfree(u->uid);
|
||||||
vtMemFree(u->uname);
|
vtfree(u->uname);
|
||||||
if(u->leader != nil)
|
if(u->leader != nil)
|
||||||
vtMemFree(u->leader);
|
vtfree(u->leader);
|
||||||
if(u->ngroup){
|
if(u->ngroup){
|
||||||
for(i = 0; i < u->ngroup; i++)
|
for(i = 0; i < u->ngroup; i++)
|
||||||
vtMemFree(u->group[i]);
|
vtfree(u->group[i]);
|
||||||
vtMemFree(u->group);
|
vtfree(u->group);
|
||||||
}
|
}
|
||||||
vtMemFree(u);
|
vtfree(u);
|
||||||
}
|
}
|
||||||
|
|
||||||
static User*
|
static User*
|
||||||
@ -327,9 +327,9 @@ userAlloc(char* uid, char* uname)
|
|||||||
{
|
{
|
||||||
User *u;
|
User *u;
|
||||||
|
|
||||||
u = vtMemAllocZ(sizeof(User));
|
u = vtmallocz(sizeof(User));
|
||||||
u->uid = vtStrDup(uid);
|
u->uid = vtstrdup(uid);
|
||||||
u->uname = vtStrDup(uname);
|
u->uname = vtstrdup(uname);
|
||||||
|
|
||||||
return u;
|
return u;
|
||||||
}
|
}
|
||||||
@ -404,7 +404,7 @@ usersFileWrite(Ubox* box)
|
|||||||
if(!fileTruncate(file, uidadm))
|
if(!fileTruncate(file, uidadm))
|
||||||
goto tidy;
|
goto tidy;
|
||||||
|
|
||||||
p = s = vtMemAlloc(box->len+1);
|
p = s = vtmalloc(box->len+1);
|
||||||
q = p + box->len+1;
|
q = p + box->len+1;
|
||||||
for(u = box->head; u != nil; u = u->next){
|
for(u = box->head; u != nil; u = u->next){
|
||||||
p += snprint(p, q-p, "%s:%s:", u->uid, u->uname);
|
p += snprint(p, q-p, "%s:%s:", u->uid, u->uname);
|
||||||
@ -419,7 +419,7 @@ usersFileWrite(Ubox* box)
|
|||||||
p += snprint(p, q-p, "\n");
|
p += snprint(p, q-p, "\n");
|
||||||
}
|
}
|
||||||
r = fileWrite(file, s, box->len, 0, uidadm);
|
r = fileWrite(file, s, box->len, 0, uidadm);
|
||||||
vtMemFree(s);
|
vtfree(s);
|
||||||
|
|
||||||
tidy:
|
tidy:
|
||||||
if(file != nil)
|
if(file != nil)
|
||||||
@ -506,7 +506,7 @@ uboxFree(Ubox* box)
|
|||||||
next = u->next;
|
next = u->next;
|
||||||
userFree(u);
|
userFree(u);
|
||||||
}
|
}
|
||||||
vtMemFree(box);
|
vtfree(box);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -525,7 +525,7 @@ uboxInit(char* users, int len)
|
|||||||
blank = 1;
|
blank = 1;
|
||||||
comment = nline = 0;
|
comment = nline = 0;
|
||||||
|
|
||||||
s = p = buf = vtMemAlloc(len+1);
|
s = p = buf = vtmalloc(len+1);
|
||||||
for(q = users; *q != '\0'; q++){
|
for(q = users; *q != '\0'; q++){
|
||||||
if(*q == '\r' || *q == '\t' || *q == ' ')
|
if(*q == '\r' || *q == '\t' || *q == ' ')
|
||||||
continue;
|
continue;
|
||||||
@ -549,18 +549,18 @@ uboxInit(char* users, int len)
|
|||||||
}
|
}
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
|
|
||||||
line = vtMemAllocZ((nline+2)*sizeof(char*));
|
line = vtmallocz((nline+2)*sizeof(char*));
|
||||||
if((i = gettokens(buf, line, nline+2, "\n")) != nline){
|
if((i = gettokens(buf, line, nline+2, "\n")) != nline){
|
||||||
fprint(2, "nline %d (%d) botch\n", nline, i);
|
fprint(2, "nline %d (%d) botch\n", nline, i);
|
||||||
vtMemFree(line);
|
vtfree(line);
|
||||||
vtMemFree(buf);
|
vtfree(buf);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Everything is updated in a local Ubox until verified.
|
* Everything is updated in a local Ubox until verified.
|
||||||
*/
|
*/
|
||||||
box = vtMemAllocZ(sizeof(Ubox));
|
box = vtmallocz(sizeof(Ubox));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* First pass - check format, check for duplicates
|
* First pass - check format, check for duplicates
|
||||||
@ -568,35 +568,35 @@ uboxInit(char* users, int len)
|
|||||||
*/
|
*/
|
||||||
nuser = 0;
|
nuser = 0;
|
||||||
for(i = 0; i < nline; i++){
|
for(i = 0; i < nline; i++){
|
||||||
s = vtStrDup(line[i]);
|
s = vtstrdup(line[i]);
|
||||||
if(getfields(s, f, nelem(f), 0, ":") != 4){
|
if(getfields(s, f, nelem(f), 0, ":") != 4){
|
||||||
fprint(2, "bad line '%s'\n", line[i]);
|
fprint(2, "bad line '%s'\n", line[i]);
|
||||||
vtMemFree(s);
|
vtfree(s);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(*f[0] == '\0' || *f[1] == '\0'){
|
if(*f[0] == '\0' || *f[1] == '\0'){
|
||||||
fprint(2, "bad line '%s'\n", line[i]);
|
fprint(2, "bad line '%s'\n", line[i]);
|
||||||
vtMemFree(s);
|
vtfree(s);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(!validUserName(f[0])){
|
if(!validUserName(f[0])){
|
||||||
fprint(2, "invalid uid '%s'\n", f[0]);
|
fprint(2, "invalid uid '%s'\n", f[0]);
|
||||||
vtMemFree(s);
|
vtfree(s);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(_userByUid(box, f[0]) != nil){
|
if(_userByUid(box, f[0]) != nil){
|
||||||
fprint(2, "duplicate uid '%s'\n", f[0]);
|
fprint(2, "duplicate uid '%s'\n", f[0]);
|
||||||
vtMemFree(s);
|
vtfree(s);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(!validUserName(f[1])){
|
if(!validUserName(f[1])){
|
||||||
fprint(2, "invalid uname '%s'\n", f[0]);
|
fprint(2, "invalid uname '%s'\n", f[0]);
|
||||||
vtMemFree(s);
|
vtfree(s);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(_userByUname(box, f[1]) != nil){
|
if(_userByUname(box, f[1]) != nil){
|
||||||
fprint(2, "duplicate uname '%s'\n", f[1]);
|
fprint(2, "duplicate uname '%s'\n", f[1]);
|
||||||
vtMemFree(s);
|
vtfree(s);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -605,7 +605,7 @@ uboxInit(char* users, int len)
|
|||||||
line[nuser] = line[i];
|
line[nuser] = line[i];
|
||||||
nuser++;
|
nuser++;
|
||||||
|
|
||||||
vtMemFree(s);
|
vtfree(s);
|
||||||
}
|
}
|
||||||
assert(box->nuser == nuser);
|
assert(box->nuser == nuser);
|
||||||
|
|
||||||
@ -613,15 +613,15 @@ uboxInit(char* users, int len)
|
|||||||
* Second pass - fill in leader and group information.
|
* Second pass - fill in leader and group information.
|
||||||
*/
|
*/
|
||||||
for(i = 0; i < nuser; i++){
|
for(i = 0; i < nuser; i++){
|
||||||
s = vtStrDup(line[i]);
|
s = vtstrdup(line[i]);
|
||||||
getfields(s, f, nelem(f), 0, ":");
|
getfields(s, f, nelem(f), 0, ":");
|
||||||
|
|
||||||
assert(g = _userByUname(box, f[1]));
|
assert(g = _userByUname(box, f[1]));
|
||||||
if(*f[2] != '\0'){
|
if(*f[2] != '\0'){
|
||||||
if((u = _userByUname(box, f[2])) == nil)
|
if((u = _userByUname(box, f[2])) == nil)
|
||||||
g->leader = vtStrDup(g->uname);
|
g->leader = vtstrdup(g->uname);
|
||||||
else
|
else
|
||||||
g->leader = vtStrDup(u->uname);
|
g->leader = vtstrdup(u->uname);
|
||||||
box->len += strlen(g->leader);
|
box->len += strlen(g->leader);
|
||||||
}
|
}
|
||||||
for(p = f[3]; p != nil; p = q){
|
for(p = f[3]; p != nil; p = q){
|
||||||
@ -632,30 +632,30 @@ uboxInit(char* users, int len)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vtMemFree(s);
|
vtfree(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
vtMemFree(line);
|
vtfree(line);
|
||||||
vtMemFree(buf);
|
vtfree(buf);
|
||||||
|
|
||||||
for(i = 0; usersMandatory[i] != nil; i++){
|
for(i = 0; usersMandatory[i] != nil; i++){
|
||||||
if((u = _userByUid(box, usersMandatory[i])) == nil){
|
if((u = _userByUid(box, usersMandatory[i])) == nil){
|
||||||
vtSetError("user '%s' is mandatory", usersMandatory[i]);
|
werrstr("user '%s' is mandatory", usersMandatory[i]);
|
||||||
uboxFree(box);
|
uboxFree(box);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(strcmp(u->uid, u->uname) != 0){
|
if(strcmp(u->uid, u->uname) != 0){
|
||||||
vtSetError("uid/uname for user '%s' must match",
|
werrstr("uid/uname for user '%s' must match",
|
||||||
usersMandatory[i]);
|
usersMandatory[i]);
|
||||||
uboxFree(box);
|
uboxFree(box);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vtLock(ubox.lock);
|
wlock(&ubox.lock);
|
||||||
obox = ubox.box;
|
obox = ubox.box;
|
||||||
ubox.box = box;
|
ubox.box = box;
|
||||||
vtUnlock(ubox.lock);
|
wunlock(&ubox.lock);
|
||||||
|
|
||||||
if(obox != nil)
|
if(obox != nil)
|
||||||
uboxFree(obox);
|
uboxFree(obox);
|
||||||
@ -683,7 +683,7 @@ usersFileRead(char* path)
|
|||||||
if((file = fileOpen(fsysGetFs(fsys), path)) != nil){
|
if((file = fileOpen(fsysGetFs(fsys), path)) != nil){
|
||||||
if(fileGetSize(file, &size)){
|
if(fileGetSize(file, &size)){
|
||||||
len = size;
|
len = size;
|
||||||
p = vtMemAlloc(size+1);
|
p = vtmalloc(size+1);
|
||||||
if(fileRead(file, p, len, 0) == len){
|
if(fileRead(file, p, len, 0) == len){
|
||||||
p[len] = '\0';
|
p[len] = '\0';
|
||||||
r = uboxInit(p, len);
|
r = uboxInit(p, len);
|
||||||
@ -720,9 +720,9 @@ cmdUname(int argc, char* argv[])
|
|||||||
if(argc < 1){
|
if(argc < 1){
|
||||||
if(!dflag)
|
if(!dflag)
|
||||||
return cliError(usage);
|
return cliError(usage);
|
||||||
vtRLock(ubox.lock);
|
rlock(&ubox.lock);
|
||||||
uboxDump(ubox.box);
|
uboxDump(ubox.box);
|
||||||
vtRUnlock(ubox.lock);
|
runlock(&ubox.lock);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -730,37 +730,37 @@ cmdUname(int argc, char* argv[])
|
|||||||
argc--; argv++;
|
argc--; argv++;
|
||||||
|
|
||||||
if(argc == 0){
|
if(argc == 0){
|
||||||
vtRLock(ubox.lock);
|
rlock(&ubox.lock);
|
||||||
if((u = _userByUname(ubox.box, uname)) == nil){
|
if((u = _userByUname(ubox.box, uname)) == nil){
|
||||||
vtRUnlock(ubox.lock);
|
runlock(&ubox.lock);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
consPrint("\t%U\n", u);
|
consPrint("\t%U\n", u);
|
||||||
vtRUnlock(ubox.lock);
|
runlock(&ubox.lock);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
vtLock(ubox.lock);
|
wlock(&ubox.lock);
|
||||||
u = _userByUname(ubox.box, uname);
|
u = _userByUname(ubox.box, uname);
|
||||||
while(argc--){
|
while(argc--){
|
||||||
if(argv[0][0] == '%'){
|
if(argv[0][0] == '%'){
|
||||||
if(u == nil){
|
if(u == nil){
|
||||||
vtUnlock(ubox.lock);
|
wunlock(&ubox.lock);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
p = &argv[0][1];
|
p = &argv[0][1];
|
||||||
if((up = _userByUname(ubox.box, p)) != nil){
|
if((up = _userByUname(ubox.box, p)) != nil){
|
||||||
vtSetError("uname: uname '%s' already exists",
|
werrstr("uname: uname '%s' already exists",
|
||||||
up->uname);
|
up->uname);
|
||||||
vtUnlock(ubox.lock);
|
wunlock(&ubox.lock);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
for(i = 0; usersMandatory[i] != nil; i++){
|
for(i = 0; usersMandatory[i] != nil; i++){
|
||||||
if(strcmp(usersMandatory[i], uname) != 0)
|
if(strcmp(usersMandatory[i], uname) != 0)
|
||||||
continue;
|
continue;
|
||||||
vtSetError("uname: uname '%s' is mandatory",
|
werrstr("uname: uname '%s' is mandatory",
|
||||||
uname);
|
uname);
|
||||||
vtUnlock(ubox.lock);
|
wunlock(&ubox.lock);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -768,80 +768,80 @@ cmdUname(int argc, char* argv[])
|
|||||||
for(up = ubox.box->head; up != nil; up = up->next){
|
for(up = ubox.box->head; up != nil; up = up->next){
|
||||||
if(up->leader != nil){
|
if(up->leader != nil){
|
||||||
if(strcmp(up->leader, u->uname) == 0){
|
if(strcmp(up->leader, u->uname) == 0){
|
||||||
vtMemFree(up->leader);
|
vtfree(up->leader);
|
||||||
up->leader = vtStrDup(p);
|
up->leader = vtstrdup(p);
|
||||||
ubox.box->len += d;
|
ubox.box->len += d;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(i = 0; i < up->ngroup; i++){
|
for(i = 0; i < up->ngroup; i++){
|
||||||
if(strcmp(up->group[i], u->uname) != 0)
|
if(strcmp(up->group[i], u->uname) != 0)
|
||||||
continue;
|
continue;
|
||||||
vtMemFree(up->group[i]);
|
vtfree(up->group[i]);
|
||||||
up->group[i] = vtStrDup(p);
|
up->group[i] = vtstrdup(p);
|
||||||
ubox.box->len += d;
|
ubox.box->len += d;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uboxRemUser(ubox.box, u);
|
uboxRemUser(ubox.box, u);
|
||||||
vtMemFree(u->uname);
|
vtfree(u->uname);
|
||||||
u->uname = vtStrDup(p);
|
u->uname = vtstrdup(p);
|
||||||
uboxAddUser(ubox.box, u);
|
uboxAddUser(ubox.box, u);
|
||||||
}
|
}
|
||||||
else if(argv[0][0] == '='){
|
else if(argv[0][0] == '='){
|
||||||
if(u == nil){
|
if(u == nil){
|
||||||
vtUnlock(ubox.lock);
|
wunlock(&ubox.lock);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if((up = _userByUname(ubox.box, &argv[0][1])) == nil){
|
if((up = _userByUname(ubox.box, &argv[0][1])) == nil){
|
||||||
if(argv[0][1] != '\0'){
|
if(argv[0][1] != '\0'){
|
||||||
vtUnlock(ubox.lock);
|
wunlock(&ubox.lock);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(u->leader != nil){
|
if(u->leader != nil){
|
||||||
ubox.box->len -= strlen(u->leader);
|
ubox.box->len -= strlen(u->leader);
|
||||||
vtMemFree(u->leader);
|
vtfree(u->leader);
|
||||||
u->leader = nil;
|
u->leader = nil;
|
||||||
}
|
}
|
||||||
if(up != nil){
|
if(up != nil){
|
||||||
u->leader = vtStrDup(up->uname);
|
u->leader = vtstrdup(up->uname);
|
||||||
ubox.box->len += strlen(u->leader);
|
ubox.box->len += strlen(u->leader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(argv[0][0] == '+'){
|
else if(argv[0][0] == '+'){
|
||||||
if(u == nil){
|
if(u == nil){
|
||||||
vtUnlock(ubox.lock);
|
wunlock(&ubox.lock);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if((up = _userByUname(ubox.box, &argv[0][1])) == nil){
|
if((up = _userByUname(ubox.box, &argv[0][1])) == nil){
|
||||||
vtUnlock(ubox.lock);
|
wunlock(&ubox.lock);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(!_groupAddMember(ubox.box, u, up->uname)){
|
if(!_groupAddMember(ubox.box, u, up->uname)){
|
||||||
vtUnlock(ubox.lock);
|
wunlock(&ubox.lock);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(argv[0][0] == '-'){
|
else if(argv[0][0] == '-'){
|
||||||
if(u == nil){
|
if(u == nil){
|
||||||
vtUnlock(ubox.lock);
|
wunlock(&ubox.lock);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if((up = _userByUname(ubox.box, &argv[0][1])) == nil){
|
if((up = _userByUname(ubox.box, &argv[0][1])) == nil){
|
||||||
vtUnlock(ubox.lock);
|
wunlock(&ubox.lock);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(!_groupRemMember(ubox.box, u, up->uname)){
|
if(!_groupRemMember(ubox.box, u, up->uname)){
|
||||||
vtUnlock(ubox.lock);
|
wunlock(&ubox.lock);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
if(u != nil){
|
if(u != nil){
|
||||||
vtSetError("uname: uname '%s' already exists",
|
werrstr("uname: uname '%s' already exists",
|
||||||
u->uname);
|
u->uname);
|
||||||
vtUnlock(ubox.lock);
|
wunlock(&ubox.lock);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -849,9 +849,9 @@ cmdUname(int argc, char* argv[])
|
|||||||
if(*uid == ':')
|
if(*uid == ':')
|
||||||
uid++;
|
uid++;
|
||||||
if((u = _userByUid(ubox.box, uid)) != nil){
|
if((u = _userByUid(ubox.box, uid)) != nil){
|
||||||
vtSetError("uname: uid '%s' already exists",
|
werrstr("uname: uid '%s' already exists",
|
||||||
u->uid);
|
u->uid);
|
||||||
vtUnlock(ubox.lock);
|
wunlock(&ubox.lock);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -861,9 +861,9 @@ cmdUname(int argc, char* argv[])
|
|||||||
// should have an option for the mode and gid
|
// should have an option for the mode and gid
|
||||||
p = smprint(createfmt, uname, uname, uname);
|
p = smprint(createfmt, uname, uname, uname);
|
||||||
r = cliExec(p);
|
r = cliExec(p);
|
||||||
vtMemFree(p);
|
vtfree(p);
|
||||||
if(r == 0){
|
if(r == 0){
|
||||||
vtUnlock(ubox.lock);
|
wunlock(&ubox.lock);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -872,12 +872,12 @@ cmdUname(int argc, char* argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(usersFileWrite(ubox.box) == 0){
|
if(usersFileWrite(ubox.box) == 0){
|
||||||
vtUnlock(ubox.lock);
|
wunlock(&ubox.lock);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(dflag)
|
if(dflag)
|
||||||
uboxDump(ubox.box);
|
uboxDump(ubox.box);
|
||||||
vtUnlock(ubox.lock);
|
wunlock(&ubox.lock);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -922,14 +922,14 @@ cmdUsers(int argc, char* argv[])
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
vtRLock(ubox.lock);
|
rlock(&ubox.lock);
|
||||||
box = ubox.box;
|
box = ubox.box;
|
||||||
consPrint("\tnuser %d len %d\n", box->nuser, box->len);
|
consPrint("\tnuser %d len %d\n", box->nuser, box->len);
|
||||||
|
|
||||||
r = 1;
|
r = 1;
|
||||||
if(wflag)
|
if(wflag)
|
||||||
r = usersFileWrite(box);
|
r = usersFileWrite(box);
|
||||||
vtRUnlock(ubox.lock);
|
runlock(&ubox.lock);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -938,7 +938,6 @@ usersInit(void)
|
|||||||
{
|
{
|
||||||
fmtinstall('U', userFmt);
|
fmtinstall('U', userFmt);
|
||||||
|
|
||||||
ubox.lock = vtLockAlloc();
|
|
||||||
uboxInit(usersDefault, sizeof(usersDefault));
|
uboxInit(usersDefault, sizeof(usersDefault));
|
||||||
|
|
||||||
cliAddCmd("users", cmdUsers);
|
cliAddCmd("users", cmdUsers);
|
||||||
|
|||||||
@ -8,7 +8,7 @@ typedef struct {
|
|||||||
} Cmd;
|
} Cmd;
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
VtLock* lock;
|
QLock lock;
|
||||||
Cmd* cmd;
|
Cmd* cmd;
|
||||||
int ncmd;
|
int ncmd;
|
||||||
int hi;
|
int hi;
|
||||||
@ -26,7 +26,7 @@ cliError(char* fmt, ...)
|
|||||||
|
|
||||||
va_start(arg, fmt);
|
va_start(arg, fmt);
|
||||||
p = vsmprint(fmt, arg);
|
p = vsmprint(fmt, arg);
|
||||||
vtSetError("%s", p);
|
werrstr("%s", p);
|
||||||
free(p);
|
free(p);
|
||||||
va_end(arg);
|
va_end(arg);
|
||||||
|
|
||||||
@ -39,32 +39,32 @@ cliExec(char* buf)
|
|||||||
int argc, i, r;
|
int argc, i, r;
|
||||||
char *argv[20], *p;
|
char *argv[20], *p;
|
||||||
|
|
||||||
p = vtStrDup(buf);
|
p = vtstrdup(buf);
|
||||||
if((argc = tokenize(p, argv, nelem(argv)-1)) == 0){
|
if((argc = tokenize(p, argv, nelem(argv)-1)) == 0){
|
||||||
vtMemFree(p);
|
vtfree(p);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
argv[argc] = 0;
|
argv[argc] = 0;
|
||||||
|
|
||||||
if(argv[0][0] == '#'){
|
if(argv[0][0] == '#'){
|
||||||
vtMemFree(p);
|
vtfree(p);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
vtLock(cbox.lock);
|
qlock(&cbox.lock);
|
||||||
for(i = 0; i < cbox.hi; i++){
|
for(i = 0; i < cbox.hi; i++){
|
||||||
if(strcmp(cbox.cmd[i].argv0, argv[0]) == 0){
|
if(strcmp(cbox.cmd[i].argv0, argv[0]) == 0){
|
||||||
vtUnlock(cbox.lock);
|
qunlock(&cbox.lock);
|
||||||
if(!(r = cbox.cmd[i].cmd(argc, argv)))
|
if(!(r = cbox.cmd[i].cmd(argc, argv)))
|
||||||
consPrint("%s\n", vtGetError());
|
consPrint("%r\n");
|
||||||
vtMemFree(p);
|
vtfree(p);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
vtUnlock(cbox.lock);
|
qunlock(&cbox.lock);
|
||||||
|
|
||||||
consPrint("%s: - eh?\n", argv[0]);
|
consPrint("%s: - eh?\n", argv[0]);
|
||||||
vtMemFree(p);
|
vtfree(p);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -75,16 +75,16 @@ cliAddCmd(char* argv0, int (*cmd)(int, char*[]))
|
|||||||
int i;
|
int i;
|
||||||
Cmd *opt;
|
Cmd *opt;
|
||||||
|
|
||||||
vtLock(cbox.lock);
|
qlock(&cbox.lock);
|
||||||
for(i = 0; i < cbox.hi; i++){
|
for(i = 0; i < cbox.hi; i++){
|
||||||
if(strcmp(argv0, cbox.cmd[i].argv0) == 0){
|
if(strcmp(argv0, cbox.cmd[i].argv0) == 0){
|
||||||
vtUnlock(cbox.lock);
|
qunlock(&cbox.lock);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(i >= cbox.hi){
|
if(i >= cbox.hi){
|
||||||
if(cbox.hi >= cbox.ncmd){
|
if(cbox.hi >= cbox.ncmd){
|
||||||
cbox.cmd = vtMemRealloc(cbox.cmd,
|
cbox.cmd = vtrealloc(cbox.cmd,
|
||||||
(cbox.ncmd+NCmdIncr)*sizeof(Cmd));
|
(cbox.ncmd+NCmdIncr)*sizeof(Cmd));
|
||||||
memset(&cbox.cmd[cbox.ncmd], 0, NCmdIncr*sizeof(Cmd));
|
memset(&cbox.cmd[cbox.ncmd], 0, NCmdIncr*sizeof(Cmd));
|
||||||
cbox.ncmd += NCmdIncr;
|
cbox.ncmd += NCmdIncr;
|
||||||
@ -95,7 +95,7 @@ cliAddCmd(char* argv0, int (*cmd)(int, char*[]))
|
|||||||
opt->argv0 = argv0;
|
opt->argv0 = argv0;
|
||||||
opt->cmd = cmd;
|
opt->cmd = cmd;
|
||||||
cbox.hi++;
|
cbox.hi++;
|
||||||
vtUnlock(cbox.lock);
|
qunlock(&cbox.lock);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -103,8 +103,7 @@ cliAddCmd(char* argv0, int (*cmd)(int, char*[]))
|
|||||||
int
|
int
|
||||||
cliInit(void)
|
cliInit(void)
|
||||||
{
|
{
|
||||||
cbox.lock = vtLockAlloc();
|
cbox.cmd = vtmallocz(NCmdIncr*sizeof(Cmd));
|
||||||
cbox.cmd = vtMemAllocZ(NCmdIncr*sizeof(Cmd));
|
|
||||||
cbox.ncmd = NCmdIncr;
|
cbox.ncmd = NCmdIncr;
|
||||||
cbox.hi = 0;
|
cbox.hi = 0;
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
#include "9.h"
|
#include "9.h"
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
VtLock* lock;
|
QLock lock;
|
||||||
|
|
||||||
Con* con;
|
Con* con;
|
||||||
int confd[2];
|
int confd[2];
|
||||||
@ -53,7 +53,7 @@ cmd9pTwstat(Fcall* f, int, char **argv)
|
|||||||
f->stat = buf;
|
f->stat = buf;
|
||||||
f->nstat = convD2M(&d, buf, sizeof buf);
|
f->nstat = convD2M(&d, buf, sizeof buf);
|
||||||
if(f->nstat < BIT16SZ){
|
if(f->nstat < BIT16SZ){
|
||||||
vtSetError("Twstat: convD2M failed (internal error)");
|
werrstr("Twstat: convD2M failed (internal error)");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,14 +131,14 @@ cmd9pTwalk(Fcall* f, int argc, char** argv)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
if(argc < 2){
|
if(argc < 2){
|
||||||
vtSetError("usage: Twalk tag fid newfid [name...]");
|
werrstr("usage: Twalk tag fid newfid [name...]");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
f->fid = strtol(argv[0], 0, 0);
|
f->fid = strtol(argv[0], 0, 0);
|
||||||
f->newfid = strtol(argv[1], 0, 0);
|
f->newfid = strtol(argv[1], 0, 0);
|
||||||
f->nwname = argc-2;
|
f->nwname = argc-2;
|
||||||
if(f->nwname > MAXWELEM){
|
if(f->nwname > MAXWELEM){
|
||||||
vtSetError("Twalk: too many names");
|
werrstr("Twalk: too many names");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
for(i = 0; i < argc-2; i++)
|
for(i = 0; i < argc-2; i++)
|
||||||
@ -181,7 +181,7 @@ cmd9pTversion(Fcall* f, int, char** argv)
|
|||||||
{
|
{
|
||||||
f->msize = strtoul(argv[0], 0, 0);
|
f->msize = strtoul(argv[0], 0, 0);
|
||||||
if(f->msize > cbox.con->msize){
|
if(f->msize > cbox.con->msize){
|
||||||
vtSetError("msize too big");
|
werrstr("msize too big");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
f->version = argv[1];
|
f->version = argv[1];
|
||||||
@ -242,7 +242,7 @@ cmd9p(int argc, char* argv[])
|
|||||||
argc--;
|
argc--;
|
||||||
argv++;
|
argv++;
|
||||||
if(cmd9pTmsg[i].argc && argc != cmd9pTmsg[i].argc){
|
if(cmd9pTmsg[i].argc && argc != cmd9pTmsg[i].argc){
|
||||||
vtSetError("usage: %s %s",
|
werrstr("usage: %s %s",
|
||||||
cmd9pTmsg[i].name, cmd9pTmsg[i].usage);
|
cmd9pTmsg[i].name, cmd9pTmsg[i].usage);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -256,33 +256,33 @@ cmd9p(int argc, char* argv[])
|
|||||||
msize = cbox.con->msize;
|
msize = cbox.con->msize;
|
||||||
if(!cmd9pTmsg[i].f(&t, argc, argv))
|
if(!cmd9pTmsg[i].f(&t, argc, argv))
|
||||||
return 0;
|
return 0;
|
||||||
buf = vtMemAlloc(msize);
|
buf = vtmalloc(msize);
|
||||||
n = convS2M(&t, buf, msize);
|
n = convS2M(&t, buf, msize);
|
||||||
if(n <= BIT16SZ){
|
if(n <= BIT16SZ){
|
||||||
vtSetError("%s: convS2M error", cmd9pTmsg[i].name);
|
werrstr("%s: convS2M error", cmd9pTmsg[i].name);
|
||||||
vtMemFree(buf);
|
vtfree(buf);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(write(cbox.confd[0], buf, n) != n){
|
if(write(cbox.confd[0], buf, n) != n){
|
||||||
vtSetError("%s: write error: %r", cmd9pTmsg[i].name);
|
werrstr("%s: write error: %r", cmd9pTmsg[i].name);
|
||||||
vtMemFree(buf);
|
vtfree(buf);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
consPrint("\t-> %F\n", &t);
|
consPrint("\t-> %F\n", &t);
|
||||||
|
|
||||||
if((n = read9pmsg(cbox.confd[0], buf, msize)) <= 0){
|
if((n = read9pmsg(cbox.confd[0], buf, msize)) <= 0){
|
||||||
vtSetError("%s: read error: %r", cmd9pTmsg[i].name);
|
werrstr("%s: read error: %r", cmd9pTmsg[i].name);
|
||||||
vtMemFree(buf);
|
vtfree(buf);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(convM2S(buf, n, &f) == 0){
|
if(convM2S(buf, n, &f) == 0){
|
||||||
vtSetError("%s: convM2S error", cmd9pTmsg[i].name);
|
werrstr("%s: convM2S error", cmd9pTmsg[i].name);
|
||||||
vtMemFree(buf);
|
vtfree(buf);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
consPrint("\t<- %F\n", &f);
|
consPrint("\t<- %F\n", &f);
|
||||||
|
|
||||||
vtMemFree(buf);
|
vtfree(buf);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -316,9 +316,9 @@ cmdDot(int argc, char* argv[])
|
|||||||
*/
|
*/
|
||||||
if((fd = open(argv[0], OREAD)) < 0)
|
if((fd = open(argv[0], OREAD)) < 0)
|
||||||
return cliError(". open %s: %r", argv[0]);
|
return cliError(". open %s: %r", argv[0]);
|
||||||
f = vtMemAlloc(dir->length+1);
|
f = vtmalloc(dir->length+1);
|
||||||
if((l = read(fd, f, length)) < 0){
|
if((l = read(fd, f, length)) < 0){
|
||||||
vtMemFree(f);
|
vtfree(f);
|
||||||
close(fd);
|
close(fd);
|
||||||
return cliError(". read %s: %r", argv[0]);
|
return cliError(". read %s: %r", argv[0]);
|
||||||
}
|
}
|
||||||
@ -333,16 +333,16 @@ cmdDot(int argc, char* argv[])
|
|||||||
*p = '\0';
|
*p = '\0';
|
||||||
if(cliExec(s) == 0){
|
if(cliExec(s) == 0){
|
||||||
r = 0;
|
r = 0;
|
||||||
consPrint("%s: %R\n", s);
|
consPrint("%s: %r\n", s);
|
||||||
}
|
}
|
||||||
s = p+1;
|
s = p+1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
vtMemFree(f);
|
vtfree(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(r == 0)
|
if(r == 0)
|
||||||
vtSetError("errors in . %#q", argv[0]);
|
werrstr("errors in . %#q", argv[0]);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -435,7 +435,6 @@ cmdBind(int argc, char* argv[])
|
|||||||
int
|
int
|
||||||
cmdInit(void)
|
cmdInit(void)
|
||||||
{
|
{
|
||||||
cbox.lock = vtLockAlloc();
|
|
||||||
cbox.confd[0] = cbox.confd[1] = -1;
|
cbox.confd[0] = cbox.confd[1] = -1;
|
||||||
|
|
||||||
cliAddCmd(".", cmdDot);
|
cliAddCmd(".", cmdDot);
|
||||||
|
|||||||
@ -8,9 +8,9 @@ enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
typedef struct Q {
|
typedef struct Q {
|
||||||
VtLock* lock;
|
QLock lock;
|
||||||
VtRendez* full;
|
Rendez full;
|
||||||
VtRendez* empty;
|
Rendez empty;
|
||||||
|
|
||||||
char q[Nq];
|
char q[Nq];
|
||||||
int n;
|
int n;
|
||||||
@ -19,7 +19,7 @@ typedef struct Q {
|
|||||||
} Q;
|
} Q;
|
||||||
|
|
||||||
typedef struct Cons {
|
typedef struct Cons {
|
||||||
VtLock* lock;
|
QLock lock;
|
||||||
int ref;
|
int ref;
|
||||||
int closed;
|
int closed;
|
||||||
int fd;
|
int fd;
|
||||||
@ -45,18 +45,18 @@ static struct {
|
|||||||
static void
|
static void
|
||||||
consClose(Cons* cons)
|
consClose(Cons* cons)
|
||||||
{
|
{
|
||||||
vtLock(cons->lock);
|
qlock(&cons->lock);
|
||||||
cons->closed = 1;
|
cons->closed = 1;
|
||||||
|
|
||||||
cons->ref--;
|
cons->ref--;
|
||||||
if(cons->ref > 0){
|
if(cons->ref > 0){
|
||||||
vtLock(cons->iq->lock);
|
qlock(&cons->iq->lock);
|
||||||
vtWakeup(cons->iq->full);
|
rwakeup(&cons->iq->full);
|
||||||
vtUnlock(cons->iq->lock);
|
qunlock(&cons->iq->lock);
|
||||||
vtLock(cons->oq->lock);
|
qlock(&cons->oq->lock);
|
||||||
vtWakeup(cons->oq->empty);
|
rwakeup(&cons->oq->empty);
|
||||||
vtUnlock(cons->oq->lock);
|
qunlock(&cons->oq->lock);
|
||||||
vtUnlock(cons->lock);
|
qunlock(&cons->lock);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,9 +72,8 @@ consClose(Cons* cons)
|
|||||||
close(cons->fd);
|
close(cons->fd);
|
||||||
cons->fd = -1;
|
cons->fd = -1;
|
||||||
}
|
}
|
||||||
vtUnlock(cons->lock);
|
qunlock(&cons->lock);
|
||||||
vtLockFree(cons->lock);
|
vtfree(cons);
|
||||||
vtMemFree(cons);
|
|
||||||
console.nopens--;
|
console.nopens--;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +85,7 @@ consIProc(void* v)
|
|||||||
int n, w;
|
int n, w;
|
||||||
char buf[Nq/4];
|
char buf[Nq/4];
|
||||||
|
|
||||||
vtThreadSetName("consI");
|
threadsetname("consI");
|
||||||
|
|
||||||
cons = v;
|
cons = v;
|
||||||
q = cons->iq;
|
q = cons->iq;
|
||||||
@ -97,9 +96,9 @@ consIProc(void* v)
|
|||||||
*/
|
*/
|
||||||
if(cons->closed || (n = read(cons->fd, buf, Nq/4)) < 0)
|
if(cons->closed || (n = read(cons->fd, buf, Nq/4)) < 0)
|
||||||
break;
|
break;
|
||||||
vtLock(q->lock);
|
qlock(&q->lock);
|
||||||
while(Nq - q->n < n && !cons->closed)
|
while(Nq - q->n < n && !cons->closed)
|
||||||
vtSleep(q->full);
|
rsleep(&q->full);
|
||||||
w = Nq - q->w;
|
w = Nq - q->w;
|
||||||
if(w < n){
|
if(w < n){
|
||||||
memmove(&q->q[q->w], buf, w);
|
memmove(&q->q[q->w], buf, w);
|
||||||
@ -109,8 +108,8 @@ consIProc(void* v)
|
|||||||
memmove(&q->q[q->w], buf, n);
|
memmove(&q->q[q->w], buf, n);
|
||||||
q->w = (q->w + n) % Nq;
|
q->w = (q->w + n) % Nq;
|
||||||
q->n += n;
|
q->n += n;
|
||||||
vtWakeup(q->empty);
|
rwakeup(&q->empty);
|
||||||
vtUnlock(q->lock);
|
qunlock(&q->lock);
|
||||||
}
|
}
|
||||||
consClose(cons);
|
consClose(cons);
|
||||||
}
|
}
|
||||||
@ -123,15 +122,15 @@ consOProc(void* v)
|
|||||||
char buf[Nq];
|
char buf[Nq];
|
||||||
int lastn, n, r;
|
int lastn, n, r;
|
||||||
|
|
||||||
vtThreadSetName("consO");
|
threadsetname("consO");
|
||||||
|
|
||||||
cons = v;
|
cons = v;
|
||||||
q = cons->oq;
|
q = cons->oq;
|
||||||
vtLock(q->lock);
|
qlock(&q->lock);
|
||||||
lastn = 0;
|
lastn = 0;
|
||||||
for(;;){
|
for(;;){
|
||||||
while(lastn == q->n && !cons->closed)
|
while(lastn == q->n && !cons->closed)
|
||||||
vtSleep(q->empty);
|
rsleep(&q->empty);
|
||||||
if((n = q->n - lastn) > Nq)
|
if((n = q->n - lastn) > Nq)
|
||||||
n = Nq;
|
n = Nq;
|
||||||
if(n > q->w){
|
if(n > q->w){
|
||||||
@ -142,11 +141,11 @@ consOProc(void* v)
|
|||||||
else
|
else
|
||||||
memmove(buf, &q->q[q->w - n], n);
|
memmove(buf, &q->q[q->w - n], n);
|
||||||
lastn = q->n;
|
lastn = q->n;
|
||||||
vtUnlock(q->lock);
|
qunlock(&q->lock);
|
||||||
if(cons->closed || write(cons->fd, buf, n) < 0)
|
if(cons->closed || write(cons->fd, buf, n) < 0)
|
||||||
break;
|
break;
|
||||||
vtLock(q->lock);
|
qlock(&q->lock);
|
||||||
vtWakeup(q->empty);
|
rwakeup(&q->empty);
|
||||||
}
|
}
|
||||||
consClose(cons);
|
consClose(cons);
|
||||||
}
|
}
|
||||||
@ -156,8 +155,7 @@ consOpen(int fd, int srvfd, int ctlfd)
|
|||||||
{
|
{
|
||||||
Cons *cons;
|
Cons *cons;
|
||||||
|
|
||||||
cons = vtMemAllocZ(sizeof(Cons));
|
cons = vtmallocz(sizeof(Cons));
|
||||||
cons->lock = vtLockAlloc();
|
|
||||||
cons->fd = fd;
|
cons->fd = fd;
|
||||||
cons->srvfd = srvfd;
|
cons->srvfd = srvfd;
|
||||||
cons->ctlfd = ctlfd;
|
cons->ctlfd = ctlfd;
|
||||||
@ -165,20 +163,20 @@ consOpen(int fd, int srvfd, int ctlfd)
|
|||||||
cons->oq = console.oq;
|
cons->oq = console.oq;
|
||||||
console.nopens++;
|
console.nopens++;
|
||||||
|
|
||||||
vtLock(cons->lock);
|
qlock(&cons->lock);
|
||||||
cons->ref = 2;
|
cons->ref = 2;
|
||||||
cons->closed = 0;
|
cons->closed = 0;
|
||||||
if(vtThread(consOProc, cons) < 0){
|
if(proccreate(consOProc, cons, STACK) < 0){
|
||||||
cons->ref--;
|
cons->ref--;
|
||||||
vtUnlock(cons->lock);
|
qunlock(&cons->lock);
|
||||||
consClose(cons);
|
consClose(cons);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
vtUnlock(cons->lock);
|
qunlock(&cons->lock);
|
||||||
|
|
||||||
if(ctlfd >= 0)
|
if(ctlfd >= 0)
|
||||||
consIProc(cons);
|
consIProc(cons);
|
||||||
else if(vtThread(consIProc, cons) < 0){
|
else if(proccreate(consIProc, cons, STACK) < 0){
|
||||||
consClose(cons);
|
consClose(cons);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -191,7 +189,7 @@ qWrite(Q* q, char* p, int n)
|
|||||||
{
|
{
|
||||||
int w;
|
int w;
|
||||||
|
|
||||||
vtLock(q->lock);
|
qlock(&q->lock);
|
||||||
if(n > Nq - q->w){
|
if(n > Nq - q->w){
|
||||||
w = Nq - q->w;
|
w = Nq - q->w;
|
||||||
memmove(&q->q[q->w], p, w);
|
memmove(&q->q[q->w], p, w);
|
||||||
@ -203,8 +201,8 @@ qWrite(Q* q, char* p, int n)
|
|||||||
q->w += n;
|
q->w += n;
|
||||||
}
|
}
|
||||||
q->n += n;
|
q->n += n;
|
||||||
vtWakeup(q->empty);
|
rwakeup(&q->empty);
|
||||||
vtUnlock(q->lock);
|
qunlock(&q->lock);
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
@ -214,10 +212,9 @@ qAlloc(void)
|
|||||||
{
|
{
|
||||||
Q *q;
|
Q *q;
|
||||||
|
|
||||||
q = vtMemAllocZ(sizeof(Q));
|
q = vtmallocz(sizeof(Q));
|
||||||
q->lock = vtLockAlloc();
|
q->full.l = &q->lock;
|
||||||
q->full = vtRendezAlloc(q->lock);
|
q->empty.l = &q->lock;
|
||||||
q->empty = vtRendezAlloc(q->lock);
|
|
||||||
q->n = q->r = q->w = 0;
|
q->n = q->r = q->w = 0;
|
||||||
|
|
||||||
return q;
|
return q;
|
||||||
@ -232,14 +229,14 @@ consProc(void*)
|
|||||||
char procname[64];
|
char procname[64];
|
||||||
|
|
||||||
snprint(procname, sizeof procname, "cons %s", currfsysname);
|
snprint(procname, sizeof procname, "cons %s", currfsysname);
|
||||||
vtThreadSetName(procname);
|
threadsetname(procname);
|
||||||
|
|
||||||
q = console.iq;
|
q = console.iq;
|
||||||
qWrite(console.oq, console.prompt, console.np);
|
qWrite(console.oq, console.prompt, console.np);
|
||||||
vtLock(q->lock);
|
qlock(&q->lock);
|
||||||
for(;;){
|
for(;;){
|
||||||
while((n = q->n) == 0)
|
while((n = q->n) == 0)
|
||||||
vtSleep(q->empty);
|
rsleep(&q->empty);
|
||||||
r = Nq - q->r;
|
r = Nq - q->r;
|
||||||
if(r < n){
|
if(r < n){
|
||||||
memmove(buf, &q->q[q->r], r);
|
memmove(buf, &q->q[q->r], r);
|
||||||
@ -249,8 +246,8 @@ consProc(void*)
|
|||||||
memmove(buf, &q->q[q->r], n);
|
memmove(buf, &q->q[q->r], n);
|
||||||
q->r = (q->r + n) % Nq;
|
q->r = (q->r + n) % Nq;
|
||||||
q->n -= n;
|
q->n -= n;
|
||||||
vtWakeup(q->full);
|
rwakeup(&q->full);
|
||||||
vtUnlock(q->lock);
|
qunlock(&q->lock);
|
||||||
|
|
||||||
for(i = 0; i < n; i++){
|
for(i = 0; i < n; i++){
|
||||||
switch(buf[i]){
|
switch(buf[i]){
|
||||||
@ -281,7 +278,7 @@ consProc(void*)
|
|||||||
break;
|
break;
|
||||||
case '\027': /* ^W */
|
case '\027': /* ^W */
|
||||||
console.l[console.nl] = '\0';
|
console.l[console.nl] = '\0';
|
||||||
wbuf = vtMemAlloc(console.nl+1);
|
wbuf = vtmalloc(console.nl+1);
|
||||||
memmove(wbuf, console.l, console.nl+1);
|
memmove(wbuf, console.l, console.nl+1);
|
||||||
argc = tokenize(wbuf, argv, nelem(argv));
|
argc = tokenize(wbuf, argv, nelem(argv));
|
||||||
if(argc > 0)
|
if(argc > 0)
|
||||||
@ -291,7 +288,7 @@ consProc(void*)
|
|||||||
for(i = 0; i < argc; i++)
|
for(i = 0; i < argc; i++)
|
||||||
lp += sprint(lp, "%q ", argv[i]);
|
lp += sprint(lp, "%q ", argv[i]);
|
||||||
console.nl = lp - console.l;
|
console.nl = lp - console.l;
|
||||||
vtMemFree(wbuf);
|
vtfree(wbuf);
|
||||||
qWrite(console.oq, "^W\n", 3);
|
qWrite(console.oq, "^W\n", 3);
|
||||||
if(console.nl == 0)
|
if(console.nl == 0)
|
||||||
break;
|
break;
|
||||||
@ -311,7 +308,7 @@ consProc(void*)
|
|||||||
qWrite(console.oq, console.prompt, console.np);
|
qWrite(console.oq, console.prompt, console.np);
|
||||||
}
|
}
|
||||||
|
|
||||||
vtLock(q->lock);
|
qlock(&q->lock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -333,9 +330,9 @@ consPrompt(char* prompt)
|
|||||||
if(prompt == nil)
|
if(prompt == nil)
|
||||||
prompt = "prompt";
|
prompt = "prompt";
|
||||||
|
|
||||||
vtMemFree(console.prompt);
|
vtfree(console.prompt);
|
||||||
console.np = snprint(buf, sizeof(buf), "%s: ", prompt);
|
console.np = snprint(buf, sizeof(buf), "%s: ", prompt);
|
||||||
console.prompt = vtStrDup(buf);
|
console.prompt = vtstrdup(buf);
|
||||||
|
|
||||||
return console.np;
|
return console.np;
|
||||||
}
|
}
|
||||||
@ -350,7 +347,7 @@ consTTY(void)
|
|||||||
if((fd = open(name, ORDWR)) < 0){
|
if((fd = open(name, ORDWR)) < 0){
|
||||||
name = "#c/cons";
|
name = "#c/cons";
|
||||||
if((fd = open(name, ORDWR)) < 0){
|
if((fd = open(name, ORDWR)) < 0){
|
||||||
vtSetError("consTTY: open %s: %r", name);
|
werrstr("consTTY: open %s: %r", name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -358,14 +355,14 @@ consTTY(void)
|
|||||||
p = smprint("%sctl", name);
|
p = smprint("%sctl", name);
|
||||||
if((ctl = open(p, OWRITE)) < 0){
|
if((ctl = open(p, OWRITE)) < 0){
|
||||||
close(fd);
|
close(fd);
|
||||||
vtSetError("consTTY: open %s: %r", p);
|
werrstr("consTTY: open %s: %r", p);
|
||||||
free(p);
|
free(p);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(write(ctl, "rawon", 5) < 0){
|
if(write(ctl, "rawon", 5) < 0){
|
||||||
close(ctl);
|
close(ctl);
|
||||||
close(fd);
|
close(fd);
|
||||||
vtSetError("consTTY: write %s: %r", p);
|
werrstr("consTTY: write %s: %r", p);
|
||||||
free(p);
|
free(p);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -389,8 +386,8 @@ consInit(void)
|
|||||||
|
|
||||||
consPrompt(nil);
|
consPrompt(nil);
|
||||||
|
|
||||||
if(vtThread(consProc, nil) < 0){
|
if(proccreate(consProc, nil, STACK) < 0){
|
||||||
vtFatal("can't start console proc");
|
sysfatal("can't start console proc");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -20,29 +20,28 @@ struct Arch
|
|||||||
uint diskSize;
|
uint diskSize;
|
||||||
Cache *c;
|
Cache *c;
|
||||||
Fs *fs;
|
Fs *fs;
|
||||||
VtSession *z;
|
VtConn *z;
|
||||||
|
|
||||||
VtLock *lk;
|
QLock lk;
|
||||||
VtRendez *starve;
|
Rendez starve;
|
||||||
VtRendez *die;
|
Rendez die;
|
||||||
};
|
};
|
||||||
|
|
||||||
Arch *
|
Arch *
|
||||||
archInit(Cache *c, Disk *disk, Fs *fs, VtSession *z)
|
archInit(Cache *c, Disk *disk, Fs *fs, VtConn *z)
|
||||||
{
|
{
|
||||||
Arch *a;
|
Arch *a;
|
||||||
|
|
||||||
a = vtMemAllocZ(sizeof(Arch));
|
a = vtmallocz(sizeof(Arch));
|
||||||
|
|
||||||
a->c = c;
|
a->c = c;
|
||||||
a->z = z;
|
a->z = z;
|
||||||
a->fs = fs;
|
a->fs = fs;
|
||||||
a->blockSize = diskBlockSize(disk);
|
a->blockSize = diskBlockSize(disk);
|
||||||
a->lk = vtLockAlloc();
|
a->starve.l = &a->lk;
|
||||||
a->starve = vtRendezAlloc(a->lk);
|
|
||||||
|
|
||||||
a->ref = 2;
|
a->ref = 2;
|
||||||
vtThread(archThread, a);
|
proccreate(archThread, a, STACK);
|
||||||
|
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
@ -51,16 +50,13 @@ void
|
|||||||
archFree(Arch *a)
|
archFree(Arch *a)
|
||||||
{
|
{
|
||||||
/* kill slave */
|
/* kill slave */
|
||||||
vtLock(a->lk);
|
qlock(&a->lk);
|
||||||
a->die = vtRendezAlloc(a->lk);
|
a->die.l = &a->lk;
|
||||||
vtWakeup(a->starve);
|
rwakeup(&a->starve);
|
||||||
while(a->ref > 1)
|
while(a->ref > 1)
|
||||||
vtSleep(a->die);
|
rsleep(&a->die);
|
||||||
vtUnlock(a->lk);
|
qunlock(&a->lk);
|
||||||
vtRendezFree(a->starve);
|
vtfree(a);
|
||||||
vtRendezFree(a->die);
|
|
||||||
vtLockFree(a->lk);
|
|
||||||
vtMemFree(a);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -71,21 +67,21 @@ ventiSend(Arch *a, Block *b, uchar *data)
|
|||||||
|
|
||||||
if(DEBUG > 1)
|
if(DEBUG > 1)
|
||||||
fprint(2, "ventiSend: sending %#ux %L to venti\n", b->addr, &b->l);
|
fprint(2, "ventiSend: sending %#ux %L to venti\n", b->addr, &b->l);
|
||||||
n = vtZeroTruncate(vtType[b->l.type], data, a->blockSize);
|
n = vtzerotruncate(vtType[b->l.type], data, a->blockSize);
|
||||||
if(DEBUG > 1)
|
if(DEBUG > 1)
|
||||||
fprint(2, "ventiSend: truncate %d to %d\n", a->blockSize, n);
|
fprint(2, "ventiSend: truncate %d to %d\n", a->blockSize, n);
|
||||||
if(!vtWrite(a->z, score, vtType[b->l.type], data, n)){
|
if(vtwrite(a->z, score, vtType[b->l.type], data, n) < 0){
|
||||||
fprint(2, "ventiSend: vtWrite block %#ux failed: %R\n", b->addr);
|
fprint(2, "ventiSend: vtwrite block %#ux failed: %r\n", b->addr);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(!vtSha1Check(score, data, n)){
|
if(vtsha1check(score, data, n) < 0){
|
||||||
uchar score2[VtScoreSize];
|
uchar score2[VtScoreSize];
|
||||||
vtSha1(score2, data, n);
|
vtsha1(score2, data, n);
|
||||||
fprint(2, "ventiSend: vtWrite block %#ux failed vtSha1Check %V %V\n",
|
fprint(2, "ventiSend: vtwrite block %#ux failed vtsha1check %V %V\n",
|
||||||
b->addr, score, score2);
|
b->addr, score, score2);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(!vtSync(a->z))
|
if(vtsync(a->z) < 0)
|
||||||
return 0;
|
return 0;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -129,7 +125,7 @@ struct Param
|
|||||||
static void
|
static void
|
||||||
shaBlock(uchar score[VtScoreSize], Block *b, uchar *data, uint bsize)
|
shaBlock(uchar score[VtScoreSize], Block *b, uchar *data, uint bsize)
|
||||||
{
|
{
|
||||||
vtSha1(score, data, vtZeroTruncate(vtType[b->l.type], data, bsize));
|
vtsha1(score, data, vtzerotruncate(vtType[b->l.type], data, bsize));
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint
|
static uint
|
||||||
@ -137,7 +133,7 @@ etype(Entry *e)
|
|||||||
{
|
{
|
||||||
uint t;
|
uint t;
|
||||||
|
|
||||||
if(e->flags&VtEntryDir)
|
if(e->flags&_VtEntryDir)
|
||||||
t = BtDir;
|
t = BtDir;
|
||||||
else
|
else
|
||||||
t = BtData;
|
t = BtData;
|
||||||
@ -149,7 +145,7 @@ copyBlock(Block *b, u32int blockSize)
|
|||||||
{
|
{
|
||||||
uchar *data;
|
uchar *data;
|
||||||
|
|
||||||
data = vtMemAlloc(blockSize);
|
data = vtmalloc(blockSize);
|
||||||
if(data == nil)
|
if(data == nil)
|
||||||
return nil;
|
return nil;
|
||||||
memmove(data, b->data, blockSize);
|
memmove(data, b->data, blockSize);
|
||||||
@ -183,15 +179,17 @@ archWalk(Param *p, u32int addr, uchar type, u32int tag)
|
|||||||
Label l;
|
Label l;
|
||||||
Entry *e;
|
Entry *e;
|
||||||
WalkPtr w;
|
WalkPtr w;
|
||||||
|
char err[ERRMAX];
|
||||||
|
|
||||||
p->nvisit++;
|
p->nvisit++;
|
||||||
|
|
||||||
b = cacheLocalData(p->c, addr, type, tag, OReadWrite,0);
|
b = cacheLocalData(p->c, addr, type, tag, OReadWrite,0);
|
||||||
if(b == nil){
|
if(b == nil){
|
||||||
fprint(2, "archive(%ud, %#ux): cannot find block: %R\n", p->snapEpoch, addr);
|
fprint(2, "archive(%ud, %#ux): cannot find block: %r\n", p->snapEpoch, addr);
|
||||||
if(strcmp(vtGetError(), ELabelMismatch) == 0){
|
rerrstr(err, sizeof err);
|
||||||
|
if(strcmp(err, ELabelMismatch) == 0){
|
||||||
/* might as well plod on so we write _something_ to Venti */
|
/* might as well plod on so we write _something_ to Venti */
|
||||||
memmove(p->score, vtZeroScore, VtScoreSize);
|
memmove(p->score, vtzeroscore, VtScoreSize);
|
||||||
return ArchFaked;
|
return ArchFaked;
|
||||||
}
|
}
|
||||||
return ArchFailure;
|
return ArchFailure;
|
||||||
@ -221,7 +219,7 @@ archWalk(Param *p, u32int addr, uchar type, u32int tag)
|
|||||||
}
|
}
|
||||||
w.data = data;
|
w.data = data;
|
||||||
}
|
}
|
||||||
memmove(e->score, vtZeroScore, VtScoreSize);
|
memmove(e->score, vtzeroscore, VtScoreSize);
|
||||||
e->depth = 0;
|
e->depth = 0;
|
||||||
e->size = 0;
|
e->size = 0;
|
||||||
e->tag = 0;
|
e->tag = 0;
|
||||||
@ -239,15 +237,15 @@ archWalk(Param *p, u32int addr, uchar type, u32int tag)
|
|||||||
p->dsize= e->dsize;
|
p->dsize= e->dsize;
|
||||||
p->psize = e->psize;
|
p->psize = e->psize;
|
||||||
}
|
}
|
||||||
vtUnlock(b->lk);
|
qunlock(&b->lk);
|
||||||
x = archWalk(p, addr, type, tag);
|
x = archWalk(p, addr, type, tag);
|
||||||
vtLock(b->lk);
|
qlock(&b->lk);
|
||||||
if(e){
|
if(e){
|
||||||
p->dsize = dsize;
|
p->dsize = dsize;
|
||||||
p->psize = psize;
|
p->psize = psize;
|
||||||
}
|
}
|
||||||
while(b->iostate != BioClean && b->iostate != BioDirty)
|
while(b->iostate != BioClean && b->iostate != BioDirty)
|
||||||
vtSleep(b->ioready);
|
rsleep(&b->ioready);
|
||||||
switch(x){
|
switch(x){
|
||||||
case ArchFailure:
|
case ArchFailure:
|
||||||
fprint(2, "archWalk %#ux failed; ptr is in %#ux offset %d\n",
|
fprint(2, "archWalk %#ux failed; ptr is in %#ux offset %d\n",
|
||||||
@ -331,7 +329,7 @@ if(0) fprint(2, "ventisend %V %p %p %p\n", p->score, data, b->data, w.data);
|
|||||||
p->l = b->l;
|
p->l = b->l;
|
||||||
Out:
|
Out:
|
||||||
if(data != b->data)
|
if(data != b->data)
|
||||||
vtMemFree(data);
|
vtfree(data);
|
||||||
p->depth--;
|
p->depth--;
|
||||||
blockPut(b);
|
blockPut(b);
|
||||||
return ret;
|
return ret;
|
||||||
@ -349,15 +347,15 @@ archThread(void *v)
|
|||||||
uchar rbuf[VtRootSize];
|
uchar rbuf[VtRootSize];
|
||||||
VtRoot root;
|
VtRoot root;
|
||||||
|
|
||||||
vtThreadSetName("arch");
|
threadsetname("arch");
|
||||||
|
|
||||||
for(;;){
|
for(;;){
|
||||||
/* look for work */
|
/* look for work */
|
||||||
vtLock(a->fs->elk);
|
wlock(&a->fs->elk);
|
||||||
b = superGet(a->c, &super);
|
b = superGet(a->c, &super);
|
||||||
if(b == nil){
|
if(b == nil){
|
||||||
vtUnlock(a->fs->elk);
|
wunlock(&a->fs->elk);
|
||||||
fprint(2, "archThread: superGet: %R\n");
|
fprint(2, "archThread: superGet: %r\n");
|
||||||
sleep(60*1000);
|
sleep(60*1000);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -370,15 +368,15 @@ archThread(void *v)
|
|||||||
}else
|
}else
|
||||||
addr = super.current;
|
addr = super.current;
|
||||||
blockPut(b);
|
blockPut(b);
|
||||||
vtUnlock(a->fs->elk);
|
wunlock(&a->fs->elk);
|
||||||
|
|
||||||
if(addr == NilBlock){
|
if(addr == NilBlock){
|
||||||
/* wait for work */
|
/* wait for work */
|
||||||
vtLock(a->lk);
|
qlock(&a->lk);
|
||||||
vtSleep(a->starve);
|
rsleep(&a->starve);
|
||||||
if(a->die != nil)
|
if(a->die.l != nil)
|
||||||
goto Done;
|
goto Done;
|
||||||
vtUnlock(a->lk);
|
qunlock(&a->lk);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -396,7 +394,7 @@ sleep(10*1000); /* window of opportunity to provoke races */
|
|||||||
default:
|
default:
|
||||||
abort();
|
abort();
|
||||||
case ArchFailure:
|
case ArchFailure:
|
||||||
fprint(2, "archiveBlock %#ux: %R\n", addr);
|
fprint(2, "archiveBlock %#ux: %r\n", addr);
|
||||||
sleep(60*1000);
|
sleep(60*1000);
|
||||||
continue;
|
continue;
|
||||||
case ArchSuccess:
|
case ArchSuccess:
|
||||||
@ -414,26 +412,25 @@ sleep(10*1000); /* window of opportunity to provoke races */
|
|||||||
|
|
||||||
/* tie up vac root */
|
/* tie up vac root */
|
||||||
memset(&root, 0, sizeof root);
|
memset(&root, 0, sizeof root);
|
||||||
root.version = VtRootVersion;
|
|
||||||
strecpy(root.type, root.type+sizeof root.type, "vac");
|
strecpy(root.type, root.type+sizeof root.type, "vac");
|
||||||
strecpy(root.name, root.name+sizeof root.name, "fossil");
|
strecpy(root.name, root.name+sizeof root.name, "fossil");
|
||||||
memmove(root.score, p.score, VtScoreSize);
|
memmove(root.score, p.score, VtScoreSize);
|
||||||
memmove(root.prev, super.last, VtScoreSize);
|
memmove(root.prev, super.last, VtScoreSize);
|
||||||
root.blockSize = a->blockSize;
|
root.blocksize = a->blockSize;
|
||||||
vtRootPack(&root, rbuf);
|
vtrootpack(&root, rbuf);
|
||||||
if(!vtWrite(a->z, p.score, VtRootType, rbuf, VtRootSize)
|
if(vtwrite(a->z, p.score, VtRootType, rbuf, VtRootSize) < 0
|
||||||
|| !vtSha1Check(p.score, rbuf, VtRootSize)){
|
|| vtsha1check(p.score, rbuf, VtRootSize) < 0){
|
||||||
fprint(2, "vtWriteBlock %#ux: %R\n", addr);
|
fprint(2, "vtWriteBlock %#ux: %r\n", addr);
|
||||||
sleep(60*1000);
|
sleep(60*1000);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* record success */
|
/* record success */
|
||||||
vtLock(a->fs->elk);
|
wlock(&a->fs->elk);
|
||||||
b = superGet(a->c, &super);
|
b = superGet(a->c, &super);
|
||||||
if(b == nil){
|
if(b == nil){
|
||||||
vtUnlock(a->fs->elk);
|
wunlock(&a->fs->elk);
|
||||||
fprint(2, "archThread: superGet: %R\n");
|
fprint(2, "archThread: superGet: %r\n");
|
||||||
sleep(60*1000);
|
sleep(60*1000);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -442,15 +439,15 @@ sleep(10*1000); /* window of opportunity to provoke races */
|
|||||||
superPack(&super, b->data);
|
superPack(&super, b->data);
|
||||||
blockDirty(b);
|
blockDirty(b);
|
||||||
blockPut(b);
|
blockPut(b);
|
||||||
vtUnlock(a->fs->elk);
|
wunlock(&a->fs->elk);
|
||||||
|
|
||||||
consPrint("archive vac:%V\n", p.score);
|
consPrint("archive vac:%V\n", p.score);
|
||||||
}
|
}
|
||||||
|
|
||||||
Done:
|
Done:
|
||||||
a->ref--;
|
a->ref--;
|
||||||
vtWakeup(a->die);
|
rwakeup(&a->die);
|
||||||
vtUnlock(a->lk);
|
qunlock(&a->lk);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -460,7 +457,7 @@ archKick(Arch *a)
|
|||||||
fprint(2, "warning: archKick nil\n");
|
fprint(2, "warning: archKick nil\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
vtLock(a->lk);
|
qlock(&a->lk);
|
||||||
vtWakeup(a->starve);
|
rwakeup(&a->starve);
|
||||||
vtUnlock(a->lk);
|
qunlock(&a->lk);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -44,7 +44,7 @@ struct WEntry
|
|||||||
|
|
||||||
struct WMap
|
struct WMap
|
||||||
{
|
{
|
||||||
VtLock *lk;
|
QLock lk;
|
||||||
|
|
||||||
WEntry *hchild[HashSize];
|
WEntry *hchild[HashSize];
|
||||||
WEntry *hparent[HashSize];
|
WEntry *hparent[HashSize];
|
||||||
@ -84,7 +84,7 @@ allocWEntry(void)
|
|||||||
|
|
||||||
w = pool;
|
w = pool;
|
||||||
if(w == nil){
|
if(w == nil){
|
||||||
w = vtMemAllocZ(1024*sizeof(WEntry));
|
w = vtmallocz(1024*sizeof(WEntry));
|
||||||
for(i=0; i<1024; i++)
|
for(i=0; i<1024; i++)
|
||||||
freeWEntry(&w[i]);
|
freeWEntry(&w[i]);
|
||||||
w = pool;
|
w = pool;
|
||||||
@ -195,16 +195,15 @@ addChild(uchar p[VtEntrySize], uchar c[VtEntrySize], int off)
|
|||||||
void
|
void
|
||||||
bwatchReset(uchar score[VtScoreSize])
|
bwatchReset(uchar score[VtScoreSize])
|
||||||
{
|
{
|
||||||
vtLock(map.lk);
|
qlock(&map.lk);
|
||||||
_bwatchResetParent(score);
|
_bwatchResetParent(score);
|
||||||
_bwatchResetChild(score);
|
_bwatchResetChild(score);
|
||||||
vtUnlock(map.lk);
|
qunlock(&map.lk);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
bwatchInit(void)
|
bwatchInit(void)
|
||||||
{
|
{
|
||||||
map.lk = vtLockAlloc();
|
|
||||||
wp = privalloc();
|
wp = privalloc();
|
||||||
*wp = nil;
|
*wp = nil;
|
||||||
}
|
}
|
||||||
@ -222,7 +221,7 @@ getWThread(void)
|
|||||||
|
|
||||||
w = *wp;
|
w = *wp;
|
||||||
if(w == nil || w->pid != getpid()){
|
if(w == nil || w->pid != getpid()){
|
||||||
w = vtMemAllocZ(sizeof(WThread));
|
w = vtmallocz(sizeof(WThread));
|
||||||
*wp = w;
|
*wp = w;
|
||||||
w->pid = getpid();
|
w->pid = getpid();
|
||||||
}
|
}
|
||||||
@ -241,7 +240,7 @@ bwatchDependency(Block *b)
|
|||||||
if(bwatchDisabled)
|
if(bwatchDisabled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
vtLock(map.lk);
|
qlock(&map.lk);
|
||||||
_bwatchResetParent(b->score);
|
_bwatchResetParent(b->score);
|
||||||
|
|
||||||
switch(b->l.type){
|
switch(b->l.type){
|
||||||
@ -264,7 +263,7 @@ bwatchDependency(Block *b)
|
|||||||
addChild(b->score, b->data+i*VtScoreSize, i);
|
addChild(b->score, b->data+i*VtScoreSize, i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
vtUnlock(map.lk);
|
qunlock(&map.lk);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -376,7 +375,7 @@ bwatchLock(Block *b)
|
|||||||
if(b->part != PartData)
|
if(b->part != PartData)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
vtLock(map.lk);
|
qlock(&map.lk);
|
||||||
w = getWThread();
|
w = getWThread();
|
||||||
for(i=0; i<w->nb; i++){
|
for(i=0; i<w->nb; i++){
|
||||||
if(lockConflicts(w->b[i]->score, b->score)){
|
if(lockConflicts(w->b[i]->score, b->score)){
|
||||||
@ -385,7 +384,7 @@ bwatchLock(Block *b)
|
|||||||
stop();
|
stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
vtUnlock(map.lk);
|
qunlock(&map.lk);
|
||||||
if(w->nb >= MaxLock){
|
if(w->nb >= MaxLock){
|
||||||
fprint(2, "%d: too many blocks held\n", w->pid);
|
fprint(2, "%d: too many blocks held\n", w->pid);
|
||||||
stop();
|
stop();
|
||||||
|
|||||||
@ -21,14 +21,14 @@ enum {
|
|||||||
|
|
||||||
struct Cache
|
struct Cache
|
||||||
{
|
{
|
||||||
VtLock *lk;
|
QLock lk;
|
||||||
int ref;
|
int ref;
|
||||||
int mode;
|
int mode;
|
||||||
|
|
||||||
Disk *disk;
|
Disk *disk;
|
||||||
int size; /* block size */
|
int size; /* block size */
|
||||||
int ndmap; /* size of per-block dirty pointer map used in blockWrite */
|
int ndmap; /* size of per-block dirty pointer map used in blockWrite */
|
||||||
VtSession *z;
|
VtConn *z;
|
||||||
u32int now; /* ticks for usage timestamps */
|
u32int now; /* ticks for usage timestamps */
|
||||||
Block **heads; /* hash table for finding address */
|
Block **heads; /* hash table for finding address */
|
||||||
int nheap; /* number of available victims */
|
int nheap; /* number of available victims */
|
||||||
@ -38,7 +38,7 @@ struct Cache
|
|||||||
u8int *mem; /* memory for all block data & blists */
|
u8int *mem; /* memory for all block data & blists */
|
||||||
|
|
||||||
BList *blfree;
|
BList *blfree;
|
||||||
VtRendez *blrend;
|
Rendez blrend;
|
||||||
|
|
||||||
int ndirty; /* number of dirty blocks in the cache */
|
int ndirty; /* number of dirty blocks in the cache */
|
||||||
int maxdirty; /* max number of dirty blocks */
|
int maxdirty; /* max number of dirty blocks */
|
||||||
@ -48,11 +48,11 @@ struct Cache
|
|||||||
|
|
||||||
FreeList *fl;
|
FreeList *fl;
|
||||||
|
|
||||||
VtRendez *die; /* daemon threads should die when != nil */
|
Rendez die; /* daemon threads should die when QLock != nil */
|
||||||
|
|
||||||
VtRendez *flush;
|
Rendez flush;
|
||||||
VtRendez *flushwait;
|
Rendez flushwait;
|
||||||
VtRendez *heapwait;
|
Rendez heapwait;
|
||||||
BAddr *baddr;
|
BAddr *baddr;
|
||||||
int bw, br, be;
|
int bw, br, be;
|
||||||
int nflush;
|
int nflush;
|
||||||
@ -62,7 +62,7 @@ struct Cache
|
|||||||
/* unlink daemon */
|
/* unlink daemon */
|
||||||
BList *uhead;
|
BList *uhead;
|
||||||
BList *utail;
|
BList *utail;
|
||||||
VtRendez *unlink;
|
Rendez unlink;
|
||||||
|
|
||||||
/* block counts */
|
/* block counts */
|
||||||
int nused;
|
int nused;
|
||||||
@ -95,7 +95,7 @@ struct BAddr {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct FreeList {
|
struct FreeList {
|
||||||
VtLock *lk;
|
QLock lk;
|
||||||
u32int last; /* last block allocated */
|
u32int last; /* last block allocated */
|
||||||
u32int end; /* end of data partition */
|
u32int end; /* end of data partition */
|
||||||
u32int nused; /* number of used blocks */
|
u32int nused; /* number of used blocks */
|
||||||
@ -123,28 +123,28 @@ static void doRemoveLink(Cache*, BList*);
|
|||||||
*/
|
*/
|
||||||
int vtType[BtMax] = {
|
int vtType[BtMax] = {
|
||||||
VtDataType, /* BtData | 0 */
|
VtDataType, /* BtData | 0 */
|
||||||
VtPointerType0, /* BtData | 1 */
|
VtDataType+1, /* BtData | 1 */
|
||||||
VtPointerType1, /* BtData | 2 */
|
VtDataType+2, /* BtData | 2 */
|
||||||
VtPointerType2, /* BtData | 3 */
|
VtDataType+3, /* BtData | 3 */
|
||||||
VtPointerType3, /* BtData | 4 */
|
VtDataType+4, /* BtData | 4 */
|
||||||
VtPointerType4, /* BtData | 5 */
|
VtDataType+5, /* BtData | 5 */
|
||||||
VtPointerType5, /* BtData | 6 */
|
VtDataType+6, /* BtData | 6 */
|
||||||
VtPointerType6, /* BtData | 7 */
|
VtDataType+7, /* BtData | 7 */
|
||||||
VtDirType, /* BtDir | 0 */
|
VtDirType, /* BtDir | 0 */
|
||||||
VtPointerType0, /* BtDir | 1 */
|
VtDirType+1, /* BtDir | 1 */
|
||||||
VtPointerType1, /* BtDir | 2 */
|
VtDirType+2, /* BtDir | 2 */
|
||||||
VtPointerType2, /* BtDir | 3 */
|
VtDirType+3, /* BtDir | 3 */
|
||||||
VtPointerType3, /* BtDir | 4 */
|
VtDirType+4, /* BtDir | 4 */
|
||||||
VtPointerType4, /* BtDir | 5 */
|
VtDirType+5, /* BtDir | 5 */
|
||||||
VtPointerType5, /* BtDir | 6 */
|
VtDirType+6, /* BtDir | 6 */
|
||||||
VtPointerType6, /* BtDir | 7 */
|
VtDirType+7, /* BtDir | 7 */
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Allocate the memory cache.
|
* Allocate the memory cache.
|
||||||
*/
|
*/
|
||||||
Cache *
|
Cache *
|
||||||
cacheAlloc(Disk *disk, VtSession *z, ulong nblocks, int mode)
|
cacheAlloc(Disk *disk, VtConn *z, ulong nblocks, int mode)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
Cache *c;
|
Cache *c;
|
||||||
@ -153,12 +153,11 @@ cacheAlloc(Disk *disk, VtSession *z, ulong nblocks, int mode)
|
|||||||
u8int *p;
|
u8int *p;
|
||||||
int nbl;
|
int nbl;
|
||||||
|
|
||||||
c = vtMemAllocZ(sizeof(Cache));
|
c = vtmallocz(sizeof(Cache));
|
||||||
|
|
||||||
/* reasonable number of BList elements */
|
/* reasonable number of BList elements */
|
||||||
nbl = nblocks * 4;
|
nbl = nblocks * 4;
|
||||||
|
|
||||||
c->lk = vtLockAlloc();
|
|
||||||
c->ref = 1;
|
c->ref = 1;
|
||||||
c->disk = disk;
|
c->disk = disk;
|
||||||
c->z = z;
|
c->z = z;
|
||||||
@ -169,21 +168,20 @@ bwatchSetBlockSize(c->size);
|
|||||||
c->ndmap = (c->size/20 + 7) / 8;
|
c->ndmap = (c->size/20 + 7) / 8;
|
||||||
c->nblocks = nblocks;
|
c->nblocks = nblocks;
|
||||||
c->hashSize = nblocks;
|
c->hashSize = nblocks;
|
||||||
c->heads = vtMemAllocZ(c->hashSize*sizeof(Block*));
|
c->heads = vtmallocz(c->hashSize*sizeof(Block*));
|
||||||
c->heap = vtMemAllocZ(nblocks*sizeof(Block*));
|
c->heap = vtmallocz(nblocks*sizeof(Block*));
|
||||||
c->blocks = vtMemAllocZ(nblocks*sizeof(Block));
|
c->blocks = vtmallocz(nblocks*sizeof(Block));
|
||||||
c->mem = vtMemAllocZ(nblocks * (c->size + c->ndmap) + nbl * sizeof(BList));
|
c->mem = vtmallocz(nblocks * (c->size + c->ndmap) + nbl * sizeof(BList));
|
||||||
c->baddr = vtMemAllocZ(nblocks * sizeof(BAddr));
|
c->baddr = vtmallocz(nblocks * sizeof(BAddr));
|
||||||
c->mode = mode;
|
c->mode = mode;
|
||||||
c->vers++;
|
c->vers++;
|
||||||
p = c->mem;
|
p = c->mem;
|
||||||
for(i = 0; i < nblocks; i++){
|
for(i = 0; i < nblocks; i++){
|
||||||
b = &c->blocks[i];
|
b = &c->blocks[i];
|
||||||
b->lk = vtLockAlloc();
|
|
||||||
b->c = c;
|
b->c = c;
|
||||||
b->data = p;
|
b->data = p;
|
||||||
b->heap = i;
|
b->heap = i;
|
||||||
b->ioready = vtRendezAlloc(b->lk);
|
b->ioready.l = &b->lk;
|
||||||
c->heap[i] = b;
|
c->heap[i] = b;
|
||||||
p += c->size;
|
p += c->size;
|
||||||
}
|
}
|
||||||
@ -201,22 +199,22 @@ bwatchSetBlockSize(c->size);
|
|||||||
p += c->ndmap;
|
p += c->ndmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
c->blrend = vtRendezAlloc(c->lk);
|
c->blrend.l = &c->lk;
|
||||||
|
|
||||||
c->maxdirty = nblocks*(DirtyPercentage*0.01);
|
c->maxdirty = nblocks*(DirtyPercentage*0.01);
|
||||||
|
|
||||||
c->fl = flAlloc(diskSize(disk, PartData));
|
c->fl = flAlloc(diskSize(disk, PartData));
|
||||||
|
|
||||||
c->unlink = vtRendezAlloc(c->lk);
|
c->unlink.l = &c->lk;
|
||||||
c->flush = vtRendezAlloc(c->lk);
|
c->flush.l = &c->lk;
|
||||||
c->flushwait = vtRendezAlloc(c->lk);
|
c->flushwait.l = &c->lk;
|
||||||
c->heapwait = vtRendezAlloc(c->lk);
|
c->heapwait.l = &c->lk;
|
||||||
c->sync = periodicAlloc(cacheSync, c, 30*1000);
|
c->sync = periodicAlloc(cacheSync, c, 30*1000);
|
||||||
|
|
||||||
if(mode == OReadWrite){
|
if(mode == OReadWrite){
|
||||||
c->ref += 2;
|
c->ref += 2;
|
||||||
vtThread(unlinkThread, c);
|
proccreate(unlinkThread, c, STACK);
|
||||||
vtThread(flushThread, c);
|
proccreate(flushThread, c, STACK);
|
||||||
}
|
}
|
||||||
cacheCheck(c);
|
cacheCheck(c);
|
||||||
|
|
||||||
@ -232,42 +230,38 @@ cacheFree(Cache *c)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* kill off daemon threads */
|
/* kill off daemon threads */
|
||||||
vtLock(c->lk);
|
qlock(&c->lk);
|
||||||
c->die = vtRendezAlloc(c->lk);
|
c->die.l = &c->lk;
|
||||||
periodicKill(c->sync);
|
periodicKill(c->sync);
|
||||||
vtWakeup(c->flush);
|
rwakeup(&c->flush);
|
||||||
vtWakeup(c->unlink);
|
rwakeup(&c->unlink);
|
||||||
while(c->ref > 1)
|
while(c->ref > 1)
|
||||||
vtSleep(c->die);
|
rsleep(&c->die);
|
||||||
|
|
||||||
/* flush everything out */
|
/* flush everything out */
|
||||||
do {
|
do {
|
||||||
unlinkBody(c);
|
unlinkBody(c);
|
||||||
vtUnlock(c->lk);
|
qunlock(&c->lk);
|
||||||
while(cacheFlushBlock(c))
|
while(cacheFlushBlock(c))
|
||||||
;
|
;
|
||||||
diskFlush(c->disk);
|
diskFlush(c->disk);
|
||||||
vtLock(c->lk);
|
qlock(&c->lk);
|
||||||
} while(c->uhead || c->ndirty);
|
} while(c->uhead || c->ndirty);
|
||||||
vtUnlock(c->lk);
|
qunlock(&c->lk);
|
||||||
|
|
||||||
cacheCheck(c);
|
cacheCheck(c);
|
||||||
|
|
||||||
for(i = 0; i < c->nblocks; i++){
|
for(i = 0; i < c->nblocks; i++){
|
||||||
assert(c->blocks[i].ref == 0);
|
assert(c->blocks[i].ref == 0);
|
||||||
vtRendezFree(c->blocks[i].ioready);
|
|
||||||
vtLockFree(c->blocks[i].lk);
|
|
||||||
}
|
}
|
||||||
flFree(c->fl);
|
flFree(c->fl);
|
||||||
vtMemFree(c->baddr);
|
vtfree(c->baddr);
|
||||||
vtMemFree(c->heads);
|
vtfree(c->heads);
|
||||||
vtMemFree(c->blocks);
|
vtfree(c->blocks);
|
||||||
vtMemFree(c->mem);
|
vtfree(c->mem);
|
||||||
vtLockFree(c->lk);
|
|
||||||
diskFree(c->disk);
|
diskFree(c->disk);
|
||||||
vtRendezFree(c->blrend);
|
|
||||||
/* don't close vtSession */
|
/* don't close vtSession */
|
||||||
vtMemFree(c);
|
vtfree(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -297,22 +291,22 @@ cacheCheck(Cache *c)
|
|||||||
|
|
||||||
for(i = 0; i < c->nheap; i++){
|
for(i = 0; i < c->nheap; i++){
|
||||||
if(c->heap[i]->heap != i)
|
if(c->heap[i]->heap != i)
|
||||||
vtFatal("mis-heaped at %d: %d", i, c->heap[i]->heap);
|
sysfatal("mis-heaped at %d: %d", i, c->heap[i]->heap);
|
||||||
if(i > 0 && c->heap[(i - 1) >> 1]->used - now > c->heap[i]->used - now)
|
if(i > 0 && c->heap[(i - 1) >> 1]->used - now > c->heap[i]->used - now)
|
||||||
vtFatal("bad heap ordering");
|
sysfatal("bad heap ordering");
|
||||||
k = (i << 1) + 1;
|
k = (i << 1) + 1;
|
||||||
if(k < c->nheap && c->heap[i]->used - now > c->heap[k]->used - now)
|
if(k < c->nheap && c->heap[i]->used - now > c->heap[k]->used - now)
|
||||||
vtFatal("bad heap ordering");
|
sysfatal("bad heap ordering");
|
||||||
k++;
|
k++;
|
||||||
if(k < c->nheap && c->heap[i]->used - now > c->heap[k]->used - now)
|
if(k < c->nheap && c->heap[i]->used - now > c->heap[k]->used - now)
|
||||||
vtFatal("bad heap ordering");
|
sysfatal("bad heap ordering");
|
||||||
}
|
}
|
||||||
|
|
||||||
refed = 0;
|
refed = 0;
|
||||||
for(i = 0; i < c->nblocks; i++){
|
for(i = 0; i < c->nblocks; i++){
|
||||||
b = &c->blocks[i];
|
b = &c->blocks[i];
|
||||||
if(b->data != &c->mem[i * size])
|
if(b->data != &c->mem[i * size])
|
||||||
vtFatal("mis-blocked at %d", i);
|
sysfatal("mis-blocked at %d", i);
|
||||||
if(b->ref && b->heap == BadHeap){
|
if(b->ref && b->heap == BadHeap){
|
||||||
refed++;
|
refed++;
|
||||||
}
|
}
|
||||||
@ -352,8 +346,8 @@ cacheBumpBlock(Cache *c)
|
|||||||
printed = 0;
|
printed = 0;
|
||||||
if(c->nheap == 0){
|
if(c->nheap == 0){
|
||||||
while(c->nheap == 0){
|
while(c->nheap == 0){
|
||||||
vtWakeup(c->flush);
|
rwakeup(&c->flush);
|
||||||
vtSleep(c->heapwait);
|
rsleep(&c->heapwait);
|
||||||
if(c->nheap == 0){
|
if(c->nheap == 0){
|
||||||
printed = 1;
|
printed = 1;
|
||||||
fprint(2, "%s: entire cache is busy, %d dirty "
|
fprint(2, "%s: entire cache is busy, %d dirty "
|
||||||
@ -414,27 +408,27 @@ _cacheLocalLookup(Cache *c, int part, u32int addr, u32int vers,
|
|||||||
/*
|
/*
|
||||||
* look for the block in the cache
|
* look for the block in the cache
|
||||||
*/
|
*/
|
||||||
vtLock(c->lk);
|
qlock(&c->lk);
|
||||||
for(b = c->heads[h]; b != nil; b = b->next){
|
for(b = c->heads[h]; b != nil; b = b->next){
|
||||||
if(b->part == part && b->addr == addr)
|
if(b->part == part && b->addr == addr)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(b == nil || b->vers != vers){
|
if(b == nil || b->vers != vers){
|
||||||
vtUnlock(c->lk);
|
qunlock(&c->lk);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
if(!waitlock && !vtCanLock(b->lk)){
|
if(!waitlock && !canqlock(&b->lk)){
|
||||||
*lockfailure = 1;
|
*lockfailure = 1;
|
||||||
vtUnlock(c->lk);
|
qunlock(&c->lk);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
heapDel(b);
|
heapDel(b);
|
||||||
b->ref++;
|
b->ref++;
|
||||||
vtUnlock(c->lk);
|
qunlock(&c->lk);
|
||||||
|
|
||||||
bwatchLock(b);
|
bwatchLock(b);
|
||||||
if(waitlock)
|
if(waitlock)
|
||||||
vtLock(b->lk);
|
qlock(&b->lk);
|
||||||
b->nlock = 1;
|
b->nlock = 1;
|
||||||
|
|
||||||
for(;;){
|
for(;;){
|
||||||
@ -452,15 +446,15 @@ _cacheLocalLookup(Cache *c, int part, u32int addr, u32int vers,
|
|||||||
return b;
|
return b;
|
||||||
case BioReading:
|
case BioReading:
|
||||||
case BioWriting:
|
case BioWriting:
|
||||||
vtSleep(b->ioready);
|
rsleep(&b->ioready);
|
||||||
break;
|
break;
|
||||||
case BioVentiError:
|
case BioVentiError:
|
||||||
blockPut(b);
|
blockPut(b);
|
||||||
vtSetError("venti i/o error block 0x%.8ux", addr);
|
werrstr("venti i/o error block 0x%.8ux", addr);
|
||||||
return nil;
|
return nil;
|
||||||
case BioReadError:
|
case BioReadError:
|
||||||
blockPut(b);
|
blockPut(b);
|
||||||
vtSetError("error reading block 0x%.8ux", addr);
|
werrstr("error reading block 0x%.8ux", addr);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -490,14 +484,14 @@ _cacheLocal(Cache *c, int part, u32int addr, int mode, u32int epoch)
|
|||||||
/*
|
/*
|
||||||
* look for the block in the cache
|
* look for the block in the cache
|
||||||
*/
|
*/
|
||||||
vtLock(c->lk);
|
qlock(&c->lk);
|
||||||
for(b = c->heads[h]; b != nil; b = b->next){
|
for(b = c->heads[h]; b != nil; b = b->next){
|
||||||
if(b->part != part || b->addr != addr)
|
if(b->part != part || b->addr != addr)
|
||||||
continue;
|
continue;
|
||||||
if(epoch && b->l.epoch != epoch){
|
if(epoch && b->l.epoch != epoch){
|
||||||
fprint(2, "%s: _cacheLocal want epoch %ud got %ud\n", argv0, epoch, b->l.epoch);
|
fprint(2, "%s: _cacheLocal want epoch %ud got %ud\n", argv0, epoch, b->l.epoch);
|
||||||
vtUnlock(c->lk);
|
qunlock(&c->lk);
|
||||||
vtSetError(ELabelMismatch);
|
werrstr(ELabelMismatch);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
heapDel(b);
|
heapDel(b);
|
||||||
@ -520,7 +514,7 @@ fprint(2, "%s: _cacheLocal want epoch %ud got %ud\n", argv0, epoch, b->l.epoch);
|
|||||||
b->prev = &c->heads[h];
|
b->prev = &c->heads[h];
|
||||||
}
|
}
|
||||||
|
|
||||||
vtUnlock(c->lk);
|
qunlock(&c->lk);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* BUG: what if the epoch changes right here?
|
* BUG: what if the epoch changes right here?
|
||||||
@ -534,7 +528,7 @@ fprint(2, "%s: _cacheLocal want epoch %ud got %ud\n", argv0, epoch, b->l.epoch);
|
|||||||
|
|
||||||
if(0)fprint(2, "%s: cacheLocal: %d: %d %x\n", argv0, getpid(), b->part, b->addr);
|
if(0)fprint(2, "%s: cacheLocal: %d: %d %x\n", argv0, getpid(), b->part, b->addr);
|
||||||
bwatchLock(b);
|
bwatchLock(b);
|
||||||
vtLock(b->lk);
|
qlock(&b->lk);
|
||||||
b->nlock = 1;
|
b->nlock = 1;
|
||||||
|
|
||||||
if(part == PartData && b->iostate == BioEmpty){
|
if(part == PartData && b->iostate == BioEmpty){
|
||||||
@ -547,7 +541,7 @@ if(0)fprint(2, "%s: cacheLocal: %d: %d %x\n", argv0, getpid(), b->part, b->addr)
|
|||||||
if(epoch && b->l.epoch != epoch){
|
if(epoch && b->l.epoch != epoch){
|
||||||
blockPut(b);
|
blockPut(b);
|
||||||
fprint(2, "%s: _cacheLocal want epoch %ud got %ud\n", argv0, epoch, b->l.epoch);
|
fprint(2, "%s: _cacheLocal want epoch %ud got %ud\n", argv0, epoch, b->l.epoch);
|
||||||
vtSetError(ELabelMismatch);
|
werrstr(ELabelMismatch);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -566,19 +560,19 @@ fprint(2, "%s: _cacheLocal want epoch %ud got %ud\n", argv0, epoch, b->l.epoch);
|
|||||||
/* fall through */
|
/* fall through */
|
||||||
case BioEmpty:
|
case BioEmpty:
|
||||||
diskRead(c->disk, b);
|
diskRead(c->disk, b);
|
||||||
vtSleep(b->ioready);
|
rsleep(&b->ioready);
|
||||||
break;
|
break;
|
||||||
case BioClean:
|
case BioClean:
|
||||||
case BioDirty:
|
case BioDirty:
|
||||||
return b;
|
return b;
|
||||||
case BioReading:
|
case BioReading:
|
||||||
case BioWriting:
|
case BioWriting:
|
||||||
vtSleep(b->ioready);
|
rsleep(&b->ioready);
|
||||||
break;
|
break;
|
||||||
case BioReadError:
|
case BioReadError:
|
||||||
blockSetIOState(b, BioEmpty);
|
blockSetIOState(b, BioEmpty);
|
||||||
blockPut(b);
|
blockPut(b);
|
||||||
vtSetError("error reading block 0x%.8ux", addr);
|
werrstr("error reading block 0x%.8ux", addr);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -607,7 +601,7 @@ cacheLocalData(Cache *c, u32int addr, int type, u32int tag, int mode, u32int epo
|
|||||||
if(b->l.type != type || b->l.tag != tag){
|
if(b->l.type != type || b->l.tag != tag){
|
||||||
fprint(2, "%s: cacheLocalData: addr=%d type got %d exp %d: tag got %ux exp %ux\n",
|
fprint(2, "%s: cacheLocalData: addr=%d type got %d exp %d: tag got %ux exp %ux\n",
|
||||||
argv0, addr, b->l.type, type, b->l.tag, tag);
|
argv0, addr, b->l.type, type, b->l.tag, tag);
|
||||||
vtSetError(ELabelMismatch);
|
werrstr(ELabelMismatch);
|
||||||
blockPut(b);
|
blockPut(b);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
@ -641,7 +635,7 @@ cacheGlobal(Cache *c, uchar score[VtScoreSize], int type, u32int tag, int mode)
|
|||||||
/*
|
/*
|
||||||
* look for the block in the cache
|
* look for the block in the cache
|
||||||
*/
|
*/
|
||||||
vtLock(c->lk);
|
qlock(&c->lk);
|
||||||
for(b = c->heads[h]; b != nil; b = b->next){
|
for(b = c->heads[h]; b != nil; b = b->next){
|
||||||
if(b->part != PartVenti || memcmp(b->score, score, VtScoreSize) != 0 || b->l.type != type)
|
if(b->part != PartVenti || memcmp(b->score, score, VtScoreSize) != 0 || b->l.type != type)
|
||||||
continue;
|
continue;
|
||||||
@ -667,10 +661,10 @@ if(0)fprint(2, "%s: cacheGlobal %V %d\n", argv0, score, type);
|
|||||||
b->next->prev = &b->next;
|
b->next->prev = &b->next;
|
||||||
b->prev = &c->heads[h];
|
b->prev = &c->heads[h];
|
||||||
}
|
}
|
||||||
vtUnlock(c->lk);
|
qunlock(&c->lk);
|
||||||
|
|
||||||
bwatchLock(b);
|
bwatchLock(b);
|
||||||
vtLock(b->lk);
|
qlock(&b->lk);
|
||||||
b->nlock = 1;
|
b->nlock = 1;
|
||||||
b->pc = getcallerpc(&c);
|
b->pc = getcallerpc(&c);
|
||||||
|
|
||||||
@ -678,27 +672,27 @@ if(0)fprint(2, "%s: cacheGlobal %V %d\n", argv0, score, type);
|
|||||||
default:
|
default:
|
||||||
abort();
|
abort();
|
||||||
case BioEmpty:
|
case BioEmpty:
|
||||||
n = vtRead(c->z, score, vtType[type], b->data, c->size);
|
n = vtread(c->z, score, vtType[type], b->data, c->size);
|
||||||
if(n < 0 || !vtSha1Check(score, b->data, n)){
|
if(n < 0 || vtsha1check(score, b->data, n) < 0){
|
||||||
blockSetIOState(b, BioVentiError);
|
blockSetIOState(b, BioVentiError);
|
||||||
blockPut(b);
|
blockPut(b);
|
||||||
vtSetError(
|
werrstr(
|
||||||
"venti error reading block %V or wrong score: %r",
|
"venti error reading block %V or wrong score: %r",
|
||||||
score);
|
score);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
vtZeroExtend(vtType[type], b->data, n, c->size);
|
vtzeroextend(vtType[type], b->data, n, c->size);
|
||||||
blockSetIOState(b, BioClean);
|
blockSetIOState(b, BioClean);
|
||||||
return b;
|
return b;
|
||||||
case BioClean:
|
case BioClean:
|
||||||
return b;
|
return b;
|
||||||
case BioVentiError:
|
case BioVentiError:
|
||||||
blockPut(b);
|
blockPut(b);
|
||||||
vtSetError("venti i/o error or wrong score, block %V", score);
|
werrstr("venti i/o error or wrong score, block %V", score);
|
||||||
return nil;
|
return nil;
|
||||||
case BioReadError:
|
case BioReadError:
|
||||||
blockPut(b);
|
blockPut(b);
|
||||||
vtSetError("error reading block %V", b->score);
|
werrstr("error reading block %V", b->score);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
/* NOT REACHED */
|
/* NOT REACHED */
|
||||||
@ -722,12 +716,12 @@ cacheAllocBlock(Cache *c, int type, u32int tag, u32int epoch, u32int epochLow)
|
|||||||
n = c->size / LabelSize;
|
n = c->size / LabelSize;
|
||||||
fl = c->fl;
|
fl = c->fl;
|
||||||
|
|
||||||
vtLock(fl->lk);
|
qlock(&fl->lk);
|
||||||
addr = fl->last;
|
addr = fl->last;
|
||||||
b = cacheLocal(c, PartLabel, addr/n, OReadOnly);
|
b = cacheLocal(c, PartLabel, addr/n, OReadOnly);
|
||||||
if(b == nil){
|
if(b == nil){
|
||||||
fprint(2, "%s: cacheAllocBlock: xxx %R\n", argv0);
|
fprint(2, "%s: cacheAllocBlock: xxx %r\n", argv0);
|
||||||
vtUnlock(fl->lk);
|
qunlock(&fl->lk);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
nwrap = 0;
|
nwrap = 0;
|
||||||
@ -736,16 +730,16 @@ cacheAllocBlock(Cache *c, int type, u32int tag, u32int epoch, u32int epochLow)
|
|||||||
addr = 0;
|
addr = 0;
|
||||||
if(++nwrap >= 2){
|
if(++nwrap >= 2){
|
||||||
blockPut(b);
|
blockPut(b);
|
||||||
vtSetError("disk is full");
|
werrstr("disk is full");
|
||||||
/*
|
/*
|
||||||
* try to avoid a continuous spew of console
|
* try to avoid a continuous spew of console
|
||||||
* messages.
|
* messages.
|
||||||
*/
|
*/
|
||||||
if (fl->last != 0)
|
if (fl->last != 0)
|
||||||
fprint(2, "%s: cacheAllocBlock: xxx1 %R\n",
|
fprint(2, "%s: cacheAllocBlock: xxx1 %r\n",
|
||||||
argv0);
|
argv0);
|
||||||
fl->last = 0;
|
fl->last = 0;
|
||||||
vtUnlock(fl->lk);
|
qunlock(&fl->lk);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -754,8 +748,8 @@ cacheAllocBlock(Cache *c, int type, u32int tag, u32int epoch, u32int epochLow)
|
|||||||
b = cacheLocal(c, PartLabel, addr/n, OReadOnly);
|
b = cacheLocal(c, PartLabel, addr/n, OReadOnly);
|
||||||
if(b == nil){
|
if(b == nil){
|
||||||
fl->last = addr;
|
fl->last = addr;
|
||||||
fprint(2, "%s: cacheAllocBlock: xxx2 %R\n", argv0);
|
fprint(2, "%s: cacheAllocBlock: xxx2 %r\n", argv0);
|
||||||
vtUnlock(fl->lk);
|
qunlock(&fl->lk);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -771,7 +765,7 @@ Found:
|
|||||||
blockPut(b);
|
blockPut(b);
|
||||||
b = cacheLocal(c, PartData, addr, OOverWrite);
|
b = cacheLocal(c, PartData, addr, OOverWrite);
|
||||||
if(b == nil){
|
if(b == nil){
|
||||||
fprint(2, "%s: cacheAllocBlock: xxx3 %R\n", argv0);
|
fprint(2, "%s: cacheAllocBlock: xxx3 %r\n", argv0);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
assert(b->iostate == BioLabel || b->iostate == BioClean);
|
assert(b->iostate == BioLabel || b->iostate == BioClean);
|
||||||
@ -782,17 +776,17 @@ assert(b->iostate == BioLabel || b->iostate == BioClean);
|
|||||||
lab.epoch = epoch;
|
lab.epoch = epoch;
|
||||||
lab.epochClose = ~(u32int)0;
|
lab.epochClose = ~(u32int)0;
|
||||||
if(!blockSetLabel(b, &lab, 1)){
|
if(!blockSetLabel(b, &lab, 1)){
|
||||||
fprint(2, "%s: cacheAllocBlock: xxx4 %R\n", argv0);
|
fprint(2, "%s: cacheAllocBlock: xxx4 %r\n", argv0);
|
||||||
blockPut(b);
|
blockPut(b);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
vtZeroExtend(vtType[type], b->data, 0, c->size);
|
vtzeroextend(vtType[type], b->data, 0, c->size);
|
||||||
if(0)diskWrite(c->disk, b);
|
if(0)diskWrite(c->disk, b);
|
||||||
|
|
||||||
if(0)fprint(2, "%s: fsAlloc %ud type=%d tag = %ux\n", argv0, addr, type, tag);
|
if(0)fprint(2, "%s: fsAlloc %ud type=%d tag = %ux\n", argv0, addr, type, tag);
|
||||||
lastAlloc = addr;
|
lastAlloc = addr;
|
||||||
fl->nused++;
|
fl->nused++;
|
||||||
vtUnlock(fl->lk);
|
qunlock(&fl->lk);
|
||||||
b->pc = getcallerpc(&c);
|
b->pc = getcallerpc(&c);
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
@ -815,11 +809,11 @@ cacheCountUsed(Cache *c, u32int epochLow, u32int *used, u32int *total, u32int *b
|
|||||||
fl = c->fl;
|
fl = c->fl;
|
||||||
n = c->size / LabelSize;
|
n = c->size / LabelSize;
|
||||||
*bsize = c->size;
|
*bsize = c->size;
|
||||||
vtLock(fl->lk);
|
qlock(&fl->lk);
|
||||||
if(fl->epochLow == epochLow){
|
if(fl->epochLow == epochLow){
|
||||||
*used = fl->nused;
|
*used = fl->nused;
|
||||||
*total = fl->end;
|
*total = fl->end;
|
||||||
vtUnlock(fl->lk);
|
qunlock(&fl->lk);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
b = nil;
|
b = nil;
|
||||||
@ -829,7 +823,7 @@ cacheCountUsed(Cache *c, u32int epochLow, u32int *used, u32int *total, u32int *b
|
|||||||
blockPut(b);
|
blockPut(b);
|
||||||
b = cacheLocal(c, PartLabel, addr/n, OReadOnly);
|
b = cacheLocal(c, PartLabel, addr/n, OReadOnly);
|
||||||
if(b == nil){
|
if(b == nil){
|
||||||
fprint(2, "%s: flCountUsed: loading %ux: %R\n",
|
fprint(2, "%s: flCountUsed: loading %ux: %r\n",
|
||||||
argv0, addr/n);
|
argv0, addr/n);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -850,7 +844,7 @@ cacheCountUsed(Cache *c, u32int epochLow, u32int *used, u32int *total, u32int *b
|
|||||||
}
|
}
|
||||||
*used = nused;
|
*used = nused;
|
||||||
*total = fl->end;
|
*total = fl->end;
|
||||||
vtUnlock(fl->lk);
|
qunlock(&fl->lk);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -859,8 +853,7 @@ flAlloc(u32int end)
|
|||||||
{
|
{
|
||||||
FreeList *fl;
|
FreeList *fl;
|
||||||
|
|
||||||
fl = vtMemAllocZ(sizeof(*fl));
|
fl = vtmallocz(sizeof(*fl));
|
||||||
fl->lk = vtLockAlloc();
|
|
||||||
fl->last = 0;
|
fl->last = 0;
|
||||||
fl->end = end;
|
fl->end = end;
|
||||||
return fl;
|
return fl;
|
||||||
@ -869,8 +862,7 @@ flAlloc(u32int end)
|
|||||||
static void
|
static void
|
||||||
flFree(FreeList *fl)
|
flFree(FreeList *fl)
|
||||||
{
|
{
|
||||||
vtLockFree(fl->lk);
|
vtfree(fl);
|
||||||
vtMemFree(fl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
u32int
|
u32int
|
||||||
@ -914,8 +906,8 @@ if(0)fprint(2, "%s: blockPut: %d: %d %x %d %s\n", argv0, getpid(), b->part, b->a
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* b->nlock should probably stay at zero while
|
* b->nlock should probably stay at zero while
|
||||||
* the block is unlocked, but diskThread and vtSleep
|
* the block is unlocked, but diskThread and rsleep
|
||||||
* conspire to assume that they can just vtLock(b->lk); blockPut(b),
|
* conspire to assume that they can just qlock(&b->lk); blockPut(b),
|
||||||
* so we have to keep b->nlock set to 1 even
|
* so we have to keep b->nlock set to 1 even
|
||||||
* when the block is unlocked.
|
* when the block is unlocked.
|
||||||
*/
|
*/
|
||||||
@ -924,12 +916,12 @@ if(0)fprint(2, "%s: blockPut: %d: %d %x %d %s\n", argv0, getpid(), b->part, b->a
|
|||||||
// b->pc = 0;
|
// b->pc = 0;
|
||||||
|
|
||||||
bwatchUnlock(b);
|
bwatchUnlock(b);
|
||||||
vtUnlock(b->lk);
|
qunlock(&b->lk);
|
||||||
c = b->c;
|
c = b->c;
|
||||||
vtLock(c->lk);
|
qlock(&c->lk);
|
||||||
|
|
||||||
if(--b->ref > 0){
|
if(--b->ref > 0){
|
||||||
vtUnlock(c->lk);
|
qunlock(&c->lk);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -950,7 +942,7 @@ if(0)fprint(2, "%s: blockPut: %d: %d %x %d %s\n", argv0, getpid(), b->part, b->a
|
|||||||
case BioDirty:
|
case BioDirty:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
vtUnlock(c->lk);
|
qunlock(&c->lk);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1098,12 +1090,12 @@ blockDirty(Block *b)
|
|||||||
return 1;
|
return 1;
|
||||||
assert(b->iostate == BioClean || b->iostate == BioLabel);
|
assert(b->iostate == BioClean || b->iostate == BioLabel);
|
||||||
|
|
||||||
vtLock(c->lk);
|
qlock(&c->lk);
|
||||||
b->iostate = BioDirty;
|
b->iostate = BioDirty;
|
||||||
c->ndirty++;
|
c->ndirty++;
|
||||||
if(c->ndirty > (c->maxdirty>>1))
|
if(c->ndirty > (c->maxdirty>>1))
|
||||||
vtWakeup(c->flush);
|
rwakeup(&c->flush);
|
||||||
vtUnlock(c->lk);
|
qunlock(&c->lk);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -1288,7 +1280,7 @@ if(0) fprint(2, "%s: iostate part=%d addr=%x %s->%s\n", argv0, b->part, b->addr,
|
|||||||
* queue to the cache unlink queue.
|
* queue to the cache unlink queue.
|
||||||
*/
|
*/
|
||||||
if(b->iostate == BioDirty || b->iostate == BioWriting){
|
if(b->iostate == BioDirty || b->iostate == BioWriting){
|
||||||
vtLock(c->lk);
|
qlock(&c->lk);
|
||||||
c->ndirty--;
|
c->ndirty--;
|
||||||
b->iostate = iostate; /* change here to keep in sync with ndirty */
|
b->iostate = iostate; /* change here to keep in sync with ndirty */
|
||||||
b->vers = c->vers++;
|
b->vers = c->vers++;
|
||||||
@ -1296,13 +1288,13 @@ if(0) fprint(2, "%s: iostate part=%d addr=%x %s->%s\n", argv0, b->part, b->addr,
|
|||||||
/* add unlink blocks to unlink queue */
|
/* add unlink blocks to unlink queue */
|
||||||
if(c->uhead == nil){
|
if(c->uhead == nil){
|
||||||
c->uhead = b->uhead;
|
c->uhead = b->uhead;
|
||||||
vtWakeup(c->unlink);
|
rwakeup(&c->unlink);
|
||||||
}else
|
}else
|
||||||
c->utail->next = b->uhead;
|
c->utail->next = b->uhead;
|
||||||
c->utail = b->utail;
|
c->utail = b->utail;
|
||||||
b->uhead = nil;
|
b->uhead = nil;
|
||||||
}
|
}
|
||||||
vtUnlock(c->lk);
|
qunlock(&c->lk);
|
||||||
}
|
}
|
||||||
assert(!b->uhead);
|
assert(!b->uhead);
|
||||||
dowakeup = 1;
|
dowakeup = 1;
|
||||||
@ -1313,9 +1305,9 @@ if(0) fprint(2, "%s: iostate part=%d addr=%x %s->%s\n", argv0, b->part, b->addr,
|
|||||||
* Bump a version count, leave it dirty.
|
* Bump a version count, leave it dirty.
|
||||||
*/
|
*/
|
||||||
if(b->iostate == BioWriting){
|
if(b->iostate == BioWriting){
|
||||||
vtLock(c->lk);
|
qlock(&c->lk);
|
||||||
b->vers = c->vers++;
|
b->vers = c->vers++;
|
||||||
vtUnlock(c->lk);
|
qunlock(&c->lk);
|
||||||
dowakeup = 1;
|
dowakeup = 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -1327,9 +1319,9 @@ if(0) fprint(2, "%s: iostate part=%d addr=%x %s->%s\n", argv0, b->part, b->addr,
|
|||||||
* This is here because we need to lock c->lk to
|
* This is here because we need to lock c->lk to
|
||||||
* manipulate the ref count.
|
* manipulate the ref count.
|
||||||
*/
|
*/
|
||||||
vtLock(c->lk);
|
qlock(&c->lk);
|
||||||
b->ref++;
|
b->ref++;
|
||||||
vtUnlock(c->lk);
|
qunlock(&c->lk);
|
||||||
break;
|
break;
|
||||||
case BioReadError:
|
case BioReadError:
|
||||||
case BioVentiError:
|
case BioVentiError:
|
||||||
@ -1344,7 +1336,7 @@ if(0) fprint(2, "%s: iostate part=%d addr=%x %s->%s\n", argv0, b->part, b->addr,
|
|||||||
* Now that the state has changed, we can wake the waiters.
|
* Now that the state has changed, we can wake the waiters.
|
||||||
*/
|
*/
|
||||||
if(dowakeup)
|
if(dowakeup)
|
||||||
vtWakeupAll(b->ioready);
|
rwakeupall(&b->ioready);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1571,11 +1563,11 @@ doRemoveLink(Cache *c, BList *p)
|
|||||||
l.state |= BsClosed;
|
l.state |= BsClosed;
|
||||||
l.epochClose = p->epoch;
|
l.epochClose = p->epoch;
|
||||||
if(l.epochClose == l.epoch){
|
if(l.epochClose == l.epoch){
|
||||||
vtLock(c->fl->lk);
|
qlock(&c->fl->lk);
|
||||||
if(l.epoch == c->fl->epochLow)
|
if(l.epoch == c->fl->epochLow)
|
||||||
c->fl->nused--;
|
c->fl->nused--;
|
||||||
blockSetLabel(b, &l, 0);
|
blockSetLabel(b, &l, 0);
|
||||||
vtUnlock(c->fl->lk);
|
qunlock(&c->fl->lk);
|
||||||
}else
|
}else
|
||||||
blockSetLabel(b, &l, 0);
|
blockSetLabel(b, &l, 0);
|
||||||
blockPut(b);
|
blockPut(b);
|
||||||
@ -1603,7 +1595,7 @@ blistAlloc(Block *b)
|
|||||||
}
|
}
|
||||||
|
|
||||||
c = b->c;
|
c = b->c;
|
||||||
vtLock(c->lk);
|
qlock(&c->lk);
|
||||||
if(c->blfree == nil){
|
if(c->blfree == nil){
|
||||||
/*
|
/*
|
||||||
* No free BLists. What are our options?
|
* No free BLists. What are our options?
|
||||||
@ -1611,7 +1603,7 @@ blistAlloc(Block *b)
|
|||||||
|
|
||||||
/* Block has no priors? Just write it. */
|
/* Block has no priors? Just write it. */
|
||||||
if(b->prior == nil){
|
if(b->prior == nil){
|
||||||
vtUnlock(c->lk);
|
qunlock(&c->lk);
|
||||||
diskWriteAndWait(c->disk, b);
|
diskWriteAndWait(c->disk, b);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
@ -1629,8 +1621,8 @@ blistAlloc(Block *b)
|
|||||||
* so it can't deadlock like we can.)
|
* so it can't deadlock like we can.)
|
||||||
*/
|
*/
|
||||||
while(c->blfree == nil){
|
while(c->blfree == nil){
|
||||||
vtWakeup(c->flush);
|
rwakeup(&c->flush);
|
||||||
vtSleep(c->blrend);
|
rsleep(&c->blrend);
|
||||||
if(c->blfree == nil)
|
if(c->blfree == nil)
|
||||||
fprint(2, "%s: flushing for blists\n", argv0);
|
fprint(2, "%s: flushing for blists\n", argv0);
|
||||||
}
|
}
|
||||||
@ -1638,18 +1630,18 @@ blistAlloc(Block *b)
|
|||||||
|
|
||||||
p = c->blfree;
|
p = c->blfree;
|
||||||
c->blfree = p->next;
|
c->blfree = p->next;
|
||||||
vtUnlock(c->lk);
|
qunlock(&c->lk);
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
blistFree(Cache *c, BList *bl)
|
blistFree(Cache *c, BList *bl)
|
||||||
{
|
{
|
||||||
vtLock(c->lk);
|
qlock(&c->lk);
|
||||||
bl->next = c->blfree;
|
bl->next = c->blfree;
|
||||||
c->blfree = bl;
|
c->blfree = bl;
|
||||||
vtWakeup(c->blrend);
|
rwakeup(&c->blrend);
|
||||||
vtUnlock(c->lk);
|
qunlock(&c->lk);
|
||||||
}
|
}
|
||||||
|
|
||||||
char*
|
char*
|
||||||
@ -1843,7 +1835,7 @@ heapIns(Block *b)
|
|||||||
{
|
{
|
||||||
assert(b->heap == BadHeap);
|
assert(b->heap == BadHeap);
|
||||||
upHeap(b->c->nheap++, b);
|
upHeap(b->c->nheap++, b);
|
||||||
vtWakeup(b->c->heapwait);
|
rwakeup(&b->c->heapwait);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1884,9 +1876,9 @@ unlinkBody(Cache *c)
|
|||||||
while(c->uhead != nil){
|
while(c->uhead != nil){
|
||||||
p = c->uhead;
|
p = c->uhead;
|
||||||
c->uhead = p->next;
|
c->uhead = p->next;
|
||||||
vtUnlock(c->lk);
|
qunlock(&c->lk);
|
||||||
doRemoveLink(c, p);
|
doRemoveLink(c, p);
|
||||||
vtLock(c->lk);
|
qlock(&c->lk);
|
||||||
p->next = c->blfree;
|
p->next = c->blfree;
|
||||||
c->blfree = p;
|
c->blfree = p;
|
||||||
}
|
}
|
||||||
@ -1900,19 +1892,19 @@ unlinkThread(void *a)
|
|||||||
{
|
{
|
||||||
Cache *c = a;
|
Cache *c = a;
|
||||||
|
|
||||||
vtThreadSetName("unlink");
|
threadsetname("unlink");
|
||||||
|
|
||||||
vtLock(c->lk);
|
qlock(&c->lk);
|
||||||
for(;;){
|
for(;;){
|
||||||
while(c->uhead == nil && c->die == nil)
|
while(c->uhead == nil && c->die.l == nil)
|
||||||
vtSleep(c->unlink);
|
rsleep(&c->unlink);
|
||||||
if(c->die != nil)
|
if(c->die.l != nil)
|
||||||
break;
|
break;
|
||||||
unlinkBody(c);
|
unlinkBody(c);
|
||||||
}
|
}
|
||||||
c->ref--;
|
c->ref--;
|
||||||
vtWakeup(c->die);
|
rwakeup(&c->die);
|
||||||
vtUnlock(c->lk);
|
qunlock(&c->lk);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -1943,9 +1935,9 @@ flushFill(Cache *c)
|
|||||||
BAddr *p;
|
BAddr *p;
|
||||||
Block *b;
|
Block *b;
|
||||||
|
|
||||||
vtLock(c->lk);
|
qlock(&c->lk);
|
||||||
if(c->ndirty == 0){
|
if(c->ndirty == 0){
|
||||||
vtUnlock(c->lk);
|
qunlock(&c->lk);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1969,7 +1961,7 @@ flushFill(Cache *c)
|
|||||||
argv0, c->ndirty, ndirty);
|
argv0, c->ndirty, ndirty);
|
||||||
c->ndirty = ndirty;
|
c->ndirty = ndirty;
|
||||||
}
|
}
|
||||||
vtUnlock(c->lk);
|
qunlock(&c->lk);
|
||||||
|
|
||||||
c->bw = p - c->baddr;
|
c->bw = p - c->baddr;
|
||||||
qsort(c->baddr, c->bw, sizeof(BAddr), baddrCmp);
|
qsort(c->baddr, c->bw, sizeof(BAddr), baddrCmp);
|
||||||
@ -2043,11 +2035,11 @@ flushThread(void *a)
|
|||||||
Cache *c = a;
|
Cache *c = a;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
vtThreadSetName("flush");
|
threadsetname("flush");
|
||||||
vtLock(c->lk);
|
qlock(&c->lk);
|
||||||
while(c->die == nil){
|
while(c->die.l == nil){
|
||||||
vtSleep(c->flush);
|
rsleep(&c->flush);
|
||||||
vtUnlock(c->lk);
|
qunlock(&c->lk);
|
||||||
for(i=0; i<FlushSize; i++)
|
for(i=0; i<FlushSize; i++)
|
||||||
if(!cacheFlushBlock(c)){
|
if(!cacheFlushBlock(c)){
|
||||||
/*
|
/*
|
||||||
@ -2073,12 +2065,12 @@ flushThread(void *a)
|
|||||||
*/
|
*/
|
||||||
sleep(100);
|
sleep(100);
|
||||||
}
|
}
|
||||||
vtLock(c->lk);
|
qlock(&c->lk);
|
||||||
vtWakeupAll(c->flushwait);
|
rwakeupall(&c->flushwait);
|
||||||
}
|
}
|
||||||
c->ref--;
|
c->ref--;
|
||||||
vtWakeup(c->die);
|
rwakeup(&c->die);
|
||||||
vtUnlock(c->lk);
|
qunlock(&c->lk);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -2087,18 +2079,18 @@ flushThread(void *a)
|
|||||||
void
|
void
|
||||||
cacheFlush(Cache *c, int wait)
|
cacheFlush(Cache *c, int wait)
|
||||||
{
|
{
|
||||||
vtLock(c->lk);
|
qlock(&c->lk);
|
||||||
if(wait){
|
if(wait){
|
||||||
while(c->ndirty){
|
while(c->ndirty){
|
||||||
// consPrint("cacheFlush: %d dirty blocks, uhead %p\n",
|
// consPrint("cacheFlush: %d dirty blocks, uhead %p\n",
|
||||||
// c->ndirty, c->uhead);
|
// c->ndirty, c->uhead);
|
||||||
vtWakeup(c->flush);
|
rwakeup(&c->flush);
|
||||||
vtSleep(c->flushwait);
|
rsleep(&c->flushwait);
|
||||||
}
|
}
|
||||||
// consPrint("cacheFlush: done (uhead %p)\n", c->ndirty, c->uhead);
|
// consPrint("cacheFlush: done (uhead %p)\n", c->ndirty, c->uhead);
|
||||||
}else if(c->ndirty)
|
}else if(c->ndirty)
|
||||||
vtWakeup(c->flush);
|
rwakeup(&c->flush);
|
||||||
vtUnlock(c->lk);
|
qunlock(&c->lk);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@ -61,7 +61,7 @@ fsCheck(Fsck *chk)
|
|||||||
checkInit(chk);
|
checkInit(chk);
|
||||||
b = superGet(chk->cache, &super);
|
b = superGet(chk->cache, &super);
|
||||||
if(b == nil){
|
if(b == nil){
|
||||||
chk->print("could not load super block: %R");
|
chk->print("could not load super block: %r");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
blockPut(b);
|
blockPut(b);
|
||||||
@ -69,9 +69,9 @@ fsCheck(Fsck *chk)
|
|||||||
chk->hint = super.active;
|
chk->hint = super.active;
|
||||||
checkEpochs(chk);
|
checkEpochs(chk);
|
||||||
|
|
||||||
chk->smap = vtMemAllocZ(chk->nblocks/8+1);
|
chk->smap = vtmallocz(chk->nblocks/8+1);
|
||||||
checkDirs(chk);
|
checkDirs(chk);
|
||||||
vtMemFree(chk->smap);
|
vtfree(chk->smap);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void checkEpoch(Fsck*, u32int);
|
static void checkEpoch(Fsck*, u32int);
|
||||||
@ -87,10 +87,10 @@ checkEpochs(Fsck *chk)
|
|||||||
uint nb;
|
uint nb;
|
||||||
|
|
||||||
nb = chk->nblocks;
|
nb = chk->nblocks;
|
||||||
chk->amap = vtMemAllocZ(nb/8+1);
|
chk->amap = vtmallocz(nb/8+1);
|
||||||
chk->emap = vtMemAllocZ(nb/8+1);
|
chk->emap = vtmallocz(nb/8+1);
|
||||||
chk->xmap = vtMemAllocZ(nb/8+1);
|
chk->xmap = vtmallocz(nb/8+1);
|
||||||
chk->errmap = vtMemAllocZ(nb/8+1);
|
chk->errmap = vtmallocz(nb/8+1);
|
||||||
|
|
||||||
for(e = chk->fs->ehi; e >= chk->fs->elo; e--){
|
for(e = chk->fs->ehi; e >= chk->fs->elo; e--){
|
||||||
memset(chk->emap, 0, chk->nblocks/8+1);
|
memset(chk->emap, 0, chk->nblocks/8+1);
|
||||||
@ -98,10 +98,10 @@ checkEpochs(Fsck *chk)
|
|||||||
checkEpoch(chk, e);
|
checkEpoch(chk, e);
|
||||||
}
|
}
|
||||||
checkLeak(chk);
|
checkLeak(chk);
|
||||||
vtMemFree(chk->amap);
|
vtfree(chk->amap);
|
||||||
vtMemFree(chk->emap);
|
vtfree(chk->emap);
|
||||||
vtMemFree(chk->xmap);
|
vtfree(chk->xmap);
|
||||||
vtMemFree(chk->errmap);
|
vtfree(chk->errmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -131,7 +131,7 @@ checkEpoch(Fsck *chk, u32int epoch)
|
|||||||
a = (a+chk->hint)%chk->nblocks;
|
a = (a+chk->hint)%chk->nblocks;
|
||||||
b = cacheLocalData(chk->cache, a, BtDir, RootTag, OReadOnly, 0);
|
b = cacheLocalData(chk->cache, a, BtDir, RootTag, OReadOnly, 0);
|
||||||
if(b == nil){
|
if(b == nil){
|
||||||
error(chk, "could not read root block 0x%.8#ux: %R", a);
|
error(chk, "could not read root block 0x%.8#ux: %r", a);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,7 +146,7 @@ checkEpoch(Fsck *chk, u32int epoch)
|
|||||||
* just a convenience to help the search.
|
* just a convenience to help the search.
|
||||||
*/
|
*/
|
||||||
if(!entryUnpack(&e, b->data, 0)){
|
if(!entryUnpack(&e, b->data, 0)){
|
||||||
error(chk, "could not unpack root block 0x%.8#ux: %R", a);
|
error(chk, "could not unpack root block 0x%.8#ux: %r", a);
|
||||||
blockPut(b);
|
blockPut(b);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -186,7 +186,7 @@ walkEpoch(Fsck *chk, Block *b, uchar score[VtScoreSize], int type, u32int tag,
|
|||||||
|
|
||||||
bb = cacheGlobal(chk->cache, score, type, tag, OReadOnly);
|
bb = cacheGlobal(chk->cache, score, type, tag, OReadOnly);
|
||||||
if(bb == nil){
|
if(bb == nil){
|
||||||
error(chk, "could not load block %V type %d tag %ux: %R",
|
error(chk, "could not load block %V type %d tag %ux: %r",
|
||||||
score, type, tag);
|
score, type, tag);
|
||||||
chk->walkdepth--;
|
chk->walkdepth--;
|
||||||
return 0;
|
return 0;
|
||||||
@ -284,7 +284,7 @@ walkEpoch(Fsck *chk, Block *b, uchar score[VtScoreSize], int type, u32int tag,
|
|||||||
case BtDir:
|
case BtDir:
|
||||||
for(i = 0; i < chk->bsize/VtEntrySize; i++){
|
for(i = 0; i < chk->bsize/VtEntrySize; i++){
|
||||||
if(!entryUnpack(&e, bb->data, i)){
|
if(!entryUnpack(&e, bb->data, i)){
|
||||||
// error(chk, "walk: could not unpack entry: %ux[%d]: %R",
|
// error(chk, "walk: could not unpack entry: %ux[%d]: %r",
|
||||||
// addr, i);
|
// addr, i);
|
||||||
setBit(chk->errmap, bb->addr);
|
setBit(chk->errmap, bb->addr);
|
||||||
chk->clre(chk, bb, i);
|
chk->clre(chk, bb, i);
|
||||||
@ -360,7 +360,7 @@ checkLeak(Fsck *chk)
|
|||||||
|
|
||||||
for(a = 0; a < chk->nblocks; a++){
|
for(a = 0; a < chk->nblocks; a++){
|
||||||
if(!readLabel(chk->cache, &l, a)){
|
if(!readLabel(chk->cache, &l, a)){
|
||||||
error(chk, "could not read label: addr 0x%ux %d %d: %R",
|
error(chk, "could not read label: addr 0x%ux %d %d: %r",
|
||||||
a, l.type, l.state);
|
a, l.type, l.state);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -416,7 +416,7 @@ openSource(Fsck *chk, Source *s, char *name, uchar *bm, u32int offset,
|
|||||||
|
|
||||||
r = sourceOpen(s, offset, OReadOnly, 0);
|
r = sourceOpen(s, offset, OReadOnly, 0);
|
||||||
if(r == nil){
|
if(r == nil){
|
||||||
warn(chk, "could not open source: %s -> %d: %R", name, offset);
|
warn(chk, "could not open source: %s -> %d: %r", name, offset);
|
||||||
goto Err;
|
goto Err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -469,7 +469,7 @@ chkMetaBlock(MetaBlock *mb)
|
|||||||
int oo, o, n, i;
|
int oo, o, n, i;
|
||||||
uchar *p;
|
uchar *p;
|
||||||
|
|
||||||
mc = vtMemAlloc(mb->nindex*sizeof(MetaChunk));
|
mc = vtmalloc(mb->nindex*sizeof(MetaChunk));
|
||||||
p = mb->buf + MetaHeaderSize;
|
p = mb->buf + MetaHeaderSize;
|
||||||
for(i = 0; i < mb->nindex; i++){
|
for(i = 0; i < mb->nindex; i++){
|
||||||
mc[i].offset = p[0]<<8 | p[1];
|
mc[i].offset = p[0]<<8 | p[1];
|
||||||
@ -494,7 +494,7 @@ chkMetaBlock(MetaBlock *mb)
|
|||||||
if(o+n > mb->size || mb->size - oo != mb->free)
|
if(o+n > mb->size || mb->size - oo != mb->free)
|
||||||
goto Err;
|
goto Err;
|
||||||
|
|
||||||
vtMemFree(mc);
|
vtfree(mc);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
Err:
|
Err:
|
||||||
@ -509,7 +509,7 @@ if(0){
|
|||||||
fprint(2, "\tused=%d size=%d free=%d free2=%d\n",
|
fprint(2, "\tused=%d size=%d free=%d free2=%d\n",
|
||||||
oo, mb->size, mb->free, mb->size - oo);
|
oo, mb->size, mb->free, mb->size - oo);
|
||||||
}
|
}
|
||||||
vtMemFree(mc);
|
vtfree(mc);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -571,11 +571,11 @@ chkDir(Fsck *chk, char *name, Source *source, Source *meta)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if(!sourceLock2(source, meta, OReadOnly)){
|
if(!sourceLock2(source, meta, OReadOnly)){
|
||||||
warn(chk, "could not lock sources for %s: %R", name);
|
warn(chk, "could not lock sources for %s: %r", name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(!sourceGetEntry(source, &e1) || !sourceGetEntry(meta, &e2)){
|
if(!sourceGetEntry(source, &e1) || !sourceGetEntry(meta, &e2)){
|
||||||
warn(chk, "could not load entries for %s: %R", name);
|
warn(chk, "could not load entries for %s: %r", name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
a1 = globalToLocal(e1.score);
|
a1 = globalToLocal(e1.score);
|
||||||
@ -589,13 +589,13 @@ chkDir(Fsck *chk, char *name, Source *source, Source *meta)
|
|||||||
setBit(chk->smap, a1);
|
setBit(chk->smap, a1);
|
||||||
setBit(chk->smap, a2);
|
setBit(chk->smap, a2);
|
||||||
|
|
||||||
bm = vtMemAllocZ(sourceGetDirSize(source)/8 + 1);
|
bm = vtmallocz(sourceGetDirSize(source)/8 + 1);
|
||||||
|
|
||||||
nb = (sourceGetSize(meta) + meta->dsize - 1)/meta->dsize;
|
nb = (sourceGetSize(meta) + meta->dsize - 1)/meta->dsize;
|
||||||
for(o = 0; o < nb; o++){
|
for(o = 0; o < nb; o++){
|
||||||
b = sourceBlock(meta, o, OReadOnly);
|
b = sourceBlock(meta, o, OReadOnly);
|
||||||
if(b == nil){
|
if(b == nil){
|
||||||
error(chk, "could not read block in meta file: %s[%ud]: %R",
|
error(chk, "could not read block in meta file: %s[%ud]: %r",
|
||||||
name, o);
|
name, o);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -606,13 +606,13 @@ if(0) fprint(2, "source %V:%d block %d addr %d\n", source->score,
|
|||||||
b->addr, name);
|
b->addr, name);
|
||||||
|
|
||||||
if(!mbUnpack(&mb, b->data, meta->dsize)){
|
if(!mbUnpack(&mb, b->data, meta->dsize)){
|
||||||
error(chk, "could not unpack meta block: %s[%ud]: %R",
|
error(chk, "could not unpack meta block: %s[%ud]: %r",
|
||||||
name, o);
|
name, o);
|
||||||
blockPut(b);
|
blockPut(b);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(!chkMetaBlock(&mb)){
|
if(!chkMetaBlock(&mb)){
|
||||||
error(chk, "bad meta block: %s[%ud]: %R", name, o);
|
error(chk, "bad meta block: %s[%ud]: %r", name, o);
|
||||||
blockPut(b);
|
blockPut(b);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -621,7 +621,7 @@ if(0) fprint(2, "source %V:%d block %d addr %d\n", source->score,
|
|||||||
meUnpack(&me, &mb, i);
|
meUnpack(&me, &mb, i);
|
||||||
if(!deUnpack(&de, &me)){
|
if(!deUnpack(&de, &me)){
|
||||||
error(chk,
|
error(chk,
|
||||||
"could not unpack dir entry: %s[%ud][%d]: %R",
|
"could not unpack dir entry: %s[%ud][%d]: %r",
|
||||||
name, o, i);
|
name, o, i);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -629,8 +629,8 @@ if(0) fprint(2, "source %V:%d block %d addr %d\n", source->score,
|
|||||||
error(chk,
|
error(chk,
|
||||||
"dir entry out of order: %s[%ud][%d] = %s last = %s",
|
"dir entry out of order: %s[%ud][%d] = %s last = %s",
|
||||||
name, o, i, de.elem, s);
|
name, o, i, de.elem, s);
|
||||||
vtMemFree(s);
|
vtfree(s);
|
||||||
s = vtStrDup(de.elem);
|
s = vtstrdup(de.elem);
|
||||||
nn = smprint("%s/%s", name, de.elem);
|
nn = smprint("%s/%s", name, de.elem);
|
||||||
if(nn == nil){
|
if(nn == nil){
|
||||||
error(chk, "out of memory");
|
error(chk, "out of memory");
|
||||||
@ -684,7 +684,7 @@ if(0) fprint(2, "source %V:%d block %d addr %d\n", source->score,
|
|||||||
deCleanup(&de);
|
deCleanup(&de);
|
||||||
|
|
||||||
}
|
}
|
||||||
vtMemFree(s);
|
vtfree(s);
|
||||||
blockPut(b);
|
blockPut(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -710,7 +710,7 @@ if(0) fprint(2, "source %V:%d block %d addr %d\n", source->score,
|
|||||||
|
|
||||||
sourceUnlock(source);
|
sourceUnlock(source);
|
||||||
sourceUnlock(meta);
|
sourceUnlock(meta);
|
||||||
vtMemFree(bm);
|
vtfree(bm);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -760,7 +760,7 @@ error(Fsck *chk, char *fmt, ...)
|
|||||||
chk->print("error: %s\n", buf);
|
chk->print("error: %s\n", buf);
|
||||||
|
|
||||||
// if(nerr++ > 20)
|
// if(nerr++ > 20)
|
||||||
// vtFatal("too many errors");
|
// sysfatal("too many errors");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|||||||
@ -37,7 +37,6 @@ enum {
|
|||||||
Nowaitlock,
|
Nowaitlock,
|
||||||
Waitlock,
|
Waitlock,
|
||||||
|
|
||||||
NilBlock = (~0UL),
|
|
||||||
MaxBlock = (1UL<<31),
|
MaxBlock = (1UL<<31),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -79,7 +78,7 @@ struct Fs {
|
|||||||
int mode; /* immutable */
|
int mode; /* immutable */
|
||||||
int noatimeupd; /* immutable */
|
int noatimeupd; /* immutable */
|
||||||
int blockSize; /* immutable */
|
int blockSize; /* immutable */
|
||||||
VtSession *z; /* immutable */
|
VtConn *z; /* immutable */
|
||||||
Snap *snap; /* immutable */
|
Snap *snap; /* immutable */
|
||||||
/* immutable; copy here & Fsys to ease error reporting */
|
/* immutable; copy here & Fsys to ease error reporting */
|
||||||
char *name;
|
char *name;
|
||||||
@ -94,7 +93,7 @@ struct Fs {
|
|||||||
* Deletion and creation of snapshots occurs under a write lock of elk,
|
* Deletion and creation of snapshots occurs under a write lock of elk,
|
||||||
* ensuring no file operations are occurring concurrently.
|
* ensuring no file operations are occurring concurrently.
|
||||||
*/
|
*/
|
||||||
VtLock *elk; /* epoch lock */
|
RWLock elk; /* epoch lock */
|
||||||
u32int ehi; /* epoch high */
|
u32int ehi; /* epoch high */
|
||||||
u32int elo; /* epoch low */
|
u32int elo; /* epoch low */
|
||||||
|
|
||||||
@ -136,7 +135,7 @@ struct Source {
|
|||||||
Source *parent; /* immutable */
|
Source *parent; /* immutable */
|
||||||
File *file; /* immutable; point back */
|
File *file; /* immutable; point back */
|
||||||
|
|
||||||
VtLock *lk;
|
QLock lk;
|
||||||
int ref;
|
int ref;
|
||||||
/*
|
/*
|
||||||
* epoch for the source
|
* epoch for the source
|
||||||
@ -233,7 +232,7 @@ struct Block {
|
|||||||
int nlock;
|
int nlock;
|
||||||
uintptr pc; /* pc that fetched this block from the cache */
|
uintptr pc; /* pc that fetched this block from the cache */
|
||||||
|
|
||||||
VtLock *lk;
|
QLock lk;
|
||||||
|
|
||||||
int part;
|
int part;
|
||||||
u32int addr;
|
u32int addr;
|
||||||
@ -261,7 +260,7 @@ struct Block {
|
|||||||
|
|
||||||
Block *ionext;
|
Block *ionext;
|
||||||
int iostate;
|
int iostate;
|
||||||
VtRendez *ioready;
|
Rendez ioready;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* tree walker, for gc and archiver */
|
/* tree walker, for gc and archiver */
|
||||||
|
|||||||
@ -15,16 +15,16 @@ enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct Disk {
|
struct Disk {
|
||||||
VtLock *lk;
|
QLock lk;
|
||||||
int ref;
|
int ref;
|
||||||
|
|
||||||
int fd;
|
int fd;
|
||||||
Header h;
|
Header h;
|
||||||
|
|
||||||
VtRendez *flow;
|
Rendez flow;
|
||||||
VtRendez *starve;
|
Rendez starve;
|
||||||
VtRendez *flush;
|
Rendez flush;
|
||||||
VtRendez *die;
|
Rendez die;
|
||||||
|
|
||||||
int nqueue;
|
int nqueue;
|
||||||
|
|
||||||
@ -49,25 +49,23 @@ diskAlloc(int fd)
|
|||||||
Disk *disk;
|
Disk *disk;
|
||||||
|
|
||||||
if(pread(fd, buf, HeaderSize, HeaderOffset) < HeaderSize){
|
if(pread(fd, buf, HeaderSize, HeaderOffset) < HeaderSize){
|
||||||
vtSetError("short read: %r");
|
werrstr("short read: %r");
|
||||||
vtOSError();
|
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!headerUnpack(&h, buf)){
|
if(!headerUnpack(&h, buf)){
|
||||||
vtSetError("bad disk header");
|
werrstr("bad disk header");
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
disk = vtMemAllocZ(sizeof(Disk));
|
disk = vtmallocz(sizeof(Disk));
|
||||||
disk->lk = vtLockAlloc();
|
disk->starve.l = &disk->lk;
|
||||||
disk->starve = vtRendezAlloc(disk->lk);
|
disk->flow.l = &disk->lk;
|
||||||
disk->flow = vtRendezAlloc(disk->lk);
|
disk->flush.l = &disk->lk;
|
||||||
disk->flush = vtRendezAlloc(disk->lk);
|
|
||||||
disk->fd = fd;
|
disk->fd = fd;
|
||||||
disk->h = h;
|
disk->h = h;
|
||||||
|
|
||||||
disk->ref = 2;
|
disk->ref = 2;
|
||||||
vtThread(diskThread, disk);
|
proccreate(diskThread, disk, STACK);
|
||||||
|
|
||||||
return disk;
|
return disk;
|
||||||
}
|
}
|
||||||
@ -78,18 +76,14 @@ diskFree(Disk *disk)
|
|||||||
diskFlush(disk);
|
diskFlush(disk);
|
||||||
|
|
||||||
/* kill slave */
|
/* kill slave */
|
||||||
vtLock(disk->lk);
|
qlock(&disk->lk);
|
||||||
disk->die = vtRendezAlloc(disk->lk);
|
disk->die.l = &disk->lk;
|
||||||
vtWakeup(disk->starve);
|
rwakeup(&disk->starve);
|
||||||
while(disk->ref > 1)
|
while(disk->ref > 1)
|
||||||
vtSleep(disk->die);
|
rsleep(&disk->die);
|
||||||
vtUnlock(disk->lk);
|
qunlock(&disk->lk);
|
||||||
vtRendezFree(disk->flow);
|
|
||||||
vtRendezFree(disk->starve);
|
|
||||||
vtRendezFree(disk->die);
|
|
||||||
vtLockFree(disk->lk);
|
|
||||||
close(disk->fd);
|
close(disk->fd);
|
||||||
vtMemFree(disk);
|
vtfree(disk);
|
||||||
}
|
}
|
||||||
|
|
||||||
static u32int
|
static u32int
|
||||||
@ -134,7 +128,7 @@ diskReadRaw(Disk *disk, int part, u32int addr, uchar *buf)
|
|||||||
end = partEnd(disk, part);
|
end = partEnd(disk, part);
|
||||||
|
|
||||||
if(addr >= end-start){
|
if(addr >= end-start){
|
||||||
vtSetError(EBadAddr);
|
werrstr(EBadAddr);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,11 +137,11 @@ diskReadRaw(Disk *disk, int part, u32int addr, uchar *buf)
|
|||||||
while(n > 0){
|
while(n > 0){
|
||||||
nn = pread(disk->fd, buf, n, offset);
|
nn = pread(disk->fd, buf, n, offset);
|
||||||
if(nn < 0){
|
if(nn < 0){
|
||||||
vtOSError();
|
werrstr("%r");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(nn == 0){
|
if(nn == 0){
|
||||||
vtSetError("eof reading disk");
|
werrstr("eof reading disk");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
n -= nn;
|
n -= nn;
|
||||||
@ -168,18 +162,18 @@ diskWriteRaw(Disk *disk, int part, u32int addr, uchar *buf)
|
|||||||
end = partEnd(disk, part);
|
end = partEnd(disk, part);
|
||||||
|
|
||||||
if(addr >= end - start){
|
if(addr >= end - start){
|
||||||
vtSetError(EBadAddr);
|
werrstr(EBadAddr);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
offset = ((u64int)(addr + start))*disk->h.blockSize;
|
offset = ((u64int)(addr + start))*disk->h.blockSize;
|
||||||
n = pwrite(disk->fd, buf, disk->h.blockSize, offset);
|
n = pwrite(disk->fd, buf, disk->h.blockSize, offset);
|
||||||
if(n < 0){
|
if(n < 0){
|
||||||
vtOSError();
|
werrstr("%r");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(n < disk->h.blockSize) {
|
if(n < disk->h.blockSize) {
|
||||||
vtSetError("short write");
|
werrstr("short write");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,9 +185,9 @@ diskQueue(Disk *disk, Block *b)
|
|||||||
{
|
{
|
||||||
Block **bp, *bb;
|
Block **bp, *bb;
|
||||||
|
|
||||||
vtLock(disk->lk);
|
qlock(&disk->lk);
|
||||||
while(disk->nqueue >= QueueSize)
|
while(disk->nqueue >= QueueSize)
|
||||||
vtSleep(disk->flow);
|
rsleep(&disk->flow);
|
||||||
if(disk->cur == nil || b->addr > disk->cur->addr)
|
if(disk->cur == nil || b->addr > disk->cur->addr)
|
||||||
bp = &disk->cur;
|
bp = &disk->cur;
|
||||||
else
|
else
|
||||||
@ -207,9 +201,9 @@ diskQueue(Disk *disk, Block *b)
|
|||||||
b->ionext = bb;
|
b->ionext = bb;
|
||||||
*bp = b;
|
*bp = b;
|
||||||
if(disk->nqueue == 0)
|
if(disk->nqueue == 0)
|
||||||
vtWakeup(disk->starve);
|
rwakeup(&disk->starve);
|
||||||
disk->nqueue++;
|
disk->nqueue++;
|
||||||
vtUnlock(disk->lk);
|
qunlock(&disk->lk);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -238,7 +232,7 @@ diskWriteAndWait(Disk *disk, Block *b)
|
|||||||
/*
|
/*
|
||||||
* If b->nlock > 1, the block is aliased within
|
* If b->nlock > 1, the block is aliased within
|
||||||
* a single thread. That thread is us.
|
* a single thread. That thread is us.
|
||||||
* DiskWrite does some funny stuff with VtLock
|
* DiskWrite does some funny stuff with QLock
|
||||||
* and blockPut that basically assumes b->nlock==1.
|
* and blockPut that basically assumes b->nlock==1.
|
||||||
* We humor diskWrite by temporarily setting
|
* We humor diskWrite by temporarily setting
|
||||||
* nlock to 1. This needs to be revisited.
|
* nlock to 1. This needs to be revisited.
|
||||||
@ -248,7 +242,7 @@ diskWriteAndWait(Disk *disk, Block *b)
|
|||||||
b->nlock = 1;
|
b->nlock = 1;
|
||||||
diskWrite(disk, b);
|
diskWrite(disk, b);
|
||||||
while(b->iostate != BioClean)
|
while(b->iostate != BioClean)
|
||||||
vtSleep(b->ioready);
|
rsleep(&b->ioready);
|
||||||
b->nlock = nlock;
|
b->nlock = nlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -263,15 +257,15 @@ diskFlush(Disk *disk)
|
|||||||
{
|
{
|
||||||
Dir dir;
|
Dir dir;
|
||||||
|
|
||||||
vtLock(disk->lk);
|
qlock(&disk->lk);
|
||||||
while(disk->nqueue > 0)
|
while(disk->nqueue > 0)
|
||||||
vtSleep(disk->flush);
|
rsleep(&disk->flush);
|
||||||
vtUnlock(disk->lk);
|
qunlock(&disk->lk);
|
||||||
|
|
||||||
/* there really should be a cleaner interface to flush an fd */
|
/* there really should be a cleaner interface to flush an fd */
|
||||||
nulldir(&dir);
|
nulldir(&dir);
|
||||||
if(dirfwstat(disk->fd, &dir) < 0){
|
if(dirfwstat(disk->fd, &dir) < 0){
|
||||||
vtOSError();
|
werrstr("%r");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
@ -308,13 +302,13 @@ diskThread(void *a)
|
|||||||
double t;
|
double t;
|
||||||
int nio;
|
int nio;
|
||||||
|
|
||||||
vtThreadSetName("disk");
|
threadsetname("disk");
|
||||||
|
|
||||||
//fprint(2, "diskThread %d\n", getpid());
|
//fprint(2, "diskThread %d\n", getpid());
|
||||||
|
|
||||||
buf = vtMemAlloc(disk->h.blockSize);
|
buf = vtmalloc(disk->h.blockSize);
|
||||||
|
|
||||||
vtLock(disk->lk);
|
qlock(&disk->lk);
|
||||||
if (Timing) {
|
if (Timing) {
|
||||||
nio = 0;
|
nio = 0;
|
||||||
t = -nsec();
|
t = -nsec();
|
||||||
@ -330,9 +324,9 @@ diskThread(void *a)
|
|||||||
t = 0;
|
t = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(disk->die != nil)
|
if(disk->die.l != nil)
|
||||||
goto Done;
|
goto Done;
|
||||||
vtSleep(disk->starve);
|
rsleep(&disk->starve);
|
||||||
if (Timing)
|
if (Timing)
|
||||||
t -= nsec();
|
t -= nsec();
|
||||||
}
|
}
|
||||||
@ -344,7 +338,7 @@ diskThread(void *a)
|
|||||||
}
|
}
|
||||||
b = disk->cur;
|
b = disk->cur;
|
||||||
disk->cur = b->ionext;
|
disk->cur = b->ionext;
|
||||||
vtUnlock(disk->lk);
|
qunlock(&disk->lk);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* no one should hold onto blocking in the
|
* no one should hold onto blocking in the
|
||||||
@ -353,7 +347,7 @@ diskThread(void *a)
|
|||||||
*/
|
*/
|
||||||
if(0)fprint(2, "fossil: diskThread: %d:%d %x\n", getpid(), b->part, b->addr);
|
if(0)fprint(2, "fossil: diskThread: %d:%d %x\n", getpid(), b->part, b->addr);
|
||||||
bwatchLock(b);
|
bwatchLock(b);
|
||||||
vtLock(b->lk);
|
qlock(&b->lk);
|
||||||
b->pc = mypc(0);
|
b->pc = mypc(0);
|
||||||
assert(b->nlock == 1);
|
assert(b->nlock == 1);
|
||||||
switch(b->iostate){
|
switch(b->iostate){
|
||||||
@ -388,19 +382,19 @@ if(0)fprint(2, "fossil: diskThread: %d:%d %x\n", getpid(), b->part, b->addr);
|
|||||||
}
|
}
|
||||||
|
|
||||||
blockPut(b); /* remove extra reference, unlock */
|
blockPut(b); /* remove extra reference, unlock */
|
||||||
vtLock(disk->lk);
|
qlock(&disk->lk);
|
||||||
disk->nqueue--;
|
disk->nqueue--;
|
||||||
if(disk->nqueue == QueueSize-1)
|
if(disk->nqueue == QueueSize-1)
|
||||||
vtWakeup(disk->flow);
|
rwakeup(&disk->flow);
|
||||||
if(disk->nqueue == 0)
|
if(disk->nqueue == 0)
|
||||||
vtWakeup(disk->flush);
|
rwakeup(&disk->flush);
|
||||||
if(Timing)
|
if(Timing)
|
||||||
nio++;
|
nio++;
|
||||||
}
|
}
|
||||||
Done:
|
Done:
|
||||||
//fprint(2, "diskThread done\n");
|
//fprint(2, "diskThread done\n");
|
||||||
disk->ref--;
|
disk->ref--;
|
||||||
vtWakeup(disk->die);
|
rwakeup(&disk->die);
|
||||||
vtUnlock(disk->lk);
|
qunlock(&disk->lk);
|
||||||
vtMemFree(buf);
|
vtfree(buf);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,11 +8,11 @@ void
|
|||||||
usage(void)
|
usage(void)
|
||||||
{
|
{
|
||||||
fprint(2, "usage: fossil/epoch fs [new-low-epoch]\n");
|
fprint(2, "usage: fossil/epoch fs [new-low-epoch]\n");
|
||||||
exits("usage");
|
threadexitsall("usage");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
main(int argc, char **argv)
|
threadmain(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
Header h;
|
Header h;
|
||||||
@ -47,5 +47,5 @@ main(int argc, char **argv)
|
|||||||
if(pwrite(fd, buf, h.blockSize, (vlong)h.super*h.blockSize) != h.blockSize)
|
if(pwrite(fd, buf, h.blockSize, (vlong)h.super*h.blockSize) != h.blockSize)
|
||||||
sysfatal("writing super block: %r");
|
sysfatal("writing super block: %r");
|
||||||
}
|
}
|
||||||
exits(0);
|
threadexitsall(0);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,7 +26,7 @@ struct File {
|
|||||||
File *next; /* sibling */
|
File *next; /* sibling */
|
||||||
|
|
||||||
/* data for file */
|
/* data for file */
|
||||||
VtLock *lk; /* lock for the following */
|
RWLock lk; /* lock for the following */
|
||||||
Source *source;
|
Source *source;
|
||||||
Source *msource; /* for directories: meta data for children */
|
Source *msource; /* for directories: meta data for children */
|
||||||
File *down; /* children */
|
File *down; /* children */
|
||||||
@ -51,8 +51,7 @@ fileAlloc(Fs *fs)
|
|||||||
{
|
{
|
||||||
File *f;
|
File *f;
|
||||||
|
|
||||||
f = vtMemAllocZ(sizeof(File));
|
f = vtmallocz(sizeof(File));
|
||||||
f->lk = vtLockAlloc();
|
|
||||||
f->ref = 1;
|
f->ref = 1;
|
||||||
f->fs = fs;
|
f->fs = fs;
|
||||||
f->boff = NilBlock;
|
f->boff = NilBlock;
|
||||||
@ -64,12 +63,11 @@ static void
|
|||||||
fileFree(File *f)
|
fileFree(File *f)
|
||||||
{
|
{
|
||||||
sourceClose(f->source);
|
sourceClose(f->source);
|
||||||
vtLockFree(f->lk);
|
|
||||||
sourceClose(f->msource);
|
sourceClose(f->msource);
|
||||||
deCleanup(&f->dir);
|
deCleanup(&f->dir);
|
||||||
|
|
||||||
memset(f, ~0, sizeof(File));
|
memset(f, ~0, sizeof(File));
|
||||||
vtMemFree(f);
|
vtfree(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -115,7 +113,7 @@ dirLookup(File *f, char *elem)
|
|||||||
blockPut(b);
|
blockPut(b);
|
||||||
b = nil;
|
b = nil;
|
||||||
}
|
}
|
||||||
vtSetError(ENoFile);
|
werrstr(ENoFile);
|
||||||
/* fall through */
|
/* fall through */
|
||||||
Err:
|
Err:
|
||||||
sourceUnlock(meta);
|
sourceUnlock(meta);
|
||||||
@ -216,7 +214,7 @@ fileOpenSource(File *f, u32int offset, u32int gen, int dir, uint mode,
|
|||||||
if(r == nil)
|
if(r == nil)
|
||||||
return nil;
|
return nil;
|
||||||
if(r->gen != gen){
|
if(r->gen != gen){
|
||||||
vtSetError(ERemoved);
|
werrstr(ERemoved);
|
||||||
goto Err;
|
goto Err;
|
||||||
}
|
}
|
||||||
if(r->dir != dir && r->mode != -1){
|
if(r->dir != dir && r->mode != -1){
|
||||||
@ -229,7 +227,7 @@ fileOpenSource(File *f, u32int offset, u32int gen, int dir, uint mode,
|
|||||||
free(rname);
|
free(rname);
|
||||||
free(fname);
|
free(fname);
|
||||||
|
|
||||||
vtSetError(EBadMeta);
|
werrstr(EBadMeta);
|
||||||
goto Err;
|
goto Err;
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
@ -246,12 +244,12 @@ _fileWalk(File *f, char *elem, int partial)
|
|||||||
fileRAccess(f);
|
fileRAccess(f);
|
||||||
|
|
||||||
if(elem[0] == 0){
|
if(elem[0] == 0){
|
||||||
vtSetError(EBadPath);
|
werrstr(EBadPath);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!fileIsDir(f)){
|
if(!fileIsDir(f)){
|
||||||
vtSetError(ENotDir);
|
werrstr(ENotDir);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -347,14 +345,14 @@ _fileOpen(Fs *fs, char *path, int partial)
|
|||||||
n = p - path;
|
n = p - path;
|
||||||
if(n > 0){
|
if(n > 0){
|
||||||
if(n > VtMaxStringSize){
|
if(n > VtMaxStringSize){
|
||||||
vtSetError("%s: element too long", EBadPath);
|
werrstr("%s: element too long", EBadPath);
|
||||||
goto Err;
|
goto Err;
|
||||||
}
|
}
|
||||||
memmove(elem, path, n);
|
memmove(elem, path, n);
|
||||||
elem[n] = 0;
|
elem[n] = 0;
|
||||||
ff = _fileWalk(f, elem, partial && *p=='\0');
|
ff = _fileWalk(f, elem, partial && *p=='\0');
|
||||||
if(ff == nil){
|
if(ff == nil){
|
||||||
vtSetError("%.*s: %R", utfnlen(opath, p-opath),
|
werrstr("%.*s: %r", utfnlen(opath, p-opath),
|
||||||
opath);
|
opath);
|
||||||
goto Err;
|
goto Err;
|
||||||
}
|
}
|
||||||
@ -422,20 +420,20 @@ fileCreate(File *f, char *elem, ulong mode, char *uid)
|
|||||||
for(ff = f->down; ff; ff=ff->next){
|
for(ff = f->down; ff; ff=ff->next){
|
||||||
if(strcmp(elem, ff->dir.elem) == 0 && !ff->removed){
|
if(strcmp(elem, ff->dir.elem) == 0 && !ff->removed){
|
||||||
ff = nil;
|
ff = nil;
|
||||||
vtSetError(EExists);
|
werrstr(EExists);
|
||||||
goto Err1;
|
goto Err1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ff = dirLookup(f, elem);
|
ff = dirLookup(f, elem);
|
||||||
if(ff != nil){
|
if(ff != nil){
|
||||||
vtSetError(EExists);
|
werrstr(EExists);
|
||||||
goto Err1;
|
goto Err1;
|
||||||
}
|
}
|
||||||
|
|
||||||
pr = f->source;
|
pr = f->source;
|
||||||
if(pr->mode != OReadWrite){
|
if(pr->mode != OReadWrite){
|
||||||
vtSetError(EReadOnly);
|
werrstr(EReadOnly);
|
||||||
goto Err1;
|
goto Err1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -455,7 +453,7 @@ fileCreate(File *f, char *elem, ulong mode, char *uid)
|
|||||||
}
|
}
|
||||||
|
|
||||||
dir = &ff->dir;
|
dir = &ff->dir;
|
||||||
dir->elem = vtStrDup(elem);
|
dir->elem = vtstrdup(elem);
|
||||||
dir->entry = r->offset;
|
dir->entry = r->offset;
|
||||||
dir->gen = r->gen;
|
dir->gen = r->gen;
|
||||||
if(isdir){
|
if(isdir){
|
||||||
@ -465,9 +463,9 @@ fileCreate(File *f, char *elem, ulong mode, char *uid)
|
|||||||
dir->size = 0;
|
dir->size = 0;
|
||||||
if(!fsNextQid(f->fs, &dir->qid))
|
if(!fsNextQid(f->fs, &dir->qid))
|
||||||
goto Err;
|
goto Err;
|
||||||
dir->uid = vtStrDup(uid);
|
dir->uid = vtstrdup(uid);
|
||||||
dir->gid = vtStrDup(f->dir.gid);
|
dir->gid = vtstrdup(f->dir.gid);
|
||||||
dir->mid = vtStrDup(uid);
|
dir->mid = vtstrdup(uid);
|
||||||
dir->mtime = time(0L);
|
dir->mtime = time(0L);
|
||||||
dir->mcount = 0;
|
dir->mcount = 0;
|
||||||
dir->ctime = dir->mtime;
|
dir->ctime = dir->mtime;
|
||||||
@ -541,7 +539,7 @@ if(0)fprint(2, "fileRead: %s %d, %lld\n", f->dir.elem, cnt, offset);
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if(offset < 0){
|
if(offset < 0){
|
||||||
vtSetError(EBadOffset);
|
werrstr(EBadOffset);
|
||||||
goto Err1;
|
goto Err1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -607,12 +605,12 @@ fileMapBlock(File *f, ulong bn, uchar score[VtScoreSize], ulong tag)
|
|||||||
|
|
||||||
s = nil;
|
s = nil;
|
||||||
if(f->dir.mode & ModeDir){
|
if(f->dir.mode & ModeDir){
|
||||||
vtSetError(ENotFile);
|
werrstr(ENotFile);
|
||||||
goto Err;
|
goto Err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(f->source->mode != OReadWrite){
|
if(f->source->mode != OReadWrite){
|
||||||
vtSetError(EReadOnly);
|
werrstr(EReadOnly);
|
||||||
goto Err;
|
goto Err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -656,11 +654,11 @@ fileSetSize(File *f, uvlong size)
|
|||||||
return 0;
|
return 0;
|
||||||
r = 0;
|
r = 0;
|
||||||
if(f->dir.mode & ModeDir){
|
if(f->dir.mode & ModeDir){
|
||||||
vtSetError(ENotFile);
|
werrstr(ENotFile);
|
||||||
goto Err;
|
goto Err;
|
||||||
}
|
}
|
||||||
if(f->source->mode != OReadWrite){
|
if(f->source->mode != OReadWrite){
|
||||||
vtSetError(EReadOnly);
|
werrstr(EReadOnly);
|
||||||
goto Err;
|
goto Err;
|
||||||
}
|
}
|
||||||
if(!sourceLock(f->source, -1))
|
if(!sourceLock(f->source, -1))
|
||||||
@ -689,16 +687,16 @@ if(0)fprint(2, "fileWrite: %s %d, %lld\n", f->dir.elem, cnt, offset);
|
|||||||
|
|
||||||
s = nil;
|
s = nil;
|
||||||
if(f->dir.mode & ModeDir){
|
if(f->dir.mode & ModeDir){
|
||||||
vtSetError(ENotFile);
|
werrstr(ENotFile);
|
||||||
goto Err;
|
goto Err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(f->source->mode != OReadWrite){
|
if(f->source->mode != OReadWrite){
|
||||||
vtSetError(EReadOnly);
|
werrstr(EReadOnly);
|
||||||
goto Err;
|
goto Err;
|
||||||
}
|
}
|
||||||
if(offset < 0){
|
if(offset < 0){
|
||||||
vtSetError(EBadOffset);
|
werrstr(EBadOffset);
|
||||||
goto Err;
|
goto Err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -773,7 +771,7 @@ int
|
|||||||
fileTruncate(File *f, char *uid)
|
fileTruncate(File *f, char *uid)
|
||||||
{
|
{
|
||||||
if(fileIsDir(f)){
|
if(fileIsDir(f)){
|
||||||
vtSetError(ENotFile);
|
werrstr(ENotFile);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -781,7 +779,7 @@ fileTruncate(File *f, char *uid)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if(f->source->mode != OReadWrite){
|
if(f->source->mode != OReadWrite){
|
||||||
vtSetError(EReadOnly);
|
werrstr(EReadOnly);
|
||||||
fileUnlock(f);
|
fileUnlock(f);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -812,7 +810,7 @@ fileSetDir(File *f, DirEntry *dir, char *uid)
|
|||||||
|
|
||||||
/* can not set permissions for the root */
|
/* can not set permissions for the root */
|
||||||
if(fileIsRoot(f)){
|
if(fileIsRoot(f)){
|
||||||
vtSetError(ERoot);
|
werrstr(ERoot);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -820,7 +818,7 @@ fileSetDir(File *f, DirEntry *dir, char *uid)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if(f->source->mode != OReadWrite){
|
if(f->source->mode != OReadWrite){
|
||||||
vtSetError(EReadOnly);
|
werrstr(EReadOnly);
|
||||||
fileUnlock(f);
|
fileUnlock(f);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -831,7 +829,7 @@ fileSetDir(File *f, DirEntry *dir, char *uid)
|
|||||||
if(strcmp(f->dir.elem, dir->elem) != 0){
|
if(strcmp(f->dir.elem, dir->elem) != 0){
|
||||||
for(ff = f->up->down; ff; ff=ff->next){
|
for(ff = f->up->down; ff; ff=ff->next){
|
||||||
if(strcmp(dir->elem, ff->dir.elem) == 0 && !ff->removed){
|
if(strcmp(dir->elem, ff->dir.elem) == 0 && !ff->removed){
|
||||||
vtSetError(EExists);
|
werrstr(EExists);
|
||||||
goto Err;
|
goto Err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -839,7 +837,7 @@ fileSetDir(File *f, DirEntry *dir, char *uid)
|
|||||||
ff = dirLookup(f->up, dir->elem);
|
ff = dirLookup(f->up, dir->elem);
|
||||||
if(ff != nil){
|
if(ff != nil){
|
||||||
fileDecRef(ff);
|
fileDecRef(ff);
|
||||||
vtSetError(EExists);
|
werrstr(EExists);
|
||||||
goto Err;
|
goto Err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -868,17 +866,17 @@ fileSetDir(File *f, DirEntry *dir, char *uid)
|
|||||||
oelem = nil;
|
oelem = nil;
|
||||||
if(strcmp(f->dir.elem, dir->elem) != 0){
|
if(strcmp(f->dir.elem, dir->elem) != 0){
|
||||||
oelem = f->dir.elem;
|
oelem = f->dir.elem;
|
||||||
f->dir.elem = vtStrDup(dir->elem);
|
f->dir.elem = vtstrdup(dir->elem);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(strcmp(f->dir.uid, dir->uid) != 0){
|
if(strcmp(f->dir.uid, dir->uid) != 0){
|
||||||
vtMemFree(f->dir.uid);
|
vtfree(f->dir.uid);
|
||||||
f->dir.uid = vtStrDup(dir->uid);
|
f->dir.uid = vtstrdup(dir->uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(strcmp(f->dir.gid, dir->gid) != 0){
|
if(strcmp(f->dir.gid, dir->gid) != 0){
|
||||||
vtMemFree(f->dir.gid);
|
vtfree(f->dir.gid);
|
||||||
f->dir.gid = vtStrDup(dir->gid);
|
f->dir.gid = vtstrdup(dir->gid);
|
||||||
}
|
}
|
||||||
|
|
||||||
f->dir.mtime = dir->mtime;
|
f->dir.mtime = dir->mtime;
|
||||||
@ -892,7 +890,7 @@ fileSetDir(File *f, DirEntry *dir, char *uid)
|
|||||||
//fprint(2, "->%x\n", f->dir.mode);
|
//fprint(2, "->%x\n", f->dir.mode);
|
||||||
|
|
||||||
fileMetaFlush2(f, oelem);
|
fileMetaFlush2(f, oelem);
|
||||||
vtMemFree(oelem);
|
vtfree(oelem);
|
||||||
|
|
||||||
fileMetaUnlock(f);
|
fileMetaUnlock(f);
|
||||||
fileUnlock(f);
|
fileUnlock(f);
|
||||||
@ -1025,7 +1023,7 @@ fileMetaFlush(File *f, int rec)
|
|||||||
nkids = 0;
|
nkids = 0;
|
||||||
for(p=f->down; p; p=p->next)
|
for(p=f->down; p; p=p->next)
|
||||||
nkids++;
|
nkids++;
|
||||||
kids = vtMemAlloc(nkids*sizeof(File*));
|
kids = vtmalloc(nkids*sizeof(File*));
|
||||||
i = 0;
|
i = 0;
|
||||||
for(p=f->down; p; p=p->next){
|
for(p=f->down; p; p=p->next){
|
||||||
kids[i++] = p;
|
kids[i++] = p;
|
||||||
@ -1037,7 +1035,7 @@ fileMetaFlush(File *f, int rec)
|
|||||||
rv |= fileMetaFlush(kids[i], 1);
|
rv |= fileMetaFlush(kids[i], 1);
|
||||||
fileDecRef(kids[i]);
|
fileDecRef(kids[i]);
|
||||||
}
|
}
|
||||||
vtMemFree(kids);
|
vtfree(kids);
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1204,7 +1202,7 @@ fileCheckEmpty(File *f)
|
|||||||
if(!mbUnpack(&mb, b->data, r->dsize))
|
if(!mbUnpack(&mb, b->data, r->dsize))
|
||||||
goto Err;
|
goto Err;
|
||||||
if(mb.nindex > 0){
|
if(mb.nindex > 0){
|
||||||
vtSetError(ENotEmpty);
|
werrstr(ENotEmpty);
|
||||||
goto Err;
|
goto Err;
|
||||||
}
|
}
|
||||||
blockPut(b);
|
blockPut(b);
|
||||||
@ -1222,7 +1220,7 @@ fileRemove(File *f, char *uid)
|
|||||||
|
|
||||||
/* can not remove the root */
|
/* can not remove the root */
|
||||||
if(fileIsRoot(f)){
|
if(fileIsRoot(f)){
|
||||||
vtSetError(ERoot);
|
werrstr(ERoot);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1230,7 +1228,7 @@ fileRemove(File *f, char *uid)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if(f->source->mode != OReadWrite){
|
if(f->source->mode != OReadWrite){
|
||||||
vtSetError(EReadOnly);
|
werrstr(EReadOnly);
|
||||||
goto Err1;
|
goto Err1;
|
||||||
}
|
}
|
||||||
if(!sourceLock2(f->source, f->msource, -1))
|
if(!sourceLock2(f->source, f->msource, -1))
|
||||||
@ -1273,7 +1271,7 @@ clri(File *f, char *uid)
|
|||||||
if(f == nil)
|
if(f == nil)
|
||||||
return 0;
|
return 0;
|
||||||
if(f->up->source->mode != OReadWrite){
|
if(f->up->source->mode != OReadWrite){
|
||||||
vtSetError(EReadOnly);
|
werrstr(EReadOnly);
|
||||||
fileDecRef(f);
|
fileDecRef(f);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1359,7 +1357,7 @@ deeOpen(File *f)
|
|||||||
File *p;
|
File *p;
|
||||||
|
|
||||||
if(!fileIsDir(f)){
|
if(!fileIsDir(f)){
|
||||||
vtSetError(ENotDir);
|
werrstr(ENotDir);
|
||||||
fileDecRef(f);
|
fileDecRef(f);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
@ -1371,7 +1369,7 @@ deeOpen(File *f)
|
|||||||
fileMetaFlush2(p, nil);
|
fileMetaFlush2(p, nil);
|
||||||
fileUnlock(f);
|
fileUnlock(f);
|
||||||
|
|
||||||
dee = vtMemAllocZ(sizeof(DirEntryEnum));
|
dee = vtmallocz(sizeof(DirEntryEnum));
|
||||||
dee->file = fileIncRef(f);
|
dee->file = fileIncRef(f);
|
||||||
|
|
||||||
return dee;
|
return dee;
|
||||||
@ -1422,7 +1420,7 @@ deeFill(DirEntryEnum *dee)
|
|||||||
/* clean up first */
|
/* clean up first */
|
||||||
for(i=dee->i; i<dee->n; i++)
|
for(i=dee->i; i<dee->n; i++)
|
||||||
deCleanup(dee->buf+i);
|
deCleanup(dee->buf+i);
|
||||||
vtMemFree(dee->buf);
|
vtfree(dee->buf);
|
||||||
dee->buf = nil;
|
dee->buf = nil;
|
||||||
dee->i = 0;
|
dee->i = 0;
|
||||||
dee->n = 0;
|
dee->n = 0;
|
||||||
@ -1439,7 +1437,7 @@ deeFill(DirEntryEnum *dee)
|
|||||||
goto Err;
|
goto Err;
|
||||||
|
|
||||||
n = mb.nindex;
|
n = mb.nindex;
|
||||||
dee->buf = vtMemAlloc(n * sizeof(DirEntry));
|
dee->buf = vtmalloc(n * sizeof(DirEntry));
|
||||||
|
|
||||||
for(i=0; i<n; i++){
|
for(i=0; i<n; i++){
|
||||||
de = dee->buf + i;
|
de = dee->buf + i;
|
||||||
@ -1467,7 +1465,7 @@ deeRead(DirEntryEnum *dee, DirEntry *de)
|
|||||||
u32int nb;
|
u32int nb;
|
||||||
|
|
||||||
if(dee == nil){
|
if(dee == nil){
|
||||||
vtSetError("cannot happen in deeRead");
|
werrstr("cannot happen in deeRead");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1517,9 +1515,9 @@ deeClose(DirEntryEnum *dee)
|
|||||||
return;
|
return;
|
||||||
for(i=dee->i; i<dee->n; i++)
|
for(i=dee->i; i<dee->n; i++)
|
||||||
deCleanup(dee->buf+i);
|
deCleanup(dee->buf+i);
|
||||||
vtMemFree(dee->buf);
|
vtfree(dee->buf);
|
||||||
fileDecRef(dee->file);
|
fileDecRef(dee->file);
|
||||||
vtMemFree(dee);
|
vtfree(dee);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1574,7 +1572,7 @@ fileMetaAlloc(File *f, DirEntry *dir, u32int start)
|
|||||||
/* mbAlloc might have changed block */
|
/* mbAlloc might have changed block */
|
||||||
mbPack(&mb);
|
mbPack(&mb);
|
||||||
blockDirty(b);
|
blockDirty(b);
|
||||||
vtSetError(EBadMeta);
|
werrstr(EBadMeta);
|
||||||
goto Err;
|
goto Err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1617,7 +1615,7 @@ chkSource(File *f)
|
|||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if(f->source == nil || (f->dir.mode & ModeDir) && f->msource == nil){
|
if(f->source == nil || (f->dir.mode & ModeDir) && f->msource == nil){
|
||||||
vtSetError(ERemoved);
|
werrstr(ERemoved);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
@ -1626,8 +1624,8 @@ chkSource(File *f)
|
|||||||
static int
|
static int
|
||||||
fileRLock(File *f)
|
fileRLock(File *f)
|
||||||
{
|
{
|
||||||
assert(!vtCanLock(f->fs->elk));
|
assert(!canwlock(&f->fs->elk));
|
||||||
vtRLock(f->lk);
|
rlock(&f->lk);
|
||||||
if(!chkSource(f)){
|
if(!chkSource(f)){
|
||||||
fileRUnlock(f);
|
fileRUnlock(f);
|
||||||
return 0;
|
return 0;
|
||||||
@ -1638,14 +1636,14 @@ fileRLock(File *f)
|
|||||||
static void
|
static void
|
||||||
fileRUnlock(File *f)
|
fileRUnlock(File *f)
|
||||||
{
|
{
|
||||||
vtRUnlock(f->lk);
|
runlock(&f->lk);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
fileLock(File *f)
|
fileLock(File *f)
|
||||||
{
|
{
|
||||||
assert(!vtCanLock(f->fs->elk));
|
assert(!canwlock(&f->fs->elk));
|
||||||
vtLock(f->lk);
|
wlock(&f->lk);
|
||||||
if(!chkSource(f)){
|
if(!chkSource(f)){
|
||||||
fileUnlock(f);
|
fileUnlock(f);
|
||||||
return 0;
|
return 0;
|
||||||
@ -1656,7 +1654,7 @@ fileLock(File *f)
|
|||||||
static void
|
static void
|
||||||
fileUnlock(File *f)
|
fileUnlock(File *f)
|
||||||
{
|
{
|
||||||
vtUnlock(f->lk);
|
wunlock(&f->lk);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1670,14 +1668,14 @@ fileMetaLock(File *f)
|
|||||||
if(f->up == nil)
|
if(f->up == nil)
|
||||||
fprint(2, "f->elem = %s\n", f->dir.elem);
|
fprint(2, "f->elem = %s\n", f->dir.elem);
|
||||||
assert(f->up != nil);
|
assert(f->up != nil);
|
||||||
assert(!vtCanLock(f->fs->elk));
|
assert(!canwlock(&f->fs->elk));
|
||||||
vtLock(f->up->lk);
|
wlock(&f->up->lk);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
fileMetaUnlock(File *f)
|
fileMetaUnlock(File *f)
|
||||||
{
|
{
|
||||||
vtUnlock(f->up->lk);
|
wunlock(&f->up->lk);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1709,8 +1707,8 @@ fileWAccess(File* f, char *mid)
|
|||||||
fileMetaLock(f);
|
fileMetaLock(f);
|
||||||
f->dir.atime = f->dir.mtime = time(0L);
|
f->dir.atime = f->dir.mtime = time(0L);
|
||||||
if(strcmp(f->dir.mid, mid) != 0){
|
if(strcmp(f->dir.mid, mid) != 0){
|
||||||
vtMemFree(f->dir.mid);
|
vtfree(f->dir.mid);
|
||||||
f->dir.mid = vtStrDup(mid);
|
f->dir.mid = vtstrdup(mid);
|
||||||
}
|
}
|
||||||
f->dir.mcount++;
|
f->dir.mcount++;
|
||||||
f->dirty = 1;
|
f->dirty = 1;
|
||||||
@ -1842,11 +1840,11 @@ fileName(File *f)
|
|||||||
static char root[] = "/";
|
static char root[] = "/";
|
||||||
|
|
||||||
if (f == nil)
|
if (f == nil)
|
||||||
return vtStrDup("/**GOK**");
|
return vtstrdup("/**GOK**");
|
||||||
|
|
||||||
p = fileGetParent(f);
|
p = fileGetParent(f);
|
||||||
if (p == f)
|
if (p == f)
|
||||||
name = vtStrDup(root);
|
name = vtstrdup(root);
|
||||||
else {
|
else {
|
||||||
pname = fileName(p);
|
pname = fileName(p);
|
||||||
if (strcmp(pname, root) == 0)
|
if (strcmp(pname, root) == 0)
|
||||||
|
|||||||
@ -10,7 +10,7 @@ static void
|
|||||||
usage(void)
|
usage(void)
|
||||||
{
|
{
|
||||||
fprint(2, "usage: %s [-c cachesize] [-h host] file\n", argv0);
|
fprint(2, "usage: %s [-c cachesize] [-h host] file\n", argv0);
|
||||||
exits("usage");
|
threadexitsall("usage");
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma varargck argpos flprint 1
|
#pragma varargck argpos flprint 1
|
||||||
@ -52,10 +52,10 @@ flclose(Fsck*, Block *b, u32int epoch)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
main(int argc, char *argv[])
|
threadmain(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int csize = 1000;
|
int csize = 1000;
|
||||||
VtSession *z;
|
VtConn *z;
|
||||||
char *host = nil;
|
char *host = nil;
|
||||||
|
|
||||||
fsck.useventi = 1;
|
fsck.useventi = 1;
|
||||||
@ -82,28 +82,25 @@ main(int argc, char *argv[])
|
|||||||
if(argc != 1)
|
if(argc != 1)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
vtAttach();
|
|
||||||
|
|
||||||
fmtinstall('L', labelFmt);
|
fmtinstall('L', labelFmt);
|
||||||
fmtinstall('V', scoreFmt);
|
fmtinstall('V', scoreFmt);
|
||||||
fmtinstall('R', vtErrFmt);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Connect to Venti.
|
* Connect to Venti.
|
||||||
*/
|
*/
|
||||||
z = vtDial(host, 0);
|
z = vtdial(host);
|
||||||
if(z == nil){
|
if(z == nil){
|
||||||
if(fsck.useventi)
|
if(fsck.useventi)
|
||||||
vtFatal("could not connect to server: %s", vtGetError());
|
sysfatal("could not connect to server: %r");
|
||||||
}else if(!vtConnect(z, 0))
|
}else if(vtconnect(z) < 0)
|
||||||
vtFatal("vtConnect: %s", vtGetError());
|
sysfatal("vtconnect: %r");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize file system.
|
* Initialize file system.
|
||||||
*/
|
*/
|
||||||
fsck.fs = fsOpen(argv[0], z, csize, OReadOnly);
|
fsck.fs = fsOpen(argv[0], z, csize, OReadOnly);
|
||||||
if(fsck.fs == nil)
|
if(fsck.fs == nil)
|
||||||
vtFatal("could not open file system: %R");
|
sysfatal("could not open file system: %r");
|
||||||
|
|
||||||
fsck.print = flprint;
|
fsck.print = flprint;
|
||||||
fsck.clre = flclre;
|
fsck.clre = flclre;
|
||||||
@ -113,6 +110,6 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
fsCheck(&fsck);
|
fsCheck(&fsck);
|
||||||
|
|
||||||
exits(0);
|
threadexitsall(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -18,7 +18,7 @@ static u32int rootInit(Entry *e);
|
|||||||
static void topLevel(char *name);
|
static void topLevel(char *name);
|
||||||
static int parseScore(uchar[VtScoreSize], char*);
|
static int parseScore(uchar[VtScoreSize], char*);
|
||||||
static u32int ventiRoot(char*, char*);
|
static u32int ventiRoot(char*, char*);
|
||||||
static VtSession *z;
|
static VtConn *z;
|
||||||
|
|
||||||
#define TWID64 ((u64int)~(u64int)0)
|
#define TWID64 ((u64int)~(u64int)0)
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ confirm(char *msg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
main(int argc, char *argv[])
|
threadmain(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int fd, force;
|
int fd, force;
|
||||||
Header h;
|
Header h;
|
||||||
@ -96,28 +96,25 @@ main(int argc, char *argv[])
|
|||||||
usage();
|
usage();
|
||||||
|
|
||||||
if(iso9660file && score)
|
if(iso9660file && score)
|
||||||
vtFatal("cannot use -i with -v");
|
sysfatal("cannot use -i with -v");
|
||||||
|
|
||||||
vtAttach();
|
|
||||||
|
|
||||||
fmtinstall('V', scoreFmt);
|
fmtinstall('V', scoreFmt);
|
||||||
fmtinstall('R', vtErrFmt);
|
|
||||||
fmtinstall('L', labelFmt);
|
fmtinstall('L', labelFmt);
|
||||||
|
|
||||||
fd = open(argv[0], ORDWR);
|
fd = open(argv[0], ORDWR);
|
||||||
if(fd < 0)
|
if(fd < 0)
|
||||||
vtFatal("could not open file: %s: %r", argv[0]);
|
sysfatal("could not open file: %s: %r", argv[0]);
|
||||||
|
|
||||||
buf = vtMemAllocZ(bsize);
|
buf = vtmallocz(bsize);
|
||||||
if(pread(fd, buf, bsize, HeaderOffset) != bsize)
|
if(pread(fd, buf, bsize, HeaderOffset) != bsize)
|
||||||
vtFatal("could not read fs header block: %r");
|
sysfatal("could not read fs header block: %r");
|
||||||
|
|
||||||
if(headerUnpack(&h, buf) && !force
|
if(headerUnpack(&h, buf) && !force
|
||||||
&& !confirm("fs header block already exists; are you sure?"))
|
&& !confirm("fs header block already exists; are you sure?"))
|
||||||
goto Out;
|
goto Out;
|
||||||
|
|
||||||
if((d = dirfstat(fd)) == nil)
|
if((d = dirfstat(fd)) == nil)
|
||||||
vtFatal("dirfstat: %r");
|
sysfatal("dirfstat: %r");
|
||||||
|
|
||||||
if(d->type == 'M' && !force
|
if(d->type == 'M' && !force
|
||||||
&& !confirm("fs file is mounted via devmnt (is not a kernel device); are you sure?"))
|
&& !confirm("fs file is mounted via devmnt (is not a kernel device); are you sure?"))
|
||||||
@ -126,11 +123,11 @@ main(int argc, char *argv[])
|
|||||||
partition(fd, bsize, &h);
|
partition(fd, bsize, &h);
|
||||||
headerPack(&h, buf);
|
headerPack(&h, buf);
|
||||||
if(pwrite(fd, buf, bsize, HeaderOffset) < bsize)
|
if(pwrite(fd, buf, bsize, HeaderOffset) < bsize)
|
||||||
vtFatal("could not write fs header: %r");
|
sysfatal("could not write fs header: %r");
|
||||||
|
|
||||||
disk = diskAlloc(fd);
|
disk = diskAlloc(fd);
|
||||||
if(disk == nil)
|
if(disk == nil)
|
||||||
vtFatal("could not open disk: %r");
|
sysfatal("could not open disk: %r");
|
||||||
|
|
||||||
if(iso9660file)
|
if(iso9660file)
|
||||||
iso9660init(fd, &h, iso9660file, iso9660off);
|
iso9660init(fd, &h, iso9660file, iso9660off);
|
||||||
@ -150,15 +147,14 @@ main(int argc, char *argv[])
|
|||||||
root = rootInit(&e);
|
root = rootInit(&e);
|
||||||
}
|
}
|
||||||
|
|
||||||
superInit(label, root, vtZeroScore);
|
superInit(label, root, vtzeroscore);
|
||||||
diskFree(disk);
|
diskFree(disk);
|
||||||
|
|
||||||
if(score == nil)
|
if(score == nil)
|
||||||
topLevel(argv[0]);
|
topLevel(argv[0]);
|
||||||
|
|
||||||
Out:
|
Out:
|
||||||
vtDetach();
|
threadexitsall(0);
|
||||||
exits(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static u64int
|
static u64int
|
||||||
@ -169,7 +165,7 @@ fdsize(int fd)
|
|||||||
|
|
||||||
dir = dirfstat(fd);
|
dir = dirfstat(fd);
|
||||||
if(dir == nil)
|
if(dir == nil)
|
||||||
vtFatal("could not stat file: %r");
|
sysfatal("could not stat file: %r");
|
||||||
size = dir->length;
|
size = dir->length;
|
||||||
free(dir);
|
free(dir);
|
||||||
return size;
|
return size;
|
||||||
@ -180,7 +176,7 @@ usage(void)
|
|||||||
{
|
{
|
||||||
fprint(2, "usage: %s [-b blocksize] [-h host] [-i file offset] "
|
fprint(2, "usage: %s [-b blocksize] [-h host] [-i file offset] "
|
||||||
"[-l label] [-v score] [-y] file\n", argv0);
|
"[-l label] [-v score] [-y] file\n", argv0);
|
||||||
exits("usage");
|
threadexitsall("usage");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -203,7 +199,7 @@ partition(int fd, int bsize, Header *h)
|
|||||||
|
|
||||||
/* sanity check */
|
/* sanity check */
|
||||||
if(nblock < (HeaderOffset*10)/bsize)
|
if(nblock < (HeaderOffset*10)/bsize)
|
||||||
vtFatal("file too small");
|
sysfatal("file too small");
|
||||||
|
|
||||||
h->super = (HeaderOffset + 2*bsize)/bsize;
|
h->super = (HeaderOffset + 2*bsize)/bsize;
|
||||||
h->label = h->super + 1;
|
h->label = h->super + 1;
|
||||||
@ -236,7 +232,7 @@ entryInit(Entry *e)
|
|||||||
e->flags = VtEntryActive;
|
e->flags = VtEntryActive;
|
||||||
e->depth = 0;
|
e->depth = 0;
|
||||||
e->size = 0;
|
e->size = 0;
|
||||||
memmove(e->score, vtZeroScore, VtScoreSize);
|
memmove(e->score, vtzeroscore, VtScoreSize);
|
||||||
e->tag = tagGen();
|
e->tag = tagGen();
|
||||||
e->snap = 0;
|
e->snap = 0;
|
||||||
e->archive = 0;
|
e->archive = 0;
|
||||||
@ -252,16 +248,16 @@ rootMetaInit(Entry *e)
|
|||||||
MetaEntry me;
|
MetaEntry me;
|
||||||
|
|
||||||
memset(&de, 0, sizeof(de));
|
memset(&de, 0, sizeof(de));
|
||||||
de.elem = vtStrDup("root");
|
de.elem = vtstrdup("root");
|
||||||
de.entry = 0;
|
de.entry = 0;
|
||||||
de.gen = 0;
|
de.gen = 0;
|
||||||
de.mentry = 1;
|
de.mentry = 1;
|
||||||
de.mgen = 0;
|
de.mgen = 0;
|
||||||
de.size = 0;
|
de.size = 0;
|
||||||
de.qid = qid++;
|
de.qid = qid++;
|
||||||
de.uid = vtStrDup("adm");
|
de.uid = vtstrdup("adm");
|
||||||
de.gid = vtStrDup("adm");
|
de.gid = vtstrdup("adm");
|
||||||
de.mid = vtStrDup("adm");
|
de.mid = vtstrdup("adm");
|
||||||
de.mtime = time(0);
|
de.mtime = time(0);
|
||||||
de.mcount = 0;
|
de.mcount = 0;
|
||||||
de.ctime = time(0);
|
de.ctime = time(0);
|
||||||
@ -306,7 +302,7 @@ rootInit(Entry *e)
|
|||||||
entryPack(e, buf, 2);
|
entryPack(e, buf, 2);
|
||||||
|
|
||||||
entryInit(e);
|
entryInit(e);
|
||||||
e->flags |= VtEntryDir;
|
e->flags |= _VtEntryDir;
|
||||||
entryPack(e, buf, 0);
|
entryPack(e, buf, 0);
|
||||||
|
|
||||||
entryInit(e);
|
entryInit(e);
|
||||||
@ -315,7 +311,7 @@ rootInit(Entry *e)
|
|||||||
blockWrite(PartData, addr);
|
blockWrite(PartData, addr);
|
||||||
|
|
||||||
entryInit(e);
|
entryInit(e);
|
||||||
e->flags |= VtEntryLocal|VtEntryDir;
|
e->flags |= VtEntryLocal|_VtEntryDir;
|
||||||
e->size = VtEntrySize*3;
|
e->size = VtEntrySize*3;
|
||||||
e->tag = tag;
|
e->tag = tag;
|
||||||
localToGlobal(addr, e->score);
|
localToGlobal(addr, e->score);
|
||||||
@ -341,9 +337,9 @@ blockAlloc(int type, u32int tag)
|
|||||||
|
|
||||||
blockRead(PartLabel, addr/lpb);
|
blockRead(PartLabel, addr/lpb);
|
||||||
if(!labelUnpack(&l, buf, addr % lpb))
|
if(!labelUnpack(&l, buf, addr % lpb))
|
||||||
vtFatal("bad label: %r");
|
sysfatal("bad label: %r");
|
||||||
if(l.state != BsFree)
|
if(l.state != BsFree)
|
||||||
vtFatal("want to allocate block already in use");
|
sysfatal("want to allocate block already in use");
|
||||||
l.epoch = 1;
|
l.epoch = 1;
|
||||||
l.epochClose = ~(u32int)0;
|
l.epochClose = ~(u32int)0;
|
||||||
l.type = type;
|
l.type = type;
|
||||||
@ -403,14 +399,14 @@ static void
|
|||||||
blockRead(int part, u32int addr)
|
blockRead(int part, u32int addr)
|
||||||
{
|
{
|
||||||
if(!diskReadRaw(disk, part, addr, buf))
|
if(!diskReadRaw(disk, part, addr, buf))
|
||||||
vtFatal("read failed: %r");
|
sysfatal("read failed: %r");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
blockWrite(int part, u32int addr)
|
blockWrite(int part, u32int addr)
|
||||||
{
|
{
|
||||||
if(!diskWriteRaw(disk, part, addr, buf))
|
if(!diskWriteRaw(disk, part, addr, buf))
|
||||||
vtFatal("write failed: %r");
|
sysfatal("write failed: %r");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -420,7 +416,7 @@ addFile(File *root, char *name, uint mode)
|
|||||||
|
|
||||||
f = fileCreate(root, name, mode | ModeDir, "adm");
|
f = fileCreate(root, name, mode | ModeDir, "adm");
|
||||||
if(f == nil)
|
if(f == nil)
|
||||||
vtFatal("could not create file: %s: %r", name);
|
sysfatal("could not create file: %s: %r", name);
|
||||||
fileDecRef(f);
|
fileDecRef(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -433,18 +429,18 @@ topLevel(char *name)
|
|||||||
/* ok, now we can open as a fs */
|
/* ok, now we can open as a fs */
|
||||||
fs = fsOpen(name, z, 100, OReadWrite);
|
fs = fsOpen(name, z, 100, OReadWrite);
|
||||||
if(fs == nil)
|
if(fs == nil)
|
||||||
vtFatal("could not open file system: %r");
|
sysfatal("could not open file system: %r");
|
||||||
vtRLock(fs->elk);
|
rlock(&fs->elk);
|
||||||
root = fsGetRoot(fs);
|
root = fsGetRoot(fs);
|
||||||
if(root == nil)
|
if(root == nil)
|
||||||
vtFatal("could not open root: %r");
|
sysfatal("could not open root: %r");
|
||||||
addFile(root, "active", 0555);
|
addFile(root, "active", 0555);
|
||||||
addFile(root, "archive", 0555);
|
addFile(root, "archive", 0555);
|
||||||
addFile(root, "snapshot", 0555);
|
addFile(root, "snapshot", 0555);
|
||||||
fileDecRef(root);
|
fileDecRef(root);
|
||||||
if(iso9660file)
|
if(iso9660file)
|
||||||
iso9660copy(fs);
|
iso9660copy(fs);
|
||||||
vtRUnlock(fs->elk);
|
runlock(&fs->elk);
|
||||||
fsClose(fs);
|
fsClose(fs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -453,10 +449,10 @@ ventiRead(uchar score[VtScoreSize], int type)
|
|||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
n = vtRead(z, score, type, buf, bsize);
|
n = vtread(z, score, type, buf, bsize);
|
||||||
if(n < 0)
|
if(n < 0)
|
||||||
vtFatal("ventiRead %V (%d) failed: %R", score, type);
|
sysfatal("ventiRead %V (%d) failed: %r", score, type);
|
||||||
vtZeroExtend(type, buf, n, bsize);
|
vtzeroextend(type, buf, n, bsize);
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -473,18 +469,18 @@ ventiRoot(char *host, char *s)
|
|||||||
VtRoot root;
|
VtRoot root;
|
||||||
|
|
||||||
if(!parseScore(score, s))
|
if(!parseScore(score, s))
|
||||||
vtFatal("bad score '%s'", s);
|
sysfatal("bad score '%s'", s);
|
||||||
|
|
||||||
if((z = vtDial(host, 0)) == nil
|
if((z = vtdial(host)) == nil
|
||||||
|| !vtConnect(z, nil))
|
|| vtconnect(z) < 0)
|
||||||
vtFatal("connect to venti: %R");
|
sysfatal("connect to venti: %r");
|
||||||
|
|
||||||
tag = tagGen();
|
tag = tagGen();
|
||||||
addr = blockAlloc(BtDir, tag);
|
addr = blockAlloc(BtDir, tag);
|
||||||
|
|
||||||
ventiRead(score, VtRootType);
|
ventiRead(score, VtRootType);
|
||||||
if(!vtRootUnpack(&root, buf))
|
if(vtrootunpack(&root, buf) < 0)
|
||||||
vtFatal("corrupted root: vtRootUnpack");
|
sysfatal("corrupted root: vtrootunpack");
|
||||||
n = ventiRead(root.score, VtDirType);
|
n = ventiRead(root.score, VtDirType);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -493,7 +489,7 @@ ventiRoot(char *host, char *s)
|
|||||||
*/
|
*/
|
||||||
if(n <= 2*VtEntrySize){
|
if(n <= 2*VtEntrySize){
|
||||||
if(!entryUnpack(&e, buf, 0))
|
if(!entryUnpack(&e, buf, 0))
|
||||||
vtFatal("bad root: top entry");
|
sysfatal("bad root: top entry");
|
||||||
n = ventiRead(e.score, VtDirType);
|
n = ventiRead(e.score, VtDirType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -505,11 +501,11 @@ ventiRoot(char *host, char *s)
|
|||||||
|| !(e.flags&VtEntryActive)
|
|| !(e.flags&VtEntryActive)
|
||||||
|| e.psize < 256
|
|| e.psize < 256
|
||||||
|| e.dsize < 256)
|
|| e.dsize < 256)
|
||||||
vtFatal("bad root: entry %d", i);
|
sysfatal("bad root: entry %d", i);
|
||||||
fprint(2, "%V\n", e.score);
|
fprint(2, "%V\n", e.score);
|
||||||
}
|
}
|
||||||
if(n > 3*VtEntrySize)
|
if(n > 3*VtEntrySize)
|
||||||
vtFatal("bad root: entry count");
|
sysfatal("bad root: entry count");
|
||||||
|
|
||||||
blockWrite(PartData, addr);
|
blockWrite(PartData, addr);
|
||||||
|
|
||||||
@ -518,19 +514,19 @@ ventiRoot(char *host, char *s)
|
|||||||
*/
|
*/
|
||||||
ventiRead(e.score, VtDataType);
|
ventiRead(e.score, VtDataType);
|
||||||
if(!mbUnpack(&mb, buf, bsize))
|
if(!mbUnpack(&mb, buf, bsize))
|
||||||
vtFatal("bad root: mbUnpack");
|
sysfatal("bad root: mbUnpack");
|
||||||
meUnpack(&me, &mb, 0);
|
meUnpack(&me, &mb, 0);
|
||||||
if(!deUnpack(&de, &me))
|
if(!deUnpack(&de, &me))
|
||||||
vtFatal("bad root: dirUnpack");
|
sysfatal("bad root: dirUnpack");
|
||||||
if(!de.qidSpace)
|
if(!de.qidSpace)
|
||||||
vtFatal("bad root: no qidSpace");
|
sysfatal("bad root: no qidSpace");
|
||||||
qid = de.qidMax;
|
qid = de.qidMax;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Recreate the top layer of source.
|
* Recreate the top layer of source.
|
||||||
*/
|
*/
|
||||||
entryInit(&e);
|
entryInit(&e);
|
||||||
e.flags |= VtEntryLocal|VtEntryDir;
|
e.flags |= VtEntryLocal|_VtEntryDir;
|
||||||
e.size = VtEntrySize*3;
|
e.size = VtEntrySize*3;
|
||||||
e.tag = tag;
|
e.tag = tag;
|
||||||
localToGlobal(addr, e.score);
|
localToGlobal(addr, e.score);
|
||||||
|
|||||||
@ -28,7 +28,7 @@ enum{
|
|||||||
#pragma varargck type "L" uchar*
|
#pragma varargck type "L" uchar*
|
||||||
#pragma varargck type "B" uchar*
|
#pragma varargck type "B" uchar*
|
||||||
#pragma varargck type "N" uchar*
|
#pragma varargck type "N" uchar*
|
||||||
#pragma varargck type "T" uchar*
|
#pragma varargck type "C" uchar*
|
||||||
#pragma varargck type "D" uchar*
|
#pragma varargck type "D" uchar*
|
||||||
|
|
||||||
typedef struct Voldesc Voldesc;
|
typedef struct Voldesc Voldesc;
|
||||||
@ -73,8 +73,8 @@ dumpbootvol(void *a)
|
|||||||
if(v->magic[0] == 0xFF)
|
if(v->magic[0] == 0xFF)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
print("system %.32T\n", v->systemid);
|
print("system %.32C\n", v->systemid);
|
||||||
print("volume %.32T\n", v->volumeid);
|
print("volume %.32C\n", v->volumeid);
|
||||||
print("volume size %.4N\n", v->volsize);
|
print("volume size %.4N\n", v->volsize);
|
||||||
print("charset %.2ux %.2ux %.2ux %.2ux %.2ux %.2ux %.2ux %.2ux\n",
|
print("charset %.2ux %.2ux %.2ux %.2ux %.2ux %.2ux %.2ux %.2ux\n",
|
||||||
v->charset[0], v->charset[1], v->charset[2], v->charset[3],
|
v->charset[0], v->charset[1], v->charset[2], v->charset[3],
|
||||||
@ -88,13 +88,13 @@ dumpbootvol(void *a)
|
|||||||
print("mpath loc %.4B\n", v->mpathloc);
|
print("mpath loc %.4B\n", v->mpathloc);
|
||||||
print("opt mpath loc %.4B\n", v->ompathloc);
|
print("opt mpath loc %.4B\n", v->ompathloc);
|
||||||
print("rootdir %D\n", v->rootdir);
|
print("rootdir %D\n", v->rootdir);
|
||||||
print("volume set identifier %.128T\n", v->volsetid);
|
print("volume set identifier %.128C\n", v->volsetid);
|
||||||
print("publisher %.128T\n", v->publisher);
|
print("publisher %.128C\n", v->publisher);
|
||||||
print("preparer %.128T\n", v->prepid);
|
print("preparer %.128C\n", v->prepid);
|
||||||
print("application %.128T\n", v->applid);
|
print("application %.128C\n", v->applid);
|
||||||
print("notice %.37T\n", v->notice);
|
print("notice %.37C\n", v->notice);
|
||||||
print("abstract %.37T\n", v->abstract);
|
print("abstract %.37C\n", v->abstract);
|
||||||
print("biblio %.37T\n", v->biblio);
|
print("biblio %.37C\n", v->biblio);
|
||||||
print("creation date %.17s\n", v->cdate);
|
print("creation date %.17s\n", v->cdate);
|
||||||
print("modification date %.17s\n", v->mdate);
|
print("modification date %.17s\n", v->mdate);
|
||||||
print("expiration date %.17s\n", v->xdate);
|
print("expiration date %.17s\n", v->xdate);
|
||||||
@ -129,7 +129,7 @@ Dfmt(Fmt *fmt)
|
|||||||
snprint(buf, sizeof buf, ".%s dloc %.4N dlen %.4N",
|
snprint(buf, sizeof buf, ".%s dloc %.4N dlen %.4N",
|
||||||
c->name[0] ? "." : "", c->dloc, c->dlen);
|
c->name[0] ? "." : "", c->dloc, c->dlen);
|
||||||
} else {
|
} else {
|
||||||
snprint(buf, sizeof buf, "%.*T dloc %.4N dlen %.4N", c->namelen, c->name,
|
snprint(buf, sizeof buf, "%.*C dloc %.4N dlen %.4N", c->namelen, c->name,
|
||||||
c->dloc, c->dlen);
|
c->dloc, c->dlen);
|
||||||
}
|
}
|
||||||
fmtstrcpy(fmt, buf);
|
fmtstrcpy(fmt, buf);
|
||||||
@ -239,7 +239,7 @@ asciiTfmt(Fmt *fmt)
|
|||||||
static void
|
static void
|
||||||
ascii(void)
|
ascii(void)
|
||||||
{
|
{
|
||||||
fmtinstall('T', asciiTfmt);
|
fmtinstall('C', asciiTfmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -299,35 +299,35 @@ iso9660init(int xfd, Header *xh, char *xfile9660, int xoff9660)
|
|||||||
off9660 = xoff9660;
|
off9660 = xoff9660;
|
||||||
|
|
||||||
if((b = Bopen(file9660, OREAD)) == nil)
|
if((b = Bopen(file9660, OREAD)) == nil)
|
||||||
vtFatal("Bopen %s: %r", file9660);
|
sysfatal("Bopen %s: %r", file9660);
|
||||||
|
|
||||||
getsect(root, 16);
|
getsect(root, 16);
|
||||||
ascii();
|
ascii();
|
||||||
|
|
||||||
v = (Voldesc*)root;
|
v = (Voldesc*)root;
|
||||||
if(memcmp(v->magic, "\x01CD001\x01\x00", 8) != 0)
|
if(memcmp(v->magic, "\x01CD001\x01\x00", 8) != 0)
|
||||||
vtFatal("%s not a cd image", file9660);
|
sysfatal("%s not a cd image", file9660);
|
||||||
|
|
||||||
startoff = iso9660start((Cdir*)v->rootdir)*Blocksize;
|
startoff = iso9660start((Cdir*)v->rootdir)*Blocksize;
|
||||||
endoff = little(v->volsize, 4); /* already in bytes */
|
endoff = little(v->volsize, 4); /* already in bytes */
|
||||||
|
|
||||||
fsoff = off9660 + h->data*h->blockSize;
|
fsoff = off9660 + h->data*h->blockSize;
|
||||||
if(fsoff > startoff)
|
if(fsoff > startoff)
|
||||||
vtFatal("fossil data starts after cd data");
|
sysfatal("fossil data starts after cd data");
|
||||||
if(off9660 + (vlong)h->end*h->blockSize < endoff)
|
if(off9660 + (vlong)h->end*h->blockSize < endoff)
|
||||||
vtFatal("fossil data ends before cd data");
|
sysfatal("fossil data ends before cd data");
|
||||||
if(fsoff%h->blockSize)
|
if(fsoff%h->blockSize)
|
||||||
vtFatal("cd offset not a multiple of fossil block size");
|
sysfatal("cd offset not a multiple of fossil block size");
|
||||||
|
|
||||||
/* Read "same" block via CD image and via Fossil image */
|
/* Read "same" block via CD image and via Fossil image */
|
||||||
getsect(sect, startoff/Blocksize);
|
getsect(sect, startoff/Blocksize);
|
||||||
if(seek(fd, startoff-off9660, 0) < 0)
|
if(seek(fd, startoff-off9660, 0) < 0)
|
||||||
vtFatal("cannot seek to first data sector on cd via fossil");
|
sysfatal("cannot seek to first data sector on cd via fossil");
|
||||||
fprint(2, "look for %lud at %lud\n", startoff, startoff-off9660);
|
fprint(2, "look for %lud at %lud\n", startoff, startoff-off9660);
|
||||||
if(readn(fd, sect2, Blocksize) != Blocksize)
|
if(readn(fd, sect2, Blocksize) != Blocksize)
|
||||||
vtFatal("cannot read first data sector on cd via fossil");
|
sysfatal("cannot read first data sector on cd via fossil");
|
||||||
if(memcmp(sect, sect2, Blocksize) != 0)
|
if(memcmp(sect, sect2, Blocksize) != 0)
|
||||||
vtFatal("iso9660 offset is a lie %08ux %08ux", *(long*)sect, *(long*)sect2);
|
sysfatal("iso9660 offset is a lie %08lux %08lux", *(long*)sect, *(long*)sect2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -339,10 +339,10 @@ iso9660labels(Disk *disk, uchar *buf, void (*write)(int, u32int))
|
|||||||
uchar sect[Blocksize];
|
uchar sect[Blocksize];
|
||||||
|
|
||||||
if(!diskReadRaw(disk, PartData, (startoff-fsoff)/h->blockSize, buf))
|
if(!diskReadRaw(disk, PartData, (startoff-fsoff)/h->blockSize, buf))
|
||||||
vtFatal("disk read failed: %r");
|
sysfatal("disk read failed: %r");
|
||||||
getsect(sect, startoff/Blocksize);
|
getsect(sect, startoff/Blocksize);
|
||||||
if(memcmp(buf, sect, Blocksize) != 0)
|
if(memcmp(buf, sect, Blocksize) != 0)
|
||||||
vtFatal("fsoff is wrong");
|
sysfatal("fsoff is wrong");
|
||||||
|
|
||||||
sb = (startoff-fsoff)/h->blockSize;
|
sb = (startoff-fsoff)/h->blockSize;
|
||||||
eb = (endoff-fsoff+h->blockSize-1)/h->blockSize;
|
eb = (endoff-fsoff+h->blockSize-1)/h->blockSize;
|
||||||
@ -378,10 +378,10 @@ iso9660copy(Fs *fs)
|
|||||||
root = fileOpen(fs, "/active");
|
root = fileOpen(fs, "/active");
|
||||||
iso9660copydir(fs, root, (Cdir*)v->rootdir);
|
iso9660copydir(fs, root, (Cdir*)v->rootdir);
|
||||||
fileDecRef(root);
|
fileDecRef(root);
|
||||||
vtRUnlock(fs->elk);
|
runlock(&fs->elk);
|
||||||
if(!fsSnapshot(fs, nil, nil, 0))
|
if(!fsSnapshot(fs, nil, nil, 0))
|
||||||
vtFatal("snapshot failed: %R");
|
sysfatal("snapshot failed: %r");
|
||||||
vtRLock(fs->elk);
|
rlock(&fs->elk);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -400,7 +400,7 @@ iso9660start(Cdir *c)
|
|||||||
c = (Cdir*)((uchar*)c+c->len); /* skip dotdot */
|
c = (Cdir*)((uchar*)c+c->len); /* skip dotdot */
|
||||||
/* oops: might happen if leftmost directory is empty or leftmost file is zero length! */
|
/* oops: might happen if leftmost directory is empty or leftmost file is zero length! */
|
||||||
if(little(c->dloc, 4) == 0)
|
if(little(c->dloc, 4) == 0)
|
||||||
vtFatal("error parsing cd image or unfortunate cd image");
|
sysfatal("error parsing cd image or unfortunate cd image");
|
||||||
}
|
}
|
||||||
return little(c->dloc, 4);
|
return little(c->dloc, 4);
|
||||||
}
|
}
|
||||||
@ -519,7 +519,7 @@ iso9660copyfile(Fs *fs, File *dir, Cdir *c)
|
|||||||
p++;
|
p++;
|
||||||
sysl = (uchar*)c + c->len - p;
|
sysl = (uchar*)c + c->len - p;
|
||||||
if(sysl <= 0)
|
if(sysl <= 0)
|
||||||
vtFatal("missing plan9 directory entry on %d/%d/%.*s", c->namelen, c->name[0], c->namelen, c->name);
|
sysfatal("missing plan9 directory entry on %d/%d/%.*s", c->namelen, c->name[0], c->namelen, c->name);
|
||||||
d.name = getname(&p);
|
d.name = getname(&p);
|
||||||
d.uid = getname(&p);
|
d.uid = getname(&p);
|
||||||
d.gid = getname(&p);
|
d.gid = getname(&p);
|
||||||
@ -537,7 +537,7 @@ if(d.mode&DMDIR) print("%*scopy %s %s %s %luo\n", ind*2, "", d.name, d.uid, d.gi
|
|||||||
if(d.mode&DMDIR)
|
if(d.mode&DMDIR)
|
||||||
mode |= ModeDir;
|
mode |= ModeDir;
|
||||||
if((f = fileCreate(dir, d.name, mode, d.uid)) == nil)
|
if((f = fileCreate(dir, d.name, mode, d.uid)) == nil)
|
||||||
vtFatal("could not create file '%s': %r", d.name);
|
sysfatal("could not create file '%s': %r", d.name);
|
||||||
if(d.mode&DMDIR)
|
if(d.mode&DMDIR)
|
||||||
iso9660copydir(fs, f, c);
|
iso9660copydir(fs, f, c);
|
||||||
else{
|
else{
|
||||||
@ -546,20 +546,20 @@ if(d.mode&DMDIR) print("%*scopy %s %s %s %luo\n", ind*2, "", d.name, d.uid, d.gi
|
|||||||
for(foff=0; foff<len; foff+=h->blockSize){
|
for(foff=0; foff<len; foff+=h->blockSize){
|
||||||
localToGlobal((off+foff-fsoff)/h->blockSize, score);
|
localToGlobal((off+foff-fsoff)/h->blockSize, score);
|
||||||
if(!fileMapBlock(f, foff/h->blockSize, score, Tag))
|
if(!fileMapBlock(f, foff/h->blockSize, score, Tag))
|
||||||
vtFatal("fileMapBlock: %R");
|
sysfatal("fileMapBlock: %r");
|
||||||
}
|
}
|
||||||
if(!fileSetSize(f, len))
|
if(!fileSetSize(f, len))
|
||||||
vtFatal("fileSetSize: %R");
|
sysfatal("fileSetSize: %r");
|
||||||
}
|
}
|
||||||
if(!fileGetDir(f, &de))
|
if(!fileGetDir(f, &de))
|
||||||
vtFatal("fileGetDir: %R");
|
sysfatal("fileGetDir: %r");
|
||||||
de.uid = d.uid;
|
de.uid = d.uid;
|
||||||
de.gid = d.gid;
|
de.gid = d.gid;
|
||||||
de.mtime = d.mtime;
|
de.mtime = d.mtime;
|
||||||
de.atime = d.atime;
|
de.atime = d.atime;
|
||||||
de.mode = d.mode&0777;
|
de.mode = d.mode&0777;
|
||||||
if(!fileSetDir(f, &de, "sys"))
|
if(!fileSetDir(f, &de, "sys"))
|
||||||
vtFatal("fileSetDir: %R");
|
sysfatal("fileSetDir: %r");
|
||||||
fileDecRef(f);
|
fileDecRef(f);
|
||||||
ind--;
|
ind--;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,7 +18,7 @@ int sourceTruncate(Source*);
|
|||||||
void sourceUnlock(Source*);
|
void sourceUnlock(Source*);
|
||||||
|
|
||||||
Block* cacheAllocBlock(Cache*, int, u32int, u32int, u32int);
|
Block* cacheAllocBlock(Cache*, int, u32int, u32int, u32int);
|
||||||
Cache* cacheAlloc(Disk*, VtSession*, ulong, int);
|
Cache* cacheAlloc(Disk*, VtConn*, ulong, int);
|
||||||
void cacheCountUsed(Cache*, u32int, u32int*, u32int*, u32int*);
|
void cacheCountUsed(Cache*, u32int, u32int*, u32int*, u32int*);
|
||||||
int cacheDirty(Cache*);
|
int cacheDirty(Cache*);
|
||||||
void cacheFlush(Cache*, int);
|
void cacheFlush(Cache*, int);
|
||||||
@ -81,11 +81,11 @@ int fileGetSources(File*, Entry*, Entry*);
|
|||||||
File* fileRoot(Source*);
|
File* fileRoot(Source*);
|
||||||
int fileSnapshot(File*, File*, u32int, int);
|
int fileSnapshot(File*, File*, u32int, int);
|
||||||
int fsNextQid(Fs*, u64int*);
|
int fsNextQid(Fs*, u64int*);
|
||||||
int mkVac(VtSession*, uint, Entry*, Entry*, DirEntry*, uchar[VtScoreSize]);
|
int mkVac(VtConn*, uint, Entry*, Entry*, DirEntry*, uchar[VtScoreSize]);
|
||||||
Block* superGet(Cache*, Super*);
|
Block* superGet(Cache*, Super*);
|
||||||
|
|
||||||
void archFree(Arch*);
|
void archFree(Arch*);
|
||||||
Arch* archInit(Cache*, Disk*, Fs*, VtSession*);
|
Arch* archInit(Cache*, Disk*, Fs*, VtConn*);
|
||||||
void archKick(Arch*);
|
void archKick(Arch*);
|
||||||
|
|
||||||
void bwatchDependency(Block*);
|
void bwatchDependency(Block*);
|
||||||
|
|||||||
@ -12,7 +12,7 @@ static void
|
|||||||
usage(void)
|
usage(void)
|
||||||
{
|
{
|
||||||
fprint(2, "usage: %s [-Dt] [-c cmd] [-f partition] [-m %%]\n", argv0);
|
fprint(2, "usage: %s [-Dt] [-c cmd] [-f partition] [-m %%]\n", argv0);
|
||||||
exits("usage");
|
threadexitsall("usage");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -44,7 +44,7 @@ readCmdPart(char *file, char ***pcmd, int *pncmd)
|
|||||||
for(i=0; i<nf; i++){
|
for(i=0; i<nf; i++){
|
||||||
if(f[i][0] == '#')
|
if(f[i][0] == '#')
|
||||||
continue;
|
continue;
|
||||||
cmd = vtMemRealloc(cmd, (ncmd+1)*sizeof(char*));
|
cmd = vtrealloc(cmd, (ncmd+1)*sizeof(char*));
|
||||||
/* expand argument '*' to mean current file */
|
/* expand argument '*' to mean current file */
|
||||||
if((p = strchr(f[i], '*')) && (p==f[i]||isspace(p[-1])) && (p[1]==0||isspace(p[1]))){
|
if((p = strchr(f[i], '*')) && (p==f[i]||isspace(p[-1])) && (p[1]==0||isspace(p[1]))){
|
||||||
memmove(tbuf, f[i], p-f[i]);
|
memmove(tbuf, f[i], p-f[i]);
|
||||||
@ -52,7 +52,7 @@ readCmdPart(char *file, char ***pcmd, int *pncmd)
|
|||||||
strecpy(tbuf+strlen(tbuf), tbuf+sizeof tbuf, p+1);
|
strecpy(tbuf+strlen(tbuf), tbuf+sizeof tbuf, p+1);
|
||||||
f[i] = tbuf;
|
f[i] = tbuf;
|
||||||
}
|
}
|
||||||
cmd[ncmd++] = vtStrDup(f[i]);
|
cmd[ncmd++] = vtstrdup(f[i]);
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
*pcmd = cmd;
|
*pcmd = cmd;
|
||||||
@ -60,7 +60,7 @@ readCmdPart(char *file, char ***pcmd, int *pncmd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
main(int argc, char* argv[])
|
threadmain(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
char **cmd, *p;
|
char **cmd, *p;
|
||||||
int i, ncmd, tflag;
|
int i, ncmd, tflag;
|
||||||
@ -84,8 +84,6 @@ main(int argc, char* argv[])
|
|||||||
cmd = nil;
|
cmd = nil;
|
||||||
ncmd = tflag = 0;
|
ncmd = tflag = 0;
|
||||||
|
|
||||||
vtAttach();
|
|
||||||
|
|
||||||
ARGBEGIN{
|
ARGBEGIN{
|
||||||
case '?':
|
case '?':
|
||||||
default:
|
default:
|
||||||
@ -94,7 +92,7 @@ main(int argc, char* argv[])
|
|||||||
case 'c':
|
case 'c':
|
||||||
p = EARGF(usage());
|
p = EARGF(usage());
|
||||||
currfsysname = p;
|
currfsysname = p;
|
||||||
cmd = vtMemRealloc(cmd, (ncmd+1)*sizeof(char*));
|
cmd = vtrealloc(cmd, (ncmd+1)*sizeof(char*));
|
||||||
cmd[ncmd++] = p;
|
cmd[ncmd++] = p;
|
||||||
break;
|
break;
|
||||||
case 'D':
|
case 'D':
|
||||||
@ -132,12 +130,11 @@ main(int argc, char* argv[])
|
|||||||
|
|
||||||
for(i = 0; i < ncmd; i++)
|
for(i = 0; i < ncmd; i++)
|
||||||
if(cliExec(cmd[i]) == 0)
|
if(cliExec(cmd[i]) == 0)
|
||||||
fprint(2, "%s: %R\n", cmd[i]);
|
fprint(2, "%s: %r\n", cmd[i]);
|
||||||
vtMemFree(cmd);
|
vtfree(cmd);
|
||||||
|
|
||||||
if(tflag && consTTY() == 0)
|
if(tflag && consTTY() == 0)
|
||||||
consPrint("%s\n", vtGetError());
|
consPrint("%r\n");
|
||||||
|
|
||||||
vtDetach();
|
threadexits(0);
|
||||||
exits(0);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,7 +8,7 @@ static Snap *snapInit(Fs*);
|
|||||||
static void snapClose(Snap*);
|
static void snapClose(Snap*);
|
||||||
|
|
||||||
Fs *
|
Fs *
|
||||||
fsOpen(char *file, VtSession *z, long ncache, int mode)
|
fsOpen(char *file, VtConn *z, long ncache, int mode)
|
||||||
{
|
{
|
||||||
int fd, m;
|
int fd, m;
|
||||||
uchar oscore[VtScoreSize];
|
uchar oscore[VtScoreSize];
|
||||||
@ -16,10 +16,11 @@ fsOpen(char *file, VtSession *z, long ncache, int mode)
|
|||||||
Disk *disk;
|
Disk *disk;
|
||||||
Fs *fs;
|
Fs *fs;
|
||||||
Super super;
|
Super super;
|
||||||
|
char e[ERRMAX];
|
||||||
|
|
||||||
switch(mode){
|
switch(mode){
|
||||||
default:
|
default:
|
||||||
vtSetError(EBadMode);
|
werrstr(EBadMode);
|
||||||
return nil;
|
return nil;
|
||||||
case OReadOnly:
|
case OReadOnly:
|
||||||
m = OREAD;
|
m = OREAD;
|
||||||
@ -30,23 +31,22 @@ fsOpen(char *file, VtSession *z, long ncache, int mode)
|
|||||||
}
|
}
|
||||||
fd = open(file, m);
|
fd = open(file, m);
|
||||||
if(fd < 0){
|
if(fd < 0){
|
||||||
vtSetError("open %s: %r", file);
|
werrstr("open %s: %r", file);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
bwatchInit();
|
bwatchInit();
|
||||||
disk = diskAlloc(fd);
|
disk = diskAlloc(fd);
|
||||||
if(disk == nil){
|
if(disk == nil){
|
||||||
vtSetError("diskAlloc: %R");
|
werrstr("diskAlloc: %r");
|
||||||
close(fd);
|
close(fd);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
fs = vtMemAllocZ(sizeof(Fs));
|
fs = vtmallocz(sizeof(Fs));
|
||||||
fs->mode = mode;
|
fs->mode = mode;
|
||||||
fs->name = vtStrDup(file);
|
fs->name = vtstrdup(file);
|
||||||
fs->blockSize = diskBlockSize(disk);
|
fs->blockSize = diskBlockSize(disk);
|
||||||
fs->elk = vtLockAlloc();
|
|
||||||
fs->cache = cacheAlloc(disk, z, ncache, mode);
|
fs->cache = cacheAlloc(disk, z, ncache, mode);
|
||||||
if(mode == OReadWrite && z)
|
if(mode == OReadWrite && z)
|
||||||
fs->arch = archInit(fs->cache, disk, fs, z);
|
fs->arch = archInit(fs->cache, disk, fs, z);
|
||||||
@ -57,7 +57,7 @@ fsOpen(char *file, VtSession *z, long ncache, int mode)
|
|||||||
goto Err;
|
goto Err;
|
||||||
if(!superUnpack(&super, b->data)){
|
if(!superUnpack(&super, b->data)){
|
||||||
blockPut(b);
|
blockPut(b);
|
||||||
vtSetError("bad super block");
|
werrstr("bad super block");
|
||||||
goto Err;
|
goto Err;
|
||||||
}
|
}
|
||||||
blockPut(b);
|
blockPut(b);
|
||||||
@ -73,17 +73,18 @@ fsOpen(char *file, VtSession *z, long ncache, int mode)
|
|||||||
* Perhaps it failed because the block is copy-on-write.
|
* Perhaps it failed because the block is copy-on-write.
|
||||||
* Do the copy and try again.
|
* Do the copy and try again.
|
||||||
*/
|
*/
|
||||||
if(mode == OReadOnly || strcmp(vtGetError(), EBadRoot) != 0)
|
rerrstr(e, sizeof e);
|
||||||
|
if(mode == OReadOnly || strcmp(e, EBadRoot) != 0)
|
||||||
goto Err;
|
goto Err;
|
||||||
b = cacheLocalData(fs->cache, super.active, BtDir, RootTag,
|
b = cacheLocalData(fs->cache, super.active, BtDir, RootTag,
|
||||||
OReadWrite, 0);
|
OReadWrite, 0);
|
||||||
if(b == nil){
|
if(b == nil){
|
||||||
vtSetError("cacheLocalData: %R");
|
werrstr("cacheLocalData: %r");
|
||||||
goto Err;
|
goto Err;
|
||||||
}
|
}
|
||||||
if(b->l.epoch == fs->ehi){
|
if(b->l.epoch == fs->ehi){
|
||||||
blockPut(b);
|
blockPut(b);
|
||||||
vtSetError("bad root source block");
|
werrstr("bad root source block");
|
||||||
goto Err;
|
goto Err;
|
||||||
}
|
}
|
||||||
b = blockCopy(b, RootTag, fs->ehi, fs->elo);
|
b = blockCopy(b, RootTag, fs->ehi, fs->elo);
|
||||||
@ -94,7 +95,7 @@ fsOpen(char *file, VtSession *z, long ncache, int mode)
|
|||||||
bs = cacheLocal(fs->cache, PartSuper, 0, OReadWrite);
|
bs = cacheLocal(fs->cache, PartSuper, 0, OReadWrite);
|
||||||
if(bs == nil){
|
if(bs == nil){
|
||||||
blockPut(b);
|
blockPut(b);
|
||||||
vtSetError("cacheLocal: %R");
|
werrstr("cacheLocal: %r");
|
||||||
goto Err;
|
goto Err;
|
||||||
}
|
}
|
||||||
superPack(&super, bs->data);
|
superPack(&super, bs->data);
|
||||||
@ -105,19 +106,19 @@ fsOpen(char *file, VtSession *z, long ncache, int mode)
|
|||||||
blockPut(bs);
|
blockPut(bs);
|
||||||
fs->source = sourceRoot(fs, super.active, mode);
|
fs->source = sourceRoot(fs, super.active, mode);
|
||||||
if(fs->source == nil){
|
if(fs->source == nil){
|
||||||
vtSetError("sourceRoot: %R");
|
werrstr("sourceRoot: %r");
|
||||||
goto Err;
|
goto Err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//fprint(2, "%s: got fs source\n", argv0);
|
//fprint(2, "%s: got fs source\n", argv0);
|
||||||
|
|
||||||
vtRLock(fs->elk);
|
rlock(&fs->elk);
|
||||||
fs->file = fileRoot(fs->source);
|
fs->file = fileRoot(fs->source);
|
||||||
fs->source->file = fs->file; /* point back */
|
fs->source->file = fs->file; /* point back */
|
||||||
vtRUnlock(fs->elk);
|
runlock(&fs->elk);
|
||||||
if(fs->file == nil){
|
if(fs->file == nil){
|
||||||
vtSetError("fileRoot: %R");
|
werrstr("fileRoot: %r");
|
||||||
goto Err;
|
goto Err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,32 +139,31 @@ fprint(2, "%s: fsOpen error\n", argv0);
|
|||||||
void
|
void
|
||||||
fsClose(Fs *fs)
|
fsClose(Fs *fs)
|
||||||
{
|
{
|
||||||
vtRLock(fs->elk);
|
rlock(&fs->elk);
|
||||||
periodicKill(fs->metaFlush);
|
periodicKill(fs->metaFlush);
|
||||||
snapClose(fs->snap);
|
snapClose(fs->snap);
|
||||||
if(fs->file){
|
if(fs->file){
|
||||||
fileMetaFlush(fs->file, 0);
|
fileMetaFlush(fs->file, 0);
|
||||||
if(!fileDecRef(fs->file))
|
if(!fileDecRef(fs->file))
|
||||||
vtFatal("fsClose: files still in use: %r\n");
|
sysfatal("fsClose: files still in use: %r");
|
||||||
}
|
}
|
||||||
fs->file = nil;
|
fs->file = nil;
|
||||||
sourceClose(fs->source);
|
sourceClose(fs->source);
|
||||||
cacheFree(fs->cache);
|
cacheFree(fs->cache);
|
||||||
if(fs->arch)
|
if(fs->arch)
|
||||||
archFree(fs->arch);
|
archFree(fs->arch);
|
||||||
vtMemFree(fs->name);
|
vtfree(fs->name);
|
||||||
vtRUnlock(fs->elk);
|
runlock(&fs->elk);
|
||||||
vtLockFree(fs->elk);
|
|
||||||
memset(fs, ~0, sizeof(Fs));
|
memset(fs, ~0, sizeof(Fs));
|
||||||
vtMemFree(fs);
|
vtfree(fs);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
fsRedial(Fs *fs, char *host)
|
fsRedial(Fs *fs, char *host)
|
||||||
{
|
{
|
||||||
if(!vtRedial(fs->z, host))
|
if(vtredial(fs->z, host) < 0)
|
||||||
return 0;
|
return 0;
|
||||||
if(!vtConnect(fs->z, 0))
|
if(vtconnect(fs->z) < 0)
|
||||||
return 0;
|
return 0;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -186,11 +186,11 @@ superGet(Cache *c, Super* super)
|
|||||||
Block *b;
|
Block *b;
|
||||||
|
|
||||||
if((b = cacheLocal(c, PartSuper, 0, OReadWrite)) == nil){
|
if((b = cacheLocal(c, PartSuper, 0, OReadWrite)) == nil){
|
||||||
fprint(2, "%s: superGet: cacheLocal failed: %R\n", argv0);
|
fprint(2, "%s: superGet: cacheLocal failed: %r\n", argv0);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
if(!superUnpack(super, b->data)){
|
if(!superUnpack(super, b->data)){
|
||||||
fprint(2, "%s: superGet: superUnpack failed: %R\n", argv0);
|
fprint(2, "%s: superGet: superUnpack failed: %r\n", argv0);
|
||||||
blockPut(b);
|
blockPut(b);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
@ -212,7 +212,7 @@ superWrite(Block* b, Super* super, int forceWrite)
|
|||||||
}
|
}
|
||||||
while(b->iostate != BioClean && b->iostate != BioDirty){
|
while(b->iostate != BioClean && b->iostate != BioDirty){
|
||||||
assert(b->iostate == BioWriting);
|
assert(b->iostate == BioWriting);
|
||||||
vtSleep(b->ioready);
|
rsleep(&b->ioready);
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* it's okay that b might still be dirty.
|
* it's okay that b might still be dirty.
|
||||||
@ -361,13 +361,13 @@ fsNeedArch(Fs *fs, uint archMinute)
|
|||||||
snprint(buf, sizeof buf, "/archive/%d/%02d%02d",
|
snprint(buf, sizeof buf, "/archive/%d/%02d%02d",
|
||||||
now.year+1900, now.mon+1, now.mday);
|
now.year+1900, now.mon+1, now.mday);
|
||||||
need = 1;
|
need = 1;
|
||||||
vtRLock(fs->elk);
|
rlock(&fs->elk);
|
||||||
f = fileOpen(fs, buf);
|
f = fileOpen(fs, buf);
|
||||||
if(f){
|
if(f){
|
||||||
need = 0;
|
need = 0;
|
||||||
fileDecRef(f);
|
fileDecRef(f);
|
||||||
}
|
}
|
||||||
vtRUnlock(fs->elk);
|
runlock(&fs->elk);
|
||||||
return need;
|
return need;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -377,15 +377,15 @@ fsEpochLow(Fs *fs, u32int low)
|
|||||||
Block *bs;
|
Block *bs;
|
||||||
Super super;
|
Super super;
|
||||||
|
|
||||||
vtLock(fs->elk);
|
wlock(&fs->elk);
|
||||||
if(low > fs->ehi){
|
if(low > fs->ehi){
|
||||||
vtSetError("bad low epoch (must be <= %ud)", fs->ehi);
|
werrstr("bad low epoch (must be <= %ud)", fs->ehi);
|
||||||
vtUnlock(fs->elk);
|
wunlock(&fs->elk);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((bs = superGet(fs->cache, &super)) == nil){
|
if((bs = superGet(fs->cache, &super)) == nil){
|
||||||
vtUnlock(fs->elk);
|
wunlock(&fs->elk);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -393,7 +393,7 @@ fsEpochLow(Fs *fs, u32int low)
|
|||||||
fs->elo = low;
|
fs->elo = low;
|
||||||
superWrite(bs, &super, 1);
|
superWrite(bs, &super, 1);
|
||||||
blockPut(bs);
|
blockPut(bs);
|
||||||
vtUnlock(fs->elk);
|
wunlock(&fs->elk);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -421,14 +421,14 @@ bumpEpoch(Fs *fs, int doarchive)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
memset(&e, 0, sizeof e);
|
memset(&e, 0, sizeof e);
|
||||||
e.flags = VtEntryActive | VtEntryLocal | VtEntryDir;
|
e.flags = VtEntryActive | VtEntryLocal | _VtEntryDir;
|
||||||
memmove(e.score, b->score, VtScoreSize);
|
memmove(e.score, b->score, VtScoreSize);
|
||||||
e.tag = RootTag;
|
e.tag = RootTag;
|
||||||
e.snap = b->l.epoch;
|
e.snap = b->l.epoch;
|
||||||
|
|
||||||
b = blockCopy(b, RootTag, fs->ehi+1, fs->elo);
|
b = blockCopy(b, RootTag, fs->ehi+1, fs->elo);
|
||||||
if(b == nil){
|
if(b == nil){
|
||||||
fprint(2, "%s: bumpEpoch: blockCopy: %R\n", argv0);
|
fprint(2, "%s: bumpEpoch: blockCopy: %r\n", argv0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -507,14 +507,14 @@ fsSnapshot(Fs *fs, char *srcpath, char *dstpath, int doarchive)
|
|||||||
dst = nil;
|
dst = nil;
|
||||||
|
|
||||||
if(fs->halted){
|
if(fs->halted){
|
||||||
vtSetError("file system is halted");
|
werrstr("file system is halted");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Freeze file system activity.
|
* Freeze file system activity.
|
||||||
*/
|
*/
|
||||||
vtLock(fs->elk);
|
wlock(&fs->elk);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the root of the directory we're going to save.
|
* Get the root of the directory we're going to save.
|
||||||
@ -599,7 +599,7 @@ fsSnapshot(Fs *fs, char *srcpath, char *dstpath, int doarchive)
|
|||||||
goto Err;
|
goto Err;
|
||||||
}
|
}
|
||||||
|
|
||||||
vtUnlock(fs->elk);
|
wunlock(&fs->elk);
|
||||||
|
|
||||||
/* BUG? can fs->arch fall out from under us here? */
|
/* BUG? can fs->arch fall out from under us here? */
|
||||||
if(doarchive && fs->arch)
|
if(doarchive && fs->arch)
|
||||||
@ -608,12 +608,12 @@ fsSnapshot(Fs *fs, char *srcpath, char *dstpath, int doarchive)
|
|||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
Err:
|
Err:
|
||||||
fprint(2, "%s: fsSnapshot: %R\n", argv0);
|
fprint(2, "%s: fsSnapshot: %r\n", argv0);
|
||||||
if(src)
|
if(src)
|
||||||
fileDecRef(src);
|
fileDecRef(src);
|
||||||
if(dst)
|
if(dst)
|
||||||
fileDecRef(dst);
|
fileDecRef(dst);
|
||||||
vtUnlock(fs->elk);
|
wunlock(&fs->elk);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -625,37 +625,37 @@ fsVac(Fs *fs, char *name, uchar score[VtScoreSize])
|
|||||||
Entry e, ee;
|
Entry e, ee;
|
||||||
File *f;
|
File *f;
|
||||||
|
|
||||||
vtRLock(fs->elk);
|
rlock(&fs->elk);
|
||||||
f = fileOpen(fs, name);
|
f = fileOpen(fs, name);
|
||||||
if(f == nil){
|
if(f == nil){
|
||||||
vtRUnlock(fs->elk);
|
runlock(&fs->elk);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!fileGetSources(f, &e, &ee) || !fileGetDir(f, &de)){
|
if(!fileGetSources(f, &e, &ee) || !fileGetDir(f, &de)){
|
||||||
fileDecRef(f);
|
fileDecRef(f);
|
||||||
vtRUnlock(fs->elk);
|
runlock(&fs->elk);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
fileDecRef(f);
|
fileDecRef(f);
|
||||||
|
|
||||||
r = mkVac(fs->z, fs->blockSize, &e, &ee, &de, score);
|
r = mkVac(fs->z, fs->blockSize, &e, &ee, &de, score);
|
||||||
vtRUnlock(fs->elk);
|
runlock(&fs->elk);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
vtWriteBlock(VtSession *z, uchar *buf, uint n, uint type, uchar score[VtScoreSize])
|
vtWriteBlock(VtConn *z, uchar *buf, uint n, uint type, uchar score[VtScoreSize])
|
||||||
{
|
{
|
||||||
if(!vtWrite(z, score, type, buf, n))
|
if(vtwrite(z, score, type, buf, n) < 0)
|
||||||
return 0;
|
return 0;
|
||||||
if(!vtSha1Check(score, buf, n))
|
if(vtsha1check(score, buf, n) < 0)
|
||||||
return 0;
|
return 0;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
mkVac(VtSession *z, uint blockSize, Entry *pe, Entry *pee, DirEntry *pde, uchar score[VtScoreSize])
|
mkVac(VtConn *z, uint blockSize, Entry *pe, Entry *pee, DirEntry *pde, uchar score[VtScoreSize])
|
||||||
{
|
{
|
||||||
uchar buf[8192];
|
uchar buf[8192];
|
||||||
int i;
|
int i;
|
||||||
@ -673,7 +673,7 @@ mkVac(VtSession *z, uint blockSize, Entry *pe, Entry *pee, DirEntry *pde, uchar
|
|||||||
|
|
||||||
if(globalToLocal(e.score) != NilBlock
|
if(globalToLocal(e.score) != NilBlock
|
||||||
|| (ee.flags&VtEntryActive && globalToLocal(ee.score) != NilBlock)){
|
|| (ee.flags&VtEntryActive && globalToLocal(ee.score) != NilBlock)){
|
||||||
vtSetError("can only vac paths already stored on venti");
|
werrstr("can only vac paths already stored on venti");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -682,7 +682,7 @@ mkVac(VtSession *z, uint blockSize, Entry *pe, Entry *pee, DirEntry *pde, uchar
|
|||||||
*/
|
*/
|
||||||
n = deSize(&de);
|
n = deSize(&de);
|
||||||
if(n+MetaHeaderSize+MetaIndexSize > sizeof buf){
|
if(n+MetaHeaderSize+MetaIndexSize > sizeof buf){
|
||||||
vtSetError("DirEntry too big");
|
werrstr("DirEntry too big");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
memset(buf, 0, sizeof buf);
|
memset(buf, 0, sizeof buf);
|
||||||
@ -721,11 +721,10 @@ mkVac(VtSession *z, uint blockSize, Entry *pe, Entry *pee, DirEntry *pde, uchar
|
|||||||
/*
|
/*
|
||||||
* Save root.
|
* Save root.
|
||||||
*/
|
*/
|
||||||
root.version = VtRootVersion;
|
|
||||||
strecpy(root.type, root.type+sizeof root.type, "vac");
|
strecpy(root.type, root.type+sizeof root.type, "vac");
|
||||||
strecpy(root.name, root.name+sizeof root.name, de.elem);
|
strecpy(root.name, root.name+sizeof root.name, de.elem);
|
||||||
root.blockSize = blockSize;
|
root.blocksize = blockSize;
|
||||||
vtRootPack(&root, buf);
|
vtrootpack(&root, buf);
|
||||||
if(!vtWriteBlock(z, buf, VtRootSize, VtRootType, score))
|
if(!vtWriteBlock(z, buf, VtRootSize, VtRootType, score))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -735,17 +734,17 @@ mkVac(VtSession *z, uint blockSize, Entry *pe, Entry *pee, DirEntry *pde, uchar
|
|||||||
int
|
int
|
||||||
fsSync(Fs *fs)
|
fsSync(Fs *fs)
|
||||||
{
|
{
|
||||||
vtLock(fs->elk);
|
wlock(&fs->elk);
|
||||||
fileMetaFlush(fs->file, 1);
|
fileMetaFlush(fs->file, 1);
|
||||||
cacheFlush(fs->cache, 1);
|
cacheFlush(fs->cache, 1);
|
||||||
vtUnlock(fs->elk);
|
wunlock(&fs->elk);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
fsHalt(Fs *fs)
|
fsHalt(Fs *fs)
|
||||||
{
|
{
|
||||||
vtLock(fs->elk);
|
wlock(&fs->elk);
|
||||||
fs->halted = 1;
|
fs->halted = 1;
|
||||||
fileMetaFlush(fs->file, 1);
|
fileMetaFlush(fs->file, 1);
|
||||||
cacheFlush(fs->cache, 1);
|
cacheFlush(fs->cache, 1);
|
||||||
@ -758,7 +757,7 @@ fsUnhalt(Fs *fs)
|
|||||||
if(!fs->halted)
|
if(!fs->halted)
|
||||||
return 0;
|
return 0;
|
||||||
fs->halted = 0;
|
fs->halted = 0;
|
||||||
vtUnlock(fs->elk);
|
wunlock(&fs->elk);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -789,9 +788,9 @@ fsMetaFlush(void *a)
|
|||||||
int rv;
|
int rv;
|
||||||
Fs *fs = a;
|
Fs *fs = a;
|
||||||
|
|
||||||
vtRLock(fs->elk);
|
rlock(&fs->elk);
|
||||||
rv = fileMetaFlush(fs->file, 1);
|
rv = fileMetaFlush(fs->file, 1);
|
||||||
vtRUnlock(fs->elk);
|
runlock(&fs->elk);
|
||||||
if(rv > 0)
|
if(rv > 0)
|
||||||
cacheFlush(fs->cache, 0);
|
cacheFlush(fs->cache, 0);
|
||||||
}
|
}
|
||||||
@ -828,7 +827,7 @@ fsEsearch1(File *f, char *path, u32int savetime, u32int *plo)
|
|||||||
if((ff = fileWalk(f, de.elem)) != nil){
|
if((ff = fileWalk(f, de.elem)) != nil){
|
||||||
t = smprint("%s/%s", path, de.elem);
|
t = smprint("%s/%s", path, de.elem);
|
||||||
n += fsEsearch1(ff, t, savetime, plo);
|
n += fsEsearch1(ff, t, savetime, plo);
|
||||||
vtMemFree(t);
|
vtfree(t);
|
||||||
fileDecRef(ff);
|
fileDecRef(ff);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -876,11 +875,11 @@ fsSnapshotCleanup(Fs *fs, u32int age)
|
|||||||
* given that we need to save all the unventied archives
|
* given that we need to save all the unventied archives
|
||||||
* and all the snapshots younger than age.
|
* and all the snapshots younger than age.
|
||||||
*/
|
*/
|
||||||
vtRLock(fs->elk);
|
rlock(&fs->elk);
|
||||||
lo = fs->ehi;
|
lo = fs->ehi;
|
||||||
fsEsearch(fs, "/archive", 0, &lo);
|
fsEsearch(fs, "/archive", 0, &lo);
|
||||||
fsEsearch(fs, "/snapshot", time(0)-age*60, &lo);
|
fsEsearch(fs, "/snapshot", time(0)-age*60, &lo);
|
||||||
vtRUnlock(fs->elk);
|
runlock(&fs->elk);
|
||||||
|
|
||||||
fsEpochLow(fs, lo);
|
fsEpochLow(fs, lo);
|
||||||
fsSnapshotRemove(fs);
|
fsSnapshotRemove(fs);
|
||||||
@ -895,7 +894,7 @@ fsRsearch1(File *f, char *s)
|
|||||||
DirEntry de;
|
DirEntry de;
|
||||||
DirEntryEnum *dee;
|
DirEntryEnum *dee;
|
||||||
File *ff;
|
File *ff;
|
||||||
char *t;
|
char *t, e[ERRMAX];
|
||||||
|
|
||||||
dee = deeOpen(f);
|
dee = deeOpen(f);
|
||||||
if(dee == nil)
|
if(dee == nil)
|
||||||
@ -908,9 +907,10 @@ fsRsearch1(File *f, char *s)
|
|||||||
break;
|
break;
|
||||||
n++;
|
n++;
|
||||||
if(de.mode & ModeSnapshot){
|
if(de.mode & ModeSnapshot){
|
||||||
|
rerrstr(e, sizeof e);
|
||||||
if((ff = fileWalk(f, de.elem)) != nil)
|
if((ff = fileWalk(f, de.elem)) != nil)
|
||||||
fileDecRef(ff);
|
fileDecRef(ff);
|
||||||
else if(strcmp(vtGetError(), ESnapOld) == 0){
|
else if(strcmp(e, ESnapOld) == 0){
|
||||||
if(fileClri(f, de.elem, "adm"))
|
if(fileClri(f, de.elem, "adm"))
|
||||||
n--;
|
n--;
|
||||||
}
|
}
|
||||||
@ -921,7 +921,7 @@ fsRsearch1(File *f, char *s)
|
|||||||
if(fsRsearch1(ff, t) == 0)
|
if(fsRsearch1(ff, t) == 0)
|
||||||
if(fileRemove(ff, "adm"))
|
if(fileRemove(ff, "adm"))
|
||||||
n--;
|
n--;
|
||||||
vtMemFree(t);
|
vtfree(t);
|
||||||
fileDecRef(ff);
|
fileDecRef(ff);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -961,16 +961,16 @@ fsRsearch(Fs *fs, char *path)
|
|||||||
void
|
void
|
||||||
fsSnapshotRemove(Fs *fs)
|
fsSnapshotRemove(Fs *fs)
|
||||||
{
|
{
|
||||||
vtRLock(fs->elk);
|
rlock(&fs->elk);
|
||||||
fsRsearch(fs, "/snapshot");
|
fsRsearch(fs, "/snapshot");
|
||||||
vtRUnlock(fs->elk);
|
runlock(&fs->elk);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Snap
|
struct Snap
|
||||||
{
|
{
|
||||||
Fs *fs;
|
Fs *fs;
|
||||||
Periodic*tick;
|
Periodic*tick;
|
||||||
VtLock *lk;
|
QLock lk;
|
||||||
uint snapMinutes;
|
uint snapMinutes;
|
||||||
uint archMinute;
|
uint archMinute;
|
||||||
uint snapLife;
|
uint snapLife;
|
||||||
@ -992,7 +992,7 @@ snapEvent(void *v)
|
|||||||
s = v;
|
s = v;
|
||||||
|
|
||||||
now = time(0)/60;
|
now = time(0)/60;
|
||||||
vtLock(s->lk);
|
qlock(&s->lk);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Snapshots happen every snapMinutes minutes.
|
* Snapshots happen every snapMinutes minutes.
|
||||||
@ -1002,7 +1002,7 @@ snapEvent(void *v)
|
|||||||
if(s->snapMinutes != ~0 && s->snapMinutes != 0
|
if(s->snapMinutes != ~0 && s->snapMinutes != 0
|
||||||
&& now%s->snapMinutes==0 && now != s->lastSnap){
|
&& now%s->snapMinutes==0 && now != s->lastSnap){
|
||||||
if(!fsSnapshot(s->fs, nil, nil, 0))
|
if(!fsSnapshot(s->fs, nil, nil, 0))
|
||||||
fprint(2, "%s: fsSnapshot snap: %R\n", argv0);
|
fprint(2, "%s: fsSnapshot snap: %r\n", argv0);
|
||||||
s->lastSnap = now;
|
s->lastSnap = now;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1038,7 +1038,7 @@ snapEvent(void *v)
|
|||||||
fsSnapshotCleanup(s->fs, s->snapLife);
|
fsSnapshotCleanup(s->fs, s->snapLife);
|
||||||
s->lastCleanup = now;
|
s->lastCleanup = now;
|
||||||
}
|
}
|
||||||
vtUnlock(s->lk);
|
qunlock(&s->lk);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Snap*
|
static Snap*
|
||||||
@ -1046,10 +1046,9 @@ snapInit(Fs *fs)
|
|||||||
{
|
{
|
||||||
Snap *s;
|
Snap *s;
|
||||||
|
|
||||||
s = vtMemAllocZ(sizeof(Snap));
|
s = vtmallocz(sizeof(Snap));
|
||||||
s->fs = fs;
|
s->fs = fs;
|
||||||
s->tick = periodicAlloc(snapEvent, s, 10*1000);
|
s->tick = periodicAlloc(snapEvent, s, 10*1000);
|
||||||
s->lk = vtLockAlloc();
|
|
||||||
s->snapMinutes = -1;
|
s->snapMinutes = -1;
|
||||||
s->archMinute = -1;
|
s->archMinute = -1;
|
||||||
s->snapLife = -1;
|
s->snapLife = -1;
|
||||||
@ -1067,11 +1066,11 @@ snapGetTimes(Snap *s, u32int *arch, u32int *snap, u32int *snaplen)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
vtLock(s->lk);
|
qlock(&s->lk);
|
||||||
*snap = s->snapMinutes;
|
*snap = s->snapMinutes;
|
||||||
*arch = s->archMinute;
|
*arch = s->archMinute;
|
||||||
*snaplen = s->snapLife;
|
*snaplen = s->snapLife;
|
||||||
vtUnlock(s->lk);
|
qunlock(&s->lk);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -1080,11 +1079,11 @@ snapSetTimes(Snap *s, u32int arch, u32int snap, u32int snaplen)
|
|||||||
if(s == nil)
|
if(s == nil)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
vtLock(s->lk);
|
qlock(&s->lk);
|
||||||
s->snapMinutes = snap;
|
s->snapMinutes = snap;
|
||||||
s->archMinute = arch;
|
s->archMinute = arch;
|
||||||
s->snapLife = snaplen;
|
s->snapLife = snaplen;
|
||||||
vtUnlock(s->lk);
|
qunlock(&s->lk);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -1094,6 +1093,6 @@ snapClose(Snap *s)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
periodicKill(s->tick);
|
periodicKill(s->tick);
|
||||||
vtMemFree(s);
|
vtfree(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -6,6 +6,17 @@ typedef struct DirEntryEnum DirEntryEnum;
|
|||||||
#pragma incomplete File
|
#pragma incomplete File
|
||||||
#pragma incomplete DirEntryEnum
|
#pragma incomplete DirEntryEnum
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
STACK = 32*1024,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
// XXX What to do here?
|
||||||
|
VtMaxLumpSize = 65536,
|
||||||
|
};
|
||||||
|
|
||||||
/* modes */
|
/* modes */
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
@ -21,7 +32,7 @@ void fsClose(Fs*);
|
|||||||
int fsEpochLow(Fs*, u32int);
|
int fsEpochLow(Fs*, u32int);
|
||||||
File *fsGetRoot(Fs*);
|
File *fsGetRoot(Fs*);
|
||||||
int fsHalt(Fs*);
|
int fsHalt(Fs*);
|
||||||
Fs *fsOpen(char*, VtSession*, long, int);
|
Fs *fsOpen(char*, VtConn*, long, int);
|
||||||
int fsRedial(Fs*, char*);
|
int fsRedial(Fs*, char*);
|
||||||
void fsSnapshotCleanup(Fs*, u32int);
|
void fsSnapshotCleanup(Fs*, u32int);
|
||||||
int fsSnapshot(Fs*, char*, char*, int);
|
int fsSnapshot(Fs*, char*, char*, int);
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
</$objtype/mkfile
|
</$objtype/mkfile
|
||||||
BIN=/$objtype/bin/fossil
|
BIN=/$objtype/bin/fossil
|
||||||
|
|
||||||
TARG=fossil flchk flfmt conf last
|
TARG=fossil flchk flfmt conf last view
|
||||||
|
|
||||||
LIBFILES=\
|
LIBFILES=\
|
||||||
9p\
|
9p\
|
||||||
@ -37,7 +37,7 @@ LIBOFILES=${LIBFILES:%=%.$O}
|
|||||||
LIB=libfs.a$O
|
LIB=libfs.a$O
|
||||||
|
|
||||||
HFILES=\
|
HFILES=\
|
||||||
/sys/include/oventi.h\
|
/sys/include/venti.h\
|
||||||
stdinc.h\
|
stdinc.h\
|
||||||
vac.h\
|
vac.h\
|
||||||
dat.h\
|
dat.h\
|
||||||
|
|||||||
@ -35,12 +35,12 @@ int
|
|||||||
headerUnpack(Header *h, uchar *p)
|
headerUnpack(Header *h, uchar *p)
|
||||||
{
|
{
|
||||||
if(U32GET(p) != HeaderMagic){
|
if(U32GET(p) != HeaderMagic){
|
||||||
vtSetError("vac header bad magic");
|
werrstr("vac header bad magic");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
h->version = U16GET(p+4);
|
h->version = U16GET(p+4);
|
||||||
if(h->version != HeaderVersion){
|
if(h->version != HeaderVersion){
|
||||||
vtSetError("vac header bad version");
|
werrstr("vac header bad version");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
h->blockSize = U16GET(p+6);
|
h->blockSize = U16GET(p+6);
|
||||||
@ -74,7 +74,7 @@ labelUnpack(Label *l, uchar *p, int i)
|
|||||||
|
|
||||||
if(l->type > BtMax){
|
if(l->type > BtMax){
|
||||||
Bad:
|
Bad:
|
||||||
vtSetError(EBadLabel);
|
werrstr(EBadLabel);
|
||||||
fprint(2, "%s: labelUnpack: bad label: 0x%.2ux 0x%.2ux 0x%.8ux "
|
fprint(2, "%s: labelUnpack: bad label: 0x%.2ux 0x%.2ux 0x%.8ux "
|
||||||
"0x%.8ux 0x%.8ux\n", argv0, l->state, l->type, l->epoch,
|
"0x%.8ux 0x%.8ux\n", argv0, l->state, l->type, l->epoch,
|
||||||
l->epochClose, l->tag);
|
l->epochClose, l->tag);
|
||||||
@ -124,7 +124,7 @@ entryPack(Entry *e, uchar *p, int index)
|
|||||||
U32PUT(p, e->gen);
|
U32PUT(p, e->gen);
|
||||||
U16PUT(p+4, e->psize);
|
U16PUT(p+4, e->psize);
|
||||||
U16PUT(p+6, e->dsize);
|
U16PUT(p+6, e->dsize);
|
||||||
flags = e->flags | ((e->depth << VtEntryDepthShift) & VtEntryDepthMask);
|
flags = e->flags | ((e->depth << _VtEntryDepthShift) & _VtEntryDepthMask);
|
||||||
U8PUT(p+8, flags);
|
U8PUT(p+8, flags);
|
||||||
memset(p+9, 0, 5);
|
memset(p+9, 0, 5);
|
||||||
U48PUT(p+14, e->size, t32);
|
U48PUT(p+14, e->size, t32);
|
||||||
@ -150,8 +150,8 @@ entryUnpack(Entry *e, uchar *p, int index)
|
|||||||
e->psize = U16GET(p+4);
|
e->psize = U16GET(p+4);
|
||||||
e->dsize = U16GET(p+6);
|
e->dsize = U16GET(p+6);
|
||||||
e->flags = U8GET(p+8);
|
e->flags = U8GET(p+8);
|
||||||
e->depth = (e->flags & VtEntryDepthMask) >> VtEntryDepthShift;
|
e->depth = (e->flags & _VtEntryDepthMask) >> _VtEntryDepthShift;
|
||||||
e->flags &= ~VtEntryDepthMask;
|
e->flags &= ~_VtEntryDepthMask;
|
||||||
e->size = U48GET(p+14);
|
e->size = U48GET(p+14);
|
||||||
|
|
||||||
if(e->flags & VtEntryLocal){
|
if(e->flags & VtEntryLocal){
|
||||||
@ -173,7 +173,7 @@ entryUnpack(Entry *e, uchar *p, int index)
|
|||||||
int
|
int
|
||||||
entryType(Entry *e)
|
entryType(Entry *e)
|
||||||
{
|
{
|
||||||
return (((e->flags & VtEntryDir) != 0) << 3) | e->depth;
|
return (((e->flags & _VtEntryDir) != 0) << 3) | e->depth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -219,7 +219,7 @@ superUnpack(Super *s, uchar *p)
|
|||||||
return 1;
|
return 1;
|
||||||
Err:
|
Err:
|
||||||
memset(s, 0, sizeof(*s));
|
memset(s, 0, sizeof(*s));
|
||||||
vtSetError(EBadSuper);
|
werrstr(EBadSuper);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
#include "error.h"
|
#include "error.h"
|
||||||
|
|
||||||
struct Periodic {
|
struct Periodic {
|
||||||
VtLock *lk;
|
QLock lk;
|
||||||
int die; /* flag: quit if set */
|
int die; /* flag: quit if set */
|
||||||
void (*f)(void*); /* call this each period */
|
void (*f)(void*); /* call this each period */
|
||||||
void *a; /* argument to f */
|
void *a; /* argument to f */
|
||||||
@ -18,15 +18,14 @@ periodicAlloc(void (*f)(void*), void *a, int msec)
|
|||||||
{
|
{
|
||||||
Periodic *p;
|
Periodic *p;
|
||||||
|
|
||||||
p = vtMemAllocZ(sizeof(Periodic));
|
p = vtmallocz(sizeof(Periodic));
|
||||||
p->lk = vtLockAlloc();
|
|
||||||
p->f = f;
|
p->f = f;
|
||||||
p->a = a;
|
p->a = a;
|
||||||
p->msec = msec;
|
p->msec = msec;
|
||||||
if(p->msec < 10)
|
if(p->msec < 10)
|
||||||
p->msec = 10;
|
p->msec = 10;
|
||||||
|
|
||||||
vtThread(periodicThread, p);
|
proccreate(periodicThread, p, STACK);
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,16 +34,15 @@ periodicKill(Periodic *p)
|
|||||||
{
|
{
|
||||||
if(p == nil)
|
if(p == nil)
|
||||||
return;
|
return;
|
||||||
vtLock(p->lk);
|
qlock(&p->lk);
|
||||||
p->die = 1;
|
p->die = 1;
|
||||||
vtUnlock(p->lk);
|
qunlock(&p->lk);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
periodicFree(Periodic *p)
|
periodicFree(Periodic *p)
|
||||||
{
|
{
|
||||||
vtLockFree(p->lk);
|
vtfree(p);
|
||||||
vtMemFree(p);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -53,7 +51,7 @@ periodicThread(void *a)
|
|||||||
Periodic *p = a;
|
Periodic *p = a;
|
||||||
vlong t, ct, ts; /* times in ms. */
|
vlong t, ct, ts; /* times in ms. */
|
||||||
|
|
||||||
vtThreadSetName("periodic");
|
threadsetname("periodic");
|
||||||
|
|
||||||
ct = nsec() / 1000000;
|
ct = nsec() / 1000000;
|
||||||
t = ct + p->msec; /* call p->f at or after this time */
|
t = ct + p->msec; /* call p->f at or after this time */
|
||||||
@ -65,9 +63,9 @@ periodicThread(void *a)
|
|||||||
if(ts > 0)
|
if(ts > 0)
|
||||||
sleep(ts); /* wait for cycle's start */
|
sleep(ts); /* wait for cycle's start */
|
||||||
|
|
||||||
vtLock(p->lk);
|
qlock(&p->lk);
|
||||||
if(p->die){
|
if(p->die){
|
||||||
vtUnlock(p->lk);
|
qunlock(&p->lk);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ct = nsec() / 1000000;
|
ct = nsec() / 1000000;
|
||||||
@ -77,7 +75,7 @@ periodicThread(void *a)
|
|||||||
while(t <= ct) /* advance t to future cycle start */
|
while(t <= ct) /* advance t to future cycle start */
|
||||||
t += p->msec;
|
t += p->msec;
|
||||||
}
|
}
|
||||||
vtUnlock(p->lk);
|
qunlock(&p->lk);
|
||||||
}
|
}
|
||||||
periodicFree(p);
|
periodicFree(p);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -83,12 +83,12 @@ sourceAlloc(Fs *fs, Block *b, Source *p, u32int offset, int mode, int issnapshot
|
|||||||
epoch = b->l.epoch;
|
epoch = b->l.epoch;
|
||||||
if(mode == OReadWrite){
|
if(mode == OReadWrite){
|
||||||
if(e.snap != 0){
|
if(e.snap != 0){
|
||||||
vtSetError(ESnapRO);
|
werrstr(ESnapRO);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
}else if(e.snap != 0){
|
}else if(e.snap != 0){
|
||||||
if(e.snap < fs->elo){
|
if(e.snap < fs->elo){
|
||||||
vtSetError(ESnapOld);
|
werrstr(ESnapOld);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
if(e.snap >= fs->ehi)
|
if(e.snap >= fs->ehi)
|
||||||
@ -96,21 +96,20 @@ sourceAlloc(Fs *fs, Block *b, Source *p, u32int offset, int mode, int issnapshot
|
|||||||
epoch = e.snap;
|
epoch = e.snap;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = vtMemAllocZ(sizeof(Source));
|
r = vtmallocz(sizeof(Source));
|
||||||
r->fs = fs;
|
r->fs = fs;
|
||||||
r->mode = mode;
|
r->mode = mode;
|
||||||
r->issnapshot = issnapshot;
|
r->issnapshot = issnapshot;
|
||||||
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.flags & _VtEntryDir) != 0;
|
||||||
r->lk = vtLockAlloc();
|
|
||||||
r->ref = 1;
|
r->ref = 1;
|
||||||
r->parent = p;
|
r->parent = p;
|
||||||
if(p){
|
if(p){
|
||||||
vtLock(p->lk);
|
qlock(&p->lk);
|
||||||
assert(mode == OReadOnly || p->mode == OReadWrite);
|
assert(mode == OReadOnly || p->mode == OReadWrite);
|
||||||
p->ref++;
|
p->ref++;
|
||||||
vtUnlock(p->lk);
|
qunlock(&p->lk);
|
||||||
}
|
}
|
||||||
r->epoch = epoch;
|
r->epoch = epoch;
|
||||||
// consPrint("sourceAlloc: have %V be.%d fse.%d %s\n", b->score,
|
// consPrint("sourceAlloc: have %V be.%d fse.%d %s\n", b->score,
|
||||||
@ -126,7 +125,7 @@ sourceAlloc(Fs *fs, Block *b, Source *p, u32int offset, int mode, int issnapshot
|
|||||||
return r;
|
return r;
|
||||||
Bad:
|
Bad:
|
||||||
free(pname);
|
free(pname);
|
||||||
vtSetError(EBadEntry);
|
werrstr(EBadEntry);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,7 +143,7 @@ sourceRoot(Fs *fs, u32int addr, int mode)
|
|||||||
consPrint("sourceRoot: fs->ehi = %ud, b->l = %L\n",
|
consPrint("sourceRoot: fs->ehi = %ud, b->l = %L\n",
|
||||||
fs->ehi, &b->l);
|
fs->ehi, &b->l);
|
||||||
blockPut(b);
|
blockPut(b);
|
||||||
vtSetError(EBadRoot);
|
werrstr(EBadRoot);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,7 +162,7 @@ sourceOpen(Source *r, ulong offset, int mode, int issnapshot)
|
|||||||
if(r->mode == OReadWrite)
|
if(r->mode == OReadWrite)
|
||||||
assert(r->epoch == r->b->l.epoch);
|
assert(r->epoch == r->b->l.epoch);
|
||||||
if(!r->dir){
|
if(!r->dir){
|
||||||
vtSetError(ENotDir);
|
werrstr(ENotDir);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,7 +188,7 @@ sourceCreate(Source *r, int dsize, int dir, u32int offset)
|
|||||||
assert(sourceIsLocked(r));
|
assert(sourceIsLocked(r));
|
||||||
|
|
||||||
if(!r->dir){
|
if(!r->dir){
|
||||||
vtSetError(ENotDir);
|
werrstr(ENotDir);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -219,7 +218,7 @@ sourceCreate(Source *r, int dsize, int dir, u32int offset)
|
|||||||
blockPut(b);
|
blockPut(b);
|
||||||
if(offset == size){
|
if(offset == size){
|
||||||
fprint(2, "sourceCreate: cannot happen\n");
|
fprint(2, "sourceCreate: cannot happen\n");
|
||||||
vtSetError("sourceCreate: cannot happen");
|
werrstr("sourceCreate: cannot happen");
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
offset = size;
|
offset = size;
|
||||||
@ -232,10 +231,10 @@ Found:
|
|||||||
assert(psize && dsize);
|
assert(psize && dsize);
|
||||||
e.flags = VtEntryActive;
|
e.flags = VtEntryActive;
|
||||||
if(dir)
|
if(dir)
|
||||||
e.flags |= VtEntryDir;
|
e.flags |= _VtEntryDir;
|
||||||
e.depth = 0;
|
e.depth = 0;
|
||||||
e.size = 0;
|
e.size = 0;
|
||||||
memmove(e.score, vtZeroScore, VtScoreSize);
|
memmove(e.score, vtzeroscore, VtScoreSize);
|
||||||
e.tag = 0;
|
e.tag = 0;
|
||||||
e.snap = 0;
|
e.snap = 0;
|
||||||
e.archive = 0;
|
e.archive = 0;
|
||||||
@ -294,7 +293,7 @@ sourceKill(Source *r, int doremove)
|
|||||||
e.depth = 0;
|
e.depth = 0;
|
||||||
e.size = 0;
|
e.size = 0;
|
||||||
e.tag = 0;
|
e.tag = 0;
|
||||||
memmove(e.score, vtZeroScore, VtScoreSize);
|
memmove(e.score, vtzeroscore, VtScoreSize);
|
||||||
entryPack(&e, b->data, r->offset % r->epb);
|
entryPack(&e, b->data, r->offset % r->epb);
|
||||||
blockDirty(b);
|
blockDirty(b);
|
||||||
if(addr != NilBlock)
|
if(addr != NilBlock)
|
||||||
@ -370,7 +369,7 @@ sourceShrinkSize(Source *r, Entry *e, uvlong size)
|
|||||||
i = (size+ptrsz-1)/ptrsz;
|
i = (size+ptrsz-1)/ptrsz;
|
||||||
for(; i<ppb; i++){
|
for(; i<ppb; i++){
|
||||||
addr = globalToLocal(b->data+i*VtScoreSize);
|
addr = globalToLocal(b->data+i*VtScoreSize);
|
||||||
memmove(b->data+i*VtScoreSize, vtZeroScore, VtScoreSize);
|
memmove(b->data+i*VtScoreSize, vtzeroscore, VtScoreSize);
|
||||||
blockDirty(b);
|
blockDirty(b);
|
||||||
if(addr != NilBlock)
|
if(addr != NilBlock)
|
||||||
blockRemoveLink(b, addr, type-1, e->tag, 1);
|
blockRemoveLink(b, addr, type-1, e->tag, 1);
|
||||||
@ -420,7 +419,7 @@ sourceSetSize(Source *r, uvlong size)
|
|||||||
return sourceTruncate(r);
|
return sourceTruncate(r);
|
||||||
|
|
||||||
if(size > VtMaxFileSize || size > ((uvlong)MaxBlock)*r->dsize){
|
if(size > VtMaxFileSize || size > ((uvlong)MaxBlock)*r->dsize){
|
||||||
vtSetError(ETooBig);
|
werrstr(ETooBig);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -637,7 +636,7 @@ sourceGrowDepth(Source *r, Block *p, Entry *e, int depth)
|
|||||||
type++;
|
type++;
|
||||||
e->tag = tag;
|
e->tag = tag;
|
||||||
e->flags |= VtEntryLocal;
|
e->flags |= VtEntryLocal;
|
||||||
blockDependency(bb, b, 0, vtZeroScore, nil);
|
blockDependency(bb, b, 0, vtzeroscore, nil);
|
||||||
blockPut(b);
|
blockPut(b);
|
||||||
b = bb;
|
b = bb;
|
||||||
blockDirty(b);
|
blockDirty(b);
|
||||||
@ -718,7 +717,7 @@ sourceShrinkDepth(Source *r, Block *p, Entry *e, int depth)
|
|||||||
blockDirty(p);
|
blockDirty(p);
|
||||||
|
|
||||||
/* (ii) */
|
/* (ii) */
|
||||||
memmove(ob->data, vtZeroScore, VtScoreSize);
|
memmove(ob->data, vtzeroscore, VtScoreSize);
|
||||||
blockDependency(ob, p, 0, b->score, nil);
|
blockDependency(ob, p, 0, b->score, nil);
|
||||||
blockDirty(ob);
|
blockDirty(ob);
|
||||||
|
|
||||||
@ -761,7 +760,7 @@ _sourceBlock(Source *r, ulong bn, int mode, int early, ulong tag)
|
|||||||
return nil;
|
return nil;
|
||||||
if(r->issnapshot && (e.flags & VtEntryNoArchive)){
|
if(r->issnapshot && (e.flags & VtEntryNoArchive)){
|
||||||
blockPut(b);
|
blockPut(b);
|
||||||
vtSetError(ENotArchived);
|
werrstr(ENotArchived);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -770,7 +769,7 @@ _sourceBlock(Source *r, ulong bn, int mode, int early, ulong tag)
|
|||||||
e.tag = tag;
|
e.tag = tag;
|
||||||
else if(e.tag != tag){
|
else if(e.tag != tag){
|
||||||
fprint(2, "tag mismatch\n");
|
fprint(2, "tag mismatch\n");
|
||||||
vtSetError("tag mismatch");
|
werrstr("tag mismatch");
|
||||||
goto Err;
|
goto Err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -779,7 +778,7 @@ _sourceBlock(Source *r, ulong bn, int mode, int early, ulong tag)
|
|||||||
memset(index, 0, sizeof(index));
|
memset(index, 0, sizeof(index));
|
||||||
for(i=0; bn > 0; i++){
|
for(i=0; bn > 0; i++){
|
||||||
if(i >= VtPointerDepth){
|
if(i >= VtPointerDepth){
|
||||||
vtSetError(EBadAddr);
|
werrstr(EBadAddr);
|
||||||
goto Err;
|
goto Err;
|
||||||
}
|
}
|
||||||
index[i] = bn % np;
|
index[i] = bn % np;
|
||||||
@ -788,7 +787,7 @@ _sourceBlock(Source *r, ulong bn, int mode, int early, ulong tag)
|
|||||||
|
|
||||||
if(i > e.depth){
|
if(i > e.depth){
|
||||||
if(mode == OReadOnly){
|
if(mode == OReadOnly){
|
||||||
vtSetError(EBadAddr);
|
werrstr(EBadAddr);
|
||||||
goto Err;
|
goto Err;
|
||||||
}
|
}
|
||||||
if(!sourceGrowDepth(r, b, &e, i))
|
if(!sourceGrowDepth(r, b, &e, i))
|
||||||
@ -827,19 +826,18 @@ sourceClose(Source *r)
|
|||||||
{
|
{
|
||||||
if(r == nil)
|
if(r == nil)
|
||||||
return;
|
return;
|
||||||
vtLock(r->lk);
|
qlock(&r->lk);
|
||||||
r->ref--;
|
r->ref--;
|
||||||
if(r->ref){
|
if(r->ref){
|
||||||
vtUnlock(r->lk);
|
qunlock(&r->lk);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
assert(r->ref == 0);
|
assert(r->ref == 0);
|
||||||
vtUnlock(r->lk);
|
qunlock(&r->lk);
|
||||||
if(r->parent)
|
if(r->parent)
|
||||||
sourceClose(r->parent);
|
sourceClose(r->parent);
|
||||||
vtLockFree(r->lk);
|
|
||||||
memset(r, ~0, sizeof(*r));
|
memset(r, ~0, sizeof(*r));
|
||||||
vtMemFree(r);
|
vtfree(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -858,6 +856,7 @@ sourceLoadBlock(Source *r, int mode)
|
|||||||
{
|
{
|
||||||
u32int addr;
|
u32int addr;
|
||||||
Block *b;
|
Block *b;
|
||||||
|
char e[ERRMAX];
|
||||||
|
|
||||||
switch(r->mode){
|
switch(r->mode){
|
||||||
default:
|
default:
|
||||||
@ -912,7 +911,8 @@ sourceLoadBlock(Source *r, int mode)
|
|||||||
* a snapshot. (Or else the file system is read-only, but then
|
* a snapshot. (Or else the file system is read-only, but then
|
||||||
* the archiver isn't going around deleting blocks.)
|
* the archiver isn't going around deleting blocks.)
|
||||||
*/
|
*/
|
||||||
if(strcmp(vtGetError(), ELabelMismatch) == 0){
|
rerrstr(e, sizeof e);
|
||||||
|
if(strcmp(e, ELabelMismatch) == 0){
|
||||||
if(!sourceLock(r->parent, OReadOnly))
|
if(!sourceLock(r->parent, OReadOnly))
|
||||||
return nil;
|
return nil;
|
||||||
b = sourceBlock(r->parent, r->offset/r->epb, OReadOnly);
|
b = sourceBlock(r->parent, r->offset/r->epb, OReadOnly);
|
||||||
@ -1027,7 +1027,7 @@ sourceLoad(Source *r, Entry *e)
|
|||||||
if(!entryUnpack(e, b->data, r->offset % r->epb))
|
if(!entryUnpack(e, b->data, r->offset % r->epb))
|
||||||
return nil;
|
return nil;
|
||||||
if(e->gen != r->gen){
|
if(e->gen != r->gen){
|
||||||
vtSetError(ERemoved);
|
werrstr(ERemoved);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
blockDupLock(b);
|
blockDupLock(b);
|
||||||
|
|||||||
@ -1,11 +1,12 @@
|
|||||||
#include <u.h>
|
#include <u.h>
|
||||||
#include <libc.h>
|
#include <libc.h>
|
||||||
|
#include <libsec.h>
|
||||||
|
#include <thread.h>
|
||||||
|
|
||||||
typedef uvlong u64int;
|
typedef uvlong u64int;
|
||||||
typedef uchar u8int;
|
typedef uchar u8int;
|
||||||
typedef ushort u16int;
|
typedef ushort u16int;
|
||||||
|
|
||||||
#include "oventi.h"
|
#include "venti.h"
|
||||||
#include "vac.h"
|
#include "vac.h"
|
||||||
#include "fs.h"
|
#include "fs.h"
|
||||||
|
|
||||||
|
|||||||
@ -45,7 +45,7 @@ stringUnpack(char **s, uchar **p, int *n)
|
|||||||
*n -= 2;
|
*n -= 2;
|
||||||
if(nn > *n)
|
if(nn > *n)
|
||||||
return 0;
|
return 0;
|
||||||
*s = vtMemAlloc(nn+1);
|
*s = vtmalloc(nn+1);
|
||||||
memmove(*s, *p, nn);
|
memmove(*s, *p, nn);
|
||||||
(*s)[nn] = 0;
|
(*s)[nn] = 0;
|
||||||
*p += nn;
|
*p += nn;
|
||||||
@ -99,7 +99,7 @@ if(0)fprint(2, "mbSearch %s\n", elem);
|
|||||||
*ri = b; /* b is the index to insert this entry */
|
*ri = b; /* b is the index to insert this entry */
|
||||||
memset(me, 0, sizeof(*me));
|
memset(me, 0, sizeof(*me));
|
||||||
|
|
||||||
vtSetError(ENoFile);
|
werrstr(ENoFile);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,7 +164,7 @@ mbUnpack(MetaBlock *mb, uchar *p, int n)
|
|||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
Err:
|
Err:
|
||||||
vtSetError(EBadMeta);
|
werrstr(EBadMeta);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -375,7 +375,7 @@ metaChunks(MetaBlock *mb)
|
|||||||
int oo, o, n, i;
|
int oo, o, n, i;
|
||||||
uchar *p;
|
uchar *p;
|
||||||
|
|
||||||
mc = vtMemAlloc(mb->nindex*sizeof(MetaChunk));
|
mc = vtmalloc(mb->nindex*sizeof(MetaChunk));
|
||||||
p = mb->buf + MetaHeaderSize;
|
p = mb->buf + MetaHeaderSize;
|
||||||
for(i = 0; i<mb->nindex; i++){
|
for(i = 0; i<mb->nindex; i++){
|
||||||
mc[i].offset = U16GET(p);
|
mc[i].offset = U16GET(p);
|
||||||
@ -411,8 +411,8 @@ fprint(2, "\t%d: %d %d\n", i, mc[i].offset, mc[i].offset + mc[i].size);
|
|||||||
oo += mc[i].size;
|
oo += mc[i].size;
|
||||||
}
|
}
|
||||||
fprint(2, "\tused=%d size=%d free=%d free2=%d\n", oo, mb->size, mb->free, mb->size - oo);
|
fprint(2, "\tused=%d size=%d free=%d free2=%d\n", oo, mb->size, mb->free, mb->size - oo);
|
||||||
vtSetError(EBadMeta);
|
werrstr(EBadMeta);
|
||||||
vtMemFree(mc);
|
vtfree(mc);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -461,23 +461,23 @@ fprint(2, "mbAlloc: metaChunks failed: %r\n");
|
|||||||
o = MetaHeaderSize + mb->maxindex*MetaIndexSize;
|
o = MetaHeaderSize + mb->maxindex*MetaIndexSize;
|
||||||
for(i=0; i<mb->nindex; i++){
|
for(i=0; i<mb->nindex; i++){
|
||||||
if(mc[i].offset - o >= n){
|
if(mc[i].offset - o >= n){
|
||||||
vtMemFree(mc);
|
vtfree(mc);
|
||||||
return mb->buf + o;
|
return mb->buf + o;
|
||||||
}
|
}
|
||||||
o = mc[i].offset + mc[i].size;
|
o = mc[i].offset + mc[i].size;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(mb->maxsize - o >= n){
|
if(mb->maxsize - o >= n){
|
||||||
vtMemFree(mc);
|
vtfree(mc);
|
||||||
return mb->buf + o;
|
return mb->buf + o;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* compact and return off the end */
|
/* compact and return off the end */
|
||||||
mbCompact(mb, mc);
|
mbCompact(mb, mc);
|
||||||
vtMemFree(mc);
|
vtfree(mc);
|
||||||
|
|
||||||
if(mb->maxsize - mb->size < n){
|
if(mb->maxsize - mb->size < n){
|
||||||
vtSetError(EBadMeta);
|
werrstr(EBadMeta);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
return mb->buf + mb->size;
|
return mb->buf + mb->size;
|
||||||
@ -717,7 +717,7 @@ if(0)print("deUnpack: correct size\n");
|
|||||||
return 1;
|
return 1;
|
||||||
Err:
|
Err:
|
||||||
if(0)print("deUnpack: XXXXXXXXXXXX EBadMeta\n");
|
if(0)print("deUnpack: XXXXXXXXXXXX EBadMeta\n");
|
||||||
vtSetError(EBadMeta);
|
werrstr(EBadMeta);
|
||||||
deCleanup(dir);
|
deCleanup(dir);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -725,13 +725,13 @@ if(0)print("deUnpack: XXXXXXXXXXXX EBadMeta\n");
|
|||||||
void
|
void
|
||||||
deCleanup(DirEntry *dir)
|
deCleanup(DirEntry *dir)
|
||||||
{
|
{
|
||||||
vtMemFree(dir->elem);
|
vtfree(dir->elem);
|
||||||
dir->elem = nil;
|
dir->elem = nil;
|
||||||
vtMemFree(dir->uid);
|
vtfree(dir->uid);
|
||||||
dir->uid = nil;
|
dir->uid = nil;
|
||||||
vtMemFree(dir->gid);
|
vtfree(dir->gid);
|
||||||
dir->gid = nil;
|
dir->gid = nil;
|
||||||
vtMemFree(dir->mid);
|
vtfree(dir->mid);
|
||||||
dir->mid = nil;
|
dir->mid = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -739,8 +739,8 @@ void
|
|||||||
deCopy(DirEntry *dst, DirEntry *src)
|
deCopy(DirEntry *dst, DirEntry *src)
|
||||||
{
|
{
|
||||||
*dst = *src;
|
*dst = *src;
|
||||||
dst->elem = vtStrDup(src->elem);
|
dst->elem = vtstrdup(src->elem);
|
||||||
dst->uid = vtStrDup(src->uid);
|
dst->uid = vtstrdup(src->uid);
|
||||||
dst->gid = vtStrDup(src->gid);
|
dst->gid = vtstrdup(src->gid);
|
||||||
dst->mid = vtStrDup(src->mid);
|
dst->mid = vtstrdup(src->mid);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -52,9 +52,10 @@ Tnode *initxdatablock(Block*, uint);
|
|||||||
Tnode *initxroot(char *name, uchar[VtScoreSize]);
|
Tnode *initxroot(char *name, uchar[VtScoreSize]);
|
||||||
|
|
||||||
int fd;
|
int fd;
|
||||||
|
int mainstacksize = STACK;
|
||||||
Header h;
|
Header h;
|
||||||
Super super;
|
Super super;
|
||||||
VtSession *z;
|
VtConn *z;
|
||||||
VtRoot vac;
|
VtRoot vac;
|
||||||
int showinactive;
|
int showinactive;
|
||||||
|
|
||||||
@ -107,7 +108,6 @@ btStr(int type)
|
|||||||
return bttab[type];
|
return bttab[type];
|
||||||
return "unknown";
|
return "unknown";
|
||||||
}
|
}
|
||||||
#pragma varargck argpos stringnode 1
|
|
||||||
|
|
||||||
Block*
|
Block*
|
||||||
allocBlock(void)
|
allocBlock(void)
|
||||||
@ -197,21 +197,21 @@ readBlock(int part, u32int addr)
|
|||||||
|
|
||||||
int vtType[BtMax] = {
|
int vtType[BtMax] = {
|
||||||
VtDataType, /* BtData | 0 */
|
VtDataType, /* BtData | 0 */
|
||||||
VtPointerType0, /* BtData | 1 */
|
VtDataType+1, /* BtData | 1 */
|
||||||
VtPointerType1, /* BtData | 2 */
|
VtDataType+2, /* BtData | 2 */
|
||||||
VtPointerType2, /* BtData | 3 */
|
VtDataType+3, /* BtData | 3 */
|
||||||
VtPointerType3, /* BtData | 4 */
|
VtDataType+4, /* BtData | 4 */
|
||||||
VtPointerType4, /* BtData | 5 */
|
VtDataType+5, /* BtData | 5 */
|
||||||
VtPointerType5, /* BtData | 6 */
|
VtDataType+6, /* BtData | 6 */
|
||||||
VtPointerType6, /* BtData | 7 */
|
VtDataType+7, /* BtData | 7 */
|
||||||
VtDirType, /* BtDir | 0 */
|
VtDirType, /* BtDir | 0 */
|
||||||
VtPointerType0, /* BtDir | 1 */
|
VtDirType+1, /* BtDir | 1 */
|
||||||
VtPointerType1, /* BtDir | 2 */
|
VtDirType+2, /* BtDir | 2 */
|
||||||
VtPointerType2, /* BtDir | 3 */
|
VtDirType+3, /* BtDir | 3 */
|
||||||
VtPointerType3, /* BtDir | 4 */
|
VtDirType+4, /* BtDir | 4 */
|
||||||
VtPointerType4, /* BtDir | 5 */
|
VtDirType+5, /* BtDir | 5 */
|
||||||
VtPointerType5, /* BtDir | 6 */
|
VtDirType+6, /* BtDir | 6 */
|
||||||
VtPointerType6, /* BtDir | 7 */
|
VtDirType+7, /* BtDir | 7 */
|
||||||
};
|
};
|
||||||
|
|
||||||
Block*
|
Block*
|
||||||
@ -224,13 +224,13 @@ ventiBlock(uchar score[VtScoreSize], uint type)
|
|||||||
memmove(b->score, score, VtScoreSize);
|
memmove(b->score, score, VtScoreSize);
|
||||||
b->addr = NilBlock;
|
b->addr = NilBlock;
|
||||||
|
|
||||||
n = vtRead(z, b->score, vtType[type], b->data, h.blockSize);
|
n = vtread(z, b->score, vtType[type], b->data, h.blockSize);
|
||||||
if(n < 0){
|
if(n < 0){
|
||||||
fprint(2, "vtRead returns %d: %R\n", n);
|
fprint(2, "vtread returns %d: %r\n", n);
|
||||||
blockPut(b);
|
blockPut(b);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
vtZeroExtend(vtType[type], b->data, n, h.blockSize);
|
vtzeroextend(vtType[type], b->data, n, h.blockSize);
|
||||||
b->l.type = type;
|
b->l.type = type;
|
||||||
b->l.state = 0;
|
b->l.state = 0;
|
||||||
b->l.tag = 0;
|
b->l.tag = 0;
|
||||||
@ -255,7 +255,7 @@ dataBlock(uchar score[VtScoreSize], uint type, uint tag)
|
|||||||
if(bl == nil)
|
if(bl == nil)
|
||||||
return nil;
|
return nil;
|
||||||
if(!labelUnpack(&l, bl->data, addr%lpb)){
|
if(!labelUnpack(&l, bl->data, addr%lpb)){
|
||||||
werrstr("%R");
|
werrstr("%r");
|
||||||
blockPut(bl);
|
blockPut(bl);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
@ -363,7 +363,7 @@ initxheader(void)
|
|||||||
if(pread(fd, buf, HeaderSize, HeaderOffset) < HeaderSize)
|
if(pread(fd, buf, HeaderSize, HeaderOffset) < HeaderSize)
|
||||||
return stringnode("error reading header: %r");
|
return stringnode("error reading header: %r");
|
||||||
if(!headerUnpack(&h, buf))
|
if(!headerUnpack(&h, buf))
|
||||||
return stringnode("error unpacking header: %R");
|
return stringnode("error unpacking header: %r");
|
||||||
|
|
||||||
t = stringnode("header "
|
t = stringnode("header "
|
||||||
"version=%#ux (%d) "
|
"version=%#ux (%d) "
|
||||||
@ -403,7 +403,7 @@ initxsuper(void)
|
|||||||
return stringnode("reading super: %r");
|
return stringnode("reading super: %r");
|
||||||
if(!superUnpack(&super, b->data)){
|
if(!superUnpack(&super, b->data)){
|
||||||
blockPut(b);
|
blockPut(b);
|
||||||
return stringnode("unpacking super: %R");
|
return stringnode("unpacking super: %r");
|
||||||
}
|
}
|
||||||
blockPut(b);
|
blockPut(b);
|
||||||
t = stringnode("super "
|
t = stringnode("super "
|
||||||
@ -440,15 +440,15 @@ initxvacroot(uchar score[VtScoreSize])
|
|||||||
uchar buf[VtRootSize];
|
uchar buf[VtRootSize];
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
if((n = vtRead(z, score, VtRootType, buf, VtRootSize)) < 0)
|
if((n = vtread(z, score, VtRootType, buf, VtRootSize)) < 0)
|
||||||
return stringnode("reading root %V: %R", score);
|
return stringnode("reading root %V: %r", score);
|
||||||
|
|
||||||
if(!vtRootUnpack(&vac, buf))
|
if(vtrootunpack(&vac, buf) < 0)
|
||||||
return stringnode("unpack %d-byte root: %R", n);
|
return stringnode("unpack %d-byte root: %r", n);
|
||||||
|
|
||||||
h.blockSize = vac.blockSize;
|
h.blockSize = vac.blocksize;
|
||||||
t = stringnode("vac version=%#ux name=%s type=%s blockSize=%ud score=%V prev=%V",
|
t = stringnode("vac version=%#ux name=%s type=%s blocksize=%lud score=%V prev=%V",
|
||||||
vac.version, vac.name, vac.type, vac.blockSize, vac.score, vac.prev);
|
VtRootVersion, vac.name, vac.type, vac.blocksize, vac.score, vac.prev);
|
||||||
t->expand = xvacrootexpand;
|
t->expand = xvacrootexpand;
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
@ -603,7 +603,7 @@ ptrgen(void *v, Block *b, int o, Tnode **tp)
|
|||||||
e = *ed;
|
e = *ed;
|
||||||
e.depth--;
|
e.depth--;
|
||||||
memmove(e.score, b->data+o*VtScoreSize, VtScoreSize);
|
memmove(e.score, b->data+o*VtScoreSize, VtScoreSize);
|
||||||
if(memcmp(e.score, vtZeroScore, VtScoreSize) == 0)
|
if(memcmp(e.score, vtzeroscore, VtScoreSize) == 0)
|
||||||
return 0;
|
return 0;
|
||||||
*tp = initxsource(e, 0);
|
*tp = initxsource(e, 0);
|
||||||
return 1;
|
return 1;
|
||||||
@ -614,7 +614,7 @@ etype(int flags, int depth)
|
|||||||
{
|
{
|
||||||
uint t;
|
uint t;
|
||||||
|
|
||||||
if(flags&VtEntryDir)
|
if(flags&_VtEntryDir)
|
||||||
t = BtDir;
|
t = BtDir;
|
||||||
else
|
else
|
||||||
t = BtData;
|
t = BtData;
|
||||||
@ -635,12 +635,12 @@ initxsource(Entry e, int dowrap)
|
|||||||
return stringnode("inactive Entry");
|
return stringnode("inactive Entry");
|
||||||
|
|
||||||
if(e.depth == 0){
|
if(e.depth == 0){
|
||||||
if(e.flags & VtEntryDir)
|
if(e.flags & _VtEntryDir)
|
||||||
tt = initxentryblock(b, copyEntry(e));
|
tt = initxentryblock(b, copyEntry(e));
|
||||||
else
|
else
|
||||||
tt = initxdatablock(b, e.dsize);
|
tt = initxdatablock(b, e.dsize);
|
||||||
}else{
|
}else{
|
||||||
tt = initxblock(b, smprint("%s+%d pointer", (e.flags & VtEntryDir) ? "BtDir" : "BtData", e.depth),
|
tt = initxblock(b, smprint("%s+%d pointer", (e.flags & _VtEntryDir) ? "BtDir" : "BtData", e.depth),
|
||||||
ptrgen, copyEntry(e));
|
ptrgen, copyEntry(e));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -679,7 +679,7 @@ initxlocalroot(char *name, u32int addr)
|
|||||||
localToGlobal(addr, score);
|
localToGlobal(addr, score);
|
||||||
b = dataBlock(score, BtDir, RootTag);
|
b = dataBlock(score, BtDir, RootTag);
|
||||||
if(b == nil)
|
if(b == nil)
|
||||||
return stringnode("read data block %#ux: %R", addr);
|
return stringnode("read data block %#ux: %r", addr);
|
||||||
return initxblock(b, smprint("'%s' fs root", name), xlocalrootgen, nil);
|
return initxblock(b, smprint("'%s' fs root", name), xlocalrootgen, nil);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -702,7 +702,7 @@ initxroot(char *name, uchar score[VtScoreSize])
|
|||||||
|
|
||||||
b = dataBlock(score, BtDir, RootTag);
|
b = dataBlock(score, BtDir, RootTag);
|
||||||
if(b == nil)
|
if(b == nil)
|
||||||
return stringnode("read data block %V: %R", score);
|
return stringnode("read data block %V: %r", score);
|
||||||
return initxblock(b, smprint("'%s' fs root", name), xvacrootgen, nil);
|
return initxblock(b, smprint("'%s' fs root", name), xvacrootgen, nil);
|
||||||
}
|
}
|
||||||
Tnode*
|
Tnode*
|
||||||
@ -712,7 +712,7 @@ initxdirentry(MetaEntry *me)
|
|||||||
Tnode *t;
|
Tnode *t;
|
||||||
|
|
||||||
if(!deUnpack(&dir, me))
|
if(!deUnpack(&dir, me))
|
||||||
return stringnode("deUnpack: %R");
|
return stringnode("deUnpack: %r");
|
||||||
|
|
||||||
t = stringnode("dirEntry elem=%s size=%llud data=%#lux/%#lux meta=%#lux/%#lux", dir.elem, dir.size, dir.entry, dir.gen, dir.mentry, dir.mgen);
|
t = stringnode("dirEntry elem=%s size=%llud data=%#lux/%#lux meta=%#lux/%#lux", dir.elem, dir.size, dir.entry, dir.gen, dir.mentry, dir.mgen);
|
||||||
t->nkid = 1;
|
t->nkid = 1;
|
||||||
@ -845,16 +845,13 @@ atreeinit(char *arg)
|
|||||||
Atree *a;
|
Atree *a;
|
||||||
uchar score[VtScoreSize];
|
uchar score[VtScoreSize];
|
||||||
|
|
||||||
vtAttach();
|
|
||||||
|
|
||||||
fmtinstall('V', scoreFmt);
|
fmtinstall('V', scoreFmt);
|
||||||
fmtinstall('R', vtErrFmt);
|
|
||||||
|
|
||||||
z = vtDial(nil, 1);
|
z = vtdial(nil);
|
||||||
if(z == nil)
|
if(z == nil)
|
||||||
fprint(2, "warning: cannot dial venti: %R\n");
|
fprint(2, "warning: cannot dial venti: %r\n");
|
||||||
if(!vtConnect(z, 0)){
|
else if(vtconnect(z) < 0){
|
||||||
fprint(2, "warning: cannot connect to venti: %R\n");
|
fprint(2, "warning: cannot connect to venti: %r\n");
|
||||||
z = nil;
|
z = nil;
|
||||||
}
|
}
|
||||||
a = mallocz(sizeof(Atree), 1);
|
a = mallocz(sizeof(Atree), 1);
|
||||||
@ -999,8 +996,8 @@ findnode(Tnode *t, Point p)
|
|||||||
void
|
void
|
||||||
usage(void)
|
usage(void)
|
||||||
{
|
{
|
||||||
fprint(2, "usage: vtree /dev/sdC0/fossil\n");
|
fprint(2, "usage: fossil/view /dev/sdC0/fossil\n");
|
||||||
exits("usage");
|
threadexitsall("usage");
|
||||||
}
|
}
|
||||||
|
|
||||||
Tree t;
|
Tree t;
|
||||||
@ -1030,7 +1027,7 @@ enum { IExit, };
|
|||||||
Menu menu;
|
Menu menu;
|
||||||
|
|
||||||
void
|
void
|
||||||
main(int argc, char **argv)
|
threadmain(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
char *dir;
|
char *dir;
|
||||||
@ -1106,7 +1103,7 @@ main(int argc, char **argv)
|
|||||||
break;
|
break;
|
||||||
switch(n){
|
switch(n){
|
||||||
case IExit:
|
case IExit:
|
||||||
exits(nil);
|
threadexitsall(nil);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Right:
|
case Right:
|
||||||
|
|||||||
@ -11,7 +11,7 @@ etype(Entry *e)
|
|||||||
{
|
{
|
||||||
uint t;
|
uint t;
|
||||||
|
|
||||||
if(e->flags&VtEntryDir)
|
if(e->flags&_VtEntryDir)
|
||||||
t = BtDir;
|
t = BtDir;
|
||||||
else
|
else
|
||||||
t = BtData;
|
t = BtData;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user