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