Python3 os.fstatvfs()方法

statvfs()方法返回關於檔描述符fd相關聯的檔的檔系統資訊。這將返回以下結構:
  • f_bsize: 檔系統的塊大小

  • f_frsize: 片段大小

  • f_blocks: fs在f_frsize單位的大小

  • f_bfree: 空閒塊

  • f_bavail: 對於非root用戶自由塊

  • f_files: 索引節點

  • f_ffree: 空閒節點

  • f_favail: 對於非root用戶空閒節點

  • f_fsid: 檔系統ID

  • f_flag: 掛載標誌

  • f_namemax: 最大檔案名長度

語法

以下是 statvfs() 方法的語法:
os.fstatvfs(fd)

參數

  • fd -- 這是將被返回檔描述符的系統資訊

返回值

此方法返回包含相關檔的檔系統資訊。

示例

下麵的例子顯示 statvfs()方法的使用。
#!/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

上一篇: Python3檔方法 下一篇: Python3 os檔目錄的方法