xref: /openbsd-src/lib/libc/sys/getfsstat.2 (revision b2ea75c1b17e1a9a339660e7ed45cd24946b230e)
1.\"	$OpenBSD: getfsstat.2,v 1.12 2000/03/24 19:07:49 millert Exp $
2.\"	$NetBSD: getfsstat.2,v 1.6 1995/06/29 11:40:44 cgd Exp $
3.\"
4.\" Copyright (c) 1989, 1991, 1993
5.\"	The Regents of the University of California.  All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\"    notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\"    notice, this list of conditions and the following disclaimer in the
14.\"    documentation and/or other materials provided with the distribution.
15.\" 3. All advertising materials mentioning features or use of this software
16.\"    must display the following acknowledgement:
17.\"	This product includes software developed by the University of
18.\"	California, Berkeley and its contributors.
19.\" 4. Neither the name of the University nor the names of its contributors
20.\"    may be used to endorse or promote products derived from this software
21.\"    without specific prior written permission.
22.\"
23.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33.\" SUCH DAMAGE.
34.\"
35.\"	@(#)getfsstat.2	8.1 (Berkeley) 6/9/93
36.\"
37.Dd June 9, 1993
38.Dt GETFSSTAT 2
39.Os
40.Sh NAME
41.Nm getfsstat
42.Nd get list of all mounted file systems
43.Sh SYNOPSIS
44.Fd #include <sys/param.h>
45.Fd #include <sys/mount.h>
46.Ft int
47.Fn getfsstat "struct statfs *buf" "size_t bufsize" "int flags"
48.Sh DESCRIPTION
49.Fn getfsstat
50returns information about all mounted file systems.
51.Fa buf
52is a pointer to an array of
53.Xr statfs 2
54structures defined as follows:
55.Bd -literal
56typedef struct { int32_t val[2]; } fsid_t;
57
58#define MFSNAMELEN   16 /* length of fs type name, including NUL */
59#define MNAMELEN     32	/* length of buffer for returned name */
60
61struct statfs {
62    u_int32_t  f_flags;       /* copy of mount flags */
63    int32_t    f_bsize;       /* fundamental file system block size */
64    u_int32_t  f_iosize;      /* optimal transfer block size */
65    u_int32_t  f_blocks;      /* total data blocks in file system */
66    u_int32_t  f_bfree;       /* free blocks in fs */
67    int32_t    f_bavail;      /* free blocks avail to non-superuser */
68    u_int32_t  f_files;       /* total file nodes in file system */
69    u_int32_t  f_ffree;       /* free file nodes in fs */
70    fsid_t     f_fsid;        /* file system id */
71    uid_t      f_owner;       /* user that mounted the file system */
72    u_int32_t  f_syncwrites;  /* count of sync writes since mount */
73    u_int32_t  f_asyncwrites; /* count of async writes since mount */
74    u_int32_t  f_spare[4];    /* spare for later */
75    char       f_fstypename[MFSNAMELEN]; /* fs type name */
76    char       f_mntonname[MNAMELEN];    /* directory on which mounted */
77    char       f_mntfromname[MNAMELEN];  /* mounted file system */
78    union mount_info mount_info;         /* per-filesystem mount options */
79};
80.Ed
81.Pp
82The buffer is filled with an array of
83.Fa statfs
84structures, one for each mounted file system
85up to the size specified by
86.Fa bufsize .
87.Pp
88If
89.Fa buf
90is
91.Dv NULL ,
92.Fn getfsstat
93returns just the number of mounted file systems.
94.Pp
95Normally
96.Fa flags
97should be specified as
98.Dv MNT_WAIT .
99If
100.Fa flags
101is set to
102.Dv MNT_NOWAIT ,
103.Fn getfsstat
104will return the information it has available without requesting
105an update from each file system.
106Thus, some of the information will be out of date, but
107.Fn getfsstat
108will not block waiting for information from a file system that is
109unable to respond.
110.Sh RETURN VALUES
111Upon successful completion, the number of
112.Fa statfs
113structures is returned.
114Otherwise, \-1 is returned and the global variable
115.Va errno
116is set to indicate the error.
117.Sh ERRORS
118.Fn getfsstat
119fails if one or more of the following are true:
120.Bl -tag -width Er
121.It Bq Er EFAULT
122.Fa buf
123points to an invalid address.
124.It Bq Er EIO
125An
126.Tn I/O
127error occurred while reading from or writing to the file system.
128.El
129.Sh SEE ALSO
130.Xr statfs 2 ,
131.Xr fstab 5 ,
132.Xr mount 8
133.Sh HISTORY
134The
135.Fn getfsstat
136function first appeared in
137.Bx 4.4 .
138