139317Smckusick /* 239317Smckusick * Copyright (c) 1989 The Regents of the University of California. 339317Smckusick * All rights reserved. 439317Smckusick * 5*42624Sbostic * %sccs.include.redist.c% 639317Smckusick */ 739317Smckusick 839317Smckusick #if defined(LIBC_SCCS) && !defined(lint) 9*42624Sbostic static char sccsid[] = "@(#)getmntinfo.c 6.3 (Berkeley) 06/01/90"; 1039317Smckusick #endif /* LIBC_SCCS and not lint */ 1139317Smckusick 1239317Smckusick #include <sys/types.h> 1339317Smckusick #include <sys/mount.h> 1439317Smckusick 1539317Smckusick /* 1639317Smckusick * Return information about mounted filesystems. 1739317Smckusick */ 1839317Smckusick int 1940336Smckusick getmntinfo(mntbufp, flags) 2039317Smckusick struct statfs **mntbufp; 2140336Smckusick int flags; 2239317Smckusick { 2339317Smckusick static struct statfs *mntbuf; 2439317Smckusick static int mntsize, bufsize; 2539317Smckusick 2640336Smckusick if (mntsize <= 0 && (mntsize = getfsstat(0, 0, MNT_NOWAIT)) < 0) 2739317Smckusick return (0); 2840336Smckusick if (bufsize > 0 && (mntsize = getfsstat(mntbuf, bufsize, flags)) < 0) 2939317Smckusick return (0); 3039317Smckusick while (bufsize <= mntsize * sizeof(struct statfs)) { 3139317Smckusick if (mntbuf) 3239317Smckusick free(mntbuf); 3339317Smckusick bufsize = (mntsize + 1) * sizeof(struct statfs); 3439317Smckusick if ((mntbuf = (struct statfs *)malloc(bufsize)) == 0) 3539317Smckusick return (0); 3640336Smckusick if ((mntsize = getfsstat(mntbuf, bufsize, flags)) < 0) 3739317Smckusick return (0); 3839317Smckusick } 3939317Smckusick *mntbufp = mntbuf; 4039317Smckusick return (mntsize); 4139317Smckusick } 42