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 | |
Elliott Hughes | 06040fd | 2013-07-09 13:25:03 -0700 | [diff] [blame] | 24 | #include <sys/cdefs.h> |
Elliott Hughes | 414dd2d | 2024-10-16 14:48:30 +0000 | [diff] [blame^] | 25 | |
| 26 | #include <stdint.h> |
Elliott Hughes | 06040fd | 2013-07-09 13:25:03 -0700 | [diff] [blame] | 27 | #include <sys/types.h> |
| 28 | |
| 29 | __BEGIN_DECLS |
| 30 | |
Elliott Hughes | 3c3736e | 2023-02-21 21:15:15 +0000 | [diff] [blame] | 31 | #define __STATVFS64_BODY \ |
| 32 | /** Block size. */ \ |
| 33 | unsigned long f_bsize; \ |
| 34 | /** Fragment size. */ \ |
| 35 | unsigned long f_frsize; \ |
| 36 | /** Total size of filesystem in `f_frsize` blocks. */ \ |
| 37 | fsblkcnt_t f_blocks; \ |
| 38 | /** Number of free blocks. */ \ |
| 39 | fsblkcnt_t f_bfree; \ |
| 40 | /** Number of free blocks for non-root. */ \ |
| 41 | fsblkcnt_t f_bavail; \ |
| 42 | /** Number of inodes. */ \ |
| 43 | fsfilcnt_t f_files; \ |
| 44 | /** Number of free inodes. */ \ |
| 45 | fsfilcnt_t f_ffree; \ |
| 46 | /** Number of free inodes for non-root. */ \ |
| 47 | fsfilcnt_t f_favail; \ |
| 48 | /** Filesystem id. */ \ |
| 49 | unsigned long f_fsid; \ |
| 50 | /** Mount flags. (See `ST_` constants.) */ \ |
| 51 | unsigned long f_flag; \ |
| 52 | /** Maximum filename length. */ \ |
| 53 | unsigned long f_namemax; \ |
Elliott Hughes | 261bd74 | 2019-08-29 20:45:14 -0700 | [diff] [blame] | 54 | |
| 55 | #if defined(__LP64__) |
Elliott Hughes | 3c3736e | 2023-02-21 21:15:15 +0000 | [diff] [blame] | 56 | #define __STATVFS64_CODA uint32_t __f_reserved[6]; |
| 57 | #else |
| 58 | #define __STATVFS64_CODA |
Calin Juravle | 7bec121 | 2014-05-09 22:28:09 +0100 | [diff] [blame] | 59 | #endif |
| 60 | |
Elliott Hughes | 3c3736e | 2023-02-21 21:15:15 +0000 | [diff] [blame] | 61 | struct statvfs { __STATVFS64_BODY __STATVFS64_CODA }; |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 62 | |
Elliott Hughes | 3c3736e | 2023-02-21 21:15:15 +0000 | [diff] [blame] | 63 | struct statvfs64 { __STATVFS64_BODY __STATVFS64_CODA }; |
Elliott Hughes | 06040fd | 2013-07-09 13:25:03 -0700 | [diff] [blame] | 64 | |
Elliott Hughes | 261bd74 | 2019-08-29 20:45:14 -0700 | [diff] [blame] | 65 | /** Flag for `f_flag` in `struct statvfs`: mounted read-only. */ |
Elliott Hughes | 06040fd | 2013-07-09 13:25:03 -0700 | [diff] [blame] | 66 | #define ST_RDONLY 0x0001 |
Elliott Hughes | 261bd74 | 2019-08-29 20:45:14 -0700 | [diff] [blame] | 67 | |
| 68 | /** Flag for `f_flag` in `struct statvfs`: setuid/setgid ignored. */ |
Elliott Hughes | 06040fd | 2013-07-09 13:25:03 -0700 | [diff] [blame] | 69 | #define ST_NOSUID 0x0002 |
Elliott Hughes | 261bd74 | 2019-08-29 20:45:14 -0700 | [diff] [blame] | 70 | |
| 71 | /** Flag for `f_flag` in `struct statvfs`: access to device files disallowed. */ |
Elliott Hughes | 06040fd | 2013-07-09 13:25:03 -0700 | [diff] [blame] | 72 | #define ST_NODEV 0x0004 |
Elliott Hughes | 261bd74 | 2019-08-29 20:45:14 -0700 | [diff] [blame] | 73 | |
| 74 | /** Flag for `f_flag` in `struct statvfs`: execution disallowed. */ |
Elliott Hughes | 06040fd | 2013-07-09 13:25:03 -0700 | [diff] [blame] | 75 | #define ST_NOEXEC 0x0008 |
Elliott Hughes | 261bd74 | 2019-08-29 20:45:14 -0700 | [diff] [blame] | 76 | |
| 77 | /** Flag for `f_flag` in `struct statvfs`: writes synced immediately. */ |
Elliott Hughes | 06040fd | 2013-07-09 13:25:03 -0700 | [diff] [blame] | 78 | #define ST_SYNCHRONOUS 0x0010 |
Elliott Hughes | 261bd74 | 2019-08-29 20:45:14 -0700 | [diff] [blame] | 79 | |
| 80 | /** Flag for `f_flag` in `struct statvfs`: mandatory locking permitted. */ |
Elliott Hughes | 06040fd | 2013-07-09 13:25:03 -0700 | [diff] [blame] | 81 | #define ST_MANDLOCK 0x0040 |
Elliott Hughes | 261bd74 | 2019-08-29 20:45:14 -0700 | [diff] [blame] | 82 | |
| 83 | /** Flag for `f_flag` in `struct statvfs`: access times not updated. */ |
Elliott Hughes | 06040fd | 2013-07-09 13:25:03 -0700 | [diff] [blame] | 84 | #define ST_NOATIME 0x0400 |
Elliott Hughes | 261bd74 | 2019-08-29 20:45:14 -0700 | [diff] [blame] | 85 | |
| 86 | /** Flag for `f_flag` in `struct statvfs`: directory access times not updated. */ |
Elliott Hughes | 06040fd | 2013-07-09 13:25:03 -0700 | [diff] [blame] | 87 | #define ST_NODIRATIME 0x0800 |
Elliott Hughes | 261bd74 | 2019-08-29 20:45:14 -0700 | [diff] [blame] | 88 | |
| 89 | /** Flag for `f_flag` in `struct statvfs`: see `MS_RELATIME`. */ |
Elliott Hughes | 06040fd | 2013-07-09 13:25:03 -0700 | [diff] [blame] | 90 | #define ST_RELATIME 0x1000 |
| 91 | |
Elliott Hughes | 6711d21 | 2023-09-22 19:48:05 +0000 | [diff] [blame] | 92 | /** Flag for `f_flag` in `struct statvfs`: don't follow symlinks. */ |
| 93 | #define ST_NOSYMFOLLOW 0x2000 |
| 94 | |
Elliott Hughes | 261bd74 | 2019-08-29 20:45:14 -0700 | [diff] [blame] | 95 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 96 | * [statvfs(3)](https://man7.org/linux/man-pages/man3/statvfs.3.html) |
Elliott Hughes | 261bd74 | 2019-08-29 20:45:14 -0700 | [diff] [blame] | 97 | * queries filesystem statistics for the given path. |
| 98 | * |
| 99 | * Returns 0 on success, and returns -1 and sets `errno` on failure. |
| 100 | */ |
Elliott Hughes | 655e430 | 2023-06-16 12:39:33 -0700 | [diff] [blame] | 101 | int statvfs(const char* _Nonnull __path, struct statvfs* _Nonnull __buf); |
Elliott Hughes | 261bd74 | 2019-08-29 20:45:14 -0700 | [diff] [blame] | 102 | |
| 103 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 104 | * [fstatvfs(3)](https://man7.org/linux/man-pages/man3/fstatvfs.3.html) |
Elliott Hughes | 261bd74 | 2019-08-29 20:45:14 -0700 | [diff] [blame] | 105 | * queries filesystem statistics for the given file descriptor. |
| 106 | * |
| 107 | * Returns 0 on success, and returns -1 and sets `errno` on failure. |
| 108 | */ |
Elliott Hughes | 655e430 | 2023-06-16 12:39:33 -0700 | [diff] [blame] | 109 | int fstatvfs(int __fd, struct statvfs* _Nonnull __buf); |
Elliott Hughes | 261bd74 | 2019-08-29 20:45:14 -0700 | [diff] [blame] | 110 | |
Elliott Hughes | 3c3736e | 2023-02-21 21:15:15 +0000 | [diff] [blame] | 111 | /** Equivalent to statvfs() . */ |
Elliott Hughes | 655e430 | 2023-06-16 12:39:33 -0700 | [diff] [blame] | 112 | int statvfs64(const char* _Nonnull __path, struct statvfs64* _Nonnull __buf); |
Elliott Hughes | 261bd74 | 2019-08-29 20:45:14 -0700 | [diff] [blame] | 113 | |
| 114 | /** Equivalent to fstatvfs(). */ |
Elliott Hughes | 655e430 | 2023-06-16 12:39:33 -0700 | [diff] [blame] | 115 | int fstatvfs64(int __fd, struct statvfs64* _Nonnull __buf); |
Elliott Hughes | 06040fd | 2013-07-09 13:25:03 -0700 | [diff] [blame] | 116 | |
| 117 | __END_DECLS |