xref: /minix3/tests/fs/nfs/nfsservice/getmntinfo.c (revision 11be35a165022172ed3cea20f2b5df0307540b0e)
1*11be35a1SLionel Sambuc /*	$NetBSD: getmntinfo.c,v 1.1 2010/07/26 15:53:00 pooka Exp $	*/
2*11be35a1SLionel Sambuc 
3*11be35a1SLionel Sambuc /*
4*11be35a1SLionel Sambuc  * Copyright (c) 1989, 1993
5*11be35a1SLionel Sambuc  *	The Regents of the University of California.  All rights reserved.
6*11be35a1SLionel Sambuc  *
7*11be35a1SLionel Sambuc  * Redistribution and use in source and binary forms, with or without
8*11be35a1SLionel Sambuc  * modification, are permitted provided that the following conditions
9*11be35a1SLionel Sambuc  * are met:
10*11be35a1SLionel Sambuc  * 1. Redistributions of source code must retain the above copyright
11*11be35a1SLionel Sambuc  *    notice, this list of conditions and the following disclaimer.
12*11be35a1SLionel Sambuc  * 2. Redistributions in binary form must reproduce the above copyright
13*11be35a1SLionel Sambuc  *    notice, this list of conditions and the following disclaimer in the
14*11be35a1SLionel Sambuc  *    documentation and/or other materials provided with the distribution.
15*11be35a1SLionel Sambuc  * 3. Neither the name of the University nor the names of its contributors
16*11be35a1SLionel Sambuc  *    may be used to endorse or promote products derived from this software
17*11be35a1SLionel Sambuc  *    without specific prior written permission.
18*11be35a1SLionel Sambuc  *
19*11be35a1SLionel Sambuc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20*11be35a1SLionel Sambuc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21*11be35a1SLionel Sambuc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22*11be35a1SLionel Sambuc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23*11be35a1SLionel Sambuc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24*11be35a1SLionel Sambuc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25*11be35a1SLionel Sambuc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26*11be35a1SLionel Sambuc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27*11be35a1SLionel Sambuc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28*11be35a1SLionel Sambuc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29*11be35a1SLionel Sambuc  * SUCH DAMAGE.
30*11be35a1SLionel Sambuc  */
31*11be35a1SLionel Sambuc 
32*11be35a1SLionel Sambuc #include <sys/cdefs.h>
33*11be35a1SLionel Sambuc #if defined(LIBC_SCCS) && !defined(lint)
34*11be35a1SLionel Sambuc #if 0
35*11be35a1SLionel Sambuc static char sccsid[] = "@(#)getmntinfo.c	8.1 (Berkeley) 6/4/93";
36*11be35a1SLionel Sambuc #else
37*11be35a1SLionel Sambuc __RCSID("$NetBSD: getmntinfo.c,v 1.1 2010/07/26 15:53:00 pooka Exp $");
38*11be35a1SLionel Sambuc #endif
39*11be35a1SLionel Sambuc #endif /* LIBC_SCCS and not lint */
40*11be35a1SLionel Sambuc 
41*11be35a1SLionel Sambuc #include <sys/param.h>
42*11be35a1SLionel Sambuc #include <sys/ucred.h>
43*11be35a1SLionel Sambuc #include <sys/mount.h>
44*11be35a1SLionel Sambuc 
45*11be35a1SLionel Sambuc #include <rump/rump.h>
46*11be35a1SLionel Sambuc #include <rump/rump_syscalls.h>
47*11be35a1SLionel Sambuc 
48*11be35a1SLionel Sambuc #include <assert.h>
49*11be35a1SLionel Sambuc #include <errno.h>
50*11be35a1SLionel Sambuc #include <stdlib.h>
51*11be35a1SLionel Sambuc 
52*11be35a1SLionel Sambuc #define getvfsstat(a,b,c) rump_sys_getvfsstat(a,b,c)
53*11be35a1SLionel Sambuc 
54*11be35a1SLionel Sambuc /*
55*11be35a1SLionel Sambuc  * Return information about mounted filesystems.
56*11be35a1SLionel Sambuc  */
57*11be35a1SLionel Sambuc int
getmntinfo(mntbufp,flags)58*11be35a1SLionel Sambuc getmntinfo(mntbufp, flags)
59*11be35a1SLionel Sambuc 	struct statvfs **mntbufp;
60*11be35a1SLionel Sambuc 	int flags;
61*11be35a1SLionel Sambuc {
62*11be35a1SLionel Sambuc 	static struct statvfs *mntbuf;
63*11be35a1SLionel Sambuc 	static int mntsize;
64*11be35a1SLionel Sambuc 	static size_t bufsize;
65*11be35a1SLionel Sambuc 
66*11be35a1SLionel Sambuc 	_DIAGASSERT(mntbufp != NULL);
67*11be35a1SLionel Sambuc 
68*11be35a1SLionel Sambuc 	if (mntsize <= 0 &&
69*11be35a1SLionel Sambuc 	    (mntsize = getvfsstat(NULL, (size_t)0, MNT_NOWAIT)) == -1)
70*11be35a1SLionel Sambuc 		return (0);
71*11be35a1SLionel Sambuc 	if (bufsize > 0 &&
72*11be35a1SLionel Sambuc 	    (mntsize = getvfsstat(mntbuf, bufsize, flags)) == -1)
73*11be35a1SLionel Sambuc 		return (0);
74*11be35a1SLionel Sambuc 	while (bufsize <= mntsize * sizeof(struct statvfs)) {
75*11be35a1SLionel Sambuc 		if (mntbuf)
76*11be35a1SLionel Sambuc 			free(mntbuf);
77*11be35a1SLionel Sambuc 		bufsize = (mntsize + 1) * sizeof(struct statvfs);
78*11be35a1SLionel Sambuc 		if ((mntbuf = malloc(bufsize)) == NULL)
79*11be35a1SLionel Sambuc 			return (0);
80*11be35a1SLionel Sambuc 		if ((mntsize = getvfsstat(mntbuf, bufsize, flags)) == -1)
81*11be35a1SLionel Sambuc 			return (0);
82*11be35a1SLionel Sambuc 	}
83*11be35a1SLionel Sambuc 	*mntbufp = mntbuf;
84*11be35a1SLionel Sambuc 	return (mntsize);
85*11be35a1SLionel Sambuc }
86