blob: 860824bd4cfb174c7e68f1832e2ff0d110207147 [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
Elliott Hughes06040fd2013-07-09 13:25:03 -070024#include <sys/cdefs.h>
Elliott Hughes414dd2d2024-10-16 14:48:30 +000025
26#include <stdint.h>
Elliott Hughes06040fd2013-07-09 13:25:03 -070027#include <sys/types.h>
28
29__BEGIN_DECLS
30
Elliott Hughes3c3736e2023-02-21 21:15:15 +000031#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 Hughes261bd742019-08-29 20:45:14 -070054
55#if defined(__LP64__)
Elliott Hughes3c3736e2023-02-21 21:15:15 +000056#define __STATVFS64_CODA uint32_t __f_reserved[6];
57#else
58#define __STATVFS64_CODA
Calin Juravle7bec1212014-05-09 22:28:09 +010059#endif
60
Elliott Hughes3c3736e2023-02-21 21:15:15 +000061struct statvfs { __STATVFS64_BODY __STATVFS64_CODA };
Elliott Hughesdb1ea342014-01-17 18:42:49 -080062
Elliott Hughes3c3736e2023-02-21 21:15:15 +000063struct statvfs64 { __STATVFS64_BODY __STATVFS64_CODA };
Elliott Hughes06040fd2013-07-09 13:25:03 -070064
Elliott Hughes261bd742019-08-29 20:45:14 -070065/** Flag for `f_flag` in `struct statvfs`: mounted read-only. */
Elliott Hughes06040fd2013-07-09 13:25:03 -070066#define ST_RDONLY 0x0001
Elliott Hughes261bd742019-08-29 20:45:14 -070067
68/** Flag for `f_flag` in `struct statvfs`: setuid/setgid ignored. */
Elliott Hughes06040fd2013-07-09 13:25:03 -070069#define ST_NOSUID 0x0002
Elliott Hughes261bd742019-08-29 20:45:14 -070070
71/** Flag for `f_flag` in `struct statvfs`: access to device files disallowed. */
Elliott Hughes06040fd2013-07-09 13:25:03 -070072#define ST_NODEV 0x0004
Elliott Hughes261bd742019-08-29 20:45:14 -070073
74/** Flag for `f_flag` in `struct statvfs`: execution disallowed. */
Elliott Hughes06040fd2013-07-09 13:25:03 -070075#define ST_NOEXEC 0x0008
Elliott Hughes261bd742019-08-29 20:45:14 -070076
77/** Flag for `f_flag` in `struct statvfs`: writes synced immediately. */
Elliott Hughes06040fd2013-07-09 13:25:03 -070078#define ST_SYNCHRONOUS 0x0010
Elliott Hughes261bd742019-08-29 20:45:14 -070079
80/** Flag for `f_flag` in `struct statvfs`: mandatory locking permitted. */
Elliott Hughes06040fd2013-07-09 13:25:03 -070081#define ST_MANDLOCK 0x0040
Elliott Hughes261bd742019-08-29 20:45:14 -070082
83/** Flag for `f_flag` in `struct statvfs`: access times not updated. */
Elliott Hughes06040fd2013-07-09 13:25:03 -070084#define ST_NOATIME 0x0400
Elliott Hughes261bd742019-08-29 20:45:14 -070085
86/** Flag for `f_flag` in `struct statvfs`: directory access times not updated. */
Elliott Hughes06040fd2013-07-09 13:25:03 -070087#define ST_NODIRATIME 0x0800
Elliott Hughes261bd742019-08-29 20:45:14 -070088
89/** Flag for `f_flag` in `struct statvfs`: see `MS_RELATIME`. */
Elliott Hughes06040fd2013-07-09 13:25:03 -070090#define ST_RELATIME 0x1000
91
Elliott Hughes6711d212023-09-22 19:48:05 +000092/** Flag for `f_flag` in `struct statvfs`: don't follow symlinks. */
93#define ST_NOSYMFOLLOW 0x2000
94
Elliott Hughes261bd742019-08-29 20:45:14 -070095/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +000096 * [statvfs(3)](https://man7.org/linux/man-pages/man3/statvfs.3.html)
Elliott Hughes261bd742019-08-29 20:45:14 -070097 * queries filesystem statistics for the given path.
98 *
99 * Returns 0 on success, and returns -1 and sets `errno` on failure.
100 */
Elliott Hughes655e4302023-06-16 12:39:33 -0700101int statvfs(const char* _Nonnull __path, struct statvfs* _Nonnull __buf);
Elliott Hughes261bd742019-08-29 20:45:14 -0700102
103/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +0000104 * [fstatvfs(3)](https://man7.org/linux/man-pages/man3/fstatvfs.3.html)
Elliott Hughes261bd742019-08-29 20:45:14 -0700105 * queries filesystem statistics for the given file descriptor.
106 *
107 * Returns 0 on success, and returns -1 and sets `errno` on failure.
108 */
Elliott Hughes655e4302023-06-16 12:39:33 -0700109int fstatvfs(int __fd, struct statvfs* _Nonnull __buf);
Elliott Hughes261bd742019-08-29 20:45:14 -0700110
Elliott Hughes3c3736e2023-02-21 21:15:15 +0000111/** Equivalent to statvfs() . */
Elliott Hughes655e4302023-06-16 12:39:33 -0700112int statvfs64(const char* _Nonnull __path, struct statvfs64* _Nonnull __buf);
Elliott Hughes261bd742019-08-29 20:45:14 -0700113
114/** Equivalent to fstatvfs(). */
Elliott Hughes655e4302023-06-16 12:39:33 -0700115int fstatvfs64(int __fd, struct statvfs64* _Nonnull __buf);
Elliott Hughes06040fd2013-07-09 13:25:03 -0700116
117__END_DECLS