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) | |
c5980113 | 9 | static char sccsid[] = "@(#)getmntinfo.c 6.4 (Berkeley) %G%"; |
e5afe6d2 KM |
10 | #endif /* LIBC_SCCS and not lint */ |
11 | ||
12 | #include <sys/types.h> | |
13 | #include <sys/mount.h> | |
c5980113 | 14 | #include <stdlib.h> |
e5afe6d2 KM |
15 | |
16 | /* | |
17 | * Return information about mounted filesystems. | |
18 | */ | |
19 | int | |
e14902d3 | 20 | getmntinfo(mntbufp, flags) |
e5afe6d2 | 21 | struct statfs **mntbufp; |
e14902d3 | 22 | int flags; |
e5afe6d2 KM |
23 | { |
24 | static struct statfs *mntbuf; | |
c5980113 DS |
25 | static int mntsize; |
26 | static long bufsize; | |
e5afe6d2 | 27 | |
e14902d3 | 28 | if (mntsize <= 0 && (mntsize = getfsstat(0, 0, MNT_NOWAIT)) < 0) |
e5afe6d2 | 29 | return (0); |
e14902d3 | 30 | if (bufsize > 0 && (mntsize = getfsstat(mntbuf, bufsize, flags)) < 0) |
e5afe6d2 KM |
31 | return (0); |
32 | while (bufsize <= mntsize * sizeof(struct statfs)) { | |
33 | if (mntbuf) | |
34 | free(mntbuf); | |
35 | bufsize = (mntsize + 1) * sizeof(struct statfs); | |
36 | if ((mntbuf = (struct statfs *)malloc(bufsize)) == 0) | |
37 | return (0); | |
e14902d3 | 38 | if ((mntsize = getfsstat(mntbuf, bufsize, flags)) < 0) |
e5afe6d2 KM |
39 | return (0); |
40 | } | |
41 | *mntbufp = mntbuf; | |
42 | return (mntsize); | |
43 | } |