xref: /freebsd-13.1/lib/libc/sys/statfs.2 (revision e42b0964)
1.\" Copyright (c) 1989, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. Neither the name of the University nor the names of its contributors
13.\"    may be used to endorse or promote products derived from this software
14.\"    without specific prior written permission.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26.\" SUCH DAMAGE.
27.\"
28.\"	@(#)statfs.2	8.5 (Berkeley) 5/24/95
29.\" $FreeBSD$
30.\"
31.Dd March 30, 2020
32.Dt STATFS 2
33.Os
34.Sh NAME
35.Nm statfs
36.Nd get file system statistics
37.Sh LIBRARY
38.Lb libc
39.Sh SYNOPSIS
40.In sys/param.h
41.In sys/mount.h
42.Ft int
43.Fn statfs "const char *path" "struct statfs *buf"
44.Ft int
45.Fn fstatfs "int fd" "struct statfs *buf"
46.Sh DESCRIPTION
47The
48.Fn statfs
49system call
50returns information about a mounted file system.
51The
52.Fa path
53argument
54is the path name of any file within the mounted file system.
55The
56.Fa buf
57argument
58is a pointer to a
59.Vt statfs
60structure defined as follows:
61.Bd -literal
62typedef struct fsid { int32_t val[2]; } fsid_t; /* file system id type */
63
64/*
65 * filesystem statistics
66 */
67
68#define	MFSNAMELEN	16		/* length of type name including null */
69#define	MNAMELEN	1024		/* size of on/from name bufs */
70#define	STATFS_VERSION	0x20140518	/* current version number */
71
72struct statfs {
73uint32_t f_version;		/* structure version number */
74uint32_t f_type;		/* type of filesystem */
75uint64_t f_flags;		/* copy of mount exported flags */
76uint64_t f_bsize;		/* filesystem fragment size */
77uint64_t f_iosize;		/* optimal transfer block size */
78uint64_t f_blocks;		/* total data blocks in filesystem */
79uint64_t f_bfree;		/* free blocks in filesystem */
80int64_t	 f_bavail;		/* free blocks avail to non-superuser */
81uint64_t f_files;		/* total file nodes in filesystem */
82int64_t	 f_ffree;		/* free nodes avail to non-superuser */
83uint64_t f_syncwrites;		/* count of sync writes since mount */
84uint64_t f_asyncwrites;		/* count of async writes since mount */
85uint64_t f_syncreads;		/* count of sync reads since mount */
86uint64_t f_asyncreads;		/* count of async reads since mount */
87uint64_t f_spare[10];		/* unused spare */
88uint32_t f_namemax;		/* maximum filename length */
89uid_t	  f_owner;		/* user that mounted the filesystem */
90fsid_t	  f_fsid;		/* filesystem id */
91char	  f_charspare[80];	    /* spare string space */
92char	  f_fstypename[MFSNAMELEN]; /* filesystem type name */
93char	  f_mntfromname[MNAMELEN];  /* mounted filesystem */
94char	  f_mntonname[MNAMELEN];    /* directory on which mounted */
95};
96.Ed
97.Pp
98The flags that may be returned include:
99.Bl -tag -width MNT_SYNCHRONOUS
100.It Dv MNT_RDONLY
101The file system is mounted read-only;
102Even the super-user may not write on it.
103.It Dv MNT_NOEXEC
104Files may not be executed from the file system.
105.It Dv MNT_NOSUID
106Setuid and setgid bits on files are not honored when they are executed.
107.It Dv MNT_SYNCHRONOUS
108All I/O to the file system is done synchronously.
109.It Dv MNT_ASYNC
110No file system I/O is done synchronously.
111.It Dv MNT_SOFTDEP
112Soft updates being done (see
113.Xr ffs 7 ) .
114.It Dv MNT_GJOURNAL
115Journaling with gjournal is enabled (see
116.Xr gjournal 8 ) .
117.It Dv MNT_SUIDDIR
118Special handling of SUID bit on directories.
119.It Dv MNT_UNION
120Union with underlying file system.
121.It Dv MNT_NOSYMFOLLOW
122Symbolic links are not followed.
123.It Dv MNT_NOCLUSTERR
124Read clustering is disabled.
125.It Dv MNT_NOCLUSTERW
126Write clustering is disabled.
127.\".It Dv MNT_JAILDEVFS
128.\"XXX
129.It Dv MNT_MULTILABEL
130Mandatory Access Control (MAC) support for individual objects
131(see
132.Xr mac 4 ) .
133.It Dv MNT_ACLS
134Access Control List (ACL) support enabled.
135.It Dv MNT_LOCAL
136The file system resides locally.
137.It Dv MNT_QUOTA
138The file system has quotas enabled on it.
139.It Dv MNT_ROOTFS
140Identifies the root file system.
141.It Dv MNT_EXRDONLY
142The file system is exported read-only.
143.It Dv MNT_NOATIME
144Updating of file access times is disabled.
145.It Dv MNT_USER
146The file system has been mounted by a user.
147.\".It Dv MNT_IGNORE
148.\"XXX
149.It Dv MNT_EXPORTED
150The file system is exported for both reading and writing.
151.It Dv MNT_DEFEXPORTED
152The file system is exported for both reading and writing to any Internet host.
153.It Dv MNT_EXPORTANON
154The file system maps all remote accesses to the anonymous user.
155.It Dv MNT_EXKERB
156The file system is exported with Kerberos uid mapping.
157.It Dv MNT_EXPUBLIC
158The file system is exported publicly (WebNFS).
159.El
160.Pp
161Fields that are undefined for a particular file system are set to -1.
162The
163.Fn fstatfs
164system call
165returns the same information about an open file referenced by descriptor
166.Fa fd .
167.Sh RETURN VALUES
168.Rv -std
169.Sh ERRORS
170The
171.Fn statfs
172system call
173fails if one or more of the following are true:
174.Bl -tag -width Er
175.It Bq Er ENOTDIR
176A component of the path prefix of
177.Fa path
178is not a directory.
179.It Bq Er ENAMETOOLONG
180The length of a component of
181.Fa path
182exceeds 255 characters,
183or the length of
184.Fa path
185exceeds 1023 characters.
186.It Bq Er ENOENT
187The file referred to by
188.Fa path
189does not exist.
190.It Bq Er EACCES
191Search permission is denied for a component of the path prefix of
192.Fa path .
193.It Bq Er ELOOP
194Too many symbolic links were encountered in translating
195.Fa path .
196.It Bq Er EFAULT
197The
198.Fa buf
199or
200.Fa path
201argument
202points to an invalid address.
203.It Bq Er EIO
204An
205.Tn I/O
206error occurred while reading from or writing to the file system.
207.It Bq Er EINTEGRITY
208Corrupted data was detected while reading from the file system.
209.El
210.Pp
211The
212.Fn fstatfs
213system call
214fails if one or more of the following are true:
215.Bl -tag -width Er
216.It Bq Er EBADF
217The
218.Fa fd
219argument
220is not a valid open file descriptor.
221.It Bq Er EFAULT
222The
223.Fa buf
224argument
225points to an invalid address.
226.It Bq Er EIO
227An
228.Tn I/O
229error occurred while reading from or writing to the file system.
230.It Bq Er EINTEGRITY
231Corrupted data was detected while reading from the file system.
232.El
233.Sh SEE ALSO
234.Xr fhstatfs 2 ,
235.Xr getfsstat 2
236.Sh HISTORY
237The
238.Fn statfs
239system call first appeared in
240.Bx 4.4 .
241