struct statvfs

Структура, характеризующая информацию о файловой системе

Прототип:

#include <sys/statvfs.h>
typedef uint64_t fsblkcnt64_t;
typedef uint64_t fsfilcnt64_t;
#if _FILE_OFFSET_BITS - 0 == 64
typedef uint64_t fsblkcnt_t;
typedef uint64_t fsfilcnt_t;
#elif !defined _FILE_OFFSET_BITS || _FILE_OFFSET_BITS - 0 == 32
typedef uint32_t fsblkcnt_t;
typedef uint32_t fsfilcnt_t;
#endif
struct statvfs {
unsigned long f_bsize; /* file system block size */
unsigned long f_frsize; /* fundamental filesystem block size */
#if _FILE_OFFSET_BITS - 0 == 64
fsblkcnt_t f_blocks; /* total number of blocks on file system in units of f_frsize */
fsblkcnt_t f_bfree; /* total number of free blocks */
fsblkcnt_t f_bavail; /* number of free blocks available to non-privileged process */
fsfilcnt_t f_files; /* total number of file serial numbers */
fsfilcnt_t f_ffree; /* total number of free file serial numbers */
fsfilcnt_t f_favail; /* number of file serial numbers available to non-privileged process */
#elif !defined(_FILE_OFFSET_BITS) || _FILE_OFFSET_BITS == 32
# if defined(__LITTLEENDIAN__)
fsblkcnt_t f_blocks; /* total number of blocks on file system in units of f_frsize */
fsblkcnt_t f_blocks_hi;
fsblkcnt_t f_bfree; /* total number of free blocks */
fsblkcnt_t f_bfree_hi;
fsblkcnt_t f_bavail; /* number of free blocks available to non-privileged process */
fsblkcnt_t f_bavail_hi;
fsfilcnt_t f_files; /* total number of file serial numbers */
fsfilcnt_t f_files_hi;
fsfilcnt_t f_ffree; /* total number of free file serial numbers */
fsfilcnt_t f_ffree_hi;
fsfilcnt_t f_favail; /* number of file serial numbers available to non-privileged process */
fsfilcnt_t f_favail_hi;
# elif defined(__BIGENDIAN__)
fsblkcnt_t f_blocks_hi;
fsblkcnt_t f_blocks; /* total number of blocks on file system in units of f_frsize */
fsblkcnt_t f_bfree_hi;
fsblkcnt_t f_bfree; /* total number of free blocks */
fsblkcnt_t f_bavail_hi;
fsblkcnt_t f_bavail; /* number of free blocks available to non-privileged process */
fsfilcnt_t f_files_hi;
fsfilcnt_t f_files; /* total number of file serial numbers */
fsfilcnt_t f_ffree_hi;
fsfilcnt_t f_ffree; /* total number of free file serial numbers */
fsfilcnt_t f_favail_hi;
fsfilcnt_t f_favail; /* number of file serial numbers available to non-privileged process */
# else
# error endian not configured for system
# endif
#else
# error _FILE_OFFSET_BITS value is unsupported
#endif
unsigned long f_fsid; /* file system id */
char f_basetype[16]; /* null terminated name of target file system*/
unsigned long f_flag; /* bit mask of f_flag values */
unsigned long f_namemax; /* maximum filename length */
unsigned long f_filler[21]; /* padding */
};
#if _LARGEFILE64_SOURCE - 0 > 0
struct statvfs64 {
unsigned long f_bsize; /* file system block size */
unsigned long f_frsize; /* fundamental filesystem block size */
fsblkcnt64_t f_blocks; /* total number of blocks on file system in units of f_frsize */
fsblkcnt64_t f_bfree; /* total number of free blocks */
fsblkcnt64_t f_bavail; /* number of free blocks available to non-privileged process */
fsfilcnt64_t f_files; /* total number of file serial numbers */
fsfilcnt64_t f_ffree; /* total number of free file serial numbers */
fsfilcnt64_t f_favail; /* number of file serial numbers available to non-privileged process */
unsigned long f_fsid; /* file system id */
char f_basetype[16]; /* null terminated name of target file system*/
unsigned long f_flag; /* bit mask of f_flag values */
unsigned long f_namemax; /* maximum filename length */
unsigned long f_filler[21]; /* padding */
};
#endif

Описание:

Тип определяет информацию о файловой системе для некоторого файла или файлового дескриптора. Структура включает следующие поля:

f_bsize
The preferred filesystem blocksize.
f_frsize
The fundamental filesystem blocksize (if supported)
f_blocks
The total number of blocks on the filesystem, in units of f_frsize.
f_bfree
The total number of free blocks.
f_bavail
The number of free blocks available to a nonsuperuser.
f_files
The total number of file nodes (inodes).
f_ffree
The total number of free file nodes.
f_favail
The number of inodes available to a nonsuperuser.
f_fsid
The filesystem ID (currently the device ID).
f_basetype
The type of the target filesystem, as a null-terminated string.
f_flag
A bitmask of flags; the function can set these flags (the _MOUNT_* and ST_* bits are equivalent):
MOUNT_* ST_* Meaning
_MOUNT_READONLY ST_RDONLY The filesystem is read-only.
_MOUNT_NOEXEC ST_NOEXEC The filesystem doesn't permit the loading of executables.
_MOUNT_NOSUID ST_NOSUID The filesystem doesn't support setuid() and setgid() semantics.
_MOUNT_NOCREAT ST_NOCREAT You can't create files on the filesystem.
_MOUNT_OFF32 ST_OFF32 The off_t type is limited to 32 bits.
_MOUNT_NOATIME ST_NOATIME The filesystem doesn't support the logging of file access times.
f_namemax
The maximum filename length.

The values returned for f_files, f_ffree, and f_favail depend on the filesystem:

fs-dos.so, fs-qnx4.so
These filesystems embed inodes in directories, so the number of files is limited by the amount of disk space, so basically there's no limit. They don't count the number of files created either, so they set all these fields to 0.
fs-qnx6.so, fs-etfs-ram, fs-ext2.so
These filesystems have a fixed inodes table, so they fill in these fields.
fs-cd.so, fs-mac.so, fs-nt.so, fs-udf.so
Read-only fsystems always set f_ffree and f_favail to 0. Where possible or known, they try to set f_files: fs-cifs
The CIFS filesystem sets these fields to 0. devf-*
Flash filesystem drivers estimate the values of these fields, based on the amount of free space.

Классификация:

struct statvfs — POSIX 1003.1 XSI; struct statvfs64 — Поддержка больших файлов

Тематические ссылки:

fs-cd.so, fs-mac.so, fs-nt.so, fs-udf.so, fstatvfs(), fstatvfs64(), statvfs(), statvfs64()




Предыдущий раздел: Описание API системной библиотеки