Python3 os.fstatvfs() Method
Python3 OS File/Directory Methods
Overview
The os.fstatvfs() method returns information about the file system of the file containing the file descriptor fd; equivalent to statvfs() in Python 3.3..
Available on Unix.
The structure returned by the fstatvfs method:
-
f_bsize: File system block size
-
f_frsize: Fragment size
-
f_blocks: Total number of data blocks in the file system
-
f_bfree: Number of free blocks
-
f_bavail:Number of blocks available to non-superusers
-
f_files: Total number of file nodes
-
f_ffree: Number of free file nodes
-
f_favail: Number of file nodes available to non-superusers
-
f_fsid: File system identifier ID
-
f_flag: Mount flags
-
f_namemax: Maximum file name length
Syntax
The **fstatvfs()** method syntax is as follows:
os.fstatvfs(fd)
Parameters
-
fd -- The file descriptor.
Return Value
Returns information about the file system of the file containing the file descriptor fd.
Example
The following example demonstrates the use of the fstatvfs() method:
#!/usr/bin/python3
import os, sys
# Open file
fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT )
# Get tuple
info = os.fstatvfs(fd)
print ("文件信息 :", info)
# Get maximum filename length
print ("文件名最大长度 :%d" % info.f_namemax)
# Get available blocks
print ("可用块数 :%d" % info.f_bfree)
# Close file
os.close( fd)
The output of the above program is:
文件信息 : (4096, 4096, 2621440L, 1113266L, 1113266L,
8929602L, 8764252L, 8764252L, 0, 255)
文件名最大长度 :255
可用块数 :1113266