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異常處理