1.\" $OpenBSD: getfsstat.2,v 1.22 2022/07/30 07:19:30 jsg 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. Neither the name of the University nor the names of its contributors 16.\" may be used to endorse or promote products derived from this software 17.\" without specific prior written permission. 18.\" 19.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29.\" SUCH DAMAGE. 30.\" 31.\" @(#)getfsstat.2 8.1 (Berkeley) 6/9/93 32.\" 33.Dd $Mdocdate: July 30 2022 $ 34.Dt GETFSSTAT 2 35.Os 36.Sh NAME 37.Nm getfsstat 38.Nd get list of all mounted file systems 39.Sh SYNOPSIS 40.In sys/types.h 41.In sys/mount.h 42.Ft int 43.Fn getfsstat "struct statfs *buf" "size_t bufsize" "int flags" 44.Sh DESCRIPTION 45.Fn getfsstat 46returns information about all mounted file systems. 47.Fa buf 48is a pointer to an array of 49.Xr statfs 2 50structures defined as follows: 51.Bd -literal 52typedef struct { int32_t val[2]; } fsid_t; 53 54#define MFSNAMELEN 16 /* length of fs type name, including nul */ 55#define MNAMELEN 90 /* length of buffer for returned name */ 56 57struct statfs { 58 u_int32_t f_flags; /* copy of mount flags */ 59 u_int32_t f_bsize; /* file system block size */ 60 u_int32_t f_iosize; /* optimal transfer block size */ 61 62 /* unit is f_bsize */ 63 u_int64_t f_blocks; /* total data blocks in file system */ 64 u_int64_t f_bfree; /* free blocks in fs */ 65 int64_t f_bavail; /* free blocks avail to non-superuser */ 66 67 u_int64_t f_files; /* total file nodes in file system */ 68 u_int64_t f_ffree; /* free file nodes in fs */ 69 int64_t f_favail; /* free file nodes avail to non-root */ 70 71 u_int64_t f_syncwrites; /* count of sync writes since mount */ 72 u_int64_t f_syncreads; /* count of sync reads since mount */ 73 u_int64_t f_asyncwrites; /* count of async writes since mount */ 74 u_int64_t f_asyncreads; /* count of async reads since mount */ 75 76 fsid_t f_fsid; /* file system id */ 77 u_int32_t f_namemax; /* maximum filename length */ 78 uid_t f_owner; /* user that mounted the file system */ 79 u_int64_t f_ctime; /* last mount [-u] time */ 80 81 char f_fstypename[MFSNAMELEN]; /* fs type name */ 82 char f_mntonname[MNAMELEN]; /* directory on which mounted */ 83 char f_mntfromname[MNAMELEN]; /* mounted file system */ 84 char f_mntfromspec[MNAMELEN]; /* special for mount request */ 85 union mount_info mount_info; /* per-filesystem mount options */ 86}; 87.Ed 88.Pp 89The buffer is filled with an array of 90.Fa statfs 91structures, one for each mounted file system 92up to the size specified by 93.Fa bufsize . 94.Pp 95If 96.Fa buf 97is 98.Dv NULL , 99.Fn getfsstat 100returns just the number of mounted file systems. 101.Pp 102Normally 103.Fa flags 104should be specified as 105.Dv MNT_WAIT . 106If 107.Fa flags 108is set to 109.Dv MNT_NOWAIT , 110.Fn getfsstat 111will return the information it has available without requesting 112an update from each file system. 113Thus, some of the information will be out of date, but 114.Fn getfsstat 115will not block waiting for information from a file system that is 116unable to respond. 117If no flags are provided, 118.Dv MNT_WAIT 119is assumed. 120.Pp 121Note that 122.Fa f_fsid 123will be empty unless the user is the superuser. 124.Sh RETURN VALUES 125Upon successful completion, the number of 126.Fa statfs 127structures is returned. 128Otherwise, \-1 is returned and the global variable 129.Va errno 130is set to indicate the error. 131.Sh ERRORS 132.Fn getfsstat 133fails if one or more of the following are true: 134.Bl -tag -width Er 135.It Bq Er EFAULT 136.Fa buf 137points to an invalid address. 138.It Bq Er EIO 139An I/O error occurred while reading from or writing to the file system. 140.El 141.Sh SEE ALSO 142.Xr statfs 2 , 143.Xr fstab 5 , 144.Xr mount 8 145.Sh HISTORY 146The 147.Fn getfsstat 148function first appeared in 149.Bx 4.3 Reno . 150