blob: d78de2ddcb0a894c6cd24d4ba6cd4204cf8b93b5 [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
17#include <sys/statfs.h>
18
19// Paper over the fact that 32-bit kernels use fstatfs64/statfs64 with
20// an extra argument, but 64-bit kernels don't have the "64" bit suffix or
21// the extra size_t argument.
22#if defined(__LP64__)
23extern "C" int __fstatfs(int, struct statfs*);
24extern "C" int __statfs(const char*, struct statfs*);
25# define __fstatfs64(fd,size,buf) __fstatfs(fd,buf)
26# define __statfs64(path,size,buf) __statfs(path,buf)
27#else
28extern "C" int __fstatfs64(int, size_t, struct statfs*);
29extern "C" int __statfs64(const char*, size_t, struct statfs*);
30#endif
31
32// The kernel sets a private ST_VALID flag to signal to the C library
33// whether the f_flags field is valid. This flag should not be exposed to
34// users of the C library.
35#define ST_VALID 0x0020
36
37int fstatfs(int fd, struct statfs* result) {
38 int rc = __fstatfs64(fd, sizeof(*result), result);
39 if (rc != 0) {
40 return rc;
41 }
42 result->f_flags &= ~ST_VALID;
43 return 0;
44}
45__strong_alias(fstatfs64, fstatfs);
46
47int statfs(const char* path, struct statfs* result) {
48 int rc = __statfs64(path, sizeof(*result), result);
49 if (rc != 0) {
50 return rc;
51 }
52 result->f_flags &= ~ST_VALID;
53 return 0;
54}
55__strong_alias(statfs64, statfs);