blob: b3a0aca0cdac4c929778c3f3e085fa32b7af185c [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 Hughes3c3736e2023-02-21 21:15:15 +000020static __inline void __bionic_statfs_to_statvfs(const struct statfs* src, struct statvfs* dst) {
21 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;
29 dst->f_fsid = src->f_fsid.__val[0] | static_cast<uint64_t>(src->f_fsid.__val[1]) << 32;
30 dst->f_flag = src->f_flags;
31 dst->f_namemax = src->f_namelen;
32}
Elliott Hughes261bd742019-08-29 20:45:14 -070033
Elliott Hughes3c3736e2023-02-21 21:15:15 +000034int statvfs(const char* path, struct statvfs* result) {
35 struct statfs tmp;
36 if (statfs(path, &tmp) == -1) return -1;
37 __bionic_statfs_to_statvfs(&tmp, result);
38 return 0;
39}
40
41int fstatvfs(int fd, struct statvfs* result) {
42 struct statfs tmp;
43 if (fstatfs(fd, &tmp) == -1) return -1;
44 __bionic_statfs_to_statvfs(&tmp, result);
45 return 0;
46}
Elliott Hughes261bd742019-08-29 20:45:14 -070047
48// Historically we provided actual symbols for statvfs64 and fstatvfs64.
49// They're not particularly useful, but we can't take them away.
50__strong_alias(statvfs64, statvfs);
51__strong_alias(fstatvfs64, fstatvfs);