Python os.fstatvfs()方法

Python的os.fstatvfs()方法返回有关包含与文件描述符fd相关联的文件的文件系统的信息。这将返回以下结构 -

  • f_bsize - 文件系统块大小
  • f_frsize - 片段大小
  • f_blocks - f_frsize单位中的fs大小
  • f_bfree - free
  • f_bavail - 非root的空闲块
  • f_files - inode
  • f_ffree - 免费的inode
  • f_favail - 非root用户的免费inode
  • f_fsid - 文件系统ID
  • f_flag - 挂载标志
  • f_namemax - 最大文件名长度

语法

以下是fstatvfs()方法的语法 -

os.fstatvfs(fd)

参数

  • fd − 这是要返回系统信息的文件描述符。

返回值

  • 此方法返回有关包含文件关联文件系统的信息。

示例

以下示例显示了fstatvfs()方法的用法。

#!/usr/bin/python3
import os, sys

# Open a file
fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT )

# Now get  the touple
info = os.fstatvfs(fd)
print ("File Info :", info)

# Now get maximum filename length
print ("Maximum filename length :%d" % info.f_namemax:)

# Now get free blocks
print ("Free blocks :%d" % info.f_bfree)

# Close opened file
os.close( fd)

执行上面代码后,将得到以下结果 -

File Info : (4096, 4096, 2621440L, 1113266L, 1113266L, 
             8929602L, 8764252L, 8764252L, 0, 255)
Maximum filename length :255
Free blocks :1113266

上一篇: Python os模块方法 下一篇: Python异常处理