Standards / Extensions | C or C++ | Dependencies |
---|---|---|
XPG4.2 |
both |
#define _XOPEN_SOURCE_EXTENDED 1
#include <sys/statvfs.h>
int statvfs(const char *_restrict_ pathname, struct statvfs *_restrict_ fsinfo);
The statvfs() function obtains information about the file system containing the file named by pathname and stores it in the area of memory pointed to by the fsinfo argument. The process does not need permissions on the file itself, but must have search permission on all directory components of the pathname.
The information is returned in the following statvfs structure, as defined in the sys/statvfs.h header file.
Value | Description |
---|---|
char f_OEcbid[4] | The structure acronym (eye catcher). |
int f_OEcblen | The length of the structure. |
unsigned long f_bsize | The file system block size. |
unsigned long f_blocks | The total number of blocks on the file system in units of f_frsize. |
unsigned long f_OEusedspace | The allocated space in block size units. |
unsigned long f_bavail | The number of free blocks available to non-privileged process. |
unsigned long f_fsid | The file system ID. |
unsigned long f_flag | A bit string indicating file system status. |
int f_OEmaxfilesizehw | The high word of maximum file size. |
unsigned long f_OEmaxfilesizelw | The low word of maximum file size. |
unsigned long f_frsize | The fundamental file system block size. |
unsigned long f_bfree | The total number of free blocks. |
unsigned long f_files | The total number of file serial numbers. |
unsigned long f_ffree | The total number of free file serial numbers. |
unsigned long f_favail | The number of file serial numbers available to non-privileged process. |
unsigned long f_namemax | The maximum file name length. |
unsigned long f_OEinvarsec | The number of seconds the file system will remain unchanged. |
If statvfs() successfully determines this information, it stores in the area indicated by the fsinfo argument. The size of the buffer determines how much information is stored; data that exceeds the size of the buffer is truncated.
If successful, statvfs() returns 0.
#include <sys/statvfs.h>
#include <stdio.h>
main() {
int fd;
struct statvfs buf;
if (statvfs(".", &buf) == -1)
perror("statvfs() error");
else {
printf("each block is %d bytes big\n", fs,
buf.f_bsize);
printf("there are %d blocks available out of a total of %d\n",
buf.f_bavail, buf.f_blocks);
printf("in bytes, that's %.0f bytes free out of a total of %.0f\n
((double)buf.f_bavail * buf.f_bsize),
((double)buf.f_blocks * buf.f_bsize));
}
}
each block is 4096 bytes big
there are 2089 blocks available out of a total of 2400
in bytes, that's 8556544 bytes free out of a total of 9830400