diff options
Diffstat (limited to 'src/libfs/stat.c')
-rw-r--r-- | src/libfs/stat.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/libfs/stat.c b/src/libfs/stat.c new file mode 100644 index 00000000..e55e0b12 --- /dev/null +++ b/src/libfs/stat.c @@ -0,0 +1,54 @@ +/* Copyright (C) 2003 Russ Cox, Massachusetts Institute of Technology */ +/* See COPYRIGHT */ + +#include <u.h> +#include <libc.h> +#include <fcall.h> +#include <fs.h> +#include "fsimpl.h" + +Dir* +fsdirstat(Fsys *fs, char *name) +{ + Dir *d; + Fid *fid; + + if((fid = fswalk(fs->root, name)) == nil) + return nil; + + d = fsdirfstat(fid); + fsclose(fid); + return d; +} + +Dir* +fsdirfstat(Fid *fid) +{ + Dir *d; + Fsys *fs; + Fcall tx, rx; + void *freep; + int n; + + fs = fid->fs; + tx.type = Tstat; + tx.fid = fid->fid; + + if(fsrpc(fs, &tx, &rx, &freep) < 0) + return nil; + + d = malloc(sizeof(Dir)+rx.nstat); + if(d == nil){ + free(freep); + return nil; + } + n = convM2D(rx.stat, rx.nstat, d, (char*)&d[1]); + free(freep); + if(n != rx.nstat){ + free(d); + werrstr("rx.nstat and convM2D disagree about dir length"); + return nil; + } + return d; +} + |