]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/statvfs.3
err.3: EXAMPLES: use EXIT_FAILURE rather than 1 as exit status
[thirdparty/man-pages.git] / man3 / statvfs.3
1 .\" Copyright (C) 2003 Andries Brouwer (aeb@cwi.nl)
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .\" The pathconf note is from Walter Harms
26 .\" This is not a system call on Linux
27 .\"
28 .\" Modified 2004-06-23 by Michael Kerrisk <mtk.manpages@gmail.com>
29 .\"
30 .TH STATVFS 3 2017-09-15 "Linux" "Linux Programmer's Manual"
31 .SH NAME
32 statvfs, fstatvfs \- get filesystem statistics
33 .SH SYNOPSIS
34 .B #include <sys/statvfs.h>
35 .PP
36 .BI "int statvfs(const char *" path ", struct statvfs *" buf );
37 .br
38 .BI "int fstatvfs(int " fd ", struct statvfs *" buf );
39 .SH DESCRIPTION
40 The function
41 .BR statvfs ()
42 returns information about a mounted filesystem.
43 .I path
44 is the pathname of any file within the mounted filesystem.
45 .I buf
46 is a pointer to a
47 .I statvfs
48 structure defined approximately as follows:
49 .PP
50 .in +4n
51 .EX
52 struct statvfs {
53 unsigned long f_bsize; /* Filesystem block size */
54 unsigned long f_frsize; /* Fragment size */
55 fsblkcnt_t f_blocks; /* Size of fs in f_frsize units */
56 fsblkcnt_t f_bfree; /* Number of free blocks */
57 fsblkcnt_t f_bavail; /* Number of free blocks for
58 unprivileged users */
59 fsfilcnt_t f_files; /* Number of inodes */
60 fsfilcnt_t f_ffree; /* Number of free inodes */
61 fsfilcnt_t f_favail; /* Number of free inodes for
62 unprivileged users */
63 unsigned long f_fsid; /* Filesystem ID */
64 unsigned long f_flag; /* Mount flags */
65 unsigned long f_namemax; /* Maximum filename length */
66 };
67 .EE
68 .in
69 .PP
70 Here the types
71 .I fsblkcnt_t
72 and
73 .I fsfilcnt_t
74 are defined in
75 .IR <sys/types.h> .
76 Both used to be
77 .IR "unsigned long" .
78 .PP
79 The field
80 .I f_flag
81 is a bit mask indicating various options that were employed
82 when mounting this filesystem.
83 It contains zero or more of the following flags:
84 .\" XXX Keep this list in sync with statfs(2)
85 .TP
86 .B ST_MANDLOCK
87 Mandatory locking is permitted on the filesystem (see
88 .BR fcntl (2)).
89 .TP
90 .B ST_NOATIME
91 Do not update access times; see
92 .BR mount (2).
93 .TP
94 .B ST_NODEV
95 Disallow access to device special files on this filesystem.
96 .TP
97 .B ST_NODIRATIME
98 Do not update directory access times; see
99 .BR mount (2).
100 .TP
101 .B ST_NOEXEC
102 Execution of programs is disallowed on this filesystem.
103 .TP
104 .B ST_NOSUID
105 The set-user-ID and set-group-ID bits are ignored by
106 .BR exec (3)
107 for executable files on this filesystem
108 .TP
109 .B ST_RDONLY
110 This filesystem is mounted read-only.
111 .TP
112 .B ST_RELATIME
113 Update atime relative to mtime/ctime; see
114 .BR mount (2).
115 .TP
116 .B ST_SYNCHRONOUS
117 Writes are synched to the filesystem immediately (see the description of
118 .B O_SYNC
119 in
120 .BR open (2)).
121 .PP
122 It is unspecified whether all members of the returned struct
123 have meaningful values on all filesystems.
124 .PP
125 .BR fstatvfs ()
126 returns the same information about an open file referenced by descriptor
127 .IR fd .
128 .SH RETURN VALUE
129 On success, zero is returned.
130 On error, \-1 is returned, and
131 .I errno
132 is set appropriately.
133 .SH ERRORS
134 .TP
135 .B EACCES
136 .RB ( statvfs ())
137 Search permission is denied for a component of the path prefix of
138 .IR path .
139 (See also
140 .BR path_resolution (7).)
141 .TP
142 .B EBADF
143 .RB ( fstatvfs ())
144 .I fd
145 is not a valid open file descriptor.
146 .TP
147 .B EFAULT
148 .I Buf
149 or
150 .I path
151 points to an invalid address.
152 .TP
153 .B EINTR
154 This call was interrupted by a signal; see
155 .BR signal (7).
156 .TP
157 .B EIO
158 An I/O error occurred while reading from the filesystem.
159 .TP
160 .B ELOOP
161 .RB ( statvfs ())
162 Too many symbolic links were encountered in translating
163 .IR path .
164 .TP
165 .B ENAMETOOLONG
166 .RB ( statvfs ())
167 .I path
168 is too long.
169 .TP
170 .B ENOENT
171 .RB ( statvfs ())
172 The file referred to by
173 .I path
174 does not exist.
175 .TP
176 .B ENOMEM
177 Insufficient kernel memory was available.
178 .TP
179 .B ENOSYS
180 The filesystem does not support this call.
181 .TP
182 .B ENOTDIR
183 .RB ( statvfs ())
184 A component of the path prefix of
185 .I path
186 is not a directory.
187 .TP
188 .B EOVERFLOW
189 Some values were too large to be represented in the returned struct.
190 .SH ATTRIBUTES
191 For an explanation of the terms used in this section, see
192 .BR attributes (7).
193 .TS
194 allbox;
195 lbw21 lb lb
196 l l l.
197 Interface Attribute Value
198 T{
199 .BR statvfs (),
200 .BR fstatvfs ()
201 T} Thread safety MT-Safe
202 .TE
203 .SH CONFORMING TO
204 POSIX.1-2001, POSIX.1-2008.
205 .PP
206 Only the
207 .B ST_NOSUID
208 and
209 .B ST_RDONLY
210 flags of the
211 .I f_flag
212 field are specified in POSIX.1.
213 To obtain definitions of the remaining flags, one must define
214 .BR _GNU_SOURCE .
215 .SH NOTES
216 The Linux kernel has system calls
217 .BR statfs (2)
218 and
219 .BR fstatfs (2)
220 to support this library call.
221 .PP
222 In glibc versions before 2.13,
223 .\" glibc commit 3cdaa6adb113a088fdfb87aa6d7747557eccc58d
224 .BR statvfs ()
225 populated the bits of the
226 .IR f_flag
227 field by scanning the mount options shown in
228 .IR /proc/mounts .
229 However, starting with Linux 2.6.36, the underlying
230 .BR statfs (2)
231 system call provides the necessary information via the
232 .IR f_flags
233 field, and since glibc version 2.13, the
234 .BR statvfs ()
235 function will use information from that field rather than scanning
236 .IR /proc/mounts .
237 .PP
238 The glibc implementations of
239 .PP
240 .in +4n
241 .EX
242 pathconf(path, _PC_REC_XFER_ALIGN);
243 pathconf(path, _PC_ALLOC_SIZE_MIN);
244 pathconf(path, _PC_REC_MIN_XFER_SIZE);
245 .EE
246 .in
247 .PP
248 respectively use the
249 .IR f_frsize ,
250 .IR f_frsize ,
251 and
252 .I f_bsize
253 fields returned by a call to
254 .BR statvfs ()
255 with the argument
256 .IR path .
257 .SH SEE ALSO
258 .BR statfs (2)