xref: /csrg-svn/lib/libc/gen/getmntinfo.c (revision 39317)
1*39317Smckusick /*
2*39317Smckusick  * Copyright (c) 1989 The Regents of the University of California.
3*39317Smckusick  * All rights reserved.
4*39317Smckusick  *
5*39317Smckusick  * Redistribution and use in source and binary forms are permitted
6*39317Smckusick  * provided that the above copyright notice and this paragraph are
7*39317Smckusick  * duplicated in all such forms and that any documentation,
8*39317Smckusick  * advertising materials, and other materials related to such
9*39317Smckusick  * distribution and use acknowledge that the software was developed
10*39317Smckusick  * by the University of California, Berkeley.  The name of the
11*39317Smckusick  * University may not be used to endorse or promote products derived
12*39317Smckusick  * from this software without specific prior written permission.
13*39317Smckusick  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14*39317Smckusick  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15*39317Smckusick  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16*39317Smckusick  */
17*39317Smckusick 
18*39317Smckusick #if defined(LIBC_SCCS) && !defined(lint)
19*39317Smckusick static char sccsid[] = "@(#)getmntinfo.c	6.1 (Berkeley) 10/17/89";
20*39317Smckusick #endif /* LIBC_SCCS and not lint */
21*39317Smckusick 
22*39317Smckusick #include <sys/types.h>
23*39317Smckusick #include <sys/mount.h>
24*39317Smckusick 
25*39317Smckusick /*
26*39317Smckusick  * Return information about mounted filesystems.
27*39317Smckusick  */
28*39317Smckusick int
29*39317Smckusick getmntinfo(mntbufp)
30*39317Smckusick 	struct statfs **mntbufp;
31*39317Smckusick {
32*39317Smckusick 	static struct statfs *mntbuf;
33*39317Smckusick 	static int mntsize, bufsize;
34*39317Smckusick 
35*39317Smckusick 	if (mntsize <= 0 && (mntsize = getfsstat(0, 0)) < 0)
36*39317Smckusick 		return (0);
37*39317Smckusick 	if (bufsize > 0 && (mntsize = getfsstat(mntbuf, bufsize)) < 0)
38*39317Smckusick 		return (0);
39*39317Smckusick 	while (bufsize <= mntsize * sizeof(struct statfs)) {
40*39317Smckusick 		if (mntbuf)
41*39317Smckusick 			free(mntbuf);
42*39317Smckusick 		bufsize = (mntsize + 1) * sizeof(struct statfs);
43*39317Smckusick 		if ((mntbuf = (struct statfs *)malloc(bufsize)) == 0)
44*39317Smckusick 			return (0);
45*39317Smckusick 		if ((mntsize = getfsstat(mntbuf, bufsize)) < 0)
46*39317Smckusick 			return (0);
47*39317Smckusick 	}
48*39317Smckusick 	*mntbufp = mntbuf;
49*39317Smckusick 	return (mntsize);
50*39317Smckusick }
51