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.5 (Berkeley) 11/19/91"; 10 #endif /* LIBC_SCCS and not lint */ 11 12 #include <sys/param.h> 13 #include <sys/ucred.h> 14 #include <sys/mount.h> 15 #include <stdlib.h> 16 17 /* 18 * Return information about mounted filesystems. 19 */ 20 int 21 getmntinfo(mntbufp, flags) 22 struct statfs **mntbufp; 23 int flags; 24 { 25 static struct statfs *mntbuf; 26 static int mntsize; 27 static long bufsize; 28 29 if (mntsize <= 0 && (mntsize = getfsstat(0, 0, MNT_NOWAIT)) < 0) 30 return (0); 31 if (bufsize > 0 && (mntsize = getfsstat(mntbuf, bufsize, flags)) < 0) 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); 39 if ((mntsize = getfsstat(mntbuf, bufsize, flags)) < 0) 40 return (0); 41 } 42 *mntbufp = mntbuf; 43 return (mntsize); 44 } 45