static void fscreate(Chan *c, char *name, int mode, ulong perm) { int m; ulong t; wchar_t *newpath; Ufsinfo *uif; m = fsomode(mode&3); uif = c->aux; t = pathtype(uif->path); newpath = catpath(uif->path, name, nil); if(waserror()){ free(newpath); nexterror(); } if(perm & DMDIR) { wchar_t *p; DIR *d; if(m || t!=TPATH_FILE) error(Eperm); if(!CreateDirectory(newpath, NULL)) oserror(); d = malloc(sizeof(*d)); p = catpath(newpath, "*.*", nil); d->handle = FindFirstFile(p, &d->wfd); free(p); if(d->handle == INVALID_HANDLE_VALUE){ free(d); oserror(); } d->keep = 1; uif->dir = d; } else { uif->dir = nil; if((uif->fh = CreateFile( newpath, fsaccess(mode), FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0)) == INVALID_HANDLE_VALUE) oserror(); } free(uif->path); uif->path = newpath; poperror(); c->qid = wfdtoqid(newpath, nil); c->offset = 0; c->flag |= COPEN; c->mode = openmode(mode); }
static int raccess(SunMsg *m) { Nfs3TAccess *tx = (Nfs3TAccess*)m->call; Nfs3RAccess rx; SunAuthUnix au; int ok; if((ok = authunixunpack(&m->rpc, &au)) != SunSuccess) return sunmsgreplyerror(m, ok); memset(&rx, 0, sizeof rx); rx.haveAttr = 1; rx.status = fsaccess(&au, &tx->handle, tx->access, &rx.access, &rx.attr); return sunmsgreply(m, &rx.call); }
static Chan* fsopen(Chan *c, int mode) { ulong t; int m, isdir; wchar_t *p; Ufsinfo *uif; m = mode & (OTRUNC|3); switch(m) { case 0: break; case 1: case 1|16: break; case 2: case 0|16: case 2|16: break; case 3: break; default: error(Ebadarg); } isdir = c->qid.type & QTDIR; if(isdir && mode != OREAD) error(Eperm); m = fsomode(m & 3); c->mode = openmode(mode); uif = c->aux; uif->offset = 0; t = pathtype(uif->path); if(isdir){ DIR *d; d = malloc(sizeof(*d)); switch(t){ case TPATH_ROOT: d->drivebuf = malloc(sizeof(wchar_t)*MAX_PATH); if(GetLogicalDriveStrings(MAX_PATH-1, d->drivebuf) == 0){ free(d->drivebuf); d->drivebuf = nil; oserror(); } d->drivep = d->drivebuf; break; case TPATH_VOLUME: case TPATH_FILE: p = catpath(uif->path, "*.*", nil); d->handle = FindFirstFile(p, &d->wfd); free(p); if(d->handle == INVALID_HANDLE_VALUE){ free(d); oserror(); } break; } d->keep = 1; uif->dir = d; } else { uif->dir = nil; if((uif->fh = CreateFile( uif->path, fsaccess(mode), FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, (mode & OTRUNC) ? TRUNCATE_EXISTING : OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0)) == INVALID_HANDLE_VALUE) oserror(); } c->offset = 0; c->flag |= COPEN; return c; }