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) | |
269a7923 | 9 | static char sccsid[] = "@(#)getmntinfo.c 6.3 (Berkeley) %G%"; |
e5afe6d2 KM |
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 | |
e14902d3 | 19 | getmntinfo(mntbufp, flags) |
e5afe6d2 | 20 | struct statfs **mntbufp; |
e14902d3 | 21 | int flags; |
e5afe6d2 KM |
22 | { |
23 | static struct statfs *mntbuf; | |
24 | static int mntsize, bufsize; | |
25 | ||
e14902d3 | 26 | if (mntsize <= 0 && (mntsize = getfsstat(0, 0, MNT_NOWAIT)) < 0) |
e5afe6d2 | 27 | return (0); |
e14902d3 | 28 | if (bufsize > 0 && (mntsize = getfsstat(mntbuf, bufsize, flags)) < 0) |
e5afe6d2 KM |
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); | |
e14902d3 | 36 | if ((mntsize = getfsstat(mntbuf, bufsize, flags)) < 0) |
e5afe6d2 KM |
37 | return (0); |
38 | } | |
39 | *mntbufp = mntbuf; | |
40 | return (mntsize); | |
41 | } |