xref: /minix3/lib/libpuffs/null.c (revision 84d9c625bfea59e274550651111ae9edfdc40fbd)
1*84d9c625SLionel Sambuc /*	$NetBSD: null.c,v 1.33 2011/11/25 15:02:02 manu Exp $	*/
2490e0de5SThomas Veerman 
3490e0de5SThomas Veerman /*
4490e0de5SThomas Veerman  * Copyright (c) 2007  Antti Kantee.  All Rights Reserved.
5490e0de5SThomas Veerman  *
6490e0de5SThomas Veerman  * Redistribution and use in source and binary forms, with or without
7490e0de5SThomas Veerman  * modification, are permitted provided that the following conditions
8490e0de5SThomas Veerman  * are met:
9490e0de5SThomas Veerman  * 1. Redistributions of source code must retain the above copyright
10490e0de5SThomas Veerman  *    notice, this list of conditions and the following disclaimer.
11490e0de5SThomas Veerman  * 2. Redistributions in binary form must reproduce the above copyright
12490e0de5SThomas Veerman  *    notice, this list of conditions and the following disclaimer in the
13490e0de5SThomas Veerman  *    documentation and/or other materials provided with the distribution.
14490e0de5SThomas Veerman  *
15490e0de5SThomas Veerman  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
16490e0de5SThomas Veerman  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17490e0de5SThomas Veerman  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18490e0de5SThomas Veerman  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19490e0de5SThomas Veerman  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20490e0de5SThomas Veerman  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21490e0de5SThomas Veerman  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22490e0de5SThomas Veerman  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23490e0de5SThomas Veerman  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24490e0de5SThomas Veerman  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25490e0de5SThomas Veerman  * SUCH DAMAGE.
26490e0de5SThomas Veerman  */
27490e0de5SThomas Veerman 
28490e0de5SThomas Veerman #include <sys/cdefs.h>
29490e0de5SThomas Veerman #if !defined(lint)
30*84d9c625SLionel Sambuc __RCSID("$NetBSD: null.c,v 1.33 2011/11/25 15:02:02 manu Exp $");
31490e0de5SThomas Veerman #endif /* !lint */
32490e0de5SThomas Veerman 
33490e0de5SThomas Veerman /*
34490e0de5SThomas Veerman  * A "nullfs" using puffs, i.e. maps one location in the hierarchy
35490e0de5SThomas Veerman  * to another using standard system calls.
36490e0de5SThomas Veerman  */
37490e0de5SThomas Veerman 
38490e0de5SThomas Veerman #include <sys/types.h>
39*84d9c625SLionel Sambuc #include <sys/stat.h>
40490e0de5SThomas Veerman #include <sys/time.h>
41490e0de5SThomas Veerman 
42490e0de5SThomas Veerman #include <assert.h>
43490e0de5SThomas Veerman #include <dirent.h>
44490e0de5SThomas Veerman #include <errno.h>
45490e0de5SThomas Veerman #include <fcntl.h>
46*84d9c625SLionel Sambuc #include <puffs.h>
47490e0de5SThomas Veerman #include <stdio.h>
48490e0de5SThomas Veerman #include <stdlib.h>
49*84d9c625SLionel Sambuc #include <time.h>
50490e0de5SThomas Veerman #include <unistd.h>
51490e0de5SThomas Veerman 
PUFFSOP_PROTOS(puffs_null)52490e0de5SThomas Veerman PUFFSOP_PROTOS(puffs_null)
53490e0de5SThomas Veerman 
54490e0de5SThomas Veerman /*
55490e0de5SThomas Veerman  * set attributes to what is specified.  XXX: no rollback in case of failure
56490e0de5SThomas Veerman  */
57490e0de5SThomas Veerman static int
58490e0de5SThomas Veerman processvattr(const char *path, const struct vattr *va, int regular)
59490e0de5SThomas Veerman {
60*84d9c625SLionel Sambuc 	struct timeval tv[2];
61490e0de5SThomas Veerman 
62490e0de5SThomas Veerman 	/* XXX: -1 == PUFFS_VNOVAL, but shouldn't trust that */
63490e0de5SThomas Veerman 	if (va->va_uid != (unsigned)-1 || va->va_gid != (unsigned)-1)
64*84d9c625SLionel Sambuc 		if (lchown(path, va->va_uid, va->va_gid) == -1)
65490e0de5SThomas Veerman 			return errno;
66490e0de5SThomas Veerman 
67490e0de5SThomas Veerman 	if (va->va_mode != (unsigned)PUFFS_VNOVAL)
68*84d9c625SLionel Sambuc 		if (lchmod(path, va->va_mode) == -1)
69490e0de5SThomas Veerman 			return errno;
70490e0de5SThomas Veerman 
71490e0de5SThomas Veerman 	/* sloppy */
72*84d9c625SLionel Sambuc 	if (va->va_atime.tv_sec != (time_t)PUFFS_VNOVAL
73*84d9c625SLionel Sambuc 	    || va->va_mtime.tv_sec != (time_t)PUFFS_VNOVAL) {
74*84d9c625SLionel Sambuc 		TIMESPEC_TO_TIMEVAL(&tv[0], &va->va_atime);
75*84d9c625SLionel Sambuc 		TIMESPEC_TO_TIMEVAL(&tv[1], &va->va_mtime);
76490e0de5SThomas Veerman 
77*84d9c625SLionel Sambuc 		if (lutimes(path, tv) == -1)
78490e0de5SThomas Veerman 			return errno;
79490e0de5SThomas Veerman 	}
80490e0de5SThomas Veerman 
81490e0de5SThomas Veerman 	if (regular && va->va_size != (u_quad_t)PUFFS_VNOVAL)
82490e0de5SThomas Veerman 		if (truncate(path, (off_t)va->va_size) == -1)
83490e0de5SThomas Veerman 			return errno;
84490e0de5SThomas Veerman 
85490e0de5SThomas Veerman 	return 0;
86490e0de5SThomas Veerman }
87490e0de5SThomas Veerman 
88490e0de5SThomas Veerman /*
89490e0de5SThomas Veerman  * Kludge to open files which aren't writable *any longer*.  This kinda
90490e0de5SThomas Veerman  * works because the vfs layer does validation checks based on the file's
91490e0de5SThomas Veerman  * permissions to allow writable opening before opening them.  However,
92490e0de5SThomas Veerman  * the problem arises if we want to create a file, write to it (cache),
93490e0de5SThomas Veerman  * adjust permissions and then flush the file.
94490e0de5SThomas Veerman  */
95490e0de5SThomas Veerman static int
writeableopen(const char * path)96490e0de5SThomas Veerman writeableopen(const char *path)
97490e0de5SThomas Veerman {
98490e0de5SThomas Veerman 	struct stat sb;
99490e0de5SThomas Veerman 	mode_t origmode;
100490e0de5SThomas Veerman 	int sverr = 0;
101490e0de5SThomas Veerman 	int fd;
102490e0de5SThomas Veerman 
103490e0de5SThomas Veerman 	fd = open(path, O_WRONLY);
104490e0de5SThomas Veerman 	if (fd == -1) {
105490e0de5SThomas Veerman 		if (errno == EACCES) {
106490e0de5SThomas Veerman 			if (stat(path, &sb) == -1)
107490e0de5SThomas Veerman 				return -1;
108490e0de5SThomas Veerman 			origmode = sb.st_mode & ALLPERMS;
109490e0de5SThomas Veerman 
110490e0de5SThomas Veerman 			if (chmod(path, 0200) == -1)
111490e0de5SThomas Veerman 				return -1;
112490e0de5SThomas Veerman 
113490e0de5SThomas Veerman 			fd = open(path, O_WRONLY);
114490e0de5SThomas Veerman 			if (fd == -1)
115490e0de5SThomas Veerman 				sverr = errno;
116490e0de5SThomas Veerman 
117490e0de5SThomas Veerman 			chmod(path, origmode);
118490e0de5SThomas Veerman 			if (sverr)
119490e0de5SThomas Veerman 				errno = sverr;
120490e0de5SThomas Veerman 		} else
121490e0de5SThomas Veerman 			return -1;
122490e0de5SThomas Veerman 	}
123490e0de5SThomas Veerman 
124490e0de5SThomas Veerman 	return fd;
125490e0de5SThomas Veerman }
126490e0de5SThomas Veerman 
127490e0de5SThomas Veerman /*ARGSUSED*/
128490e0de5SThomas Veerman static void *
inodecmp(struct puffs_usermount * pu,struct puffs_node * pn,void * arg)129490e0de5SThomas Veerman inodecmp(struct puffs_usermount *pu, struct puffs_node *pn, void *arg)
130490e0de5SThomas Veerman {
131490e0de5SThomas Veerman 	ino_t *cmpino = arg;
132490e0de5SThomas Veerman 
133490e0de5SThomas Veerman 	if (pn->pn_va.va_fileid == *cmpino)
134490e0de5SThomas Veerman 		return pn;
135490e0de5SThomas Veerman 	return NULL;
136490e0de5SThomas Veerman }
137490e0de5SThomas Veerman 
138490e0de5SThomas Veerman static int
makenode(struct puffs_usermount * pu,struct puffs_newinfo * pni,const struct puffs_cn * pcn,const struct vattr * va,int regular)139490e0de5SThomas Veerman makenode(struct puffs_usermount *pu, struct puffs_newinfo *pni,
140490e0de5SThomas Veerman 	const struct puffs_cn *pcn, const struct vattr *va, int regular)
141490e0de5SThomas Veerman {
142490e0de5SThomas Veerman 	struct puffs_node *pn;
143490e0de5SThomas Veerman 	struct stat sb;
144490e0de5SThomas Veerman 	int rv;
145490e0de5SThomas Veerman 
146490e0de5SThomas Veerman 	if ((rv = processvattr(PCNPATH(pcn), va, regular)) != 0)
147490e0de5SThomas Veerman 		return rv;
148490e0de5SThomas Veerman 
149490e0de5SThomas Veerman 	pn = puffs_pn_new(pu, NULL);
150490e0de5SThomas Veerman 	if (!pn)
151490e0de5SThomas Veerman 		return ENOMEM;
152490e0de5SThomas Veerman 	puffs_setvattr(&pn->pn_va, va);
153490e0de5SThomas Veerman 
154490e0de5SThomas Veerman 	if (lstat(PCNPATH(pcn), &sb) == -1)
155490e0de5SThomas Veerman 		return errno;
156490e0de5SThomas Veerman 	puffs_stat2vattr(&pn->pn_va, &sb);
157490e0de5SThomas Veerman 
158490e0de5SThomas Veerman 	puffs_newinfo_setcookie(pni, pn);
159490e0de5SThomas Veerman 	return 0;
160490e0de5SThomas Veerman }
161490e0de5SThomas Veerman 
162490e0de5SThomas Veerman /* This should be called first and overriden from the file system */
163490e0de5SThomas Veerman void
puffs_null_setops(struct puffs_ops * pops)164490e0de5SThomas Veerman puffs_null_setops(struct puffs_ops *pops)
165490e0de5SThomas Veerman {
166490e0de5SThomas Veerman 
167490e0de5SThomas Veerman 	PUFFSOP_SET(pops, puffs_null, fs, statvfs);
168490e0de5SThomas Veerman 	PUFFSOP_SETFSNOP(pops, unmount);
169490e0de5SThomas Veerman 	PUFFSOP_SETFSNOP(pops, sync);
170*84d9c625SLionel Sambuc 	PUFFSOP_SET(pops, puffs_null, fs, fhtonode);
171*84d9c625SLionel Sambuc 	PUFFSOP_SET(pops, puffs_null, fs, nodetofh);
172490e0de5SThomas Veerman 
173490e0de5SThomas Veerman 	PUFFSOP_SET(pops, puffs_null, node, lookup);
174490e0de5SThomas Veerman 	PUFFSOP_SET(pops, puffs_null, node, create);
175490e0de5SThomas Veerman 	PUFFSOP_SET(pops, puffs_null, node, mknod);
176490e0de5SThomas Veerman 	PUFFSOP_SET(pops, puffs_null, node, getattr);
177490e0de5SThomas Veerman 	PUFFSOP_SET(pops, puffs_null, node, setattr);
178490e0de5SThomas Veerman 	PUFFSOP_SET(pops, puffs_null, node, fsync);
179490e0de5SThomas Veerman 	PUFFSOP_SET(pops, puffs_null, node, remove);
180490e0de5SThomas Veerman 	PUFFSOP_SET(pops, puffs_null, node, link);
181490e0de5SThomas Veerman 	PUFFSOP_SET(pops, puffs_null, node, rename);
182490e0de5SThomas Veerman 	PUFFSOP_SET(pops, puffs_null, node, mkdir);
183490e0de5SThomas Veerman 	PUFFSOP_SET(pops, puffs_null, node, rmdir);
184490e0de5SThomas Veerman 	PUFFSOP_SET(pops, puffs_null, node, symlink);
185490e0de5SThomas Veerman 	PUFFSOP_SET(pops, puffs_null, node, readlink);
186490e0de5SThomas Veerman 	PUFFSOP_SET(pops, puffs_null, node, readdir);
187490e0de5SThomas Veerman 	PUFFSOP_SET(pops, puffs_null, node, read);
188490e0de5SThomas Veerman 	PUFFSOP_SET(pops, puffs_null, node, write);
189490e0de5SThomas Veerman 	PUFFSOP_SET(pops, puffs_genfs, node, reclaim);
190490e0de5SThomas Veerman }
191490e0de5SThomas Veerman 
192490e0de5SThomas Veerman /*ARGSUSED*/
193490e0de5SThomas Veerman int
puffs_null_fs_statvfs(struct puffs_usermount * pu,struct statvfs * svfsb)194490e0de5SThomas Veerman puffs_null_fs_statvfs(struct puffs_usermount *pu, struct statvfs *svfsb)
195490e0de5SThomas Veerman {
196490e0de5SThomas Veerman 
197490e0de5SThomas Veerman 	if (statvfs(PNPATH(puffs_getroot(pu)), svfsb) == -1)
198490e0de5SThomas Veerman 		return errno;
199490e0de5SThomas Veerman 
200490e0de5SThomas Veerman 	return 0;
201490e0de5SThomas Veerman }
202490e0de5SThomas Veerman 
203*84d9c625SLionel Sambuc /*
204*84d9c625SLionel Sambuc  * XXX: this is the stupidest crap ever, but:
205*84d9c625SLionel Sambuc  * getfh() returns the fhandle type, when we are expected to deliver
206*84d9c625SLionel Sambuc  * the fid type.  Just adjust it a bit and stop whining.
207*84d9c625SLionel Sambuc  *
208*84d9c625SLionel Sambuc  * Yes, this really really needs fixing.  Yes, *REALLY*.
209*84d9c625SLionel Sambuc  */
210*84d9c625SLionel Sambuc #define FHANDLE_HEADERLEN 8
211*84d9c625SLionel Sambuc struct kernfid {
212*84d9c625SLionel Sambuc 	unsigned short	fid_len;		/* length of data in bytes */
213*84d9c625SLionel Sambuc 	unsigned short	fid_reserved;		/* compat: historic align */
214*84d9c625SLionel Sambuc 	char		fid_data[0];		/* data (variable length) */
215*84d9c625SLionel Sambuc };
216*84d9c625SLionel Sambuc 
217*84d9c625SLionel Sambuc /*ARGSUSED*/
218*84d9c625SLionel Sambuc static void *
fhcmp(struct puffs_usermount * pu,struct puffs_node * pn,void * arg)219*84d9c625SLionel Sambuc fhcmp(struct puffs_usermount *pu, struct puffs_node *pn, void *arg)
220*84d9c625SLionel Sambuc {
221*84d9c625SLionel Sambuc 	struct kernfid *kf1, *kf2;
222*84d9c625SLionel Sambuc 
223*84d9c625SLionel Sambuc 	if ((kf1 = pn->pn_data) == NULL)
224*84d9c625SLionel Sambuc 		return NULL;
225*84d9c625SLionel Sambuc 	kf2 = arg;
226*84d9c625SLionel Sambuc 
227*84d9c625SLionel Sambuc 	if (kf1->fid_len != kf2->fid_len)
228*84d9c625SLionel Sambuc 		return NULL;
229*84d9c625SLionel Sambuc 
230*84d9c625SLionel Sambuc 	/*LINTED*/
231*84d9c625SLionel Sambuc 	if (memcmp(kf1, kf2, kf1->fid_len) == 0)
232*84d9c625SLionel Sambuc 		return pn;
233*84d9c625SLionel Sambuc 	return NULL;
234*84d9c625SLionel Sambuc }
235*84d9c625SLionel Sambuc 
236*84d9c625SLionel Sambuc /*
237*84d9c625SLionel Sambuc  * This routine only supports file handles which have been issued while
238*84d9c625SLionel Sambuc  * the server was alive.  Not really stable ones, that is.
239*84d9c625SLionel Sambuc  */
240*84d9c625SLionel Sambuc /*ARGSUSED*/
241*84d9c625SLionel Sambuc int
puffs_null_fs_fhtonode(struct puffs_usermount * pu,void * fid,size_t fidsize,struct puffs_newinfo * pni)242*84d9c625SLionel Sambuc puffs_null_fs_fhtonode(struct puffs_usermount *pu, void *fid, size_t fidsize,
243*84d9c625SLionel Sambuc 	struct puffs_newinfo *pni)
244*84d9c625SLionel Sambuc {
245*84d9c625SLionel Sambuc 	struct puffs_node *pn_res;
246*84d9c625SLionel Sambuc 
247*84d9c625SLionel Sambuc 	pn_res = puffs_pn_nodewalk(pu, fhcmp, fid);
248*84d9c625SLionel Sambuc 	if (pn_res == NULL)
249*84d9c625SLionel Sambuc 		return ENOENT;
250*84d9c625SLionel Sambuc 
251*84d9c625SLionel Sambuc 	puffs_newinfo_setcookie(pni, pn_res);
252*84d9c625SLionel Sambuc 	puffs_newinfo_setvtype(pni, pn_res->pn_va.va_type);
253*84d9c625SLionel Sambuc 	puffs_newinfo_setsize(pni, (voff_t)pn_res->pn_va.va_size);
254*84d9c625SLionel Sambuc 	puffs_newinfo_setrdev(pni, pn_res->pn_va.va_rdev);
255*84d9c625SLionel Sambuc 	return 0;
256*84d9c625SLionel Sambuc }
257*84d9c625SLionel Sambuc 
258*84d9c625SLionel Sambuc /*ARGSUSED*/
259*84d9c625SLionel Sambuc int
puffs_null_fs_nodetofh(struct puffs_usermount * pu,puffs_cookie_t opc,void * fid,size_t * fidsize)260*84d9c625SLionel Sambuc puffs_null_fs_nodetofh(struct puffs_usermount *pu, puffs_cookie_t opc,
261*84d9c625SLionel Sambuc 	void *fid, size_t *fidsize)
262*84d9c625SLionel Sambuc {
263*84d9c625SLionel Sambuc 	struct puffs_node *pn = opc;
264*84d9c625SLionel Sambuc 	struct kernfid *kfid;
265*84d9c625SLionel Sambuc 	void *bounce;
266*84d9c625SLionel Sambuc 	int rv;
267*84d9c625SLionel Sambuc 
268*84d9c625SLionel Sambuc 	rv = 0;
269*84d9c625SLionel Sambuc 	bounce = NULL;
270*84d9c625SLionel Sambuc 	if (*fidsize) {
271*84d9c625SLionel Sambuc 		bounce = malloc(*fidsize + FHANDLE_HEADERLEN);
272*84d9c625SLionel Sambuc 		if (!bounce)
273*84d9c625SLionel Sambuc 			return ENOMEM;
274*84d9c625SLionel Sambuc 		*fidsize += FHANDLE_HEADERLEN;
275*84d9c625SLionel Sambuc 	}
276*84d9c625SLionel Sambuc 	if (getfh(PNPATH(pn), bounce, fidsize) == -1)
277*84d9c625SLionel Sambuc 		rv = errno;
278*84d9c625SLionel Sambuc 	else
279*84d9c625SLionel Sambuc 		memcpy(fid, (uint8_t *)bounce + FHANDLE_HEADERLEN,
280*84d9c625SLionel Sambuc 		    *fidsize - FHANDLE_HEADERLEN);
281*84d9c625SLionel Sambuc 	kfid = fid;
282*84d9c625SLionel Sambuc 	if (rv == 0) {
283*84d9c625SLionel Sambuc 		*fidsize = kfid->fid_len;
284*84d9c625SLionel Sambuc 		pn->pn_data = malloc(*fidsize);
285*84d9c625SLionel Sambuc 		if (pn->pn_data == NULL)
286*84d9c625SLionel Sambuc 			abort(); /* lazy */
287*84d9c625SLionel Sambuc 		memcpy(pn->pn_data, fid, *fidsize);
288*84d9c625SLionel Sambuc 	} else {
289*84d9c625SLionel Sambuc 		*fidsize -= FHANDLE_HEADERLEN;
290*84d9c625SLionel Sambuc 	}
291*84d9c625SLionel Sambuc 	free(bounce);
292*84d9c625SLionel Sambuc 
293*84d9c625SLionel Sambuc 	return rv;
294*84d9c625SLionel Sambuc }
295*84d9c625SLionel Sambuc 
296490e0de5SThomas Veerman int
puffs_null_node_lookup(struct puffs_usermount * pu,puffs_cookie_t opc,struct puffs_newinfo * pni,const struct puffs_cn * pcn)297490e0de5SThomas Veerman puffs_null_node_lookup(struct puffs_usermount *pu, puffs_cookie_t opc,
298490e0de5SThomas Veerman 	struct puffs_newinfo *pni, const struct puffs_cn *pcn)
299490e0de5SThomas Veerman {
300490e0de5SThomas Veerman 	struct puffs_node *pn = opc, *pn_res;
301490e0de5SThomas Veerman 	struct stat sb;
302490e0de5SThomas Veerman 	int rv;
303490e0de5SThomas Veerman 
304490e0de5SThomas Veerman 	assert(pn->pn_va.va_type == VDIR);
305490e0de5SThomas Veerman 
306490e0de5SThomas Veerman 	/*
307490e0de5SThomas Veerman 	 * Note to whoever is copypasting this: you must first check
308490e0de5SThomas Veerman 	 * if the node is there and only then do nodewalk.  Alternatively
309490e0de5SThomas Veerman 	 * you could make sure that you don't return unlinked/rmdir'd
310490e0de5SThomas Veerman 	 * nodes in some other fashion
311490e0de5SThomas Veerman 	 */
312490e0de5SThomas Veerman 	rv = lstat(PCNPATH(pcn), &sb);
313490e0de5SThomas Veerman 	if (rv)
314490e0de5SThomas Veerman 		return errno;
315490e0de5SThomas Veerman 
316490e0de5SThomas Veerman 	/* XXX2: nodewalk is a bit too slow here */
317490e0de5SThomas Veerman 	pn_res = puffs_pn_nodewalk(pu, inodecmp, &sb.st_ino);
318490e0de5SThomas Veerman 
319490e0de5SThomas Veerman 	if (pn_res == NULL) {
320490e0de5SThomas Veerman 		pn_res = puffs_pn_new(pu, NULL);
321490e0de5SThomas Veerman 		if (pn_res == NULL)
322490e0de5SThomas Veerman 			return ENOMEM;
323490e0de5SThomas Veerman 		puffs_stat2vattr(&pn_res->pn_va, &sb);
324490e0de5SThomas Veerman 	}
325490e0de5SThomas Veerman 
326490e0de5SThomas Veerman 	puffs_newinfo_setcookie(pni, pn_res);
327490e0de5SThomas Veerman 	puffs_newinfo_setvtype(pni, pn_res->pn_va.va_type);
328490e0de5SThomas Veerman 	puffs_newinfo_setsize(pni, (voff_t)pn_res->pn_va.va_size);
329490e0de5SThomas Veerman 	puffs_newinfo_setrdev(pni, pn_res->pn_va.va_rdev);
330490e0de5SThomas Veerman 
331490e0de5SThomas Veerman 	return 0;
332490e0de5SThomas Veerman }
333490e0de5SThomas Veerman 
334490e0de5SThomas Veerman /*ARGSUSED*/
335490e0de5SThomas Veerman int
puffs_null_node_create(struct puffs_usermount * pu,puffs_cookie_t opc,struct puffs_newinfo * pni,const struct puffs_cn * pcn,const struct vattr * va)336490e0de5SThomas Veerman puffs_null_node_create(struct puffs_usermount *pu, puffs_cookie_t opc,
337490e0de5SThomas Veerman 	struct puffs_newinfo *pni, const struct puffs_cn *pcn,
338490e0de5SThomas Veerman 	const struct vattr *va)
339490e0de5SThomas Veerman {
340490e0de5SThomas Veerman 	int fd, rv;
341490e0de5SThomas Veerman 
342490e0de5SThomas Veerman 	fd = open(PCNPATH(pcn), O_RDWR | O_CREAT | O_TRUNC);
343490e0de5SThomas Veerman 	if (fd == -1)
344490e0de5SThomas Veerman 		return errno;
345490e0de5SThomas Veerman 	close(fd);
346490e0de5SThomas Veerman 
347490e0de5SThomas Veerman 	rv = makenode(pu, pni, pcn, va, 1);
348490e0de5SThomas Veerman 	if (rv)
349490e0de5SThomas Veerman 		unlink(PCNPATH(pcn));
350490e0de5SThomas Veerman 	return rv;
351490e0de5SThomas Veerman }
352490e0de5SThomas Veerman 
353490e0de5SThomas Veerman /*ARGSUSED*/
354490e0de5SThomas Veerman int
puffs_null_node_mknod(struct puffs_usermount * pu,puffs_cookie_t opc,struct puffs_newinfo * pni,const struct puffs_cn * pcn,const struct vattr * va)355490e0de5SThomas Veerman puffs_null_node_mknod(struct puffs_usermount *pu, puffs_cookie_t opc,
356490e0de5SThomas Veerman 	struct puffs_newinfo *pni, const struct puffs_cn *pcn,
357490e0de5SThomas Veerman 	const struct vattr *va)
358490e0de5SThomas Veerman {
359490e0de5SThomas Veerman 	mode_t mode;
360490e0de5SThomas Veerman 	int rv;
361490e0de5SThomas Veerman 
362490e0de5SThomas Veerman 	mode = puffs_addvtype2mode(va->va_mode, va->va_type);
363490e0de5SThomas Veerman 	if (mknod(PCNPATH(pcn), mode, va->va_rdev) == -1)
364490e0de5SThomas Veerman 		return errno;
365490e0de5SThomas Veerman 
366490e0de5SThomas Veerman 	rv = makenode(pu, pni, pcn, va, 0);
367490e0de5SThomas Veerman 	if (rv)
368490e0de5SThomas Veerman 		unlink(PCNPATH(pcn));
369490e0de5SThomas Veerman 	return rv;
370490e0de5SThomas Veerman }
371490e0de5SThomas Veerman 
372490e0de5SThomas Veerman /*ARGSUSED*/
373490e0de5SThomas Veerman int
puffs_null_node_getattr(struct puffs_usermount * pu,puffs_cookie_t opc,struct vattr * va,const struct puffs_cred * pcred)374490e0de5SThomas Veerman puffs_null_node_getattr(struct puffs_usermount *pu, puffs_cookie_t opc,
375490e0de5SThomas Veerman 	struct vattr *va, const struct puffs_cred *pcred)
376490e0de5SThomas Veerman {
377490e0de5SThomas Veerman 	struct puffs_node *pn = opc;
378490e0de5SThomas Veerman 	struct stat sb;
379490e0de5SThomas Veerman 
380490e0de5SThomas Veerman 	if (lstat(PNPATH(pn), &sb) == -1)
381490e0de5SThomas Veerman 		return errno;
382490e0de5SThomas Veerman 	puffs_stat2vattr(va, &sb);
383490e0de5SThomas Veerman 
384490e0de5SThomas Veerman 	return 0;
385490e0de5SThomas Veerman }
386490e0de5SThomas Veerman 
387490e0de5SThomas Veerman /*ARGSUSED*/
388490e0de5SThomas Veerman int
puffs_null_node_setattr(struct puffs_usermount * pu,puffs_cookie_t opc,const struct vattr * va,const struct puffs_cred * pcred)389490e0de5SThomas Veerman puffs_null_node_setattr(struct puffs_usermount *pu, puffs_cookie_t opc,
390490e0de5SThomas Veerman 	const struct vattr *va, const struct puffs_cred *pcred)
391490e0de5SThomas Veerman {
392490e0de5SThomas Veerman 	struct puffs_node *pn = opc;
393490e0de5SThomas Veerman 	int rv;
394490e0de5SThomas Veerman 
395490e0de5SThomas Veerman 	rv = processvattr(PNPATH(pn), va, pn->pn_va.va_type == VREG);
396490e0de5SThomas Veerman 	if (rv)
397490e0de5SThomas Veerman 		return rv;
398490e0de5SThomas Veerman 
399490e0de5SThomas Veerman 	puffs_setvattr(&pn->pn_va, va);
400490e0de5SThomas Veerman 
401490e0de5SThomas Veerman 	return 0;
402490e0de5SThomas Veerman }
403490e0de5SThomas Veerman 
404490e0de5SThomas Veerman /*ARGSUSED*/
405490e0de5SThomas Veerman int
puffs_null_node_fsync(struct puffs_usermount * pu,puffs_cookie_t opc,const struct puffs_cred * pcred,int how,off_t offlo,off_t offhi)406490e0de5SThomas Veerman puffs_null_node_fsync(struct puffs_usermount *pu, puffs_cookie_t opc,
407490e0de5SThomas Veerman 	const struct puffs_cred *pcred, int how,
408490e0de5SThomas Veerman 	off_t offlo, off_t offhi)
409490e0de5SThomas Veerman {
410490e0de5SThomas Veerman 	struct puffs_node *pn = opc;
411490e0de5SThomas Veerman 	int fd, rv;
412490e0de5SThomas Veerman 	int fflags;
413*84d9c625SLionel Sambuc 	struct stat sb;
414490e0de5SThomas Veerman 
415490e0de5SThomas Veerman 	rv = 0;
416*84d9c625SLionel Sambuc 	if (stat(PNPATH(pn), &sb) == -1)
417*84d9c625SLionel Sambuc 		return errno;
418*84d9c625SLionel Sambuc 	if (S_ISDIR(sb.st_mode)) {
419*84d9c625SLionel Sambuc 		DIR *dirp;
420*84d9c625SLionel Sambuc 		if ((dirp = opendir(PNPATH(pn))) == 0)
421*84d9c625SLionel Sambuc 			return errno;
422*84d9c625SLionel Sambuc 		fd = dirfd(dirp);
423*84d9c625SLionel Sambuc 		if (fd == -1)
424*84d9c625SLionel Sambuc 			return errno;
425*84d9c625SLionel Sambuc 
426*84d9c625SLionel Sambuc 		if (fsync(fd) == -1)
427*84d9c625SLionel Sambuc 			rv = errno;
428*84d9c625SLionel Sambuc 	} else {
429490e0de5SThomas Veerman 		fd = writeableopen(PNPATH(pn));
430490e0de5SThomas Veerman 		if (fd == -1)
431490e0de5SThomas Veerman 			return errno;
432490e0de5SThomas Veerman 
433490e0de5SThomas Veerman 		if (how & PUFFS_FSYNC_DATAONLY)
434490e0de5SThomas Veerman 			fflags = FDATASYNC;
435490e0de5SThomas Veerman 		else
436490e0de5SThomas Veerman 			fflags = FFILESYNC;
437490e0de5SThomas Veerman 		if (how & PUFFS_FSYNC_CACHE)
438490e0de5SThomas Veerman 			fflags |= FDISKSYNC;
439490e0de5SThomas Veerman 
440490e0de5SThomas Veerman 		if (fsync_range(fd, fflags, offlo, offhi - offlo) == -1)
441490e0de5SThomas Veerman 			rv = errno;
442*84d9c625SLionel Sambuc 	}
443490e0de5SThomas Veerman 
444490e0de5SThomas Veerman 	close(fd);
445490e0de5SThomas Veerman 
446490e0de5SThomas Veerman 	return rv;
447490e0de5SThomas Veerman }
448490e0de5SThomas Veerman 
449490e0de5SThomas Veerman /*ARGSUSED*/
450490e0de5SThomas Veerman int
puffs_null_node_remove(struct puffs_usermount * pu,puffs_cookie_t opc,puffs_cookie_t targ,const struct puffs_cn * pcn)451490e0de5SThomas Veerman puffs_null_node_remove(struct puffs_usermount *pu, puffs_cookie_t opc,
452490e0de5SThomas Veerman 	puffs_cookie_t targ, const struct puffs_cn *pcn)
453490e0de5SThomas Veerman {
454490e0de5SThomas Veerman 	struct puffs_node *pn_targ = targ;
455490e0de5SThomas Veerman 
456*84d9c625SLionel Sambuc 	if (unlink(PNPATH(pn_targ)) == -1)
457490e0de5SThomas Veerman 		return errno;
458490e0de5SThomas Veerman 	puffs_pn_remove(pn_targ);
459490e0de5SThomas Veerman 
460490e0de5SThomas Veerman 	return 0;
461490e0de5SThomas Veerman }
462490e0de5SThomas Veerman 
463490e0de5SThomas Veerman /*ARGSUSED*/
464490e0de5SThomas Veerman int
puffs_null_node_link(struct puffs_usermount * pu,puffs_cookie_t opc,puffs_cookie_t targ,const struct puffs_cn * pcn)465490e0de5SThomas Veerman puffs_null_node_link(struct puffs_usermount *pu, puffs_cookie_t opc,
466490e0de5SThomas Veerman 	puffs_cookie_t targ, const struct puffs_cn *pcn)
467490e0de5SThomas Veerman {
468490e0de5SThomas Veerman 	struct puffs_node *pn_targ = targ;
469490e0de5SThomas Veerman 
470490e0de5SThomas Veerman 	if (link(PNPATH(pn_targ), PCNPATH(pcn)) == -1)
471490e0de5SThomas Veerman 		return errno;
472490e0de5SThomas Veerman 
473490e0de5SThomas Veerman 	return 0;
474490e0de5SThomas Veerman }
475490e0de5SThomas Veerman 
476490e0de5SThomas Veerman /*ARGSUSED*/
477490e0de5SThomas Veerman int
puffs_null_node_rename(struct puffs_usermount * pu,puffs_cookie_t opc,puffs_cookie_t src,const struct puffs_cn * pcn_src,puffs_cookie_t targ_dir,puffs_cookie_t targ,const struct puffs_cn * pcn_targ)478490e0de5SThomas Veerman puffs_null_node_rename(struct puffs_usermount *pu, puffs_cookie_t opc,
479490e0de5SThomas Veerman 	puffs_cookie_t src, const struct puffs_cn *pcn_src,
480490e0de5SThomas Veerman 	puffs_cookie_t targ_dir, puffs_cookie_t targ,
481490e0de5SThomas Veerman 	const struct puffs_cn *pcn_targ)
482490e0de5SThomas Veerman {
483490e0de5SThomas Veerman 	struct puffs_node *pn_targ = targ;
484490e0de5SThomas Veerman 
485490e0de5SThomas Veerman 	if (rename(PCNPATH(pcn_src), PCNPATH(pcn_targ)) == -1)
486490e0de5SThomas Veerman 		return errno;
487490e0de5SThomas Veerman 
488490e0de5SThomas Veerman         if (pn_targ)
489490e0de5SThomas Veerman 		puffs_pn_remove(pn_targ);
490490e0de5SThomas Veerman 
491490e0de5SThomas Veerman 	return 0;
492490e0de5SThomas Veerman }
493490e0de5SThomas Veerman 
494490e0de5SThomas Veerman /*ARGSUSED*/
495490e0de5SThomas Veerman int
puffs_null_node_mkdir(struct puffs_usermount * pu,puffs_cookie_t opc,struct puffs_newinfo * pni,const struct puffs_cn * pcn,const struct vattr * va)496490e0de5SThomas Veerman puffs_null_node_mkdir(struct puffs_usermount *pu, puffs_cookie_t opc,
497490e0de5SThomas Veerman 	struct puffs_newinfo *pni, const struct puffs_cn *pcn,
498490e0de5SThomas Veerman 	const struct vattr *va)
499490e0de5SThomas Veerman {
500490e0de5SThomas Veerman 	int rv;
501490e0de5SThomas Veerman 
502490e0de5SThomas Veerman 	if (mkdir(PCNPATH(pcn), va->va_mode) == -1)
503490e0de5SThomas Veerman 		return errno;
504490e0de5SThomas Veerman 
505490e0de5SThomas Veerman 	rv = makenode(pu, pni, pcn, va, 0);
506490e0de5SThomas Veerman 	if (rv)
507490e0de5SThomas Veerman 		rmdir(PCNPATH(pcn));
508490e0de5SThomas Veerman 	return rv;
509490e0de5SThomas Veerman }
510490e0de5SThomas Veerman 
511490e0de5SThomas Veerman /*ARGSUSED*/
512490e0de5SThomas Veerman int
puffs_null_node_rmdir(struct puffs_usermount * pu,puffs_cookie_t opc,puffs_cookie_t targ,const struct puffs_cn * pcn)513490e0de5SThomas Veerman puffs_null_node_rmdir(struct puffs_usermount *pu, puffs_cookie_t opc,
514490e0de5SThomas Veerman 	puffs_cookie_t targ, const struct puffs_cn *pcn)
515490e0de5SThomas Veerman {
516490e0de5SThomas Veerman 	struct puffs_node *pn_targ = targ;
517490e0de5SThomas Veerman 
518490e0de5SThomas Veerman 	if (rmdir(PNPATH(pn_targ)) == -1)
519490e0de5SThomas Veerman 		return errno;
520490e0de5SThomas Veerman 	puffs_pn_remove(pn_targ);
521490e0de5SThomas Veerman 
522490e0de5SThomas Veerman 	return 0;
523490e0de5SThomas Veerman }
524490e0de5SThomas Veerman 
525490e0de5SThomas Veerman /*ARGSUSED*/
526490e0de5SThomas Veerman int
puffs_null_node_symlink(struct puffs_usermount * pu,puffs_cookie_t opc,struct puffs_newinfo * pni,const struct puffs_cn * pcn,const struct vattr * va,const char * linkname)527490e0de5SThomas Veerman puffs_null_node_symlink(struct puffs_usermount *pu, puffs_cookie_t opc,
528490e0de5SThomas Veerman 	struct puffs_newinfo *pni, const struct puffs_cn *pcn,
529490e0de5SThomas Veerman 	const struct vattr *va, const char *linkname)
530490e0de5SThomas Veerman {
531490e0de5SThomas Veerman 	int rv;
532490e0de5SThomas Veerman 
533490e0de5SThomas Veerman 	if (symlink(linkname, PCNPATH(pcn)) == -1)
534490e0de5SThomas Veerman 		return errno;
535490e0de5SThomas Veerman 
536490e0de5SThomas Veerman 	rv = makenode(pu, pni, pcn, va, 0);
537490e0de5SThomas Veerman 	if (rv)
538490e0de5SThomas Veerman 		unlink(PCNPATH(pcn));
539490e0de5SThomas Veerman 	return rv;
540490e0de5SThomas Veerman }
541490e0de5SThomas Veerman 
542490e0de5SThomas Veerman /*ARGSUSED*/
543490e0de5SThomas Veerman int
puffs_null_node_readlink(struct puffs_usermount * pu,puffs_cookie_t opc,const struct puffs_cred * pcred,char * linkname,size_t * linklen)544490e0de5SThomas Veerman puffs_null_node_readlink(struct puffs_usermount *pu, puffs_cookie_t opc,
545490e0de5SThomas Veerman 	const struct puffs_cred *pcred, char *linkname, size_t *linklen)
546490e0de5SThomas Veerman {
547490e0de5SThomas Veerman 	struct puffs_node *pn = opc;
548490e0de5SThomas Veerman 	ssize_t rv;
549490e0de5SThomas Veerman 
550490e0de5SThomas Veerman 	rv = readlink(PNPATH(pn), linkname, *linklen);
551490e0de5SThomas Veerman 	if (rv == -1)
552490e0de5SThomas Veerman 		return errno;
553490e0de5SThomas Veerman 
554490e0de5SThomas Veerman 	*linklen = rv;
555490e0de5SThomas Veerman 	return 0;
556490e0de5SThomas Veerman }
557490e0de5SThomas Veerman 
558490e0de5SThomas Veerman /*ARGSUSED*/
559490e0de5SThomas Veerman int
puffs_null_node_readdir(struct puffs_usermount * pu,puffs_cookie_t opc,struct dirent * de,off_t * off,size_t * reslen,const struct puffs_cred * pcred,int * eofflag,off_t * cookies,size_t * ncookies)560490e0de5SThomas Veerman puffs_null_node_readdir(struct puffs_usermount *pu, puffs_cookie_t opc,
561490e0de5SThomas Veerman 	struct dirent *de, off_t *off, size_t *reslen,
562490e0de5SThomas Veerman 	const struct puffs_cred *pcred, int *eofflag, off_t *cookies,
563490e0de5SThomas Veerman 	size_t *ncookies)
564490e0de5SThomas Veerman {
565490e0de5SThomas Veerman 	struct puffs_node *pn = opc;
566*84d9c625SLionel Sambuc 	struct dirent entry, *result;
567490e0de5SThomas Veerman 	DIR *dp;
568490e0de5SThomas Veerman 	off_t i;
569490e0de5SThomas Veerman 	int rv;
570490e0de5SThomas Veerman 
571*84d9c625SLionel Sambuc 	*ncookies = 0;
572490e0de5SThomas Veerman 	dp = opendir(PNPATH(pn));
573490e0de5SThomas Veerman 	if (dp == NULL)
574490e0de5SThomas Veerman 		return errno;
575490e0de5SThomas Veerman 
576490e0de5SThomas Veerman 	rv = 0;
577490e0de5SThomas Veerman 	i = *off;
578490e0de5SThomas Veerman 
579490e0de5SThomas Veerman 	/*
580490e0de5SThomas Veerman 	 * XXX: need to do trickery here, telldir/seekdir would be nice, but
581490e0de5SThomas Veerman 	 * then we'd need to keep state, which I'm too lazy to keep
582490e0de5SThomas Veerman 	 */
583490e0de5SThomas Veerman 	while (i--) {
584*84d9c625SLionel Sambuc 		rv = readdir_r(dp, &entry, &result);
585*84d9c625SLionel Sambuc 		if (rv != 0)
586*84d9c625SLionel Sambuc 			goto out;
587*84d9c625SLionel Sambuc 
588*84d9c625SLionel Sambuc 		if (!result) {
589490e0de5SThomas Veerman 			*eofflag = 1;
590490e0de5SThomas Veerman 			goto out;
591490e0de5SThomas Veerman 		}
592490e0de5SThomas Veerman 	}
593490e0de5SThomas Veerman 
594490e0de5SThomas Veerman 	for (;;) {
595*84d9c625SLionel Sambuc 		rv = readdir_r(dp, &entry, &result);
596*84d9c625SLionel Sambuc 		if (rv != 0)
597*84d9c625SLionel Sambuc 			goto out;
598490e0de5SThomas Veerman 
599*84d9c625SLionel Sambuc 		if (!result) {
600490e0de5SThomas Veerman 			*eofflag = 1;
601490e0de5SThomas Veerman 			goto out;
602490e0de5SThomas Veerman 		}
603490e0de5SThomas Veerman 
604*84d9c625SLionel Sambuc 		if (_DIRENT_SIZE(result) > *reslen)
605490e0de5SThomas Veerman 			goto out;
606490e0de5SThomas Veerman 
607*84d9c625SLionel Sambuc 		*de = *result;
608*84d9c625SLionel Sambuc 		*reslen -= _DIRENT_SIZE(result);
609490e0de5SThomas Veerman 		de = _DIRENT_NEXT(de);
610*84d9c625SLionel Sambuc 
611490e0de5SThomas Veerman 		(*off)++;
612*84d9c625SLionel Sambuc 		PUFFS_STORE_DCOOKIE(cookies, ncookies, *off);
613490e0de5SThomas Veerman 	}
614490e0de5SThomas Veerman 
615490e0de5SThomas Veerman  out:
616490e0de5SThomas Veerman 	closedir(dp);
617490e0de5SThomas Veerman 	return 0;
618490e0de5SThomas Veerman }
619490e0de5SThomas Veerman 
620490e0de5SThomas Veerman /*ARGSUSED*/
621490e0de5SThomas Veerman int
puffs_null_node_read(struct puffs_usermount * pu,puffs_cookie_t opc,uint8_t * buf,off_t offset,size_t * buflen,const struct puffs_cred * pcred,int ioflag)622490e0de5SThomas Veerman puffs_null_node_read(struct puffs_usermount *pu, puffs_cookie_t opc,
623490e0de5SThomas Veerman 	uint8_t *buf, off_t offset, size_t *buflen,
624490e0de5SThomas Veerman 	const struct puffs_cred *pcred, int ioflag)
625490e0de5SThomas Veerman {
626490e0de5SThomas Veerman 	struct puffs_node *pn = opc;
627490e0de5SThomas Veerman 	ssize_t n;
628490e0de5SThomas Veerman 	off_t off;
629490e0de5SThomas Veerman 	int fd, rv;
630490e0de5SThomas Veerman 
631490e0de5SThomas Veerman 	rv = 0;
632490e0de5SThomas Veerman 	fd = open(PNPATH(pn), O_RDONLY);
633490e0de5SThomas Veerman 	if (fd == -1)
634490e0de5SThomas Veerman 		return errno;
635490e0de5SThomas Veerman 	off = lseek(fd, offset, SEEK_SET);
636490e0de5SThomas Veerman 	if (off == -1) {
637490e0de5SThomas Veerman 		rv = errno;
638490e0de5SThomas Veerman 		goto out;
639490e0de5SThomas Veerman 	}
640490e0de5SThomas Veerman 
641490e0de5SThomas Veerman 	n = read(fd, buf, *buflen);
642490e0de5SThomas Veerman 	if (n == -1)
643490e0de5SThomas Veerman 		rv = errno;
644490e0de5SThomas Veerman 	else
645490e0de5SThomas Veerman 		*buflen -= n;
646490e0de5SThomas Veerman 
647490e0de5SThomas Veerman  out:
648490e0de5SThomas Veerman 	close(fd);
649490e0de5SThomas Veerman 	return rv;
650490e0de5SThomas Veerman }
651490e0de5SThomas Veerman 
652490e0de5SThomas Veerman /*ARGSUSED*/
653490e0de5SThomas Veerman int
puffs_null_node_write(struct puffs_usermount * pu,puffs_cookie_t opc,uint8_t * buf,off_t offset,size_t * buflen,const struct puffs_cred * pcred,int ioflag)654490e0de5SThomas Veerman puffs_null_node_write(struct puffs_usermount *pu, puffs_cookie_t opc,
655490e0de5SThomas Veerman 	uint8_t *buf, off_t offset, size_t *buflen,
656490e0de5SThomas Veerman 	const struct puffs_cred *pcred, int ioflag)
657490e0de5SThomas Veerman {
658490e0de5SThomas Veerman 	struct puffs_node *pn = opc;
659490e0de5SThomas Veerman 	ssize_t n;
660490e0de5SThomas Veerman 	off_t off;
661490e0de5SThomas Veerman 	int fd, rv;
662490e0de5SThomas Veerman 
663490e0de5SThomas Veerman 	rv = 0;
664490e0de5SThomas Veerman 	fd = writeableopen(PNPATH(pn));
665490e0de5SThomas Veerman 	if (fd == -1)
666490e0de5SThomas Veerman 		return errno;
667490e0de5SThomas Veerman 
668490e0de5SThomas Veerman 	off = lseek(fd, offset, SEEK_SET);
669490e0de5SThomas Veerman 	if (off == -1) {
670490e0de5SThomas Veerman 		rv = errno;
671490e0de5SThomas Veerman 		goto out;
672490e0de5SThomas Veerman 	}
673490e0de5SThomas Veerman 
674490e0de5SThomas Veerman 	n = write(fd, buf, *buflen);
675490e0de5SThomas Veerman 	if (n == -1)
676490e0de5SThomas Veerman 		rv = errno;
677490e0de5SThomas Veerman 	else
678490e0de5SThomas Veerman 		*buflen -= n;
679490e0de5SThomas Veerman 
680490e0de5SThomas Veerman  out:
681490e0de5SThomas Veerman 	close(fd);
682490e0de5SThomas Veerman 	return rv;
683490e0de5SThomas Veerman }
684