aboutsummaryrefslogtreecommitdiff
path: root/src/lib9pclient/open.c
blob: 2317bbb772b231196a51c45022773eaeef7ac6b7 (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
#include <u.h>
#include <libc.h>
#include <fcall.h>
#include <9pclient.h>
#include "fsimpl.h"

CFid*
fsopen(CFsys *fs, char *name, int mode)
{
	char e[ERRMAX];
	CFid *fid;
	Fcall tx, rx;

	if((fid = _fswalk(fs->root, name)) == nil)
		return nil;
	tx.type = Topen;
	tx.fid = fid->fid;
	tx.mode = mode;
	if(_fsrpc(fs, &tx, &rx, 0) < 0){
		rerrstr(e, sizeof e);
		fsclose(fid);
		errstr(e, sizeof e);
		return nil;
	}
	fid->mode = mode;
	return fid;
}