1*02cdd248Schristos /* $NetBSD: compat_statvfs.c,v 1.1 2019/09/22 22:59:38 christos Exp $ */
2*02cdd248Schristos
3*02cdd248Schristos /*-
4*02cdd248Schristos * Copyright (c) 2019 The NetBSD Foundation, Inc.
5*02cdd248Schristos * All rights reserved.
6*02cdd248Schristos *
7*02cdd248Schristos * This code is derived from software contributed to The NetBSD Foundation
8*02cdd248Schristos * by Christos Zoulas
9*02cdd248Schristos *
10*02cdd248Schristos * Redistribution and use in source and binary forms, with or without
11*02cdd248Schristos * modification, are permitted provided that the following conditions
12*02cdd248Schristos * are met:
13*02cdd248Schristos * 1. Redistributions of source code must retain the above copyright
14*02cdd248Schristos * notice, this list of conditions and the following disclaimer.
15*02cdd248Schristos * 2. Redistributions in binary form must reproduce the above copyright
16*02cdd248Schristos * notice, this list of conditions and the following disclaimer in the
17*02cdd248Schristos * documentation and/or other materials provided with the distribution.
18*02cdd248Schristos *
19*02cdd248Schristos * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20*02cdd248Schristos * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21*02cdd248Schristos * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22*02cdd248Schristos * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23*02cdd248Schristos * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24*02cdd248Schristos * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25*02cdd248Schristos * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26*02cdd248Schristos * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27*02cdd248Schristos * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28*02cdd248Schristos * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29*02cdd248Schristos * POSSIBILITY OF SUCH DAMAGE.
30*02cdd248Schristos */
31*02cdd248Schristos
32*02cdd248Schristos
33*02cdd248Schristos #include <sys/cdefs.h>
34*02cdd248Schristos #if defined(LIBC_SCCS) && !defined(lint)
35*02cdd248Schristos __RCSID("$NetBSD: compat_statvfs.c,v 1.1 2019/09/22 22:59:38 christos Exp $");
36*02cdd248Schristos #endif /* LIBC_SCCS and not lint */
37*02cdd248Schristos
38*02cdd248Schristos #define __LIBC12_SOURCE__
39*02cdd248Schristos
40*02cdd248Schristos #include <stdlib.h>
41*02cdd248Schristos #include <sys/types.h>
42*02cdd248Schristos #include <sys/statvfs.h>
43*02cdd248Schristos #include <compat/include/fstypes.h>
44*02cdd248Schristos #include <compat/sys/statvfs.h>
45*02cdd248Schristos
46*02cdd248Schristos __warn_references(statvfs,
47*02cdd248Schristos "warning: reference to compatibility statvfs(); include <sys/statvfs.h> to generate correct reference")
48*02cdd248Schristos __warn_references(statvfs1,
49*02cdd248Schristos "warning: reference to compatibility statvfs1(); include <sys/statvfs.h> to generate correct reference")
50*02cdd248Schristos
51*02cdd248Schristos __warn_references(fstatvfs,
52*02cdd248Schristos "warning: reference to compatibility fstatvfs(); include <sys/statvfs.h> to generate correct reference")
53*02cdd248Schristos __warn_references(fstatvfs1,
54*02cdd248Schristos "warning: reference to compatibility fstatvfs1(); include <sys/statvfs.h> to generate correct reference")
55*02cdd248Schristos
56*02cdd248Schristos __warn_references(getvfsstat,
57*02cdd248Schristos "warning: reference to compatibility getvfsstat(); include <sys/statvfs.h> to generate correct reference")
58*02cdd248Schristos
__strong_alias(statvfs,__compat_statvfs)59*02cdd248Schristos __strong_alias(statvfs, __compat_statvfs)
60*02cdd248Schristos __strong_alias(statvfs1, __compat_statvfs1)
61*02cdd248Schristos __strong_alias(fstatvfs, __compat_fstatvfs)
62*02cdd248Schristos __strong_alias(fstatvfs1, __compat_fstatvfs1)
63*02cdd248Schristos __strong_alias(getvfsstat, __compat_getvfsstat)
64*02cdd248Schristos
65*02cdd248Schristos int
66*02cdd248Schristos __compat_statvfs(const char *path, struct statvfs90 *buf)
67*02cdd248Schristos {
68*02cdd248Schristos struct statvfs sb;
69*02cdd248Schristos int error = __statvfs190(path, &sb, 0);
70*02cdd248Schristos if (error != -1)
71*02cdd248Schristos statvfs_to_statvfs90(&sb, buf);
72*02cdd248Schristos return error;
73*02cdd248Schristos }
74*02cdd248Schristos
75*02cdd248Schristos int
__compat_statvfs1(const char * path,struct statvfs90 * buf,int flags)76*02cdd248Schristos __compat_statvfs1(const char *path, struct statvfs90 *buf, int flags)
77*02cdd248Schristos {
78*02cdd248Schristos struct statvfs sb;
79*02cdd248Schristos int error = __statvfs190(path, &sb, flags);
80*02cdd248Schristos if (error != -1)
81*02cdd248Schristos statvfs_to_statvfs90(&sb, buf);
82*02cdd248Schristos return error;
83*02cdd248Schristos }
84*02cdd248Schristos
85*02cdd248Schristos int
__compat_fstatvfs(int fd,struct statvfs90 * buf)86*02cdd248Schristos __compat_fstatvfs(int fd, struct statvfs90 *buf)
87*02cdd248Schristos {
88*02cdd248Schristos struct statvfs sb;
89*02cdd248Schristos int error = __fstatvfs190(fd, &sb, 0);
90*02cdd248Schristos if (error != -1)
91*02cdd248Schristos statvfs_to_statvfs90(&sb, buf);
92*02cdd248Schristos return error;
93*02cdd248Schristos }
94*02cdd248Schristos
95*02cdd248Schristos int
__compat_fstatvfs1(int fd,struct statvfs90 * buf,int flags)96*02cdd248Schristos __compat_fstatvfs1(int fd, struct statvfs90 *buf, int flags)
97*02cdd248Schristos {
98*02cdd248Schristos struct statvfs sb;
99*02cdd248Schristos int error = __fstatvfs190(fd, &sb, flags);
100*02cdd248Schristos if (error != -1)
101*02cdd248Schristos statvfs_to_statvfs90(&sb, buf);
102*02cdd248Schristos return error;
103*02cdd248Schristos }
104*02cdd248Schristos
105*02cdd248Schristos int
__compat_getvfsstat(struct statvfs90 * buf,size_t size,int flags)106*02cdd248Schristos __compat_getvfsstat(struct statvfs90 *buf, size_t size, int flags)
107*02cdd248Schristos {
108*02cdd248Schristos size_t count = size / sizeof(*buf);
109*02cdd248Schristos struct statvfs *sb = calloc(count, sizeof(*sb));
110*02cdd248Schristos
111*02cdd248Schristos if (sb == NULL)
112*02cdd248Schristos return -1;
113*02cdd248Schristos
114*02cdd248Schristos int error = __getvfsstat90(sb, count * sizeof(*sb), flags);
115*02cdd248Schristos if (error != -1) {
116*02cdd248Schristos for (size_t i = 0; i < count; i++)
117*02cdd248Schristos statvfs_to_statvfs90(sb + i, buf + i);
118*02cdd248Schristos }
119*02cdd248Schristos free(sb);
120*02cdd248Schristos return error;
121*02cdd248Schristos }
122