xref: /freebsd-13.1/lib/libc/sys/statfs.2 (revision 578d29dd)
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. All advertising materials mentioning features or use of this software
13.\"    must display the following acknowledgement:
14.\"	This product includes software developed by the University of
15.\"	California, Berkeley and its contributors.
16.\" 4. Neither the name of the University nor the names of its contributors
17.\"    may be used to endorse or promote products derived from this software
18.\"    without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.\"	@(#)statfs.2	8.5 (Berkeley) 5/24/95
33.\" $FreeBSD$
34.\"
35.Dd May 24, 1995
36.Dt STATFS 2
37.Os
38.Sh NAME
39.Nm statfs
40.Nd get file system statistics
41.Sh SYNOPSIS
42.Fd #include <sys/param.h>
43.Fd #include <sys/mount.h>
44.Ft int
45.Fn statfs "const char *path" "struct statfs *buf"
46.Ft int
47.Fn fstatfs "int fd" "struct statfs *buf"
48.Sh DESCRIPTION
49.Fn Statfs
50returns information about a mounted file system.
51.Fa Path
52is the path name of any file within the mounted filesystem.
53.Fa Buf
54is a pointer to a
55.Fn statfs
56structure defined as follows:
57.Bd -literal
58typedef struct fsid { int32_t val[2]; } fsid_t; /* file system id type */
59
60/*
61 * file system statistics
62 */
63
64#define MFSNAMELEN 16	/* length of fs type name, including null */
65#define MNAMELEN   90	/* length of buffer for returned name */
66
67struct statfs {
68long	f_spare2;	  /* placeholder */
69long	f_bsize;	  /* fundamental file system block size */
70long	f_iosize;	  /* optimal transfer block size */
71long	f_blocks;	  /* total data blocks in file system */
72long	f_bfree;	  /* free blocks in fs */
73long	f_bavail;	  /* free blocks avail to non-superuser */
74long	f_files;	  /* total file nodes in file system */
75long	f_ffree;	  /* free file nodes in fs */
76fsid_t	f_fsid;		  /* file system id */
77uid_t	f_owner;	  /* user that mounted the filesystem */
78int	f_type;		  /* type of filesystem (see below) */
79int	f_flags;	  /* copy of mount flags */
80long    f_syncwrites;	  /* count of sync writes since mount */
81long    f_asyncwrites;	  /* count of async writes since mount */
82char	f_fstypename[MFSNAMELEN];/* fs type name */
83char	f_mntonname[MNAMELEN];	  /* mount point */
84char	f_mntfromname[MNAMELEN];  /* mounted filesystem */
85};
86.Ed
87The flags that may be returned include:
88.Bl -tag -width MNT_ASYNCHRONOUS
89.It Dv MNT_RDONLY
90The filesystem is mounted read-only;
91Even the super-user may not write on it.
92.It Dv MNT_NOEXEC
93Files may not be executed from the filesystem.
94.It Dv MNT_NOSUID
95Setuid and setgid bits on files are not honored when they are executed.
96.It Dv MNT_NODEV
97Special files in the filesystem may not be opened.
98.It Dv MNT_SYNCHRONOUS
99All I/O to the filesystem is done synchronously.
100.It Dv MNT_ASYNCHRONOUS
101No filesystem I/O is done synchronously.
102.It Dv MNT_LOCAL
103The filesystem resides locally.
104.It Dv MNT_QUOTA
105The filesystem has quotas enabled on it.
106.It Dv MNT_ROOTFS
107Identifies the root filesystem.
108.It Dv MNT_EXRDONLY
109The filesystem is exported read-only.
110.It Dv MNT_EXPORTED
111The filesystem is exported for both reading and writing.
112.It Dv MNT_DEFEXPORTED
113The filesystem is exported for both reading and writing to any Internet host.
114.It Dv MNT_EXPORTANON
115The filesystem maps all remote accesses to the anonymous user.
116.It Dv MNT_EXKERB
117The filesystem is exported with Kerberos uid mapping.
118.El
119.Pp
120Fields that are undefined for a particular file system are set to -1.
121.Fn Fstatfs
122returns the same information about an open file referenced by descriptor
123.Fa fd .
124.Sh RETURN VALUES
125Upon successful completion, a value of 0 is returned.
126Otherwise, -1 is returned and the global variable
127.Va errno
128is set to indicate the error.
129.Sh ERRORS
130.Fn Statfs
131fails if one or more of the following are true:
132.Bl -tag -width ENAMETOOLONGA
133.It Bq Er ENOTDIR
134A component of the path prefix of
135.Fa Path
136is not a directory.
137.It Bq Er ENAMETOOLONG
138The length of a component of
139.Fa path
140exceeds 255 characters,
141or the length of
142.Fa path
143exceeds 1023 characters.
144.It Bq Er ENOENT
145The file referred to by
146.Fa path
147does not exist.
148.It Bq Er EACCES
149Search permission is denied for a component of the path prefix of
150.Fa path .
151.It Bq Er ELOOP
152Too many symbolic links were encountered in translating
153.Fa path .
154.It Bq Er EFAULT
155.Fa Buf
156or
157.Fa path
158points to an invalid address.
159.It Bq Er EIO
160An
161.Tn I/O
162error occurred while reading from or writing to the file system.
163.El
164.Pp
165.Fn Fstatfs
166fails if one or more of the following are true:
167.Bl -tag -width ENAMETOOLONGA
168.It Bq Er EBADF
169.Fa Fd
170is not a valid open file descriptor.
171.It Bq Er EFAULT
172.Fa Buf
173points to an invalid address.
174.It Bq Er EIO
175An
176.Tn I/O
177error occurred while reading from or writing to the file system.
178.El
179.Sh HISTORY
180The
181.Fn statfs
182function first appeared in
183.Bx 4.4 .
184