139317Smckusick /* 2*61111Sbostic * Copyright (c) 1989, 1993 3*61111Sbostic * The Regents of the University of California. All rights reserved. 439317Smckusick * 542624Sbostic * %sccs.include.redist.c% 639317Smckusick */ 739317Smckusick 839317Smckusick #if defined(LIBC_SCCS) && !defined(lint) 9*61111Sbostic static char sccsid[] = "@(#)getmntinfo.c 8.1 (Berkeley) 06/04/93"; 1039317Smckusick #endif /* LIBC_SCCS and not lint */ 1139317Smckusick 1251743Sbostic #include <sys/param.h> 1351743Sbostic #include <sys/ucred.h> 1439317Smckusick #include <sys/mount.h> 1546597Sdonn #include <stdlib.h> 1639317Smckusick 1739317Smckusick /* 1839317Smckusick * Return information about mounted filesystems. 1939317Smckusick */ 2039317Smckusick int getmntinfo(mntbufp,flags)2140336Smckusickgetmntinfo(mntbufp, flags) 2239317Smckusick struct statfs **mntbufp; 2340336Smckusick int flags; 2439317Smckusick { 2539317Smckusick static struct statfs *mntbuf; 2646597Sdonn static int mntsize; 2746597Sdonn static long bufsize; 2839317Smckusick 2940336Smckusick if (mntsize <= 0 && (mntsize = getfsstat(0, 0, MNT_NOWAIT)) < 0) 3039317Smckusick return (0); 3140336Smckusick if (bufsize > 0 && (mntsize = getfsstat(mntbuf, bufsize, flags)) < 0) 3239317Smckusick return (0); 3339317Smckusick while (bufsize <= mntsize * sizeof(struct statfs)) { 3439317Smckusick if (mntbuf) 3539317Smckusick free(mntbuf); 3639317Smckusick bufsize = (mntsize + 1) * sizeof(struct statfs); 3739317Smckusick if ((mntbuf = (struct statfs *)malloc(bufsize)) == 0) 3839317Smckusick return (0); 3940336Smckusick if ((mntsize = getfsstat(mntbuf, bufsize, flags)) < 0) 4039317Smckusick return (0); 4139317Smckusick } 4239317Smckusick *mntbufp = mntbuf; 4339317Smckusick return (mntsize); 4439317Smckusick } 45