This doesn't give the name of the partition, but you can get the filesystem statistics directly using the statvfs
Unix system call. To call it from Python, use os.statvfs('/home/foo/bar/baz')
.
The relevant fields in the result, according to POSIX:
unsigned long f_frsize Fundamental file system block size.
fsblkcnt_t f_blocks Total number of blocks on file system in units of f_frsize.
fsblkcnt_t f_bfree Total number of free blocks.
fsblkcnt_t f_bavail Number of free blocks available to
non-privileged process.
So to make sense of the values, multiply by f_frsize
:
import os
statvfs = os.statvfs('/home/foo/bar/baz')
statvfs.f_frsize * statvfs.f_blocks # Size of filesystem in bytes
statvfs.f_frsize * statvfs.f_bfree # Actual number of free bytes
statvfs.f_frsize * statvfs.f_bavail # Number of free bytes that ordinary users
# are allowed to use (excl. reserved space)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…