aboutsummaryrefslogtreecommitdiff
path: root/src/libfs/stat.c
blob: e55e0b126e72c18fa18d454d43c55aaa3ec3f1b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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;
}