Python os.fstatvfs() Method
Python OS File/Directory Methods
Overview
The os.fstatvfs() method is used to return information about the file system of the file containing the file descriptor fd, similar to statvfs().
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-superuser
f_files:Total number of inodes
f_ffree:Number of free inodes
f_favail:Number of free inodes available to non-superuser
f_fsid:File system identifier ID
f_flag:Mount flags
f_namemax:Maximum file name length
Syntax
fstatvfs()The 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/python # -*- coding: UTF-8 -*- import os, sys # 打开文件 fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT ) # 获取元组 info = os.fstatvfs(fd) print "文件信息 :", info # 获取文件名最大长度 print "文件名最大长度 :%d" % info.f_namemax # 获取可用块数 print "可用块数 :%d" % info.f_bfree # 关闭文件 os.close( fd)
The output of the above program is:
文件信息 : (4096, 4096, 2621440L, 1113266L, 1113266L,
8929602L, 8764252L, 8764252L, 0, 255)
文件名最大长度 :255
可用块数 :1113266
Other Extensions