Elliott Hughes | 06040fd | 2013-07-09 13:25:03 -0700 | [diff] [blame] | 1 | /* |
| 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 Hughes | 261bd74 | 2019-08-29 20:45:14 -0700 | [diff] [blame^] | 17 | #pragma once |
| 18 | |
| 19 | /** |
| 20 | * @file sys/statvfs.h |
| 21 | * @brief Filesystem statistics. |
| 22 | */ |
Elliott Hughes | 06040fd | 2013-07-09 13:25:03 -0700 | [diff] [blame] | 23 | |
| 24 | #include <stdint.h> |
| 25 | #include <sys/cdefs.h> |
| 26 | #include <sys/types.h> |
| 27 | |
| 28 | __BEGIN_DECLS |
| 29 | |
Elliott Hughes | 261bd74 | 2019-08-29 20:45:14 -0700 | [diff] [blame^] | 30 | struct statvfs { |
| 31 | /** Block size. */ |
| 32 | unsigned long f_bsize; |
| 33 | /** Fragment size. */ |
| 34 | unsigned long f_frsize; |
| 35 | /** Total size of filesystem in `f_frsize` blocks. */ |
| 36 | fsblkcnt_t f_blocks; |
| 37 | /** Number of free blocks. */ |
| 38 | fsblkcnt_t f_bfree; |
| 39 | /** Number of free blocks for non-root. */ |
| 40 | fsblkcnt_t f_bavail; |
| 41 | /** Number of inodes. */ |
| 42 | fsfilcnt_t f_files; |
| 43 | /** Number of free inodes. */ |
| 44 | fsfilcnt_t f_ffree; |
| 45 | /** Number of free inodes for non-root. */ |
| 46 | fsfilcnt_t f_favail; |
| 47 | /** Filesystem id. */ |
| 48 | unsigned long f_fsid; |
| 49 | /** Mount flags. (See `ST_` constants.) */ |
| 50 | unsigned long f_flag; |
| 51 | /** Maximum filename length. */ |
| 52 | unsigned long f_namemax; |
| 53 | |
| 54 | #if defined(__LP64__) |
| 55 | uint32_t __f_reserved[6]; |
Calin Juravle | 7bec121 | 2014-05-09 22:28:09 +0100 | [diff] [blame] | 56 | #endif |
Elliott Hughes | 261bd74 | 2019-08-29 20:45:14 -0700 | [diff] [blame^] | 57 | }; |
Calin Juravle | 7bec121 | 2014-05-09 22:28:09 +0100 | [diff] [blame] | 58 | |
Elliott Hughes | 261bd74 | 2019-08-29 20:45:14 -0700 | [diff] [blame^] | 59 | struct statvfs64 { |
| 60 | /** Block size. */ |
| 61 | unsigned long f_bsize; |
| 62 | /** Fragment size. */ |
| 63 | unsigned long f_frsize; |
| 64 | /** Total size of filesystem in `f_frsize` blocks. */ |
| 65 | fsblkcnt_t f_blocks; |
| 66 | /** Number of free blocks. */ |
| 67 | fsblkcnt_t f_bfree; |
| 68 | /** Number of free blocks for non-root. */ |
| 69 | fsblkcnt_t f_bavail; |
| 70 | /** Number of inodes. */ |
| 71 | fsfilcnt_t f_files; |
| 72 | /** Number of free inodes. */ |
| 73 | fsfilcnt_t f_ffree; |
| 74 | /** Number of free inodes for non-root. */ |
| 75 | fsfilcnt_t f_favail; |
| 76 | /** Filesystem id. */ |
| 77 | unsigned long f_fsid; |
| 78 | /** Mount flags. (See `ST_` constants.) */ |
| 79 | unsigned long f_flag; |
| 80 | /** Maximum filename length. */ |
| 81 | unsigned long f_namemax; |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 82 | |
Elliott Hughes | 261bd74 | 2019-08-29 20:45:14 -0700 | [diff] [blame^] | 83 | #if defined(__LP64__) |
| 84 | uint32_t __f_reserved[6]; |
| 85 | #endif |
| 86 | }; |
Elliott Hughes | 06040fd | 2013-07-09 13:25:03 -0700 | [diff] [blame] | 87 | |
Elliott Hughes | 261bd74 | 2019-08-29 20:45:14 -0700 | [diff] [blame^] | 88 | /** Flag for `f_flag` in `struct statvfs`: mounted read-only. */ |
Elliott Hughes | 06040fd | 2013-07-09 13:25:03 -0700 | [diff] [blame] | 89 | #define ST_RDONLY 0x0001 |
Elliott Hughes | 261bd74 | 2019-08-29 20:45:14 -0700 | [diff] [blame^] | 90 | |
| 91 | /** Flag for `f_flag` in `struct statvfs`: setuid/setgid ignored. */ |
Elliott Hughes | 06040fd | 2013-07-09 13:25:03 -0700 | [diff] [blame] | 92 | #define ST_NOSUID 0x0002 |
Elliott Hughes | 261bd74 | 2019-08-29 20:45:14 -0700 | [diff] [blame^] | 93 | |
| 94 | /** Flag for `f_flag` in `struct statvfs`: access to device files disallowed. */ |
Elliott Hughes | 06040fd | 2013-07-09 13:25:03 -0700 | [diff] [blame] | 95 | #define ST_NODEV 0x0004 |
Elliott Hughes | 261bd74 | 2019-08-29 20:45:14 -0700 | [diff] [blame^] | 96 | |
| 97 | /** Flag for `f_flag` in `struct statvfs`: execution disallowed. */ |
Elliott Hughes | 06040fd | 2013-07-09 13:25:03 -0700 | [diff] [blame] | 98 | #define ST_NOEXEC 0x0008 |
Elliott Hughes | 261bd74 | 2019-08-29 20:45:14 -0700 | [diff] [blame^] | 99 | |
| 100 | /** Flag for `f_flag` in `struct statvfs`: writes synced immediately. */ |
Elliott Hughes | 06040fd | 2013-07-09 13:25:03 -0700 | [diff] [blame] | 101 | #define ST_SYNCHRONOUS 0x0010 |
Elliott Hughes | 261bd74 | 2019-08-29 20:45:14 -0700 | [diff] [blame^] | 102 | |
| 103 | /** Flag for `f_flag` in `struct statvfs`: mandatory locking permitted. */ |
Elliott Hughes | 06040fd | 2013-07-09 13:25:03 -0700 | [diff] [blame] | 104 | #define ST_MANDLOCK 0x0040 |
Elliott Hughes | 261bd74 | 2019-08-29 20:45:14 -0700 | [diff] [blame^] | 105 | |
| 106 | /** Flag for `f_flag` in `struct statvfs`: access times not updated. */ |
Elliott Hughes | 06040fd | 2013-07-09 13:25:03 -0700 | [diff] [blame] | 107 | #define ST_NOATIME 0x0400 |
Elliott Hughes | 261bd74 | 2019-08-29 20:45:14 -0700 | [diff] [blame^] | 108 | |
| 109 | /** Flag for `f_flag` in `struct statvfs`: directory access times not updated. */ |
Elliott Hughes | 06040fd | 2013-07-09 13:25:03 -0700 | [diff] [blame] | 110 | #define ST_NODIRATIME 0x0800 |
Elliott Hughes | 261bd74 | 2019-08-29 20:45:14 -0700 | [diff] [blame^] | 111 | |
| 112 | /** Flag for `f_flag` in `struct statvfs`: see `MS_RELATIME`. */ |
Elliott Hughes | 06040fd | 2013-07-09 13:25:03 -0700 | [diff] [blame] | 113 | #define ST_RELATIME 0x1000 |
| 114 | |
Elliott Hughes | 261bd74 | 2019-08-29 20:45:14 -0700 | [diff] [blame^] | 115 | #if __ANDROID_API__ >= 19 |
| 116 | // These functions are implemented as static inlines before API level 19. |
| 117 | |
| 118 | /** |
| 119 | * [statvfs(3)](http://man7.org/linux/man-pages/man3/statvfs.3.html) |
| 120 | * queries filesystem statistics for the given path. |
| 121 | * |
| 122 | * Returns 0 on success, and returns -1 and sets `errno` on failure. |
| 123 | */ |
Elliott Hughes | ff26a16 | 2017-08-17 22:34:21 +0000 | [diff] [blame] | 124 | int statvfs(const char* __path, struct statvfs* __buf) __INTRODUCED_IN(19); |
Elliott Hughes | 261bd74 | 2019-08-29 20:45:14 -0700 | [diff] [blame^] | 125 | |
| 126 | /** |
| 127 | * [fstatvfs(3)](http://man7.org/linux/man-pages/man3/fstatvfs.3.html) |
| 128 | * queries filesystem statistics for the given file descriptor. |
| 129 | * |
| 130 | * Returns 0 on success, and returns -1 and sets `errno` on failure. |
| 131 | */ |
Elliott Hughes | ff26a16 | 2017-08-17 22:34:21 +0000 | [diff] [blame] | 132 | int fstatvfs(int __fd, struct statvfs* __buf) __INTRODUCED_IN(19); |
Elliott Hughes | 261bd74 | 2019-08-29 20:45:14 -0700 | [diff] [blame^] | 133 | |
| 134 | #endif |
| 135 | |
| 136 | #if __ANDROID_API__ >= 21 |
| 137 | // These functions are implemented as static inlines before API level 21. |
| 138 | |
| 139 | /** Equivalent to statvfs(). */ |
| 140 | int statvfs64(const char* __path, struct statvfs64* __buf) __INTRODUCED_IN(21); |
| 141 | |
| 142 | /** Equivalent to fstatvfs(). */ |
Elliott Hughes | ff26a16 | 2017-08-17 22:34:21 +0000 | [diff] [blame] | 143 | int fstatvfs64(int __fd, struct statvfs64* __buf) __INTRODUCED_IN(21); |
Elliott Hughes | 06040fd | 2013-07-09 13:25:03 -0700 | [diff] [blame] | 144 | |
Elliott Hughes | 261bd74 | 2019-08-29 20:45:14 -0700 | [diff] [blame^] | 145 | #endif |
| 146 | |
Elliott Hughes | 06040fd | 2013-07-09 13:25:03 -0700 | [diff] [blame] | 147 | __END_DECLS |
| 148 | |
Elliott Hughes | 261bd74 | 2019-08-29 20:45:14 -0700 | [diff] [blame^] | 149 | #include <android/legacy_sys_statvfs_inlines.h> |