blob: 18ee340f51137acfc2a57b65d5e8266a9cf04cff [file] [log] [blame]
Elliott Hughes261bd742019-08-29 20:45:14 -07001/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Elliott Hughes3c3736e2023-02-21 21:15:15 +000017#include <sys/statfs.h>
Elliott Hughes261bd742019-08-29 20:45:14 -070018#include <sys/statvfs.h>
19
Elliott Hughes3469e7d2024-05-15 16:06:07 +000020static inline void __bionic_statfs_to_statvfs(const struct statfs* src, struct statvfs* dst) {
Elliott Hughes3c3736e2023-02-21 21:15:15 +000021 dst->f_bsize = src->f_bsize;
22 dst->f_frsize = src->f_frsize;
23 dst->f_blocks = src->f_blocks;
24 dst->f_bfree = src->f_bfree;
25 dst->f_bavail = src->f_bavail;
26 dst->f_files = src->f_files;
27 dst->f_ffree = src->f_ffree;
28 dst->f_favail = src->f_ffree;
GuangWei Zhang566527b2024-12-16 11:08:38 +080029 dst->f_fsid = static_cast<uint64_t>(src->f_fsid.__val[0]) |
30 static_cast<uint64_t>(src->f_fsid.__val[1]) << 32;
Elliott Hughes3c3736e2023-02-21 21:15:15 +000031 dst->f_flag = src->f_flags;
32 dst->f_namemax = src->f_namelen;
33}
Elliott Hughes261bd742019-08-29 20:45:14 -070034
Elliott Hughes3c3736e2023-02-21 21:15:15 +000035int statvfs(const char* path, struct statvfs* result) {
36 struct statfs tmp;
37 if (statfs(path, &tmp) == -1) return -1;
38 __bionic_statfs_to_statvfs(&tmp, result);
39 return 0;
40}
41
42int fstatvfs(int fd, struct statvfs* result) {
43 struct statfs tmp;
44 if (fstatfs(fd, &tmp) == -1) return -1;
45 __bionic_statfs_to_statvfs(&tmp, result);
46 return 0;
47}
Elliott Hughes261bd742019-08-29 20:45:14 -070048
49// Historically we provided actual symbols for statvfs64 and fstatvfs64.
50// They're not particularly useful, but we can't take them away.
51__strong_alias(statvfs64, statvfs);
52__strong_alias(fstatvfs64, fstatvfs);