make vacfs work; thanks to lucho
This commit is contained in:
parent
17465d1425
commit
a20a146803
6 changed files with 154 additions and 145 deletions
|
|
@ -95,7 +95,7 @@ dirlookup(VacFile *f, char *elem)
|
||||||
goto Err;
|
goto Err;
|
||||||
if(mbunpack(&mb, b->data, meta->dsize) < 0)
|
if(mbunpack(&mb, b->data, meta->dsize) < 0)
|
||||||
goto Err;
|
goto Err;
|
||||||
if(mbsearch(&mb, elem, &i, &me) < 0){
|
if(mbsearch(&mb, elem, &i, &me) >= 0){
|
||||||
ff = filealloc(f->fs);
|
ff = filealloc(f->fs);
|
||||||
if(vdunpack(&ff->dir, &me) < 0){
|
if(vdunpack(&ff->dir, &me) < 0){
|
||||||
filefree(ff);
|
filefree(ff);
|
||||||
|
|
@ -1333,13 +1333,20 @@ vacfiledecref(VacFile *f)
|
||||||
}
|
}
|
||||||
|
|
||||||
VacFile*
|
VacFile*
|
||||||
filegetparent(VacFile *f)
|
vacfilegetparent(VacFile *f)
|
||||||
{
|
{
|
||||||
if(vacfileisroot(f))
|
if(vacfileisroot(f))
|
||||||
return vacfileincref(f);
|
return vacfileincref(f);
|
||||||
return vacfileincref(f->up);
|
return vacfileincref(f->up);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
vacfilewrite(VacFile *file, void *buf, int n, vlong offset, char *muid)
|
||||||
|
{
|
||||||
|
werrstr("read only file system");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
VacDirEnum*
|
VacDirEnum*
|
||||||
vdeopen(VacFile *f)
|
vdeopen(VacFile *f)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ readscore(int fd, uchar score[VtScoreSize])
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
n = readn(fd, buf, sizeof(buf)-1);
|
n = readn(fd, buf, sizeof(buf)-1);
|
||||||
if(n < sizeof(buf)) {
|
if(n < sizeof(buf)-1) {
|
||||||
werrstr("short read");
|
werrstr("short read");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
@ -92,7 +92,7 @@ vacfsopenscore(VtConn *z, u8int *score, int mode, int ncache)
|
||||||
memmove(fs->score, score, VtScoreSize);
|
memmove(fs->score, score, VtScoreSize);
|
||||||
fs->mode = mode;
|
fs->mode = mode;
|
||||||
|
|
||||||
memmove(e.score, score, VtScoreSize);
|
memmove(e.score, rt.score, VtScoreSize);
|
||||||
e.gen = 0;
|
e.gen = 0;
|
||||||
e.psize = (rt.blocksize/VtEntrySize)*VtEntrySize;
|
e.psize = (rt.blocksize/VtEntrySize)*VtEntrySize;
|
||||||
e.dsize = rt.blocksize;
|
e.dsize = rt.blocksize;
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ HFILES=\
|
||||||
dat.h\
|
dat.h\
|
||||||
fns.h\
|
fns.h\
|
||||||
|
|
||||||
TARG=vac # vtdump
|
TARG=vac vacfs # vtdump
|
||||||
|
|
||||||
default:V: all
|
default:V: all
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -665,7 +665,7 @@ mbsearch(MetaBlock *mb, char *elem, int *ri, MetaEntry *me)
|
||||||
*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));
|
||||||
|
|
||||||
return 1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
||||||
|
|
@ -106,6 +106,7 @@ int vacfsgetscore(VacFs *fs, u8int *score);
|
||||||
* int vfsGraft(VacFs*, char *name, VacFs*);
|
* int vfsGraft(VacFs*, char *name, VacFs*);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
VacFile *vacfsgetroot(VacFs *fs);
|
||||||
VacFile *vacfileopen(VacFs *fs, char *path);
|
VacFile *vacfileopen(VacFs *fs, char *path);
|
||||||
VacFile *vacfilecreate(VacFile *file, char *elem, ulong perm, char *muid);
|
VacFile *vacfilecreate(VacFile *file, char *elem, ulong perm, char *muid);
|
||||||
VacFile *vacfilewalk(VacFile *file, char *elem);
|
VacFile *vacfilewalk(VacFile *file, char *elem);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#include "stdinc.h"
|
#include "stdinc.h"
|
||||||
#include <auth.h>
|
#include <auth.h>
|
||||||
#include <fcall.h>
|
#include <fcall.h>
|
||||||
|
#include <thread.h>
|
||||||
#include "vac.h"
|
#include "vac.h"
|
||||||
|
|
||||||
typedef struct Fid Fid;
|
typedef struct Fid Fid;
|
||||||
|
|
@ -56,8 +57,9 @@ uchar mdata[8192+IOHDRSZ];
|
||||||
int messagesize = sizeof mdata;
|
int messagesize = sizeof mdata;
|
||||||
Fcall rhdr;
|
Fcall rhdr;
|
||||||
Fcall thdr;
|
Fcall thdr;
|
||||||
VacFS *fs;
|
VacFs *fs;
|
||||||
VtSession *session;
|
VtConn *conn;
|
||||||
|
// VtSession *session;
|
||||||
int noperm;
|
int noperm;
|
||||||
|
|
||||||
Fid * newfid(int);
|
Fid * newfid(int);
|
||||||
|
|
@ -75,6 +77,8 @@ int dirBufUnget(DirBuf*);
|
||||||
void dirBufFree(DirBuf*);
|
void dirBufFree(DirBuf*);
|
||||||
int vacdirread(Fid *f, char *p, long off, long cnt);
|
int vacdirread(Fid *f, char *p, long off, long cnt);
|
||||||
int vdStat(VacDir *vd, uchar *p, int np);
|
int vdStat(VacDir *vd, uchar *p, int np);
|
||||||
|
void srv(void* a);
|
||||||
|
|
||||||
|
|
||||||
char *rflush(Fid*), *rversion(Fid*),
|
char *rflush(Fid*), *rversion(Fid*),
|
||||||
*rauth(Fid*), *rattach(Fid*), *rwalk(Fid*),
|
*rauth(Fid*), *rattach(Fid*), *rwalk(Fid*),
|
||||||
|
|
@ -124,18 +128,16 @@ notifyf(void *a, char *s)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
main(int argc, char *argv[])
|
threadmain(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char *defmnt;
|
char *defsrv;
|
||||||
int p[2];
|
int p[2];
|
||||||
char buf[12];
|
|
||||||
int fd;
|
|
||||||
int stdio = 0;
|
int stdio = 0;
|
||||||
char *host = nil;
|
char *host = nil;
|
||||||
long ncache = 1000;
|
long ncache = 1000;
|
||||||
int readOnly = 1;
|
int readOnly = 1;
|
||||||
|
|
||||||
defmnt = "/n/vac";
|
defsrv = "vacfs";
|
||||||
ARGBEGIN{
|
ARGBEGIN{
|
||||||
case 'd':
|
case 'd':
|
||||||
fmtinstall('F', fcallfmt);
|
fmtinstall('F', fcallfmt);
|
||||||
|
|
@ -145,7 +147,6 @@ main(int argc, char *argv[])
|
||||||
ncache = atoi(ARGF());
|
ncache = atoi(ARGF());
|
||||||
break;
|
break;
|
||||||
case 'i':
|
case 'i':
|
||||||
defmnt = 0;
|
|
||||||
stdio = 1;
|
stdio = 1;
|
||||||
mfd[0] = 0;
|
mfd[0] = 0;
|
||||||
mfd[1] = 1;
|
mfd[1] = 1;
|
||||||
|
|
@ -154,14 +155,11 @@ main(int argc, char *argv[])
|
||||||
host = ARGF();
|
host = ARGF();
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
defmnt = 0;
|
defsrv = ARGF();
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
noperm = 1;
|
noperm = 1;
|
||||||
break;
|
break;
|
||||||
case 'm':
|
|
||||||
defmnt = ARGF();
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
}ARGEND
|
}ARGEND
|
||||||
|
|
@ -169,41 +167,25 @@ main(int argc, char *argv[])
|
||||||
if(argc != 1)
|
if(argc != 1)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
vtAttach();
|
|
||||||
|
|
||||||
init(argv[0], host, ncache, readOnly);
|
init(argv[0], host, ncache, readOnly);
|
||||||
|
|
||||||
if(pipe(p) < 0)
|
if(pipe(p) < 0)
|
||||||
sysfatal("pipe failed: %r");
|
sysfatal("pipe failed: %r");
|
||||||
if(!stdio){
|
|
||||||
mfd[0] = p[0];
|
mfd[0] = p[0];
|
||||||
mfd[1] = p[0];
|
mfd[1] = p[0];
|
||||||
if(defmnt == 0){
|
proccreate(srv, 0, 32 * 1024);
|
||||||
fd = create("#s/vacfs", OWRITE, 0666);
|
|
||||||
if(fd < 0)
|
if (post9pservice(p[1], defsrv) != 0)
|
||||||
sysfatal("create of /srv/vacfs failed: %r");
|
sysfatal("post9pservice");
|
||||||
sprint(buf, "%d", p[1]);
|
|
||||||
if(write(fd, buf, strlen(buf)) < 0)
|
|
||||||
sysfatal("writing /srv/vacfs: %r");
|
threadexits(0);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(rfork(RFFDG|RFPROC|RFNAMEG|RFNOTEG)){
|
void srv(void* a) {
|
||||||
case -1:
|
|
||||||
sysfatal("fork: %r");
|
|
||||||
case 0:
|
|
||||||
vtAttach();
|
|
||||||
close(p[1]);
|
|
||||||
io();
|
io();
|
||||||
shutdown();
|
shutdown();
|
||||||
break;
|
|
||||||
default:
|
|
||||||
close(p[0]); /* don't deadlock if child fails */
|
|
||||||
if(defmnt && mount(p[1], -1, defmnt, MREPL|MCREATE, "") < 0)
|
|
||||||
sysfatal("mount failed: %r");
|
|
||||||
}
|
|
||||||
vtDetach();
|
|
||||||
exits(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
@ -225,13 +207,13 @@ rversion(Fid *unused)
|
||||||
rclunk(f);
|
rclunk(f);
|
||||||
|
|
||||||
if(rhdr.msize < 256)
|
if(rhdr.msize < 256)
|
||||||
return "version: message size too small";
|
return vtstrdup("version: message size too small");
|
||||||
messagesize = rhdr.msize;
|
messagesize = rhdr.msize;
|
||||||
if(messagesize > sizeof mdata)
|
if(messagesize > sizeof mdata)
|
||||||
messagesize = sizeof mdata;
|
messagesize = sizeof mdata;
|
||||||
thdr.msize = messagesize;
|
thdr.msize = messagesize;
|
||||||
if(strncmp(rhdr.version, "9P2000", 6) != 0)
|
if(strncmp(rhdr.version, "9P2000", 6) != 0)
|
||||||
return "unrecognized 9P version";
|
return vtstrdup("unrecognized 9P version");
|
||||||
thdr.version = "9P2000";
|
thdr.version = "9P2000";
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
@ -247,7 +229,7 @@ char*
|
||||||
rauth(Fid *f)
|
rauth(Fid *f)
|
||||||
{
|
{
|
||||||
USED(f);
|
USED(f);
|
||||||
return "vacfs: authentication not required";
|
return vtstrdup("vacfs: authentication not required");
|
||||||
}
|
}
|
||||||
|
|
||||||
char*
|
char*
|
||||||
|
|
@ -255,16 +237,20 @@ rattach(Fid *f)
|
||||||
{
|
{
|
||||||
/* no authentication for the momment */
|
/* no authentication for the momment */
|
||||||
VacFile *file;
|
VacFile *file;
|
||||||
|
char err[80];
|
||||||
|
|
||||||
|
file = vacfsgetroot(fs);
|
||||||
|
if(file == nil) {
|
||||||
|
rerrstr(err, sizeof err);
|
||||||
|
return vtstrdup(err);
|
||||||
|
}
|
||||||
|
|
||||||
file = vfsGetRoot(fs);
|
|
||||||
if(file == nil)
|
|
||||||
return vtGetError();
|
|
||||||
f->busy = 1;
|
f->busy = 1;
|
||||||
f->file = file;
|
f->file = file;
|
||||||
f->qid = (Qid){vfGetId(f->file), 0, QTDIR};
|
f->qid = (Qid){vacfilegetid(f->file), 0, QTDIR};
|
||||||
thdr.qid = f->qid;
|
thdr.qid = f->qid;
|
||||||
if(rhdr.uname[0])
|
if(rhdr.uname[0])
|
||||||
f->user = vtStrDup(rhdr.uname);
|
f->user = vtstrdup(rhdr.uname);
|
||||||
else
|
else
|
||||||
f->user = "none";
|
f->user = "none";
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -275,11 +261,11 @@ _vfWalk(VacFile *file, char *name)
|
||||||
{
|
{
|
||||||
VacFile *n;
|
VacFile *n;
|
||||||
|
|
||||||
n = vfWalk(file, name);
|
n = vacfilewalk(file, name);
|
||||||
if(n)
|
if(n)
|
||||||
return n;
|
return n;
|
||||||
if(strcmp(name, "SLASH") == 0)
|
if(strcmp(name, "SLASH") == 0)
|
||||||
return vfWalk(file, "/");
|
return vacfilewalk(file, "/");
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -290,23 +276,24 @@ rwalk(Fid *f)
|
||||||
Fid *nf;
|
Fid *nf;
|
||||||
int nqid, nwname;
|
int nqid, nwname;
|
||||||
Qid qid;
|
Qid qid;
|
||||||
|
char *err = nil;
|
||||||
|
|
||||||
if(f->busy == 0)
|
if(f->busy == 0)
|
||||||
return Enotexist;
|
return Enotexist;
|
||||||
nf = nil;
|
nf = nil;
|
||||||
if(rhdr.fid != rhdr.newfid){
|
if(rhdr.fid != rhdr.newfid){
|
||||||
if(f->open)
|
if(f->open)
|
||||||
return Eisopen;
|
return vtstrdup(Eisopen);
|
||||||
if(f->busy == 0)
|
if(f->busy == 0)
|
||||||
return Enotexist;
|
return vtstrdup(Enotexist);
|
||||||
nf = newfid(rhdr.newfid);
|
nf = newfid(rhdr.newfid);
|
||||||
if(nf->busy)
|
if(nf->busy)
|
||||||
return Eisopen;
|
return vtstrdup(Eisopen);
|
||||||
nf->busy = 1;
|
nf->busy = 1;
|
||||||
nf->open = 0;
|
nf->open = 0;
|
||||||
nf->qid = f->qid;
|
nf->qid = f->qid;
|
||||||
nf->file = vfIncRef(f->file);
|
nf->file = vacfileincref(f->file);
|
||||||
nf->user = vtStrDup(f->user);
|
nf->user = vtstrdup(f->user);
|
||||||
f = nf;
|
f = nf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -319,28 +306,28 @@ rwalk(Fid *f)
|
||||||
}
|
}
|
||||||
|
|
||||||
file = f->file;
|
file = f->file;
|
||||||
vfIncRef(file);
|
vacfileincref(file);
|
||||||
qid = f->qid;
|
qid = f->qid;
|
||||||
|
|
||||||
for(nqid = 0; nqid < nwname; nqid++){
|
for(nqid = 0; nqid < nwname; nqid++){
|
||||||
if((qid.type & QTDIR) == 0){
|
if((qid.type & QTDIR) == 0){
|
||||||
vtSetError(Enotdir);
|
err = Enotdir;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(!permf(file, f->user, Pexec)) {
|
if(!permf(file, f->user, Pexec)) {
|
||||||
vtSetError(Eperm);
|
err = Eperm;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
nfile = _vfWalk(file, rhdr.wname[nqid]);
|
nfile = _vfWalk(file, rhdr.wname[nqid]);
|
||||||
if(nfile == nil)
|
if(nfile == nil)
|
||||||
break;
|
break;
|
||||||
vfDecRef(file);
|
vacfiledecref(file);
|
||||||
file = nfile;
|
file = nfile;
|
||||||
qid.type = QTFILE;
|
qid.type = QTFILE;
|
||||||
if(vfIsDir(file))
|
if(vacfileisdir(file))
|
||||||
qid.type = QTDIR;
|
qid.type = QTDIR;
|
||||||
qid.vers = vfGetMcount(file);
|
qid.vers = vacfilegetmcount(file);
|
||||||
qid.path = vfGetId(file);
|
qid.path = vacfilegetid(file);
|
||||||
thdr.wqid[nqid] = qid;
|
thdr.wqid[nqid] = qid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -349,18 +336,18 @@ rwalk(Fid *f)
|
||||||
if(nqid == nwname){
|
if(nqid == nwname){
|
||||||
/* success */
|
/* success */
|
||||||
f->qid = thdr.wqid[nqid-1];
|
f->qid = thdr.wqid[nqid-1];
|
||||||
vfDecRef(f->file);
|
vacfiledecref(f->file);
|
||||||
f->file = file;
|
f->file = file;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
vfDecRef(file);
|
vacfiledecref(file);
|
||||||
if(nf != nil)
|
if(nf != nil)
|
||||||
rclunk(nf);
|
rclunk(nf);
|
||||||
|
|
||||||
/* only error on the first element */
|
/* only error on the first element */
|
||||||
if(nqid == 0)
|
if(nqid == 0)
|
||||||
return vtGetError();
|
return vtstrdup(err);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -371,34 +358,35 @@ ropen(Fid *f)
|
||||||
int mode, trunc;
|
int mode, trunc;
|
||||||
|
|
||||||
if(f->open)
|
if(f->open)
|
||||||
return Eisopen;
|
return vtstrdup(Eisopen);
|
||||||
if(!f->busy)
|
if(!f->busy)
|
||||||
return Enotexist;
|
return vtstrdup(Enotexist);
|
||||||
|
|
||||||
mode = rhdr.mode;
|
mode = rhdr.mode;
|
||||||
thdr.iounit = messagesize - IOHDRSZ;
|
thdr.iounit = messagesize - IOHDRSZ;
|
||||||
if(f->qid.type & QTDIR){
|
if(f->qid.type & QTDIR){
|
||||||
if(mode != OREAD)
|
if(mode != OREAD)
|
||||||
return Eperm;
|
return vtstrdup(Eperm);
|
||||||
if(!perm(f, Pread))
|
if(!perm(f, Pread))
|
||||||
return Eperm;
|
return vtstrdup(Eperm);
|
||||||
thdr.qid = f->qid;
|
thdr.qid = f->qid;
|
||||||
f->db = nil;
|
f->db = nil;
|
||||||
f->open = 1;
|
f->open = 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(mode & ORCLOSE)
|
if(mode & ORCLOSE)
|
||||||
return Erdonly;
|
return vtstrdup(Erdonly);
|
||||||
trunc = mode & OTRUNC;
|
trunc = mode & OTRUNC;
|
||||||
mode &= OPERM;
|
mode &= OPERM;
|
||||||
if(mode==OWRITE || mode==ORDWR || trunc)
|
if(mode==OWRITE || mode==ORDWR || trunc)
|
||||||
if(!perm(f, Pwrite))
|
if(!perm(f, Pwrite))
|
||||||
return Eperm;
|
return vtstrdup(Eperm);
|
||||||
if(mode==OREAD || mode==ORDWR)
|
if(mode==OREAD || mode==ORDWR)
|
||||||
if(!perm(f, Pread))
|
if(!perm(f, Pread))
|
||||||
return Eperm;
|
return vtstrdup(Eperm);
|
||||||
if(mode==OEXEC)
|
if(mode==OEXEC)
|
||||||
if(!perm(f, Pexec))
|
if(!perm(f, Pexec))
|
||||||
return Eperm;
|
return vtstrdup(Eperm);
|
||||||
thdr.qid = f->qid;
|
thdr.qid = f->qid;
|
||||||
thdr.iounit = messagesize - IOHDRSZ;
|
thdr.iounit = messagesize - IOHDRSZ;
|
||||||
f->open = 1;
|
f->open = 1;
|
||||||
|
|
@ -412,45 +400,50 @@ rcreate(Fid* fid)
|
||||||
ulong mode;
|
ulong mode;
|
||||||
|
|
||||||
if(fid->open)
|
if(fid->open)
|
||||||
return Eisopen;
|
return vtstrdup(Eisopen);
|
||||||
if(!fid->busy)
|
if(!fid->busy)
|
||||||
return Enotexist;
|
return vtstrdup(Enotexist);
|
||||||
if(vfsIsReadOnly(fs))
|
if(fs->mode & ModeSnapshot)
|
||||||
return Erdonly;
|
return vtstrdup(Erdonly);
|
||||||
vf = fid->file;
|
vf = fid->file;
|
||||||
if(!vfIsDir(vf))
|
if(!vacfileisdir(vf))
|
||||||
return Enotdir;
|
return vtstrdup(Enotdir);
|
||||||
if(!permf(vf, fid->user, Pwrite))
|
if(!permf(vf, fid->user, Pwrite))
|
||||||
return Eperm;
|
return vtstrdup(Eperm);
|
||||||
|
|
||||||
mode = rhdr.perm & 0777;
|
mode = rhdr.perm & 0777;
|
||||||
|
|
||||||
if(rhdr.perm & DMDIR){
|
if(rhdr.perm & DMDIR){
|
||||||
if((rhdr.mode & OTRUNC) || (rhdr.perm & DMAPPEND))
|
if((rhdr.mode & OTRUNC) || (rhdr.perm & DMAPPEND))
|
||||||
return Emode;
|
return vtstrdup(Emode);
|
||||||
switch(rhdr.mode & OPERM){
|
switch(rhdr.mode & OPERM){
|
||||||
default:
|
default:
|
||||||
return Emode;
|
return vtstrdup(Emode);
|
||||||
case OEXEC:
|
case OEXEC:
|
||||||
case OREAD:
|
case OREAD:
|
||||||
break;
|
break;
|
||||||
case OWRITE:
|
case OWRITE:
|
||||||
case ORDWR:
|
case ORDWR:
|
||||||
return Eperm;
|
return vtstrdup(Eperm);
|
||||||
}
|
}
|
||||||
mode |= ModeDir;
|
mode |= ModeDir;
|
||||||
}
|
}
|
||||||
vf = vfCreate(vf, rhdr.name, mode, "none");
|
vf = vacfilecreate(vf, rhdr.name, mode, "none");
|
||||||
if(vf == nil)
|
if(vf == nil) {
|
||||||
return vtGetError();
|
char err[80];
|
||||||
vfDecRef(fid->file);
|
rerrstr(err, sizeof err);
|
||||||
|
|
||||||
|
return vtstrdup(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
vacfiledecref(fid->file);
|
||||||
|
|
||||||
fid->file = vf;
|
fid->file = vf;
|
||||||
fid->qid.type = QTFILE;
|
fid->qid.type = QTFILE;
|
||||||
if(vfIsDir(vf))
|
if(vacfileisdir(vf))
|
||||||
fid->qid.type = QTDIR;
|
fid->qid.type = QTDIR;
|
||||||
fid->qid.vers = vfGetMcount(vf);
|
fid->qid.vers = vacfilegetmcount(vf);
|
||||||
fid->qid.path = vfGetId(vf);
|
fid->qid.path = vacfilegetid(vf);
|
||||||
|
|
||||||
thdr.qid = fid->qid;
|
thdr.qid = fid->qid;
|
||||||
thdr.iounit = messagesize - IOHDRSZ;
|
thdr.iounit = messagesize - IOHDRSZ;
|
||||||
|
|
@ -465,11 +458,11 @@ rread(Fid *f)
|
||||||
vlong off;
|
vlong off;
|
||||||
int cnt;
|
int cnt;
|
||||||
VacFile *vf;
|
VacFile *vf;
|
||||||
char *err;
|
char err[80];
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
if(!f->busy)
|
if(!f->busy)
|
||||||
return Enotexist;
|
return vtstrdup(Enotexist);
|
||||||
vf = f->file;
|
vf = f->file;
|
||||||
thdr.count = 0;
|
thdr.count = 0;
|
||||||
off = rhdr.offset;
|
off = rhdr.offset;
|
||||||
|
|
@ -478,12 +471,10 @@ rread(Fid *f)
|
||||||
if(f->qid.type & QTDIR)
|
if(f->qid.type & QTDIR)
|
||||||
n = vacdirread(f, buf, off, cnt);
|
n = vacdirread(f, buf, off, cnt);
|
||||||
else
|
else
|
||||||
n = vfRead(vf, buf, cnt, off);
|
n = vacfileread(vf, buf, cnt, off);
|
||||||
if(n < 0) {
|
if(n < 0) {
|
||||||
err = vtGetError();
|
rerrstr(err, sizeof err);
|
||||||
if(err == nil)
|
return vtstrdup(err);
|
||||||
err = "unknown error!";
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
thdr.count = n;
|
thdr.count = n;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -498,7 +489,7 @@ rwrite(Fid *f)
|
||||||
VacFile *vf;
|
VacFile *vf;
|
||||||
|
|
||||||
if(!f->busy)
|
if(!f->busy)
|
||||||
return Enotexist;
|
return vtstrdup(Enotexist);
|
||||||
vf = f->file;
|
vf = f->file;
|
||||||
thdr.count = 0;
|
thdr.count = 0;
|
||||||
off = rhdr.offset;
|
off = rhdr.offset;
|
||||||
|
|
@ -506,10 +497,13 @@ rwrite(Fid *f)
|
||||||
cnt = rhdr.count;
|
cnt = rhdr.count;
|
||||||
if(f->qid.type & QTDIR)
|
if(f->qid.type & QTDIR)
|
||||||
return "file is a directory";
|
return "file is a directory";
|
||||||
thdr.count = vfWrite(vf, buf, cnt, off, "none");
|
thdr.count = vacfilewrite(vf, buf, cnt, off, "none");
|
||||||
if(thdr.count < 0) {
|
if(thdr.count < 0) {
|
||||||
fprint(2, "write failed: %s\n", vtGetError());
|
char err[80];
|
||||||
return vtGetError();
|
|
||||||
|
rerrstr(err, sizeof err);
|
||||||
|
fprint(2, "write failed: %s\n", err);
|
||||||
|
return vtstrdup(err);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -519,9 +513,9 @@ rclunk(Fid *f)
|
||||||
{
|
{
|
||||||
f->busy = 0;
|
f->busy = 0;
|
||||||
f->open = 0;
|
f->open = 0;
|
||||||
vtMemFree(f->user);
|
vtfree(f->user);
|
||||||
f->user = nil;
|
f->user = nil;
|
||||||
vfDecRef(f->file);
|
vacfiledecref(f->file);
|
||||||
f->file = nil;
|
f->file = nil;
|
||||||
dirBufFree(f->db);
|
dirBufFree(f->db);
|
||||||
f->db = nil;
|
f->db = nil;
|
||||||
|
|
@ -532,27 +526,30 @@ char *
|
||||||
rremove(Fid *f)
|
rremove(Fid *f)
|
||||||
{
|
{
|
||||||
VacFile *vf, *vfp;
|
VacFile *vf, *vfp;
|
||||||
|
char errbuf[80];
|
||||||
char *err = nil;
|
char *err = nil;
|
||||||
|
|
||||||
if(!f->busy)
|
if(!f->busy)
|
||||||
return Enotexist;
|
return vtstrdup(Enotexist);
|
||||||
vf = f->file;
|
vf = f->file;
|
||||||
vfp = vfGetParent(vf);
|
vfp = vacfilegetparent(vf);
|
||||||
|
|
||||||
if(!permf(vfp, f->user, Pwrite)) {
|
if(!permf(vfp, f->user, Pwrite)) {
|
||||||
err = Eperm;
|
err = Eperm;
|
||||||
goto Exit;
|
goto Exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!vfRemove(vf, "none")) {
|
if(!vacfileremove(vf, "none")) {
|
||||||
print("vfRemove failed\n");
|
rerrstr(errbuf, sizeof errbuf);
|
||||||
err = vtGetError();
|
print("vfRemove failed: %s\n", errbuf);
|
||||||
|
|
||||||
|
err = errbuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
Exit:
|
Exit:
|
||||||
vfDecRef(vfp);
|
vacfiledecref(vfp);
|
||||||
rclunk(f);
|
rclunk(f);
|
||||||
return err;
|
return vtstrdup(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
|
|
@ -562,11 +559,11 @@ rstat(Fid *f)
|
||||||
static uchar statbuf[1024];
|
static uchar statbuf[1024];
|
||||||
|
|
||||||
if(!f->busy)
|
if(!f->busy)
|
||||||
return Enotexist;
|
return vtstrdup(Enotexist);
|
||||||
vfGetDir(f->file, &dir);
|
vacfilegetdir(f->file, &dir);
|
||||||
thdr.stat = statbuf;
|
thdr.stat = statbuf;
|
||||||
thdr.nstat = vdStat(&dir, thdr.stat, sizeof statbuf);
|
thdr.nstat = vdStat(&dir, thdr.stat, sizeof statbuf);
|
||||||
vdCleanup(&dir);
|
vdcleanup(&dir);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -574,8 +571,8 @@ char *
|
||||||
rwstat(Fid *f)
|
rwstat(Fid *f)
|
||||||
{
|
{
|
||||||
if(!f->busy)
|
if(!f->busy)
|
||||||
return Enotexist;
|
return vtstrdup(Enotexist);
|
||||||
return Erdonly;
|
return vtstrdup(Erdonly);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
@ -621,8 +618,8 @@ dirBufAlloc(VacFile *vf)
|
||||||
{
|
{
|
||||||
DirBuf *db;
|
DirBuf *db;
|
||||||
|
|
||||||
db = vtMemAllocZ(sizeof(DirBuf));
|
db = vtmallocz(sizeof(DirBuf));
|
||||||
db->vde = vfDirEnum(vf);
|
db->vde = vdeopen(vf);
|
||||||
return db;
|
return db;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -636,7 +633,7 @@ dirBufGet(DirBuf *db)
|
||||||
return nil;
|
return nil;
|
||||||
|
|
||||||
if(db->i >= db->n) {
|
if(db->i >= db->n) {
|
||||||
n = vdeRead(db->vde, db->buf, DirBufSize);
|
n = vderead(db->vde, db->buf);
|
||||||
if(n < 0)
|
if(n < 0)
|
||||||
return nil;
|
return nil;
|
||||||
db->i = 0;
|
db->i = 0;
|
||||||
|
|
@ -670,9 +667,9 @@ dirBufFree(DirBuf *db)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for(i=db->i; i<db->n; i++)
|
for(i=db->i; i<db->n; i++)
|
||||||
vdCleanup(db->buf + i);
|
vdcleanup(db->buf + i);
|
||||||
vdeFree(db->vde);
|
vdeclose(db->vde);
|
||||||
vtMemFree(db);
|
vtfree(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
@ -705,7 +702,7 @@ vacdirread(Fid *f, char *p, long off, long cnt)
|
||||||
dirBufUnget(f->db);
|
dirBufUnget(f->db);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
vdCleanup(vd);
|
vdcleanup(vd);
|
||||||
p += n;
|
p += n;
|
||||||
}
|
}
|
||||||
return nb;
|
return nb;
|
||||||
|
|
@ -726,7 +723,7 @@ newfid(int fid)
|
||||||
ff->fid = fid;
|
ff->fid = fid;
|
||||||
return ff;
|
return ff;
|
||||||
}
|
}
|
||||||
f = vtMemAllocZ(sizeof *f);
|
f = vtmallocz(sizeof *f);
|
||||||
f->fid = fid;
|
f->fid = fid;
|
||||||
f->next = fids;
|
f->next = fids;
|
||||||
fids = f;
|
fids = f;
|
||||||
|
|
@ -775,6 +772,9 @@ io(void)
|
||||||
if(dflag)
|
if(dflag)
|
||||||
fprint(2, "vacfs:->%F\n", &thdr);
|
fprint(2, "vacfs:->%F\n", &thdr);
|
||||||
n = convS2M(&thdr, mdata, messagesize);
|
n = convS2M(&thdr, mdata, messagesize);
|
||||||
|
if (err)
|
||||||
|
vtfree(err);
|
||||||
|
|
||||||
if(write(mfd[1], mdata, n) != n)
|
if(write(mfd[1], mdata, n) != n)
|
||||||
sysfatal("mount write: %r");
|
sysfatal("mount write: %r");
|
||||||
}
|
}
|
||||||
|
|
@ -786,9 +786,10 @@ permf(VacFile *vf, char *user, int p)
|
||||||
VacDir dir;
|
VacDir dir;
|
||||||
ulong perm;
|
ulong perm;
|
||||||
|
|
||||||
if(!vfGetDir(vf, &dir))
|
if(vacfilegetdir(vf, &dir))
|
||||||
return 0;
|
return 0;
|
||||||
perm = dir.mode & 0777;
|
perm = dir.mode & 0777;
|
||||||
|
|
||||||
if(noperm)
|
if(noperm)
|
||||||
goto Good;
|
goto Good;
|
||||||
if((p*Pother) & perm)
|
if((p*Pother) & perm)
|
||||||
|
|
@ -797,10 +798,10 @@ permf(VacFile *vf, char *user, int p)
|
||||||
goto Good;
|
goto Good;
|
||||||
if(strcmp(user, dir.uid)==0 && ((p*Powner) & perm))
|
if(strcmp(user, dir.uid)==0 && ((p*Powner) & perm))
|
||||||
goto Good;
|
goto Good;
|
||||||
vdCleanup(&dir);
|
vdcleanup(&dir);
|
||||||
return 0;
|
return 0;
|
||||||
Good:
|
Good:
|
||||||
vdCleanup(&dir);
|
vdcleanup(&dir);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -816,19 +817,19 @@ init(char *file, char *host, long ncache, int readOnly)
|
||||||
notify(notifyf);
|
notify(notifyf);
|
||||||
user = getuser();
|
user = getuser();
|
||||||
|
|
||||||
fmtinstall('V', vtScoreFmt);
|
fmtinstall('V', vtscorefmt);
|
||||||
fmtinstall('R', vtErrFmt);
|
// fmtinstall('R', vtErrFmt);
|
||||||
|
|
||||||
session = vtDial(host, 0);
|
conn = vtdial(host);
|
||||||
if(session == nil)
|
if(conn == nil)
|
||||||
vtFatal("could not connect to server: %s", vtGetError());
|
sysfatal("could not connect to server: %r");
|
||||||
|
|
||||||
if(!vtConnect(session, 0))
|
if(vtconnect(conn) < 0)
|
||||||
vtFatal("vtConnect: %s", vtGetError());
|
sysfatal("vtconnect: %r");
|
||||||
|
|
||||||
fs = vfsOpen(session, file, readOnly, ncache);
|
fs = vacfsopen(conn, file, /*readOnly ? ModeSnapshot :*/ VtOREAD, ncache);
|
||||||
if(fs == nil)
|
if(fs == nil)
|
||||||
vtFatal("vfsOpen: %s", vtGetError());
|
sysfatal("vfsOpen: %r");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
@ -843,7 +844,7 @@ fprint(2, "open fid: %d\n", f->fid);
|
||||||
rclunk(f);
|
rclunk(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
vfsClose(fs);
|
vacfsclose(fs);
|
||||||
vtClose(session);
|
vthangup(conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue