xref: /original-bsd/lib/libc/gen/getmntinfo.c (revision bff54947)
1 /*
2  * Copyright (c) 1989 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #if defined(LIBC_SCCS) && !defined(lint)
9 static char sccsid[] = "@(#)getmntinfo.c	6.3 (Berkeley) 06/01/90";
10 #endif /* LIBC_SCCS and not lint */
11 
12 #include <sys/types.h>
13 #include <sys/mount.h>
14 
15 /*
16  * Return information about mounted filesystems.
17  */
18 int
19 getmntinfo(mntbufp, flags)
20 	struct statfs **mntbufp;
21 	int flags;
22 {
23 	static struct statfs *mntbuf;
24 	static int mntsize, bufsize;
25 
26 	if (mntsize <= 0 && (mntsize = getfsstat(0, 0, MNT_NOWAIT)) < 0)
27 		return (0);
28 	if (bufsize > 0 && (mntsize = getfsstat(mntbuf, bufsize, flags)) < 0)
29 		return (0);
30 	while (bufsize <= mntsize * sizeof(struct statfs)) {
31 		if (mntbuf)
32 			free(mntbuf);
33 		bufsize = (mntsize + 1) * sizeof(struct statfs);
34 		if ((mntbuf = (struct statfs *)malloc(bufsize)) == 0)
35 			return (0);
36 		if ((mntsize = getfsstat(mntbuf, bufsize, flags)) < 0)
37 			return (0);
38 	}
39 	*mntbufp = mntbuf;
40 	return (mntsize);
41 }
42