1330567Sgordon/* $NetBSD: compat_getmntinfo.c,v 1.3 2013/10/04 20:49:16 christos Exp $ */ 2275970Scy 3275970Scy/* 4275970Scy * Copyright (c) 1989, 1993 5275970Scy * The Regents of the University of California. All rights reserved. 6330567Sgordon * 7275970Scy * Redistribution and use in source and binary forms, with or without 8275970Scy * modification, are permitted provided that the following conditions 9275970Scy * are met: 10275970Scy * 1. Redistributions of source code must retain the above copyright 11275970Scy * notice, this list of conditions and the following disclaimer. 12275970Scy * 2. Redistributions in binary form must reproduce the above copyright 13275970Scy * notice, this list of conditions and the following disclaimer in the 14275970Scy * documentation and/or other materials provided with the distribution. 15275970Scy * 3. Neither the name of the University nor the names of its contributors 16275970Scy * may be used to endorse or promote products derived from this software 17275970Scy * without specific prior written permission. 18275970Scy * 19275970Scy * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20275970Scy * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21275970Scy * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22275970Scy * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23275970Scy * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24275970Scy * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25275970Scy * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26275970Scy * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27275970Scy * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28275970Scy * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29275970Scy * SUCH DAMAGE. 30275970Scy */ 31275970Scy 32275970Scy#include <sys/cdefs.h> 33275970Scy#if defined(LIBC_SCCS) && !defined(lint) 34275970Scy#if 0 35275970Scystatic char sccsid[] = "@(#)getmntinfo.c 8.1 (Berkeley) 6/4/93"; 36275970Scy#else 37275970Scy__RCSID("$NetBSD: compat_getmntinfo.c,v 1.3 2013/10/04 20:49:16 christos Exp $"); 38275970Scy#endif 39275970Scy#endif /* LIBC_SCCS and not lint */ 40275970Scy 41275970Scy#define __LIBC12_SOURCE__ 42275970Scy 43275970Scy#include "namespace.h" 44275970Scy#include <sys/param.h> 45275970Scy#include <sys/ucred.h> 46275970Scy#include <sys/mount.h> 47275970Scy#include <compat/sys/mount.h> 48275970Scy 49275970Scy#include <assert.h> 50275970Scy#include <errno.h> 51275970Scy#include <stdlib.h> 52275970Scy 53275970Scy__strong_alias(getmntinfo, __compat_getmntinfo) 54275970Scy 55275970Scy/* 56275970Scy * Return information about mounted filesystems. 57275970Scy */ 58275970Scyint 59275970Scy__compat_getmntinfo(struct statfs12 **mntbufp, int flags) 60275970Scy{ 61275970Scy static struct statfs12 *mntbuf; 62275970Scy static int mntsize; 63275970Scy static size_t bufsize; 64275970Scy 65275970Scy _DIAGASSERT(mntbufp != NULL); 66275970Scy 67275970Scy if (mntsize <= 0 && 68275970Scy (mntsize = __compat_getfsstat(NULL, 0L, MNT_NOWAIT)) == -1) 69275970Scy return (0); 70275970Scy if (bufsize > 0 && 71275970Scy (mntsize = __compat_getfsstat(mntbuf, (long)bufsize, flags)) == -1) 72275970Scy return (0); 73275970Scy while (bufsize <= mntsize * sizeof(struct statfs12)) { 74275970Scy if (mntbuf) 75275970Scy free(mntbuf); 76275970Scy bufsize = (mntsize + 1) * sizeof(struct statfs12); 77275970Scy if ((mntbuf = malloc(bufsize)) == NULL) 78275970Scy return (0); 79275970Scy if ((mntsize = __compat_getfsstat(mntbuf, (long)bufsize, 80275970Scy flags)) == -1) 81275970Scy return (0); 82275970Scy } 83275970Scy *mntbufp = mntbuf; 84275970Scy return (mntsize); 85275970Scy} 86275970Scy