vacfs: plan 9 compatibility
This commit is contained in:
parent
948cc14e07
commit
ada3d479a7
2 changed files with 89 additions and 31 deletions
|
|
@ -3,7 +3,6 @@
|
||||||
LIBFILES=\
|
LIBFILES=\
|
||||||
error\
|
error\
|
||||||
file\
|
file\
|
||||||
fs\
|
|
||||||
pack\
|
pack\
|
||||||
|
|
||||||
LIB=${LIBFILES:%=%.$O} $PLAN9/lib/libventi.a
|
LIB=${LIBFILES:%=%.$O} $PLAN9/lib/libventi.a
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,13 @@
|
||||||
#include <fcall.h>
|
#include <fcall.h>
|
||||||
#include "vac.h"
|
#include "vac.h"
|
||||||
|
|
||||||
|
#ifndef PLAN9PORT
|
||||||
|
#define convM2Su(a, b, c, d) convM2S(a, b, c)
|
||||||
|
#define convS2Mu(a, b, c, d) convS2M(a, b, c)
|
||||||
|
#define convM2Du(a, b, c, d) convM2D(a, b, c)
|
||||||
|
#define convD2Mu(a, b, c, d) convD2M(a, b, c)
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct Fid Fid;
|
typedef struct Fid Fid;
|
||||||
|
|
||||||
enum
|
enum
|
||||||
|
|
@ -34,6 +41,7 @@ enum
|
||||||
Fid *fids;
|
Fid *fids;
|
||||||
uchar *data;
|
uchar *data;
|
||||||
int mfd[2];
|
int mfd[2];
|
||||||
|
int srvfd = -1;
|
||||||
char *user;
|
char *user;
|
||||||
uchar mdata[8192+IOHDRSZ];
|
uchar mdata[8192+IOHDRSZ];
|
||||||
int messagesize = sizeof mdata;
|
int messagesize = sizeof mdata;
|
||||||
|
|
@ -41,7 +49,6 @@ Fcall rhdr;
|
||||||
Fcall thdr;
|
Fcall thdr;
|
||||||
VacFs *fs;
|
VacFs *fs;
|
||||||
VtConn *conn;
|
VtConn *conn;
|
||||||
/* VtSession *session; */
|
|
||||||
int noperm;
|
int noperm;
|
||||||
int dotu;
|
int dotu;
|
||||||
char *defmnt;
|
char *defmnt;
|
||||||
|
|
@ -114,16 +121,19 @@ notifyf(void *a, char *s)
|
||||||
void
|
void
|
||||||
threadmain(int argc, char *argv[])
|
threadmain(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char *defsrv, *q;
|
char *defsrv, *srvname;
|
||||||
int p[2], l;
|
int p[2], fd;
|
||||||
int stdio = 0;
|
int stdio;
|
||||||
char *host = nil;
|
char *host = nil;
|
||||||
long ncache = 1000;
|
long ncache;
|
||||||
|
|
||||||
|
stdio = 0;
|
||||||
|
ncache = 256;
|
||||||
fmtinstall('H', encodefmt);
|
fmtinstall('H', encodefmt);
|
||||||
fmtinstall('V', vtscorefmt);
|
fmtinstall('V', vtscorefmt);
|
||||||
fmtinstall('F', vtfcallfmt);
|
fmtinstall('F', vtfcallfmt);
|
||||||
|
|
||||||
|
defmnt = nil;
|
||||||
defsrv = nil;
|
defsrv = nil;
|
||||||
ARGBEGIN{
|
ARGBEGIN{
|
||||||
case 'd':
|
case 'd':
|
||||||
|
|
@ -134,6 +144,7 @@ threadmain(int argc, char *argv[])
|
||||||
ncache = atoi(EARGF(usage()));
|
ncache = atoi(EARGF(usage()));
|
||||||
break;
|
break;
|
||||||
case 'i':
|
case 'i':
|
||||||
|
defmnt = nil;
|
||||||
stdio = 1;
|
stdio = 1;
|
||||||
mfd[0] = 0;
|
mfd[0] = 0;
|
||||||
mfd[1] = 1;
|
mfd[1] = 1;
|
||||||
|
|
@ -141,9 +152,12 @@ threadmain(int argc, char *argv[])
|
||||||
case 'h':
|
case 'h':
|
||||||
host = EARGF(usage());
|
host = EARGF(usage());
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 'S':
|
||||||
defsrv = EARGF(usage());
|
defsrv = EARGF(usage());
|
||||||
break;
|
break;
|
||||||
|
case 's':
|
||||||
|
defsrv = "vacfs";
|
||||||
|
break;
|
||||||
case 'm':
|
case 'm':
|
||||||
defmnt = EARGF(usage());
|
defmnt = EARGF(usage());
|
||||||
break;
|
break;
|
||||||
|
|
@ -160,6 +174,26 @@ threadmain(int argc, char *argv[])
|
||||||
if(argc != 1)
|
if(argc != 1)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
|
#ifdef PLAN9PORT
|
||||||
|
if(defsrv == nil && defmnt == nil && !stdio){
|
||||||
|
srvname = strchr(argv[0], '/');
|
||||||
|
if(srvname)
|
||||||
|
srvname++;
|
||||||
|
else
|
||||||
|
srvname = argv[0];
|
||||||
|
defsrv = vtmalloc(6+strlen(srvname)+1);
|
||||||
|
strcpy(defsrv, "vacfs.");
|
||||||
|
strcat(defsrv, srvname);
|
||||||
|
if(strcmp(defsrv+strlen(defsrv)-4, ".vac") == 0)
|
||||||
|
defsrv[strlen(defsrv)-4] = 0;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
if(defsrv == nil && defmnt == nil && !stdio)
|
||||||
|
defmnt = "/n/vac";
|
||||||
|
#endif
|
||||||
|
if(stdio && defmnt)
|
||||||
|
sysfatal("cannot use -m with -i");
|
||||||
|
|
||||||
initfcalls();
|
initfcalls();
|
||||||
|
|
||||||
notify(notifyf);
|
notify(notifyf);
|
||||||
|
|
@ -176,36 +210,46 @@ threadmain(int argc, char *argv[])
|
||||||
if(fs == nil)
|
if(fs == nil)
|
||||||
sysfatal("vacfsopen: %r");
|
sysfatal("vacfsopen: %r");
|
||||||
|
|
||||||
|
if(!stdio){
|
||||||
if(pipe(p) < 0)
|
if(pipe(p) < 0)
|
||||||
sysfatal("pipe failed: %r");
|
sysfatal("pipe failed: %r");
|
||||||
|
|
||||||
mfd[0] = p[0];
|
mfd[0] = p[0];
|
||||||
mfd[1] = p[0];
|
mfd[1] = p[0];
|
||||||
proccreate(srv, 0, 32 * 1024);
|
srvfd = p[1];
|
||||||
|
|
||||||
if(defsrv == nil && defmnt == nil){
|
|
||||||
q = strrchr(argv[0], '/');
|
|
||||||
if(q)
|
|
||||||
q++;
|
|
||||||
else
|
|
||||||
q = argv[0];
|
|
||||||
defsrv = vtmalloc(6+strlen(q)+1);
|
|
||||||
strcpy(defsrv, "vacfs.");
|
|
||||||
strcat(defsrv, q);
|
|
||||||
l = strlen(defsrv);
|
|
||||||
if(strcmp(defsrv+l-4, ".vac") == 0)
|
|
||||||
defsrv[l-4] = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(post9pservice(p[1], defsrv, defmnt) != 0)
|
#ifdef PLAN9PORT
|
||||||
|
USED(fd);
|
||||||
|
proccreate(srv, 0, 32 * 1024);
|
||||||
|
if(post9pservice(p[1], defsrv, defmnt) < 0)
|
||||||
sysfatal("post9pservice");
|
sysfatal("post9pservice");
|
||||||
|
#else
|
||||||
|
procrfork(srv, 0, 32 * 1024, RFFDG|RFNAMEG|RFNOTEG);
|
||||||
|
|
||||||
|
if(!stdio){
|
||||||
|
close(p[0]);
|
||||||
|
if(defsrv){
|
||||||
|
srvname = smprint("/srv/%s", defsrv);
|
||||||
|
fd = create(srvname, OWRITE|ORCLOSE, 0666);
|
||||||
|
if(fd < 0)
|
||||||
|
sysfatal("create %s: %r", srvname);
|
||||||
|
if(fprint(fd, "%d", srvfd) < 0)
|
||||||
|
sysfatal("write %s: %r", srvname);
|
||||||
|
free(srvname);
|
||||||
|
}
|
||||||
|
if(defmnt){
|
||||||
|
if(mount(srvfd, -1, defmnt, MREPL|MCREATE, "") < 0)
|
||||||
|
sysfatal("mount %s: %r", defmnt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
threadexits(0);
|
threadexits(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
srv(void *a)
|
srv(void *a)
|
||||||
{
|
{
|
||||||
|
USED(a);
|
||||||
io();
|
io();
|
||||||
vacshutdown();
|
vacshutdown();
|
||||||
}
|
}
|
||||||
|
|
@ -341,8 +385,10 @@ rwalk(Fid *f)
|
||||||
qid.type = QTFILE;
|
qid.type = QTFILE;
|
||||||
if(vacfileisdir(file))
|
if(vacfileisdir(file))
|
||||||
qid.type = QTDIR;
|
qid.type = QTDIR;
|
||||||
|
#ifdef PLAN9PORT
|
||||||
if(vacfilegetmode(file)&ModeLink)
|
if(vacfilegetmode(file)&ModeLink)
|
||||||
qid.type = QTSYMLINK;
|
qid.type = QTSYMLINK;
|
||||||
|
#endif
|
||||||
qid.vers = vacfilegetmcount(file);
|
qid.vers = vacfilegetmcount(file);
|
||||||
qid.path = vacfilegetid(file);
|
qid.path = vacfilegetid(file);
|
||||||
thdr.wqid[nqid] = qid;
|
thdr.wqid[nqid] = qid;
|
||||||
|
|
@ -506,6 +552,7 @@ rread(Fid *f)
|
||||||
char*
|
char*
|
||||||
rwrite(Fid *f)
|
rwrite(Fid *f)
|
||||||
{
|
{
|
||||||
|
USED(f);
|
||||||
return vtstrdup(Erdonly);
|
return vtstrdup(Erdonly);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -581,14 +628,18 @@ rwstat(Fid *f)
|
||||||
int
|
int
|
||||||
vacstat(VacFile *parent, VacDir *vd, uchar *p, int np)
|
vacstat(VacFile *parent, VacDir *vd, uchar *p, int np)
|
||||||
{
|
{
|
||||||
char *ext;
|
int ret;
|
||||||
int n, ret;
|
|
||||||
uvlong size;
|
|
||||||
Dir dir;
|
Dir dir;
|
||||||
|
#ifdef PLAN9PORT
|
||||||
|
int n;
|
||||||
VacFile *vf;
|
VacFile *vf;
|
||||||
|
uvlong size;
|
||||||
|
char *ext = nil;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
USED(parent);
|
||||||
|
|
||||||
memset(&dir, 0, sizeof(dir));
|
memset(&dir, 0, sizeof(dir));
|
||||||
ext = nil;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Where do path and version come from
|
* Where do path and version come from
|
||||||
|
|
@ -609,6 +660,7 @@ vacstat(VacFile *parent, VacDir *vd, uchar *p, int np)
|
||||||
dir.mode |= DMDIR;
|
dir.mode |= DMDIR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef PLAN9PORT
|
||||||
if(vd->mode & (ModeLink|ModeDevice|ModeNamedPipe)){
|
if(vd->mode & (ModeLink|ModeDevice|ModeNamedPipe)){
|
||||||
vf = vacfilewalk(parent, vd->elem);
|
vf = vacfilewalk(parent, vd->elem);
|
||||||
if(vf == nil)
|
if(vf == nil)
|
||||||
|
|
@ -629,6 +681,7 @@ vacstat(VacFile *parent, VacDir *vd, uchar *p, int np)
|
||||||
if(vd->mode & ModeNamedPipe)
|
if(vd->mode & ModeNamedPipe)
|
||||||
dir.mode |= DMNAMEDPIPE;
|
dir.mode |= DMNAMEDPIPE;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
dir.atime = vd->atime;
|
dir.atime = vd->atime;
|
||||||
dir.mtime = vd->mtime;
|
dir.mtime = vd->mtime;
|
||||||
|
|
@ -638,12 +691,16 @@ vacstat(VacFile *parent, VacDir *vd, uchar *p, int np)
|
||||||
dir.uid = vd->uid;
|
dir.uid = vd->uid;
|
||||||
dir.gid = vd->gid;
|
dir.gid = vd->gid;
|
||||||
dir.muid = vd->mid;
|
dir.muid = vd->mid;
|
||||||
|
#ifdef PLAN9PORT
|
||||||
dir.ext = ext;
|
dir.ext = ext;
|
||||||
dir.uidnum = atoi(vd->uid);
|
dir.uidnum = atoi(vd->uid);
|
||||||
dir.gidnum = atoi(vd->gid);
|
dir.gidnum = atoi(vd->gid);
|
||||||
|
#endif
|
||||||
|
|
||||||
ret = convD2Mu(&dir, p, np, dotu);
|
ret = convD2Mu(&dir, p, np, dotu);
|
||||||
|
#ifdef PLAN9PORT
|
||||||
free(ext);
|
free(ext);
|
||||||
|
#endif
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -731,7 +788,9 @@ io(void)
|
||||||
if(err){
|
if(err){
|
||||||
thdr.type = Rerror;
|
thdr.type = Rerror;
|
||||||
thdr.ename = err;
|
thdr.ename = err;
|
||||||
|
#ifdef PLAN9PORT
|
||||||
thdr.errornum = 0;
|
thdr.errornum = 0;
|
||||||
|
#endif
|
||||||
}else{
|
}else{
|
||||||
thdr.type = rhdr.type + 1;
|
thdr.type = rhdr.type + 1;
|
||||||
thdr.fid = rhdr.fid;
|
thdr.fid = rhdr.fid;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue