Blob
1 #include <u.h>2 #include <libc.h>3 #include <fcall.h>4 #include <9pclient.h>5 #include "fsimpl.h"7 int8 fsfcreate(CFid *fid, char *name, int mode, ulong perm)9 {10 Fcall tx, rx;12 tx.type = Tcreate;13 tx.name = name;14 tx.fid = fid->fid;15 tx.mode = mode;16 tx.perm = perm;17 tx.extension = nil;18 if(_fsrpc(fid->fs, &tx, &rx, 0) < 0)19 return -1;20 fid->mode = mode;21 return 0;22 }24 CFid*25 fscreate(CFsys *fs, char *name, int mode, ulong perm)26 {27 CFid *fid;28 char *p, *dir, *elem;30 p = strrchr(name, '/');31 if(p == nil){32 dir = "";33 elem = name;34 }else{35 dir = name;36 *p = 0;37 elem = p+1;38 }40 if((fid = fswalk(fs->root, dir)) == nil){41 if(p)42 *p = '/';43 return nil;44 }45 if(p)46 *p = '/';47 if(fsfcreate(fid, elem, mode, perm) < 0){48 fsclose(fid);49 return nil;50 }51 return fid;52 }