blob: 2feca81e78b1f2ec907d4e562935f8a404511cee [file] [log] [blame]
Elliott Hughes06040fd2013-07-09 13:25:03 -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 Hughes261bd742019-08-29 20:45:14 -070017#pragma once
18
19/**
20 * @file sys/statvfs.h
21 * @brief Filesystem statistics.
22 */
Elliott Hughes06040fd2013-07-09 13:25:03 -070023
24#include <stdint.h>
25#include <sys/cdefs.h>
26#include <sys/types.h>
27
28__BEGIN_DECLS
29
Elliott Hughes3c3736e2023-02-21 21:15:15 +000030#define __STATVFS64_BODY \
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; \
Elliott Hughes261bd742019-08-29 20:45:14 -070053
54#if defined(__LP64__)
Elliott Hughes3c3736e2023-02-21 21:15:15 +000055#define __STATVFS64_CODA uint32_t __f_reserved[6];
56#else
57#define __STATVFS64_CODA
Calin Juravle7bec1212014-05-09 22:28:09 +010058#endif
59
Elliott Hughes3c3736e2023-02-21 21:15:15 +000060struct statvfs { __STATVFS64_BODY __STATVFS64_CODA };
Elliott Hughesdb1ea342014-01-17 18:42:49 -080061
Elliott Hughes3c3736e2023-02-21 21:15:15 +000062struct statvfs64 { __STATVFS64_BODY __STATVFS64_CODA };
Elliott Hughes06040fd2013-07-09 13:25:03 -070063
Elliott Hughes261bd742019-08-29 20:45:14 -070064/** Flag for `f_flag` in `struct statvfs`: mounted read-only. */
Elliott Hughes06040fd2013-07-09 13:25:03 -070065#define ST_RDONLY 0x0001
Elliott Hughes261bd742019-08-29 20:45:14 -070066
67/** Flag for `f_flag` in `struct statvfs`: setuid/setgid ignored. */
Elliott Hughes06040fd2013-07-09 13:25:03 -070068#define ST_NOSUID 0x0002
Elliott Hughes261bd742019-08-29 20:45:14 -070069
70/** Flag for `f_flag` in `struct statvfs`: access to device files disallowed. */
Elliott Hughes06040fd2013-07-09 13:25:03 -070071#define ST_NODEV 0x0004
Elliott Hughes261bd742019-08-29 20:45:14 -070072
73/** Flag for `f_flag` in `struct statvfs`: execution disallowed. */
Elliott Hughes06040fd2013-07-09 13:25:03 -070074#define ST_NOEXEC 0x0008
Elliott Hughes261bd742019-08-29 20:45:14 -070075
76/** Flag for `f_flag` in `struct statvfs`: writes synced immediately. */
Elliott Hughes06040fd2013-07-09 13:25:03 -070077#define ST_SYNCHRONOUS 0x0010
Elliott Hughes261bd742019-08-29 20:45:14 -070078
79/** Flag for `f_flag` in `struct statvfs`: mandatory locking permitted. */
Elliott Hughes06040fd2013-07-09 13:25:03 -070080#define ST_MANDLOCK 0x0040
Elliott Hughes261bd742019-08-29 20:45:14 -070081
82/** Flag for `f_flag` in `struct statvfs`: access times not updated. */
Elliott Hughes06040fd2013-07-09 13:25:03 -070083#define ST_NOATIME 0x0400
Elliott Hughes261bd742019-08-29 20:45:14 -070084
85/** Flag for `f_flag` in `struct statvfs`: directory access times not updated. */
Elliott Hughes06040fd2013-07-09 13:25:03 -070086#define ST_NODIRATIME 0x0800
Elliott Hughes261bd742019-08-29 20:45:14 -070087
88/** Flag for `f_flag` in `struct statvfs`: see `MS_RELATIME`. */
Elliott Hughes06040fd2013-07-09 13:25:03 -070089#define ST_RELATIME 0x1000
90
Elliott Hughes6711d212023-09-22 19:48:05 +000091/** Flag for `f_flag` in `struct statvfs`: don't follow symlinks. */
92#define ST_NOSYMFOLLOW 0x2000
93
Elliott Hughes261bd742019-08-29 20:45:14 -070094/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +000095 * [statvfs(3)](https://man7.org/linux/man-pages/man3/statvfs.3.html)
Elliott Hughes261bd742019-08-29 20:45:14 -070096 * queries filesystem statistics for the given path.
97 *
98 * Returns 0 on success, and returns -1 and sets `errno` on failure.
99 */
Elliott Hughes655e4302023-06-16 12:39:33 -0700100int statvfs(const char* _Nonnull __path, struct statvfs* _Nonnull __buf);
Elliott Hughes261bd742019-08-29 20:45:14 -0700101
102/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +0000103 * [fstatvfs(3)](https://man7.org/linux/man-pages/man3/fstatvfs.3.html)
Elliott Hughes261bd742019-08-29 20:45:14 -0700104 * queries filesystem statistics for the given file descriptor.
105 *
106 * Returns 0 on success, and returns -1 and sets `errno` on failure.
107 */
Elliott Hughes655e4302023-06-16 12:39:33 -0700108int fstatvfs(int __fd, struct statvfs* _Nonnull __buf);
Elliott Hughes261bd742019-08-29 20:45:14 -0700109
Elliott Hughes3c3736e2023-02-21 21:15:15 +0000110/** Equivalent to statvfs() . */
Elliott Hughes655e4302023-06-16 12:39:33 -0700111int statvfs64(const char* _Nonnull __path, struct statvfs64* _Nonnull __buf);
Elliott Hughes261bd742019-08-29 20:45:14 -0700112
113/** Equivalent to fstatvfs(). */
Elliott Hughes655e4302023-06-16 12:39:33 -0700114int fstatvfs64(int __fd, struct statvfs64* _Nonnull __buf);
Elliott Hughes06040fd2013-07-09 13:25:03 -0700115
116__END_DECLS