Commit | Line | Data |
---|---|---|
e5afe6d2 KM |
1 | /* |
2 | * Copyright (c) 1989 The Regents of the University of California. | |
3 | * All rights reserved. | |
4 | * | |
269a7923 | 5 | * %sccs.include.redist.c% |
e5afe6d2 KM |
6 | */ |
7 | ||
8 | #if defined(LIBC_SCCS) && !defined(lint) | |
a06efc47 | 9 | static char sccsid[] = "@(#)getmntinfo.c 6.5 (Berkeley) %G%"; |
e5afe6d2 KM |
10 | #endif /* LIBC_SCCS and not lint */ |
11 | ||
a06efc47 KB |
12 | #include <sys/param.h> |
13 | #include <sys/ucred.h> | |
e5afe6d2 | 14 | #include <sys/mount.h> |
c5980113 | 15 | #include <stdlib.h> |
e5afe6d2 KM |
16 | |
17 | /* | |
18 | * Return information about mounted filesystems. | |
19 | */ | |
20 | int | |
e14902d3 | 21 | getmntinfo(mntbufp, flags) |
e5afe6d2 | 22 | struct statfs **mntbufp; |
e14902d3 | 23 | int flags; |
e5afe6d2 KM |
24 | { |
25 | static struct statfs *mntbuf; | |
c5980113 DS |
26 | static int mntsize; |
27 | static long bufsize; | |
e5afe6d2 | 28 | |
e14902d3 | 29 | if (mntsize <= 0 && (mntsize = getfsstat(0, 0, MNT_NOWAIT)) < 0) |
e5afe6d2 | 30 | return (0); |
e14902d3 | 31 | if (bufsize > 0 && (mntsize = getfsstat(mntbuf, bufsize, flags)) < 0) |
e5afe6d2 KM |
32 | return (0); |
33 | while (bufsize <= mntsize * sizeof(struct statfs)) { | |
34 | if (mntbuf) | |
35 | free(mntbuf); | |
36 | bufsize = (mntsize + 1) * sizeof(struct statfs); | |
37 | if ((mntbuf = (struct statfs *)malloc(bufsize)) == 0) | |
38 | return (0); | |
e14902d3 | 39 | if ((mntsize = getfsstat(mntbuf, bufsize, flags)) < 0) |
e5afe6d2 KM |
40 | return (0); |
41 | } | |
42 | *mntbufp = mntbuf; | |
43 | return (mntsize); | |
44 | } |