cwfs: remove 9p1 support

This commit is contained in:
cinap_lenrek 2015-08-21 18:43:25 +02:00
parent 501774b096
commit 0ce50ebc57
15 changed files with 318 additions and 2502 deletions

View file

@ -25,7 +25,6 @@ localconfinit(void)
}
int (*fsprotocol[])(Msgbuf*) = {
serve9p1,
serve9p2,
nil,
};

File diff suppressed because it is too large Load diff

View file

@ -1,116 +0,0 @@
#include <authsrv.h>
enum {
DIRREC = 116, /* size of a directory ascii record */
ERRREC = 64, /* size of a error record */
};
typedef struct Fcall Fcall;
struct Fcall
{
char type;
ushort fid;
short err;
short tag;
union
{
struct
{
short uid; /* T-Userstr [obs.] */
short oldtag; /* T-nFlush */
Qid9p1 qid; /* R-Attach, R-Clwalk, R-Walk,
* R-Open, R-Create */
char rauth[AUTHENTLEN]; /* R-attach */
};
struct
{
char uname[NAMELEN]; /* T-nAttach */
char aname[NAMELEN]; /* T-nAttach */
char ticket[TICKETLEN]; /* T-attach */
char auth[AUTHENTLEN]; /* T-attach */
};
struct
{
char ename[ERRREC]; /* R-nError */
char chal[CHALLEN]; /* T-session, R-session */
char authid[NAMELEN]; /* R-session */
char authdom[DOMLEN]; /* R-session */
};
struct
{
char name[NAMELEN]; /* T-Walk, T-Clwalk, T-Create, T-Remove */
long perm; /* T-Create */
ushort newfid; /* T-Clone, T-Clwalk */
char mode; /* T-Create, T-Open */
};
struct
{
Off offset; /* T-Read, T-Write */
long count; /* T-Read, T-Write, R-Read */
char* data; /* T-Write, R-Read */
};
struct
{
char stat[DIRREC]; /* T-Wstat, R-Stat */
};
};
};
/*
* P9 protocol message types
*/
enum
{
Tnop = 50,
Rnop,
Tosession = 52,
Rosession,
Terror = 54, /* illegal */
Rerror,
Tflush = 56,
Rflush,
Toattach = 58,
Roattach,
Tclone = 60,
Rclone,
Twalk = 62,
Rwalk,
Topen = 64,
Ropen,
Tcreate = 66,
Rcreate,
Tread = 68,
Rread,
Twrite = 70,
Rwrite,
Tclunk = 72,
Rclunk,
Tremove = 74,
Rremove,
Tstat = 76,
Rstat,
Twstat = 78,
Rwstat,
Tclwalk = 80,
Rclwalk,
Tauth = 82, /* illegal */
Rauth, /* illegal */
Tsession = 84,
Rsession,
Tattach = 86,
Rattach,
MAXSYSCALL
};
int convA2M9p1(Authenticator*, char*, char*);
void convM2A9p1(char*, Authenticator*, char*);
void convM2T9p1(char*, Ticket*, char*);
int convD2M9p1(Dentry*, char*);
int convM2D9p1(char*, Dentry*);
int convM2S9p1(uchar*, Fcall*, int);
int convS2M9p1(Fcall*, uchar*);
void fcall9p1(Chan*, Fcall*, Fcall*);
void (*call9p1[MAXSYSCALL])(Chan*, Fcall*, Fcall*);

View file

@ -1,523 +0,0 @@
#include "all.h"
/* BUG transition */
// int client9p = 2;
// int kernel9p = 2;
#include "9p1.h"
#define CHAR(x) *p++ = f->x
#define SHORT(x) { ulong vvv = f->x; *p++ = vvv; *p++ = vvv>>8; }
#define LONGINT(q) {*p++ = (q); *p++ = (q)>>8; *p++ = (q)>>16; *p++ = (q)>>24;}
#define LONG(x) { ulong vvv = f->x; LONGINT(vvv); }
#define VLONG(x) { \
uvlong q = f->x; \
*p++ = (q)>> 0; *p++ = (q)>> 8; *p++ = (q)>>16; *p++ = (q)>>24; \
*p++ = (q)>>32; *p++ = (q)>>40; *p++ = (q)>>48; *p++ = (q)>>56; \
}
#define BYTES(x,n) memmove(p, f->x, n); p += n
#define STRING(x,n) strncpy((char*)p, f->x, n); p += n
int
convS2M9p1(Fcall *f, uchar *ap)
{
uchar *p;
int t;
p = ap;
CHAR(type);
t = f->type;
SHORT(tag);
switch(t) {
default:
fprint(2, "convS2M9p1: bad type: %d\n", t);
return 0;
case Tnop:
case Tosession:
break;
case Tsession:
BYTES(chal, sizeof(f->chal));
break;
case Tflush:
SHORT(oldtag);
break;
case Tattach:
SHORT(fid);
STRING(uname, sizeof(f->uname));
STRING(aname, sizeof(f->aname));
BYTES(ticket, sizeof(f->ticket));
BYTES(auth, sizeof(f->auth));
break;
case Toattach:
SHORT(fid);
STRING(uname, sizeof(f->uname));
STRING(aname, sizeof(f->aname));
BYTES(ticket, NAMELEN);
break;
case Tclone:
SHORT(fid);
SHORT(newfid);
break;
case Twalk:
SHORT(fid);
STRING(name, sizeof(f->name));
break;
case Tclwalk:
SHORT(fid);
SHORT(newfid);
STRING(name, sizeof(f->name));
break;
case Topen:
SHORT(fid);
CHAR(mode);
break;
case Tcreate:
SHORT(fid);
STRING(name, sizeof(f->name));
LONG(perm);
CHAR(mode);
break;
case Tread:
SHORT(fid);
VLONG(offset);
SHORT(count);
break;
case Twrite:
SHORT(fid);
VLONG(offset);
SHORT(count);
p++;
if((uchar*)p == (uchar*)f->data) {
p += f->count;
break;
}
BYTES(data, f->count);
break;
case Tclunk:
case Tremove:
case Tstat:
SHORT(fid);
break;
case Twstat:
SHORT(fid);
BYTES(stat, sizeof(f->stat));
break;
/*
*/
case Rnop:
case Rosession:
case Rflush:
break;
case Rsession:
BYTES(chal, sizeof(f->chal));
BYTES(authid, sizeof(f->authid));
BYTES(authdom, sizeof(f->authdom));
break;
case Rerror:
STRING(ename, sizeof(f->ename));
break;
case Rclone:
case Rclunk:
case Rremove:
case Rwstat:
SHORT(fid);
break;
case Rwalk:
case Ropen:
case Rcreate:
case Rclwalk:
SHORT(fid);
LONG(qid.path);
LONG(qid.version);
break;
case Rattach:
SHORT(fid);
LONG(qid.path);
LONG(qid.version);
BYTES(rauth, sizeof(f->rauth));
break;
case Roattach:
SHORT(fid);
LONG(qid.path);
LONG(qid.version);
break;
case Rread:
SHORT(fid);
SHORT(count);
p++;
if((uchar*)p == (uchar*)f->data) {
p += f->count;
break;
}
BYTES(data, f->count);
break;
case Rwrite:
SHORT(fid);
SHORT(count);
break;
case Rstat:
SHORT(fid);
BYTES(stat, sizeof(f->stat));
break;
}
return p - (uchar*)ap;
}
/*
* buggery to give false qid for
* the top 2 levels of the dump fs
*/
static ulong
fakeqid9p1(Dentry *f)
{
ulong q;
int c;
q = f->qid.path;
if(q == (QPROOT|QPDIR)) {
c = f->name[0];
if(isascii(c) && isdigit(c)) {
q = 3|QPDIR;
c = (c-'0')*10 + (f->name[1]-'0');
if(c >= 1 && c <= 12)
q = 4|QPDIR;
}
}
return q;
}
int
convD2M9p1(Dentry *f, char *ap)
{
uchar *p;
ulong q;
p = (uchar*)ap;
STRING(name, sizeof(f->name));
memset(p, 0, 2*NAMELEN);
uidtostr((char*)p, f->uid, 1);
p += NAMELEN;
uidtostr((char*)p, f->gid, 1);
p += NAMELEN;
q = fakeqid9p1(f);
LONGINT(q);
LONG(qid.version);
q = f->mode & 0x0fff;
if(f->mode & DDIR)
q |= PDIR;
if(f->mode & DAPND)
q |= PAPND;
if(f->mode & DLOCK)
q |= PLOCK;
LONGINT(q);
LONG(atime);
LONG(mtime);
VLONG(size);
LONGINT(0);
return p - (uchar*)ap;
}
int
convA2M9p1(Authenticator *f, char *ap, char *key)
{
int n;
uchar *p;
p = (uchar*)ap;
CHAR(num);
BYTES(chal, CHALLEN);
LONG(id);
n = p - (uchar*)ap;
if(key)
encrypt(key, ap, n);
return n;
}
#undef CHAR
#undef SHORT
#undef LONG
#undef LONGINT
#undef VLONG
#undef BYTES
#undef STRING
#define CHAR(x) f->x = *p++
#define SHORT(x) f->x = (p[0] | (p[1]<<8)); p += 2
#define LONG(x) f->x = p[0] | (p[1]<<8) | (p[2]<<16) | (p[3]<<24); p += 4
#define VLONG(x) { \
f->x = (p[0] | (p[1]<<8) | (p[2]<<16) | (p[3]<<24)) | \
(uvlong)(p[4] | (p[5]<<8) | (p[6]<<16) | (p[7]<<24)) << 32; \
p += 8; \
}
#define BYTES(x,n) memmove(f->x, p, n); p += n
#define STRING(x,n) memmove(f->x, p, n); p += n
int
convM2S9p1(uchar *ap, Fcall *f, int n)
{
uchar *p;
int t;
p = ap;
CHAR(type);
t = f->type;
SHORT(tag);
switch(t) {
default:
/*
* only whine if it couldn't be a 9P2000 Tversion.
*/
if(t != 19 || ap[4] != 100)
fprint(2, "convM2S9p1: bad type: %d\n", f->type);
return 0;
case Tnop:
case Tosession:
break;
case Tsession:
BYTES(chal, sizeof(f->chal));
break;
case Tflush:
SHORT(oldtag);
break;
case Tattach:
SHORT(fid);
BYTES(uname, sizeof(f->uname));
BYTES(aname, sizeof(f->aname));
BYTES(ticket, sizeof(f->ticket));
BYTES(auth, sizeof(f->auth));
break;
case Toattach:
SHORT(fid);
BYTES(uname, sizeof(f->uname));
BYTES(aname, sizeof(f->aname));
BYTES(ticket, NAMELEN);
break;
case Tclone:
SHORT(fid);
SHORT(newfid);
break;
case Twalk:
SHORT(fid);
BYTES(name, sizeof(f->name));
break;
case Tclwalk:
SHORT(fid);
SHORT(newfid);
BYTES(name, sizeof(f->name));
break;
case Tremove:
SHORT(fid);
break;
case Topen:
SHORT(fid);
CHAR(mode);
break;
case Tcreate:
SHORT(fid);
BYTES(name, sizeof(f->name));
LONG(perm);
CHAR(mode);
break;
case Tread:
SHORT(fid);
VLONG(offset);
SHORT(count);
break;
case Twrite:
SHORT(fid);
VLONG(offset);
SHORT(count);
p++;
f->data = (char*)p; p += f->count;
break;
case Tclunk:
case Tstat:
SHORT(fid);
break;
case Twstat:
SHORT(fid);
BYTES(stat, sizeof(f->stat));
break;
/*
*/
case Rnop:
case Rosession:
break;
case Rsession:
BYTES(chal, sizeof(f->chal));
BYTES(authid, sizeof(f->authid));
BYTES(authdom, sizeof(f->authdom));
break;
case Rerror:
BYTES(ename, sizeof(f->ename));
break;
case Rflush:
break;
case Rclone:
case Rclunk:
case Rremove:
case Rwstat:
SHORT(fid);
break;
case Rwalk:
case Rclwalk:
case Ropen:
case Rcreate:
SHORT(fid);
LONG(qid.path);
LONG(qid.version);
break;
case Rattach:
SHORT(fid);
LONG(qid.path);
LONG(qid.version);
BYTES(rauth, sizeof(f->rauth));
break;
case Roattach:
SHORT(fid);
LONG(qid.path);
LONG(qid.version);
break;
case Rread:
SHORT(fid);
SHORT(count);
p++;
f->data = (char*)p; p += f->count;
break;
case Rwrite:
SHORT(fid);
SHORT(count);
break;
case Rstat:
SHORT(fid);
BYTES(stat, sizeof(f->stat));
break;
}
if((uchar*)ap+n == p)
return n;
return 0;
}
int
convM2D9p1(char *ap, Dentry *f)
{
uchar *p;
char str[NAMELEN];
p = (uchar*)ap;
BYTES(name, sizeof(f->name));
memmove(str, p, NAMELEN);
p += NAMELEN;
f->uid = strtouid(str);
memmove(str, p, NAMELEN);
p += NAMELEN;
f->gid = strtouid(str);
LONG(qid.path);
LONG(qid.version);
LONG(atime);
f->mode = (f->atime & 0x0fff) | DALLOC;
if(f->atime & PDIR)
f->mode |= DDIR;
if(f->atime & PAPND)
f->mode |= DAPND;
if(f->atime & PLOCK)
f->mode |= DLOCK;
LONG(atime);
LONG(mtime);
VLONG(size);
p += 4;
return p - (uchar*)ap;
}
void
convM2A9p1(char *ap, Authenticator *f, char *key)
{
uchar *p;
if(key)
decrypt(key, ap, AUTHENTLEN);
p = (uchar*)ap;
CHAR(num);
BYTES(chal, CHALLEN);
LONG(id);
USED(p);
}
void
convM2T9p1(char *ap, Ticket *f, char *key)
{
uchar *p;
if(key)
decrypt(key, ap, TICKETLEN);
p = (uchar*)ap;
CHAR(num);
BYTES(chal, CHALLEN);
STRING(cuid, NAMELEN);
f->cuid[NAMELEN-1] = 0;
STRING(suid, NAMELEN);
f->suid[NAMELEN-1] = 0;
BYTES(key, DESKEYLEN);
USED(p);
}

View file

@ -110,7 +110,44 @@ mkdir9p2(Dir* dir, Dentry* dentry, void* strs)
return p-op;
}
static int
/*
* buggery to give false qid for
* the top 2 levels of the dump fs
*/
void
mkqid(Qid* qid, Dentry *d, int buggery)
{
int c;
if(buggery && d->qid.path == (QPDIR|QPROOT)){
c = d->name[0];
if(isascii(c) && isdigit(c)){
qid->path = 3;
qid->vers = d->qid.version;
qid->type = QTDIR;
c = (c-'0')*10 + (d->name[1]-'0');
if(c >= 1 && c <= 12)
qid->path = 4;
return;
}
}
mkqid9p2(qid, &d->qid, d->mode);
}
int
mkqidcmp(Qid* qid, Dentry *d)
{
Qid tmp;
mkqid(&tmp, d, 1);
if(qid->path == tmp.path && qid->type == tmp.type)
return 0;
return Eqid;
}
int
version(Chan* chan, Fcall* f, Fcall* r)
{
if(chan->protocol != nil || f->msize < 256)
@ -237,7 +274,7 @@ authorize(Chan* chan, Fcall* f)
return uid;
}
static int
int
attach(Chan* chan, Fcall* f, Fcall* r)
{
char *aname;
@ -494,7 +531,7 @@ out:
return error;
}
static int
int
walk(Chan* chan, Fcall* f, Fcall* r)
{
int error, nwname;
@ -599,7 +636,7 @@ walk(Chan* chan, Fcall* f, Fcall* r)
return error;
}
static int
int
fs_open(Chan* chan, Fcall* f, Fcall* r)
{
Iobuf *p;
@ -748,7 +785,7 @@ out:
return error;
}
static int
int
fs_create(Chan* chan, Fcall* f, Fcall* r)
{
Iobuf *p, *p1;
@ -946,7 +983,7 @@ out:
return error;
}
static int
int
fs_read(Chan* chan, Fcall* f, Fcall* r, uchar* data)
{
Iobuf *p, *p1;
@ -975,6 +1012,7 @@ fs_read(Chan* chan, Fcall* f, Fcall* r, uchar* data)
}
iounit = chan->msize-IOHDRSZ;
if(count < 0 || count > iounit){
fprint(2, "fs_read %d %d\n", count, iounit);
error = Ecount;
goto out;
}
@ -1149,7 +1187,7 @@ out:
return error;
}
static int
int
fs_write(Chan* chan, Fcall* f, Fcall* r)
{
Iobuf *p, *p1;
@ -1263,6 +1301,90 @@ out:
return error;
}
int
doremove(File *f)
{
Iobuf *p, *p1;
Dentry *d, *d1;
Off addr;
int slot, err;
p = 0;
p1 = 0;
if(f->fs->dev->type == Devro) {
err = Eronly;
goto out;
}
/*
* check on parent directory of file to be deleted
*/
if(f->wpath == 0 || f->wpath->addr == f->addr) {
err = Ephase;
goto out;
}
p1 = getbuf(f->fs->dev, f->wpath->addr, Brd);
d1 = getdir(p1, f->wpath->slot);
if(!d1 || checktag(p1, Tdir, QPNONE) || !(d1->mode & DALLOC)) {
err = Ephase;
goto out;
}
if(iaccess(f, d1, DWRITE)) {
err = Eaccess;
goto out;
}
accessdir(p1, d1, FWRITE, f->uid);
putbuf(p1);
p1 = 0;
/*
* check on file to be deleted
*/
p = getbuf(f->fs->dev, f->addr, Brd);
d = getdir(p, f->slot);
if(!d || checktag(p, Tdir, QPNONE) || !(d->mode & DALLOC)) {
err = Ealloc;
goto out;
}
if(err = mkqidcmp(&f->qid, d))
goto out;
/*
* if deleting a directory, make sure it is empty
*/
if((d->mode & DDIR))
for(addr=0;; addr++) {
p1 = dnodebuf(p, d, addr, 0, f->uid);
if(!p1)
break;
if(checktag(p1, Tdir, d->qid.path)) {
err = Ephase;
goto out;
}
for(slot=0; slot<DIRPERBUF; slot++) {
d1 = getdir(p1, slot);
if(!(d1->mode & DALLOC))
continue;
err = Eempty;
goto out;
}
putbuf(p1);
}
/*
* do it
*/
dtrunc(p, d, f->uid);
memset(d, 0, sizeof(Dentry));
settag(p, Tdir, QPNONE);
out:
if(p1)
putbuf(p1);
if(p)
putbuf(p);
return err;
}
static int
_clunk(File* file, int remove)
{
@ -1299,7 +1421,7 @@ clunk(Chan* chan, Fcall* f, Fcall*)
return 0;
}
static int
int
fs_remove(Chan* chan, Fcall* f, Fcall*)
{
File *file;
@ -1309,7 +1431,7 @@ fs_remove(Chan* chan, Fcall* f, Fcall*)
return _clunk(file, 1);
}
static int
int
fs_stat(Chan* chan, Fcall* f, Fcall* r, uchar* data)
{
Dir dir;

View file

@ -1,48 +1,13 @@
#include "all.h"
#include "io.h"
#include <authsrv.h>
#include <auth.h>
Nvrsafe nvr;
static int gotnvr; /* flag: nvr contains nvram; it could be bad */
char*
nvrgetconfig(void)
{
return conf.confdev;
}
/*
* we shouldn't be writing nvram any more.
* the secstore/config field is now just secstore key.
*/
int
nvrcheck(void)
{
uchar csum;
if (readnvram(&nvr, NVread) < 0) {
fprint(2, "nvrcheck: can't read nvram\n");
return 1;
} else
gotnvr = 1;
if(chatty)
print("nvr read\n");
csum = nvcsum(nvr.machkey, sizeof nvr.machkey);
if(csum != nvr.machsum) {
fprint(2, "\n\n ** NVR key checksum is incorrect **\n");
fprint(2, " ** set password to allow attaches **\n\n");
memset(nvr.machkey, 0, sizeof nvr.machkey);
return 1;
}
return 0;
}
int
nvrsetconfig(char* word)
{
@ -51,39 +16,6 @@ nvrsetconfig(char* word)
return 0;
}
int
conslock(void)
{
char *ln;
Authkey nkey1;
static char zeroes[DESKEYLEN];
if(memcmp(nvr.machkey, zeroes, DESKEYLEN) == 0) {
print("no password set\n");
return 0;
}
for(;;) {
print("%s password:", service);
/* could turn off echo here */
if ((ln = Brdline(&bin, '\n')) == nil)
return 0;
ln[Blinelen(&bin)-1] = '\0';
/* could turn on echo here */
passtokey(&nkey1, ln);
if(memcmp(nkey1.des, nvr.machkey, DESKEYLEN) == 0) {
prdate();
break;
}
print("Bad password\n");
delay(1000);
}
return 1;
}
static char *keyspec = "proto=p9any role=server";
void*

View file

@ -25,7 +25,6 @@ localconfinit(void)
}
int (*fsprotocol[])(Msgbuf*) = {
serve9p1,
serve9p2,
nil,
};

View file

@ -965,7 +965,6 @@ arginit(void)
char word[Maxword+1], *cp;
Filsys *fs;
nvrcheck();
if(!setconfig(conf.confdev) && !conf.configfirst)
return;

View file

@ -1,147 +1,208 @@
#include "all.h"
#include "9p1.h"
#include <fcall.h>
void
fcall9p1(Chan *cp, Fcall *in, Fcall *ou)
{
int t;
rlock(&mainlock);
t = in->type;
if(t < 0 || t >= MAXSYSCALL || (t&1) || !call9p1[t]) {
fprint(2, "bad message type %d\n", t);
panic("");
}
ou->type = t+1;
ou->err = 0;
rlock(&cp->reflock);
(*call9p1[t])(cp, in, ou);
runlock(&cp->reflock);
if(ou->err && CHAT(cp))
fprint(2, "\terror: %s\n", errstr9p[ou->err]);
runlock(&mainlock);
}
/* 9p2 */
int version(Chan*, Fcall*, Fcall*);
int attach(Chan*, Fcall*, Fcall*);
int walk(Chan*, Fcall*, Fcall*);
int fs_open(Chan*, Fcall*, Fcall*);
int fs_create(Chan*, Fcall*, Fcall*);
int fs_read(Chan*, Fcall*, Fcall*, uchar*);
int fs_write(Chan*, Fcall*, Fcall*);
int fs_remove(Chan*, Fcall*, Fcall*);
int
con_session(void)
{
Fcall in, ou;
int err;
in.type = Tsession;
fcall9p1(cons.chan, &in, &ou);
return ou.err;
memset(&in, 0, sizeof(in));
memset(&ou, 0, sizeof(ou));
in.type = Tversion;
in.version = VERSION9P;
in.msize = MAXDAT + IOHDRSZ;
rlock(&mainlock);
err = version(cons.chan, &in, &ou);
runlock(&mainlock);
return err;
}
int
con_attach(int fid, char *uid, char *arg)
{
Fcall in, ou;
int err;
memset(&in, 0, sizeof(in));
memset(&ou, 0, sizeof(ou));
in.type = Tattach;
in.fid = fid;
strncpy(in.uname, uid, NAMELEN);
strncpy(in.aname, arg, NAMELEN);
fcall9p1(cons.chan, &in, &ou);
return ou.err;
in.uname = uid;
in.aname = arg;
rlock(&mainlock);
err = attach(cons.chan, &in, &ou);
runlock(&mainlock);
return err;
}
int
con_clone(int fid1, int fid2)
{
Fcall in, ou;
int err;
in.type = Tclone;
memset(&in, 0, sizeof(in));
memset(&ou, 0, sizeof(ou));
in.type = Twalk;
in.fid = fid1;
in.newfid = fid2;
fcall9p1(cons.chan, &in, &ou);
return ou.err;
in.nwname = 0;
rlock(&mainlock);
err = walk(cons.chan, &in, &ou);
runlock(&mainlock);
return err;
}
int
con_walk(int fid, char *name)
{
Fcall in, ou;
int err;
memset(&in, 0, sizeof(in));
memset(&ou, 0, sizeof(ou));
in.type = Twalk;
in.fid = fid;
strncpy(in.name, name, NAMELEN);
fcall9p1(cons.chan, &in, &ou);
return ou.err;
in.newfid = fid;
in.wname[0] = name;
in.nwname = 1;
rlock(&mainlock);
err = walk(cons.chan, &in, &ou);
runlock(&mainlock);
return err;
}
int
con_open(int fid, int mode)
{
Fcall in, ou;
int err;
memset(&in, 0, sizeof(in));
memset(&ou, 0, sizeof(ou));
in.type = Topen;
in.fid = fid;
in.mode = mode;
fcall9p1(cons.chan, &in, &ou);
return ou.err;
}
int
con_read(int fid, char *data, Off offset, int count)
{
Fcall in, ou;
rlock(&mainlock);
err = fs_open(cons.chan, &in, &ou);
runlock(&mainlock);
in.type = Tread;
in.fid = fid;
in.offset = offset;
in.count = count;
ou.data = data;
fcall9p1(cons.chan, &in, &ou);
if(ou.err)
return 0;
return ou.count;
}
int
con_write(int fid, char *data, Off offset, int count)
{
Fcall in, ou;
in.type = Twrite;
in.fid = fid;
in.data = data;
in.offset = offset;
in.count = count;
fcall9p1(cons.chan, &in, &ou);
if(ou.err)
return 0;
return ou.count;
}
int
con_remove(int fid)
{
Fcall in, ou;
in.type = Tremove;
in.fid = fid;
fcall9p1(cons.chan, &in, &ou);
return ou.err;
return err;
}
int
con_create(int fid, char *name, int uid, int gid, long perm, int mode)
{
Fcall in, ou;
int err;
cons.uid = uid; /* beyond ugly */
cons.gid = gid;
memset(&in, 0, sizeof(in));
memset(&ou, 0, sizeof(ou));
in.type = Tcreate;
in.fid = fid;
strncpy(in.name, name, NAMELEN);
in.perm = perm;
in.mode = mode;
cons.uid = uid; /* beyond ugly */
cons.gid = gid;
fcall9p1(cons.chan, &in, &ou);
return ou.err;
in.perm = perm;
in.name = name;
rlock(&mainlock);
err = fs_create(cons.chan, &in, &ou);
runlock(&mainlock);
return err;
}
int
con_read(int fid, char *data, Off offset, int count)
{
Fcall in, ou;
int err;
memset(&in, 0, sizeof(in));
memset(&ou, 0, sizeof(ou));
in.type = Tread;
in.fid = fid;
in.offset = offset;
in.count = count;
rlock(&mainlock);
err = fs_read(cons.chan, &in, &ou, (uchar*)data);
runlock(&mainlock);
return err ? 0 : ou.count;
}
int
con_write(int fid, char *data, Off offset, int count)
{
Fcall in, ou;
int err;
memset(&in, 0, sizeof(in));
memset(&ou, 0, sizeof(ou));
in.type = Twrite;
in.fid = fid;
in.offset = offset;
in.count = count;
in.data = data;
rlock(&mainlock);
err = fs_write(cons.chan, &in, &ou);
runlock(&mainlock);
return err ? 0 : ou.count;
}
int
con_remove(int fid)
{
Fcall in, ou;
int err;
memset(&in, 0, sizeof(in));
memset(&ou, 0, sizeof(ou));
in.type = Tremove;
in.fid = fid;
rlock(&mainlock);
err = fs_remove(cons.chan, &in, &ou);
runlock(&mainlock);
return err;
}
int
doclri(File *f)
{
@ -196,14 +257,15 @@ out:
return err;
}
void
static int
f_fstat(Chan *cp, Fcall *in, Fcall *ou)
{
File *f;
Iobuf *p;
Dentry *d;
int i;
int i, err;
err = 0;
if(CHAT(cp)) {
fprint(2, "c_fstat %d\n", cp->chan);
fprint(2, "\tfid = %d\n", in->fid);
@ -212,7 +274,7 @@ f_fstat(Chan *cp, Fcall *in, Fcall *ou)
p = 0;
f = filep(cp, in->fid, 0);
if(!f) {
ou->err = Efid;
err = Efid;
goto out;
}
p = getbuf(f->fs->dev, f->addr, Brd);
@ -238,12 +300,33 @@ out:
ou->fid = in->fid;
if(f)
qunlock(f);
return err;
}
void
int
con_fstat(int fid)
{
Fcall in, ou;
int err;
memset(&in, 0, sizeof(in));
memset(&ou, 0, sizeof(ou));
in.type = Tstat;
in.fid = fid;
rlock(&mainlock);
err = f_fstat(cons.chan, &in, &ou);
runlock(&mainlock);
return err;
}
static int
f_clri(Chan *cp, Fcall *in, Fcall *ou)
{
File *f;
int err;
if(CHAT(cp)) {
fprint(2, "c_clri %d\n", cp->chan);
@ -252,57 +335,33 @@ f_clri(Chan *cp, Fcall *in, Fcall *ou)
f = filep(cp, in->fid, 0);
if(!f) {
ou->err = Efid;
err = Efid;
goto out;
}
ou->err = doclri(f);
err = doclri(f);
out:
ou->fid = in->fid;
if(f)
qunlock(f);
return err;
}
int
con_clri(int fid)
{
Fcall in, ou;
Chan *cp;
int err;
memset(&in, 0, sizeof(in));
memset(&ou, 0, sizeof(ou));
in.type = Tremove;
in.fid = fid;
cp = cons.chan;
rlock(&mainlock);
ou.type = Tremove+1;
ou.err = 0;
rlock(&cp->reflock);
f_clri(cp, &in, &ou);
runlock(&cp->reflock);
err = f_clri(cons.chan, &in, &ou);
runlock(&mainlock);
return ou.err;
}
int
con_fstat(int fid)
{
Fcall in, ou;
Chan *cp;
in.type = Tstat;
in.fid = fid;
cp = cons.chan;
rlock(&mainlock);
ou.type = Tstat+1;
ou.err = 0;
rlock(&cp->reflock);
f_fstat(cp, &in, &ou);
runlock(&cp->reflock);
runlock(&mainlock);
return ou.err;
return err;
}

View file

@ -26,7 +26,6 @@ localconfinit(void)
}
int (*fsprotocol[])(Msgbuf*) = {
serve9p1,
serve9p2,
nil,
};

View file

@ -27,7 +27,6 @@ localconfinit(void)
}
int (*fsprotocol[])(Msgbuf*) = {
serve9p1,
serve9p2,
nil,
};

View file

@ -26,7 +26,6 @@ localconfinit(void)
}
int (*fsprotocol[])(Msgbuf*) = {
serve9p1,
serve9p2,
nil,
};

View file

@ -1,7 +1,6 @@
/* cached-worm file server */
#include "all.h"
#include "io.h"
#include "9p1.h"
Map *devmap;
@ -466,10 +465,11 @@ serve(void *)
if (mb->data == nil)
panic("serve: nil mb->data");
/* better sniffing code in /sys/src/cmd/disk/kfs/9p12.c */
if(cp->protocol == nil){
if(cp->protocol != nil){
/* process the request, generate an answer and reply */
cp->protocol(mb);
} else {
/* do we recognise the protocol in this packet? */
/* better sniffing code: /sys/src/cmd/disk/kfs/9p12.c */
for(i = 0; fsprotocol[i] != nil; i++)
if(fsprotocol[i](mb) != 0) {
cp->protocol = fsprotocol[i];
@ -479,9 +479,7 @@ serve(void *)
fprint(2, "no protocol for message\n");
hexdump(mb->data, 12);
}
} else
/* process the request, generate an answer and reply */
cp->protocol(mb);
}
mbfree(mb);
runlock(&mainlock);

View file

@ -1,6 +1,5 @@
void accessdir(Iobuf*, Dentry*, int, int);
void addfree(Device*, Off, Superb*);
void arpstart(void);
void arginit(void);
void* authnew(void);
void authfree(void*);
@ -12,25 +11,17 @@ Device* config(void);
Off bufalloc(Device*, int, long, int);
void buffree(Device*, Off, int, Truncstate *);
int byuid(void*, void*);
int canlock(Lock*);
int canqlock(QLock*);
void cfsdump(Filsys*);
void chanhangup(Chan *cp, char *msg);
Chan* fs_chaninit(int, int);
void cmd_check(int, char*[]);
void cmd_users(int, char*[]);
void cmd_newuser(int, char*[]);
void cmd_netdb(int, char*[]);
void cmd_printconf(int, char*[]);
void cmd_wormreset(int, char *[]);
int checkname(char*);
int checktag(Iobuf*, int, Off);
int cksum(void*, int, int);
int cksum0(int, int);
void cyclstart(void);
void dotrace(int);
void consserve(void);
int conslock(void);
int con_attach(int, char*, char*);
int con_clone(int, int);
int con_create(int, char*, int, int, long, int);
@ -75,11 +66,7 @@ void netstart(void);
void exit(void);
void fileinit(Chan*);
File* filep(Chan*, ulong, int);
void firmware(void);
int fname(char*);
int fpair(char*, char*);
void formatinit(void);
int fread(void*, int);
void freefp(File*);
void freewp(Wpath*);
Filsys* fsstr(char*);
@ -91,7 +78,6 @@ int fwormwrite(Device*, Off, void*);
Iobuf* getbuf(Device*, Off, int);
char* getwrd(char*, char*);
Dentry* getdir(Iobuf*, int);
Chan* getlcp(uchar*, long);
Off getraddr(Device*);
void hexdump(void*, int);
int iaccess(File*, Dentry*, int);
@ -101,7 +87,6 @@ Off ibbpowsum(int);
Device* iconfig(char *);
Off indfetch(Device*, Off, Off, Off , int, int, int);
int ingroup(int, int);
int inh(int, uchar*);
Devsize inqsize(char *file);
void iobufinit(void);
void* iobufmap(Iobuf*);
@ -115,13 +100,8 @@ void jukeream(Device*);
void jukerecover(Device*);
Off jukesaddr(Device*);
Devsize jukesize(Device*);
void kbdchar(int);
void lights(int, int);
void launchinit(void);
void localconfinit(void);
int leadgroup(int, int);
void lock(Lock*);
void lockinit(void);
void machinit(void);
Msgbuf* mballoc(int, Chan*, int);
void mbinit(void);
@ -143,13 +123,11 @@ void mlevinit(Device*);
int mlevread(Device*, Off, void*);
Devsize mlevsize(Device*);
int mlevwrite(Device*, Off, void*);
int nametokey(char*, char*);
File* newfp(void);
void newscsi(Device *d, Scsi *sc);
Queue* newqueue(int, char*);
void newstart(void);
Wpath* newwp(void);
int nvrcheck(void);
char* nvrgetconfig(void);
int nvrsetconfig(char*);
int walkto(char*);
@ -164,23 +142,15 @@ int partwrite(Device*, Off, void*);
void prdate(void);
void preread(Device*, Off);
int prime(vlong);
void printinit(void);
void procinit(void);
void procsetname(char *fmt, ...);
void putbuf(Iobuf*);
Off qidpathgen(Device*);
void qlock(QLock*);
void* querychanger(Device *);
void qunlock(QLock*);
void rahead(void *);
void ream(Filsys*);
void* fs_recv(Queue*, int);
void rootream(Device*, Off);
int roread(Device*, Off, void*);
void rstate(Chan*, int);
Timet rtc2sec(Rtc *);
void sched(void);
void schedinit(void);
int scsiio(Device*, int, uchar*, int, void*, int);
void scsiinit(void);
Off scsiread(int, void*, long);
@ -190,10 +160,8 @@ char* sdof(Device*);
void sec2rtc(Timet, Rtc *);
void fs_send(Queue*, void*);
void serve(void *);
int serve9p1(Msgbuf*);
int serve9p2(Msgbuf*);
void settag(Iobuf*, int, long);
void settime(Timet);
int strtouid(char*);
Off superaddr(Device*);
void superream(Device*, Off);
@ -208,11 +176,8 @@ int Tfmt(Fmt*);
Timet nextime(Timet, int, int);
Tlock* tlocked(Iobuf*, Dentry*);
Timet toytime(void);
Timet rtctime(void);
void setrtc(Timet);
void uidtostr(char*, int, int);
Uid* uidpstr(char*);
void unlock(Lock*);
void newproc(void(*)(void *), void*, char*);
void wormcopy(void *);
void wormprobe(void);
@ -232,4 +197,3 @@ void cmd_install(char*, char*, void (*)(int, char*[]));
ulong flag_install(char*, char*);
void srvinit(void);
Chan *srvchan(int, char *);

View file

@ -3,8 +3,6 @@
BIN=/$objtype/bin
TARG=cwfs$FS
OFILES=\
9p1.$O\
9p1lib.$O\
9p2.$O\
auth.$O\
chk.$O\
@ -33,7 +31,6 @@ HFILES=\
../32bit.h\
../64bit.h\
../64xbit.h\
../9p1.h\
../all.h\
dat.h\
../io.h\