1*c8863f45Schristos /* $NetBSD: compat_statfs.c,v 1.9 2019/10/04 01:28:03 christos Exp $ */
25b84b398Schristos
35b84b398Schristos /*-
402cdd248Schristos * Copyright (c) 2004, 2019 The NetBSD Foundation, Inc.
55b84b398Schristos * All rights reserved.
65b84b398Schristos *
75b84b398Schristos * This code is derived from software contributed to The NetBSD Foundation
85b84b398Schristos * by Christos Zoulas.
95b84b398Schristos *
105b84b398Schristos * Redistribution and use in source and binary forms, with or without
115b84b398Schristos * modification, are permitted provided that the following conditions
125b84b398Schristos * are met:
135b84b398Schristos * 1. Redistributions of source code must retain the above copyright
145b84b398Schristos * notice, this list of conditions and the following disclaimer.
155b84b398Schristos * 2. Redistributions in binary form must reproduce the above copyright
165b84b398Schristos * notice, this list of conditions and the following disclaimer in the
175b84b398Schristos * documentation and/or other materials provided with the distribution.
185b84b398Schristos *
195b84b398Schristos * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
205b84b398Schristos * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
215b84b398Schristos * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
225b84b398Schristos * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
235b84b398Schristos * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
245b84b398Schristos * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
255b84b398Schristos * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
265b84b398Schristos * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
275b84b398Schristos * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
285b84b398Schristos * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
295b84b398Schristos * POSSIBILITY OF SUCH DAMAGE.
305b84b398Schristos */
315b84b398Schristos
325b84b398Schristos #include <sys/cdefs.h>
335b84b398Schristos #if defined(LIBC_SCCS) && !defined(lint)
34*c8863f45Schristos __RCSID("$NetBSD: compat_statfs.c,v 1.9 2019/10/04 01:28:03 christos Exp $");
355b84b398Schristos #endif /* LIBC_SCCS and not lint */
365b84b398Schristos
375b84b398Schristos #define __LIBC12_SOURCE__
385b84b398Schristos
395b84b398Schristos #include "namespace.h"
405b84b398Schristos #include <sys/types.h>
415b84b398Schristos #include <sys/param.h>
425b84b398Schristos #include <sys/mount.h>
435b84b398Schristos #include <compat/sys/mount.h>
44b4cb63a6Smartin #include <compat/include/fstypes.h>
4502cdd248Schristos #include <compat/sys/statvfs.h>
465b84b398Schristos #include <string.h>
475b84b398Schristos #include <stdlib.h>
485b84b398Schristos
495b84b398Schristos __warn_references(statfs,
505b84b398Schristos "warning: reference to obsolete statfs(); use statvfs()")
515b84b398Schristos
525b84b398Schristos __warn_references(fstatfs,
535b84b398Schristos "warning: reference to obsolete fstatfs(); use fstatvfs()")
545b84b398Schristos
555b84b398Schristos __warn_references(fhstatfs,
565b84b398Schristos "warning: reference to obsolete fhstatfs(); use fhstatvfs()")
575b84b398Schristos
585b84b398Schristos __warn_references(getfsstat,
595b84b398Schristos "warning: reference to obsolete getfsstat(); use getvfsstat()")
605b84b398Schristos
__strong_alias(statfs,__compat_statfs)61fda5f877Schristos __strong_alias(statfs, __compat_statfs)
62fda5f877Schristos __strong_alias(fstatfs, __compat_fstatfs)
63fda5f877Schristos __strong_alias(fhstatfs, __compat_fhstatfs)
64fda5f877Schristos __strong_alias(getfsstat, __compat_getfsstat)
65ca2d95d1Schristos
665b84b398Schristos int
67fda5f877Schristos __compat_statfs(const char *file, struct statfs12 *ost)
685b84b398Schristos {
695b84b398Schristos struct statvfs nst;
705b84b398Schristos int ret;
715b84b398Schristos
7202cdd248Schristos if ((ret = __statvfs90(file, &nst)) == -1)
735b84b398Schristos return ret;
74*c8863f45Schristos statvfs_to_statfs12(&nst, ost);
755b84b398Schristos return ret;
765b84b398Schristos }
775b84b398Schristos
785b84b398Schristos int
__compat_fstatfs(int f,struct statfs12 * ost)79fda5f877Schristos __compat_fstatfs(int f, struct statfs12 *ost)
805b84b398Schristos {
815b84b398Schristos struct statvfs nst;
825b84b398Schristos int ret;
835b84b398Schristos
8402cdd248Schristos if ((ret = __fstatvfs90(f, &nst)) == -1)
855b84b398Schristos return ret;
86*c8863f45Schristos statvfs_to_statfs12(&nst, ost);
875b84b398Schristos return ret;
885b84b398Schristos }
895b84b398Schristos
905b84b398Schristos int
__compat_fhstatfs(const struct compat_30_fhandle * fh,struct statfs12 * ost)91fda5f877Schristos __compat_fhstatfs(const struct compat_30_fhandle *fh, struct statfs12 *ost)
925b84b398Schristos {
935b84b398Schristos struct statvfs nst;
945b84b398Schristos int ret;
955b84b398Schristos
9602cdd248Schristos if ((ret = __fhstatvfs190(fh, FHANDLE30_SIZE, &nst, ST_WAIT)) == -1)
975b84b398Schristos return ret;
98*c8863f45Schristos statvfs_to_statfs12(&nst, ost);
995b84b398Schristos return ret;
1005b84b398Schristos }
1015b84b398Schristos
1025b84b398Schristos int
__compat_getfsstat(struct statfs12 * ost,long size,int flags)103fda5f877Schristos __compat_getfsstat(struct statfs12 *ost, long size, int flags)
1045b84b398Schristos {
1055b84b398Schristos struct statvfs *nst;
1065b84b398Schristos int ret, i;
1075b84b398Schristos size_t bsize = (size_t)(size / sizeof(*ost)) * sizeof(*nst);
1085b84b398Schristos
1095b84b398Schristos if (ost != NULL) {
1105b84b398Schristos if ((nst = malloc(bsize)) == NULL)
1115b84b398Schristos return -1;
1125b84b398Schristos } else
1135b84b398Schristos nst = NULL;
1145b84b398Schristos
11502cdd248Schristos if ((ret = __getvfsstat90(nst, bsize, flags)) == -1)
1165b84b398Schristos goto done;
1175b84b398Schristos if (nst)
1185b84b398Schristos for (i = 0; i < ret; i++)
119*c8863f45Schristos statvfs_to_statfs12(&nst[i], &ost[i]);
1205b84b398Schristos done:
1215b84b398Schristos if (nst)
1225b84b398Schristos free(nst);
1235b84b398Schristos return ret;
1245b84b398Schristos }
125