xref: /openbsd/lib/libc/sys/statfs.2 (revision b702bb8a)
1.\"	$OpenBSD: statfs.2,v 1.19 2008/03/16 20:24:14 otto Exp $
2.\"	$NetBSD: statfs.2,v 1.10 1995/06/29 11:40:48 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.\"	@(#)statfs.2	8.3 (Berkeley) 2/11/94
32.\"
33.Dd $Mdocdate: March 16 2008 $
34.Dt STATFS 2
35.Os
36.Sh NAME
37.Nm statfs ,
38.Nm fstatfs
39.Nd get file system statistics
40.Sh SYNOPSIS
41.Fd #include <sys/param.h>
42.Fd #include <sys/mount.h>
43.Ft int
44.Fn statfs "const char *path" "struct statfs *buf"
45.Ft int
46.Fn fstatfs "int fd" "struct statfs *buf"
47.Sh DESCRIPTION
48.Fn statfs
49returns information about a mounted file system.
50.Fa path
51is the path name of any file within the mounted file system.
52.Fa buf
53is a pointer to a
54.Nm statfs
55structure defined as follows:
56.Bd -literal
57typedef struct { int32_t val[2]; } fsid_t;
58
59#define MFSNAMELEN   16 /* length of fs type name, including nul */
60#define MNAMELEN     90	/* length of buffer for returned name */
61
62struct statfs {
63   u_int32_t       f_flags;        /* copy of mount flags */
64   u_int32_t       f_bsize;        /* file system block size */
65   u_int32_t       f_iosize;       /* optimal transfer block size */
66                                   /* unit is f_bsize */
67   u_int64_t       f_blocks;       /* total data blocks in file system */
68   u_int64_t       f_bfree;        /* free blocks in fs */
69   int64_t         f_bavail;       /* free blocks avail to non-superuser */
70   u_int64_t       f_files;        /* total file nodes in file system */
71   u_int64_t       f_ffree;        /* free file nodes in fs */
72   int64_t         f_favail;       /* free file nodes avail to non-root */
73   u_int64_t       f_syncwrites;   /* count of sync writes since mount */
74   u_int64_t       f_syncreads;    /* count of sync reads since mount */
75   u_int64_t       f_asyncwrites;  /* count of async writes since mount */
76   u_int64_t       f_asyncreads;   /* count of async reads since mount */
77   fsid_t          f_fsid;         /* file system id */
78   u_int32_t       f_namemax;      /* maximum filename length */
79   uid_t           f_owner;        /* user that mounted the file system */
80   u_int32_t       f_ctime;        /* last mount [-u] time */
81   u_int32_t       f_spare[3];     /* spare for later */
82   char f_fstypename[MFSNAMELEN];  /* fs type name */
83   char f_mntonname[MNAMELEN];     /* directory on which mounted */
84   char f_mntfromname[MNAMELEN];   /* mounted file system */
85   union mount_info mount_info;    /* per-filesystem mount options */
86};
87.Ed
88.Pp
89.Fn fstatfs
90returns the same information about an open file referenced by descriptor
91.Fa fd .
92.Sh RETURN VALUES
93Upon successful completion, a value of 0 is returned.
94Otherwise, \-1 is returned and the global variable
95.Va errno
96is set to indicate the error.
97.Sh ERRORS
98.Fn statfs
99fails if one or more of the following are true:
100.Bl -tag -width Er
101.It Bq Er ENOTDIR
102A component of the path prefix of
103.Fa path
104is not a directory.
105.It Bq Er ENAMETOOLONG
106The length of a component of
107.Fa path
108exceeds
109.Dv {NAME_MAX}
110characters, or the length of
111.Fa path
112exceeds
113.Dv {PATH_MAX}
114characters.
115.It Bq Er ENOENT
116The file referred to by
117.Fa path
118does not exist.
119.It Bq Er EACCES
120Search permission is denied for a component of the path prefix of
121.Fa path .
122.It Bq Er ELOOP
123Too many symbolic links were encountered in translating
124.Fa path .
125.It Bq Er EFAULT
126.Fa buf
127or
128.Fa path
129points to an invalid address.
130.It Bq Er EIO
131An
132.Tn I/O
133error occurred while reading from or writing to the file system.
134.El
135.Pp
136.Fn fstatfs
137fails if one or more of the following are true:
138.Bl -tag -width Er
139.It Bq Er EBADF
140.Fa fd
141is not a valid open file descriptor.
142.It Bq Er EFAULT
143.Fa buf
144points to an invalid address.
145.It Bq Er EIO
146An
147.Tn I/O
148error occurred while reading from or writing to the file system.
149.El
150.Sh SEE ALSO
151.Xr df 1 ,
152.Xr mount 2 ,
153.Xr stat 2
154.Sh HISTORY
155The
156.Fn statfs
157function first appeared in
158.Bx 4.4 .
159