blob: fd4578cd55d4c61a29e0f73216f4938fafbee805 [file] [log] [blame]
Elliott Hughes261bd742019-08-29 20:45:14 -07001/*
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
41static __inline void __bionic_statfs_to_statvfs(const struct statfs* __in,
42 struct statvfs* __out) {
43 __out->f_bsize = __in->f_bsize;
44 __out->f_frsize = __in->f_frsize;
45 __out->f_blocks = __in->f_blocks;
46 __out->f_bfree = __in->f_bfree;
47 __out->f_bavail = __in->f_bavail;
48 __out->f_files = __in->f_files;
49 __out->f_ffree = __in->f_ffree;
50 __out->f_favail = __in->f_ffree;
51 __out->f_fsid = __in->f_fsid.__val[0] |
52 __BIONIC_CAST(static_cast, uint64_t, __in->f_fsid.__val[1]) << 32;
53 __out->f_flag = __in->f_flags;
54 __out->f_namemax = __in->f_namelen;
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