more functions

This commit is contained in:
rsc 2006-07-23 02:55:34 +00:00
parent 9b3357a896
commit 73a5509ae9
10 changed files with 126 additions and 29 deletions

View file

@ -4,11 +4,26 @@
#include <9pclient.h>
#include "fsimpl.h"
int
fsfcreate(CFid *fid, char *name, int mode, ulong perm)
{
Fcall tx, rx;
tx.type = Tcreate;
tx.name = name;
tx.fid = fid->fid;
tx.mode = mode;
tx.perm = perm;
if(_fsrpc(fid->fs, &tx, &rx, 0) < 0)
return -1;
fid->mode = mode;
return 0;
}
CFid*
fscreate(CFsys *fs, char *name, int mode, ulong perm)
{
CFid *fid;
Fcall tx, rx;
char *p, *dir, *elem;
p = strrchr(name, '/');
@ -21,24 +36,16 @@ fscreate(CFsys *fs, char *name, int mode, ulong perm)
elem = p+1;
}
if((fid = _fswalk(fs->root, dir)) == nil){
if((fid = fswalk(fs->root, dir)) == nil){
if(p)
*p = '/';
return nil;
}
tx.type = Tcreate;
tx.name = elem;
tx.fid = fid->fid;
tx.mode = mode;
tx.perm = perm;
if(_fsrpc(fs, &tx, &rx, 0) < 0){
if(p)
*p = '/';
fsclose(fid);
return nil;
}
if(p)
*p = '/';
fid->mode = mode;
if(fsfcreate(fid, elem, mode, perm) < 0){
fsclose(fid);
return nil;
}
return fid;
}

View file

@ -14,6 +14,7 @@ static int _fsgettag(Mux*, void*);
static int _fssettag(Mux*, void*, uint);
int chatty9pclient;
int eofkill9pclient;
enum
{
@ -318,9 +319,13 @@ static int
_fssend(Mux *mux, void *pkt)
{
CFsys *fs;
int n;
fs = mux->aux;
return iowrite(fs->iosend, fs->fd, pkt, GBIT32((uchar*)pkt));
n = iowrite(fs->iosend, fs->fd, pkt, GBIT32((uchar*)pkt));
if(n < 0 && eofkill9pclient)
threadexitsall(nil);
return n;
}
static void*
@ -333,8 +338,11 @@ _fsrecv(Mux *mux)
fs = mux->aux;
n = ioreadn(fs->iorecv, fs->fd, buf, 4);
if(n != 4)
if(n != 4){
if(eofkill9pclient)
threadexitsall(nil);
return nil;
}
n = GBIT32(buf);
pkt = malloc(n+4);
if(pkt == nil){
@ -356,3 +364,9 @@ _fsrecv(Mux *mux)
}
return pkt;
}
Qid
fsqid(CFid *fid)
{
return fid->qid;
}

View file

@ -4,19 +4,29 @@
#include <9pclient.h>
#include "fsimpl.h"
int
fsfopen(CFid *fid, int mode)
{
Fcall tx, rx;
tx.type = Topen;
tx.fid = fid->fid;
tx.mode = mode;
if(_fsrpc(fid->fs, &tx, &rx, 0) < 0)
return -1;
fid->mode = mode;
return 0;
}
CFid*
fsopen(CFsys *fs, char *name, int mode)
{
char e[ERRMAX];
CFid *fid;
Fcall tx, rx;
if((fid = _fswalk(fs->root, name)) == nil)
if((fid = fswalk(fs->root, name)) == nil)
return nil;
tx.type = Topen;
tx.fid = fid->fid;
tx.mode = mode;
if(_fsrpc(fs, &tx, &rx, 0) < 0){
if(fsfopen(fid, mode) < 0){
rerrstr(e, sizeof e);
fsclose(fid);
errstr(e, sizeof e);

View file

@ -10,7 +10,7 @@ fsopenfd(CFsys *fs, char *name, int mode)
CFid *fid;
Fcall tx, rx;
if((fid = _fswalk(fs->root, name)) == nil)
if((fid = fswalk(fs->root, name)) == nil)
return -1;
tx.type = Topenfd;
tx.fid = fid->fid;

View file

@ -12,7 +12,7 @@ fsremove(CFsys *fs, char *name)
{
CFid *fid;
if((fid = _fswalk(fs->root, name)) == nil)
if((fid = fswalk(fs->root, name)) == nil)
return -1;
return fsfremove(fid);
}

View file

@ -13,7 +13,7 @@ fsdirstat(CFsys *fs, char *name)
Dir *d;
CFid *fid;
if((fid = _fswalk(fs->root, name)) == nil)
if((fid = fswalk(fs->root, name)) == nil)
return nil;
d = fsdirfstat(fid);

View file

@ -8,7 +8,7 @@
#include "fsimpl.h"
CFid*
_fswalk(CFid *fid, char *oname)
fswalk(CFid *fid, char *oname)
{
char *freep, *name;
int i, nwalk;

View file

@ -13,7 +13,7 @@ fsdirwstat(CFsys *fs, char *name, Dir *d)
int n;
CFid *fid;
if((fid = _fswalk(fs->root, name)) == nil)
if((fid = fswalk(fs->root, name)) == nil)
return -1;
n = fsdirfwstat(fid, d);