Blob


1 /* Copyright (C) 2003 Russ Cox, Massachusetts Institute of Technology */
2 /* See COPYRIGHT */
4 #include <u.h>
5 #include <libc.h>
6 #include <fcall.h>
7 #include <9pclient.h>
8 #include "fsimpl.h"
10 Dir*
11 fsdirstat(CFsys *fs, char *name)
12 {
13 Dir *d;
14 CFid *fid;
16 if((fid = fswalk(fs->root, name)) == nil)
17 return nil;
19 d = fsdirfstat(fid);
20 fsclose(fid);
21 return d;
22 }
24 Dir*
25 fsdirfstat(CFid *fid)
26 {
27 Dir *d;
28 CFsys *fs;
29 Fcall tx, rx;
30 void *freep;
31 int n;
33 fs = fid->fs;
34 tx.type = Tstat;
35 tx.fid = fid->fid;
37 if(_fsrpc(fs, &tx, &rx, &freep) < 0)
38 return nil;
40 d = malloc(sizeof(Dir)+rx.nstat);
41 if(d == nil){
42 free(freep);
43 return nil;
44 }
45 n = convM2D(rx.stat, rx.nstat, d, (char*)&d[1]);
46 free(freep);
47 if(n != rx.nstat){
48 free(d);
49 werrstr("rx.nstat and convM2D disagree about dir length");
50 return nil;
51 }
52 return d;
53 }