Elliott Hughes | 261bd74 | 2019-08-29 20:45:14 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 The Android Open Source Project |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * * Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * * Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in |
| 12 | * the documentation and/or other materials provided with the |
| 13 | * distribution. |
| 14 | * |
| 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 16 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 17 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 18 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 19 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 21 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
| 22 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
| 23 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 24 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
| 25 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 26 | * SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | #pragma once |
| 30 | |
| 31 | #include <sys/cdefs.h> |
| 32 | #include <sys/statfs.h> |
| 33 | #include <sys/statvfs.h> |
| 34 | |
| 35 | #if defined(__BIONIC_SYS_STATVFS_INLINE) |
| 36 | |
| 37 | __BEGIN_DECLS |
| 38 | |
| 39 | #if defined(__BIONIC_NEED_STATVFS_INLINES) |
| 40 | |
Elliott Hughes | f38e8ca | 2019-11-08 13:51:12 -0800 | [diff] [blame] | 41 | static __inline void __bionic_statfs_to_statvfs(const struct statfs* __src, |
| 42 | struct statvfs* __dst) { |
| 43 | __dst->f_bsize = __src->f_bsize; |
| 44 | __dst->f_frsize = __src->f_frsize; |
| 45 | __dst->f_blocks = __src->f_blocks; |
| 46 | __dst->f_bfree = __src->f_bfree; |
| 47 | __dst->f_bavail = __src->f_bavail; |
| 48 | __dst->f_files = __src->f_files; |
| 49 | __dst->f_ffree = __src->f_ffree; |
| 50 | __dst->f_favail = __src->f_ffree; |
| 51 | __dst->f_fsid = __src->f_fsid.__val[0] | |
| 52 | __BIONIC_CAST(static_cast, uint64_t, __src->f_fsid.__val[1]) << 32; |
| 53 | __dst->f_flag = __src->f_flags; |
| 54 | __dst->f_namemax = __src->f_namelen; |
Elliott Hughes | 261bd74 | 2019-08-29 20:45:14 -0700 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | __BIONIC_SYS_STATVFS_INLINE int statvfs(const char* __path, |
| 58 | struct statvfs* __result) { |
| 59 | struct statfs __tmp; |
| 60 | int __rc = statfs(__path, &__tmp); |
| 61 | if (__rc != 0) return __rc; |
| 62 | __bionic_statfs_to_statvfs(&__tmp, __result); |
| 63 | return 0; |
| 64 | } |
| 65 | |
| 66 | __BIONIC_SYS_STATVFS_INLINE int fstatvfs(int __fd, |
| 67 | struct statvfs* __result) { |
| 68 | struct statfs __tmp; |
| 69 | int __rc = fstatfs(__fd, &__tmp); |
| 70 | if (__rc != 0) return __rc; |
| 71 | __bionic_statfs_to_statvfs(&__tmp, __result); |
| 72 | return 0; |
| 73 | } |
| 74 | |
| 75 | #endif |
| 76 | |
| 77 | #if defined(__BIONIC_NEED_STATVFS64_INLINES) |
| 78 | |
| 79 | __BIONIC_SYS_STATVFS_INLINE int statvfs64(const char* __path, |
| 80 | struct statvfs64* __result) { |
| 81 | return statvfs(__path, __BIONIC_CAST(reinterpret_cast, struct statvfs*, |
| 82 | __result)); |
| 83 | } |
| 84 | |
| 85 | __BIONIC_SYS_STATVFS_INLINE int fstatvfs64(int __fd, |
| 86 | struct statvfs64* __result) { |
| 87 | return fstatvfs(__fd, __BIONIC_CAST(reinterpret_cast, struct statvfs*, |
| 88 | __result)); |
| 89 | } |
| 90 | |
| 91 | #endif |
| 92 | |
| 93 | __END_DECLS |
| 94 | |
| 95 | #endif |