man-pages/man3/statvfs.3.html
2021-03-31 01:06:50 +01:00

385 lines
9.0 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of STATVFS</TITLE>
</HEAD><BODY>
<H1>STATVFS</H1>
Section: Linux Programmer's Manual (3)<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">&nbsp;</A>
<H2>NAME</H2>
statvfs, fstatvfs - get filesystem statistics
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<B>#include &lt;<A HREF="file:///usr/include/sys/statvfs.h">sys/statvfs.h</A>&gt;</B>
<P>
<B>int statvfs(const char *</B><I>path</I><B>, struct statvfs *</B><I>buf</I><B>);</B>
<BR>
<B>int fstatvfs(int </B><I>fd</I><B>, struct statvfs *</B><I>buf</I><B>);</B>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
The function
<B>statvfs</B>()
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>statvfs</I>
structure defined approximately as follows:
<P>
struct statvfs {
<BR>&nbsp;&nbsp;&nbsp;&nbsp;unsigned&nbsp;long&nbsp;&nbsp;f_bsize;&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;Filesystem&nbsp;block&nbsp;size&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;unsigned&nbsp;long&nbsp;&nbsp;f_frsize;&nbsp;&nbsp;&nbsp;/*&nbsp;Fragment&nbsp;size&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;fsblkcnt_t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f_blocks;&nbsp;&nbsp;&nbsp;/*&nbsp;Size&nbsp;of&nbsp;fs&nbsp;in&nbsp;f_frsize&nbsp;units&nbsp;*/
<BR>&nbsp;&nbsp;&nb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nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;unprivileged&nbsp;users&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;unsigned&nbsp;long&nbsp;&nbsp;f_fsid;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;Filesystem&nbsp;ID&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;unsigned&nbsp;long&nbsp;&nbsp;f_flag;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;Mount&nbsp;flags&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;unsigned&nbsp;long&nbsp;&nbsp;f_namemax;&nbsp;&nbsp;/*&nbsp;Maximum&nbsp;filename&nbsp;length&nbsp;*/
};
<P>
Here the types
<I>fsblkcnt_t</I>
and
<I>fsfilcnt_t</I>
are defined in
<I>&lt;<A HREF="file:///usr/include/sys/types.h">sys/types.h</A>&gt;</I>.
Both used to be
<I>unsigned long</I>.
<P>
The field
<I>f_flag</I>
is a bit mask indicating various options that were employed
when mounting this filesystem.
It contains zero or more of the following flags:
<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>
It is unspecified whether all members of the returned struct
have meaningful values on all filesystems.
<P>
<B>fstatvfs</B>()
returns the same information about an open file referenced by descriptor
<I>fd</I>.
<A NAME="lbAE">&nbsp;</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">&nbsp;</A>
<H2>ERRORS</H2>
<DL COMPACT>
<DT id="10"><B>EACCES</B>
<DD>
(<B>statvfs</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>fstatvfs</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>
This 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>statvfs</B>())
Too many symbolic links were encountered in translating
<I>path</I>.
<DT id="16"><B>ENAMETOOLONG</B>
<DD>
(<B>statvfs</B>())
<I>path</I>
is too long.
<DT id="17"><B>ENOENT</B>
<DD>
(<B>statvfs</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>statvfs</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">&nbsp;</A>
<H2>ATTRIBUTES</H2>
For an explanation of the terms used in this section, see
<B><A HREF="/cgi-bin/man/man2html?7+attributes">attributes</A></B>(7).
<TABLE BORDER>
<TR VALIGN=top><TD><B>Interface</B></TD><TD><B>Attribute</B></TD><TD><B>Value</B><BR></TD></TR>
<TR VALIGN=top><TD>
<B>statvfs</B>(),
<B>fstatvfs</B>()
</TD><TD>Thread safety</TD><TD>MT-Safe<BR></TD></TR>
</TABLE>
<A NAME="lbAH">&nbsp;</A>
<H2>CONFORMING TO</H2>
POSIX.1-2001, POSIX.1-2008.
<P>
Only the
<B>ST_NOSUID</B>
and
<B>ST_RDONLY</B>
flags of the
<I>f_flag</I>
field are specified in POSIX.1.
To obtain definitions of the remaining flags, one must define
<B>_GNU_SOURCE</B>.
<A NAME="lbAI">&nbsp;</A>
<H2>NOTES</H2>
The Linux kernel has system calls
<B><A HREF="/cgi-bin/man/man2html?2+statfs">statfs</A></B>(2)
and
<B><A HREF="/cgi-bin/man/man2html?2+fstatfs">fstatfs</A></B>(2)
to support this library call.
<P>
In glibc versions before 2.13,
<B>statvfs</B>()
populated the bits of the
<I>f_flag</I>
field by scanning the mount options shown in
<I>/proc/mounts</I>.
However, starting with Linux 2.6.36, the underlying
<B><A HREF="/cgi-bin/man/man2html?2+statfs">statfs</A></B>(2)
system call provides the necessary information via the
<I>f_flags</I>
field, and since glibc version 2.13, the
<B>statvfs</B>()
function will use information from that field rather than scanning
<I>/proc/mounts</I>.
<P>
The glibc implementations of
<P>
pathconf(path, _PC_REC_XFER_ALIGN);
pathconf(path, _PC_ALLOC_SIZE_MIN);
pathconf(path, _PC_REC_MIN_XFER_SIZE);
<P>
respectively use the
<I>f_frsize</I>,
<I>f_frsize</I>,
and
<I>f_bsize</I>
fields returned by a call to
<B>statvfs</B>()
with the argument
<I>path</I>.
<A NAME="lbAJ">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?2+statfs">statfs</A></B>(2)
<A NAME="lbAK">&nbsp;</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">&nbsp;</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">ATTRIBUTES</A><DD>
<DT id="28"><A HREF="#lbAH">CONFORMING TO</A><DD>
<DT id="29"><A HREF="#lbAI">NOTES</A><DD>
<DT id="30"><A HREF="#lbAJ">SEE ALSO</A><DD>
<DT id="31"><A HREF="#lbAK">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:57 GMT, March 31, 2021
</BODY>
</HTML>