xref: /freebsd-14.2/lib/libc/sys/getfsstat.2 (revision 9b50d902)
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.\"	@(#)getfsstat.2	8.1 (Berkeley) 6/9/93
33.\"
34.Dd June 9, 1993
35.Dt GETFSSTAT 2
36.Os
37.Sh NAME
38.Nm getfsstat
39.Nd get list of all mounted filesystems
40.Sh SYNOPSIS
41.Fd #include <sys/param.h>
42.Fd #include <sys/ucred.h>
43.Fd #include <sys/mount.h>
44.Ft int
45.Fn getfsstat "struct statfs *buf" "long bufsize" "int flags"
46.Sh DESCRIPTION
47.Fn Getfsstat
48returns information about all mounted filesystems.
49.Fa Buf
50is a pointer to
51.Xr statfs
52structures defined as follows:
53.Bd -literal
54typedef quad fsid_t;
55
56#define MNAMELEN 32	/* length of buffer for returned name */
57
58struct statfs {
59    short   f_type;	/* type of filesystem (see below) */
60    short   f_flags;	/* copy of mount flags */
61    long    f_bsize;	/* fundamental filesystem block size */
62    long    f_iosize;	/* optimal transfer block size */
63    long    f_blocks;	/* total data blocks in filesystem */
64    long    f_bfree;	/* free blocks in fs */
65    long    f_bavail;	/* free blocks avail to non-superuser */
66    long    f_files;	/* total file nodes in filesystem */
67    long    f_ffree;	/* free file nodes in fs */
68    fsid_t  f_fsid;	/* filesystem id */
69    long    f_spare[6];	/* spare for later */
70    char    f_mntonname[MNAMELEN]; /* directory on which mounted */
71    char    f_mntfromname[MNAMELEN]; /* mounted filesystem */
72};
73/*
74 * File system types.
75 */
76#define	MOUNT_UFS	1
77#define	MOUNT_NFS	2
78#define	MOUNT_PC	3
79.Ed
80.Pp
81Fields that are undefined for a particular filesystem are set to -1.
82The buffer is filled with an array of
83.Fa fsstat
84structures, one for each mounted filesystem
85up to the size specified by
86.Fa bufsize .
87.Pp
88If
89.Fa buf
90is given as NULL,
91.Fn getfsstat
92returns just the number of mounted filesystems.
93.Pp
94Normally
95.Fa flags
96should be specified as
97.Dv MNT_WAIT .
98If
99.Fa flags
100is set to
101.Dv MNT_NOWAIT ,
102.Fn getfsstat
103will return the information it has available without requesting
104an update from each filesystem.
105Thus, some of the information will be out of date, but
106.Fn getfsstat
107will not block waiting for information from a filesystem that is
108unable to respond.
109.Sh RETURN VALUES
110Upon successful completion, the number of
111.Fa fsstat
112structures is returned.
113Otherwise, -1 is returned and the global variable
114.Va errno
115is set to indicate the error.
116.Sh ERRORS
117.Fn Getfsstat
118fails if one or more of the following are true:
119.Bl -tag -width Er
120.It EFAULT
121.Fa Buf
122points to an invalid address.
123.It EIO
124An
125.Tn I/O
126error occurred while reading from or writing to the filesystem.
127.El
128.Sh SEE ALSO
129.Xr statfs 2 ,
130.Xr fstab 5 ,
131.Xr mount 8
132.Sh HISTORY
133The
134.Nm getfsstat
135function first appeared in 4.4BSD.
136