547 lines
14 KiB
HTML
547 lines
14 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of STATFS</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>STATFS</H1>
|
|
Section: Linux Programmer's Manual (2)<BR>Updated: 2017-09-15<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
statfs, fstatfs - get filesystem statistics
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<B>#include <<A HREF="file:///usr/include/sys/vfs.h">sys/vfs.h</A>> </B>/* or <<A HREF="file:///usr/include/sys/statfs.h">sys/statfs.h</A>> */
|
|
|
|
<P>
|
|
|
|
<B>int statfs(const char *</B><I>path</I><B>, struct statfs *</B><I>buf</I><B>);</B>
|
|
|
|
<BR>
|
|
|
|
<B>int fstatfs(int </B><I>fd</I><B>, struct statfs *</B><I>buf</I><B>);</B>
|
|
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
The
|
|
<B>statfs</B>()
|
|
|
|
system call returns information about a mounted filesystem.
|
|
<I>path</I>
|
|
|
|
is the pathname of any file within the mounted filesystem.
|
|
<I>buf</I>
|
|
|
|
is a pointer to a
|
|
<I>statfs</I>
|
|
|
|
structure defined approximately as follows:
|
|
<P>
|
|
|
|
|
|
|
|
struct statfs {
|
|
<BR> __fsword_t f_type; /* Type of filesystem (see below) */
|
|
<BR> __fsword_t f_bsize; /* Optimal transfer block size */
|
|
<BR> fsblkcnt_t f_blocks; /* Total data blocks in filesystem */
|
|
<BR> fsblkcnt_t f_bfree; /* Free blocks in filesystem */
|
|
<BR> fsblkcnt_t f_bavail; /* Free blocks available to
|
|
<BR> unprivileged user */
|
|
<BR> fsfilcnt_t f_files; /* Total file nodes in filesystem */
|
|
<BR> fsfilcnt_t f_ffree; /* Free file nodes in filesystem */
|
|
<BR> fsid_t f_fsid; /* Filesystem ID */
|
|
<BR> __fsword_t f_namelen; /* Maximum length of filenames */
|
|
<BR> __fsword_t f_frsize; /* Fragment size (since Linux 2.6) */
|
|
<BR> __fsword_t f_flags; /* Mount flags of filesystem
|
|
<BR> (since Linux 2.6.36) */
|
|
<BR> __fsword_t f_spare[xxx];
|
|
<BR> /* Padding bytes reserved for future use */
|
|
};
|
|
|
|
|
|
<P>
|
|
|
|
The following filesystem types may appear in
|
|
<I>f_type</I>:
|
|
|
|
<P>
|
|
|
|
|
|
|
|
ADFS_SUPER_MAGIC 0xadf5
|
|
AFFS_SUPER_MAGIC 0xadff
|
|
AFS_SUPER_MAGIC 0x5346414f
|
|
ANON_INODE_FS_MAGIC 0x09041934 /* Anonymous inode FS (for
|
|
<BR> pseudofiles that have no name;
|
|
<BR> e.g., epoll, signalfd, bpf) */
|
|
AUTOFS_SUPER_MAGIC 0x0187
|
|
BDEVFS_MAGIC 0x62646576
|
|
BEFS_SUPER_MAGIC 0x42465331
|
|
BFS_MAGIC 0x1badface
|
|
BINFMTFS_MAGIC 0x42494e4d
|
|
BPF_FS_MAGIC 0xcafe4a11
|
|
BTRFS_SUPER_MAGIC 0x9123683e
|
|
BTRFS_TEST_MAGIC 0x73727279
|
|
CGROUP_SUPER_MAGIC 0x27e0eb /* Cgroup pseudo FS */
|
|
CGROUP2_SUPER_MAGIC 0x63677270 /* Cgroup v2 pseudo FS */
|
|
CIFS_MAGIC_NUMBER 0xff534d42
|
|
CODA_SUPER_MAGIC 0x73757245
|
|
COH_SUPER_MAGIC 0x012ff7b7
|
|
CRAMFS_MAGIC 0x28cd3d45
|
|
DEBUGFS_MAGIC 0x64626720
|
|
DEVFS_SUPER_MAGIC 0x1373 /* Linux 2.6.17 and earlier */
|
|
DEVPTS_SUPER_MAGIC 0x1cd1
|
|
ECRYPTFS_SUPER_MAGIC 0xf15f
|
|
EFIVARFS_MAGIC 0xde5e81e4
|
|
EFS_SUPER_MAGIC 0x00414a53
|
|
EXT_SUPER_MAGIC 0x137d /* Linux 2.0 and earlier */
|
|
EXT2_OLD_SUPER_MAGIC 0xef51
|
|
EXT2_SUPER_MAGIC 0xef53
|
|
EXT3_SUPER_MAGIC 0xef53
|
|
EXT4_SUPER_MAGIC 0xef53
|
|
F2FS_SUPER_MAGIC 0xf2f52010
|
|
FUSE_SUPER_MAGIC 0x65735546
|
|
FUTEXFS_SUPER_MAGIC 0xbad1dea /* Unused */
|
|
HFS_SUPER_MAGIC 0x4244
|
|
HOSTFS_SUPER_MAGIC 0x00c0ffee
|
|
HPFS_SUPER_MAGIC 0xf995e849
|
|
HUGETLBFS_MAGIC 0x958458f6
|
|
ISOFS_SUPER_MAGIC 0x9660
|
|
JFFS2_SUPER_MAGIC 0x72b6
|
|
JFS_SUPER_MAGIC 0x3153464a
|
|
MINIX_SUPER_MAGIC 0x137f /* original minix FS */
|
|
MINIX_SUPER_MAGIC2 0x138f /* 30 char minix FS */
|
|
MINIX2_SUPER_MAGIC 0x2468 /* minix V2 FS */
|
|
MINIX2_SUPER_MAGIC2 0x2478 /* minix V2 FS, 30 char names */
|
|
MINIX3_SUPER_MAGIC 0x4d5a /* minix V3 FS, 60 char names */
|
|
MQUEUE_MAGIC 0x19800202 /* POSIX message queue FS */
|
|
MSDOS_SUPER_MAGIC 0x4d44
|
|
MTD_INODE_FS_MAGIC 0x11307854
|
|
NCP_SUPER_MAGIC 0x564c
|
|
NFS_SUPER_MAGIC 0x6969
|
|
NILFS_SUPER_MAGIC 0x3434
|
|
NSFS_MAGIC 0x6e736673
|
|
NTFS_SB_MAGIC 0x5346544e
|
|
OCFS2_SUPER_MAGIC 0x7461636f
|
|
OPENPROM_SUPER_MAGIC 0x9fa1
|
|
OVERLAYFS_SUPER_MAGIC 0x794c7630
|
|
PIPEFS_MAGIC 0x50495045
|
|
PROC_SUPER_MAGIC 0x9fa0 /* /proc FS */
|
|
PSTOREFS_MAGIC 0x6165676c
|
|
QNX4_SUPER_MAGIC 0x002f
|
|
QNX6_SUPER_MAGIC 0x68191122
|
|
RAMFS_MAGIC 0x858458f6
|
|
REISERFS_SUPER_MAGIC 0x52654973
|
|
ROMFS_MAGIC 0x7275
|
|
SECURITYFS_MAGIC 0x73636673
|
|
SELINUX_MAGIC 0xf97cff8c
|
|
SMACK_MAGIC 0x43415d53
|
|
SMB_SUPER_MAGIC 0x517b
|
|
SOCKFS_MAGIC 0x534f434b
|
|
SQUASHFS_MAGIC 0x73717368
|
|
SYSFS_MAGIC 0x62656572
|
|
SYSV2_SUPER_MAGIC 0x012ff7b6
|
|
SYSV4_SUPER_MAGIC 0x012ff7b5
|
|
TMPFS_MAGIC 0x01021994
|
|
TRACEFS_MAGIC 0x74726163
|
|
UDF_SUPER_MAGIC 0x15013346
|
|
UFS_MAGIC 0x00011954
|
|
USBDEVICE_SUPER_MAGIC 0x9fa2
|
|
V9FS_MAGIC 0x01021997
|
|
VXFS_SUPER_MAGIC 0xa501fcf5
|
|
XENFS_SUPER_MAGIC 0xabba1974
|
|
XENIX_SUPER_MAGIC 0x012ff7b4
|
|
XFS_SUPER_MAGIC 0x58465342
|
|
_XIAFS_SUPER_MAGIC 0x012fd16d /* Linux 2.0 and earlier */
|
|
|
|
|
|
<P>
|
|
|
|
Most of these MAGIC constants are defined in
|
|
<I>/usr/include/linux/magic.h</I>,
|
|
|
|
and some are hardcoded in kernel sources.
|
|
<P>
|
|
|
|
The
|
|
<I>f_flags</I>
|
|
|
|
field is a bit mask indicating mount options for the filesystem.
|
|
It contains zero or more of the following bits:
|
|
|
|
<DL COMPACT>
|
|
<DT id="1"><B>ST_MANDLOCK</B>
|
|
|
|
<DD>
|
|
Mandatory locking is permitted on the filesystem (see
|
|
<B><A HREF="/cgi-bin/man/man2html?2+fcntl">fcntl</A></B>(2)).
|
|
|
|
<DT id="2"><B>ST_NOATIME</B>
|
|
|
|
<DD>
|
|
Do not update access times; see
|
|
<B><A HREF="/cgi-bin/man/man2html?2+mount">mount</A></B>(2).
|
|
|
|
<DT id="3"><B>ST_NODEV</B>
|
|
|
|
<DD>
|
|
Disallow access to device special files on this filesystem.
|
|
<DT id="4"><B>ST_NODIRATIME</B>
|
|
|
|
<DD>
|
|
Do not update directory access times; see
|
|
<B><A HREF="/cgi-bin/man/man2html?2+mount">mount</A></B>(2).
|
|
|
|
<DT id="5"><B>ST_NOEXEC</B>
|
|
|
|
<DD>
|
|
Execution of programs is disallowed on this filesystem.
|
|
<DT id="6"><B>ST_NOSUID</B>
|
|
|
|
<DD>
|
|
The set-user-ID and set-group-ID bits are ignored by
|
|
<B><A HREF="/cgi-bin/man/man2html?3+exec">exec</A></B>(3)
|
|
|
|
for executable files on this filesystem
|
|
<DT id="7"><B>ST_RDONLY</B>
|
|
|
|
<DD>
|
|
This filesystem is mounted read-only.
|
|
<DT id="8"><B>ST_RELATIME</B>
|
|
|
|
<DD>
|
|
Update atime relative to mtime/ctime; see
|
|
<B><A HREF="/cgi-bin/man/man2html?2+mount">mount</A></B>(2).
|
|
|
|
<DT id="9"><B>ST_SYNCHRONOUS</B>
|
|
|
|
<DD>
|
|
Writes are synched to the filesystem immediately (see the description of
|
|
<B>O_SYNC</B>
|
|
|
|
in
|
|
<B><A HREF="/cgi-bin/man/man2html?2+open">open</A></B>(2)).
|
|
|
|
</DL>
|
|
<P>
|
|
|
|
Nobody knows what
|
|
<I>f_fsid</I>
|
|
|
|
is supposed to contain (but see below).
|
|
<P>
|
|
|
|
Fields that are undefined for a particular filesystem are set to 0.
|
|
<P>
|
|
|
|
<B>fstatfs</B>()
|
|
|
|
returns the same information about an open file referenced by descriptor
|
|
<I>fd</I>.
|
|
|
|
<A NAME="lbAE"> </A>
|
|
<H2>RETURN VALUE</H2>
|
|
|
|
On success, zero is returned.
|
|
On error, -1 is returned, and
|
|
<I>errno</I>
|
|
|
|
is set appropriately.
|
|
<A NAME="lbAF"> </A>
|
|
<H2>ERRORS</H2>
|
|
|
|
<DL COMPACT>
|
|
<DT id="10"><B>EACCES</B>
|
|
|
|
<DD>
|
|
(<B>statfs</B>())
|
|
|
|
Search permission is denied for a component of the path prefix of
|
|
<I>path</I>.
|
|
|
|
(See also
|
|
<B><A HREF="/cgi-bin/man/man2html?7+path_resolution">path_resolution</A></B>(7).)
|
|
|
|
<DT id="11"><B>EBADF</B>
|
|
|
|
<DD>
|
|
(<B>fstatfs</B>())
|
|
|
|
<I>fd</I>
|
|
|
|
is not a valid open file descriptor.
|
|
<DT id="12"><B>EFAULT</B>
|
|
|
|
<DD>
|
|
<I>buf</I>
|
|
|
|
or
|
|
<I>path</I>
|
|
|
|
points to an invalid address.
|
|
<DT id="13"><B>EINTR</B>
|
|
|
|
<DD>
|
|
The call was interrupted by a signal; see
|
|
<B><A HREF="/cgi-bin/man/man2html?7+signal">signal</A></B>(7).
|
|
|
|
<DT id="14"><B>EIO</B>
|
|
|
|
<DD>
|
|
An I/O error occurred while reading from the filesystem.
|
|
<DT id="15"><B>ELOOP</B>
|
|
|
|
<DD>
|
|
(<B>statfs</B>())
|
|
|
|
Too many symbolic links were encountered in translating
|
|
<I>path</I>.
|
|
|
|
<DT id="16"><B>ENAMETOOLONG</B>
|
|
|
|
<DD>
|
|
(<B>statfs</B>())
|
|
|
|
<I>path</I>
|
|
|
|
is too long.
|
|
<DT id="17"><B>ENOENT</B>
|
|
|
|
<DD>
|
|
(<B>statfs</B>())
|
|
|
|
The file referred to by
|
|
<I>path</I>
|
|
|
|
does not exist.
|
|
<DT id="18"><B>ENOMEM</B>
|
|
|
|
<DD>
|
|
Insufficient kernel memory was available.
|
|
<DT id="19"><B>ENOSYS</B>
|
|
|
|
<DD>
|
|
The filesystem does not support this call.
|
|
<DT id="20"><B>ENOTDIR</B>
|
|
|
|
<DD>
|
|
(<B>statfs</B>())
|
|
|
|
A component of the path prefix of
|
|
<I>path</I>
|
|
|
|
is not a directory.
|
|
<DT id="21"><B>EOVERFLOW</B>
|
|
|
|
<DD>
|
|
Some values were too large to be represented in the returned struct.
|
|
</DL>
|
|
<A NAME="lbAG"> </A>
|
|
<H2>CONFORMING TO</H2>
|
|
|
|
Linux-specific.
|
|
The Linux
|
|
<B>statfs</B>()
|
|
|
|
was inspired by the 4.4BSD one
|
|
(but they do not use the same structure).
|
|
<A NAME="lbAH"> </A>
|
|
<H2>NOTES</H2>
|
|
|
|
The
|
|
<I>__fsword_t</I>
|
|
|
|
type used for various fields in the
|
|
<I>statfs</I>
|
|
|
|
structure definition is a glibc internal type,
|
|
not intended for public use.
|
|
This leaves the programmer in a bit of a conundrum when trying to copy
|
|
or compare these fields to local variables in a program.
|
|
Using
|
|
<I>unsigned int</I>
|
|
|
|
for such variables suffices on most systems.
|
|
<P>
|
|
|
|
The original Linux
|
|
<B>statfs</B>()
|
|
|
|
and
|
|
<B>fstatfs</B>()
|
|
|
|
system calls were not designed with extremely large file sizes in mind.
|
|
Subsequently, Linux 2.6
|
|
added new
|
|
<B>statfs64</B>()
|
|
|
|
and
|
|
<B>fstatfs64</B>()
|
|
|
|
system calls that employ a new structure,
|
|
<I>statfs64</I>.
|
|
|
|
The new structure contains the same fields as the original
|
|
<I>statfs</I>
|
|
|
|
structure, but the sizes of various fields are increased,
|
|
to accommodate large file sizes.
|
|
The glibc
|
|
<B>statfs</B>()
|
|
|
|
and
|
|
<B>fstatfs</B>()
|
|
|
|
wrapper functions transparently deal with the kernel differences.
|
|
<P>
|
|
|
|
Some systems have only <I><<A HREF="file:///usr/include/sys/vfs.h">sys/vfs.h</A>></I>, other systems also have
|
|
<I><<A HREF="file:///usr/include/sys/statfs.h">sys/statfs.h</A>></I>, where the former includes the latter.
|
|
So it seems
|
|
including the former is the best choice.
|
|
<P>
|
|
|
|
LSB has deprecated the library calls
|
|
<B>statfs</B>()
|
|
|
|
and
|
|
<B>fstatfs</B>()
|
|
|
|
and tells us to use
|
|
<B><A HREF="/cgi-bin/man/man2html?2+statvfs">statvfs</A></B>(2)
|
|
|
|
and
|
|
<B><A HREF="/cgi-bin/man/man2html?2+fstatvfs">fstatvfs</A></B>(2)
|
|
|
|
instead.
|
|
<A NAME="lbAI"> </A>
|
|
<H3>The f_fsid field</H3>
|
|
|
|
Solaris, Irix and POSIX have a system call
|
|
<B><A HREF="/cgi-bin/man/man2html?2+statvfs">statvfs</A></B>(2)
|
|
|
|
that returns a
|
|
<I>struct statvfs</I>
|
|
|
|
(defined in
|
|
<I><<A HREF="file:///usr/include/sys/statvfs.h">sys/statvfs.h</A>></I>)
|
|
|
|
containing an
|
|
<I>unsigned long</I>
|
|
|
|
<I>f_fsid</I>.
|
|
|
|
Linux, SunOS, HP-UX, 4.4BSD have a system call
|
|
<B>statfs</B>()
|
|
|
|
that returns a
|
|
<I>struct statfs</I>
|
|
|
|
(defined in
|
|
<I><<A HREF="file:///usr/include/sys/vfs.h">sys/vfs.h</A>></I>)
|
|
|
|
containing a
|
|
<I>fsid_t</I>
|
|
|
|
<I>f_fsid</I>,
|
|
|
|
where
|
|
<I>fsid_t</I>
|
|
|
|
is defined as
|
|
<I>struct { int val[2]; }</I>.
|
|
|
|
The same holds for FreeBSD, except that it uses the include file
|
|
<I><<A HREF="file:///usr/include/sys/mount.h">sys/mount.h</A>></I>.
|
|
|
|
<P>
|
|
|
|
The general idea is that
|
|
<I>f_fsid</I>
|
|
|
|
contains some random stuff such that the pair
|
|
(<I>f_fsid</I>,<I>ino</I>)
|
|
|
|
uniquely determines a file.
|
|
Some operating systems use (a variation on) the device number,
|
|
or the device number combined with the filesystem type.
|
|
Several operating systems restrict giving out the
|
|
<I>f_fsid</I>
|
|
|
|
field to the superuser only (and zero it for unprivileged users),
|
|
because this field is used in the filehandle of the filesystem
|
|
when NFS-exported, and giving it out is a security concern.
|
|
<P>
|
|
|
|
Under some operating systems, the
|
|
<I>fsid</I>
|
|
|
|
can be used as the second argument to the
|
|
<B><A HREF="/cgi-bin/man/man2html?2+sysfs">sysfs</A></B>(2)
|
|
|
|
system call.
|
|
<A NAME="lbAJ"> </A>
|
|
<H2>BUGS</H2>
|
|
|
|
From Linux 2.6.38 up to and including Linux 3.1,
|
|
|
|
|
|
<B>fstatfs</B>()
|
|
|
|
failed with the error
|
|
<B>ENOSYS</B>
|
|
|
|
for file descriptors created by
|
|
<B><A HREF="/cgi-bin/man/man2html?2+pipe">pipe</A></B>(2).
|
|
|
|
<A NAME="lbAK"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+stat">stat</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+statvfs">statvfs</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?7+path_resolution">path_resolution</A></B>(7)
|
|
|
|
<A NAME="lbAL"> </A>
|
|
<H2>COLOPHON</H2>
|
|
|
|
This page is part of release 5.05 of the Linux
|
|
<I>man-pages</I>
|
|
|
|
project.
|
|
A description of the project,
|
|
information about reporting bugs,
|
|
and the latest version of this page,
|
|
can be found at
|
|
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="22"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="23"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="24"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DT id="25"><A HREF="#lbAE">RETURN VALUE</A><DD>
|
|
<DT id="26"><A HREF="#lbAF">ERRORS</A><DD>
|
|
<DT id="27"><A HREF="#lbAG">CONFORMING TO</A><DD>
|
|
<DT id="28"><A HREF="#lbAH">NOTES</A><DD>
|
|
<DL>
|
|
<DT id="29"><A HREF="#lbAI">The f_fsid field</A><DD>
|
|
</DL>
|
|
<DT id="30"><A HREF="#lbAJ">BUGS</A><DD>
|
|
<DT id="31"><A HREF="#lbAK">SEE ALSO</A><DD>
|
|
<DT id="32"><A HREF="#lbAL">COLOPHON</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:34 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|