1
from __future__ import division
7
def get_mount_info(mounts_file, statvfs_):
9
Given a mounts file (e.g., /proc/mounts), generate dicts with the following
12
- device: The device file which is mounted.
13
- mount-point: The path at which the filesystem is mounted.
14
- filesystem: The filesystem type.
15
- total-space: The capacity of the filesystem in megabytes.
16
- free-space: The amount of space available in megabytes.
18
for line in open(mounts_file):
20
device, mount_point, filesystem = line.split()[:3]
21
mount_point = mount_point.decode("string-escape")
24
megabytes = 1024 * 1024
25
stats = statvfs_(mount_point)
26
block_size = stats[statvfs.F_BSIZE]
27
total_space = (stats[statvfs.F_BLOCKS] * block_size) // megabytes
28
free_space = (stats[statvfs.F_BFREE] * block_size) // megabytes
29
yield {"device": device, "mount-point": mount_point,
30
"filesystem": filesystem, "total-space": total_space,
31
"free-space": free_space}
34
def get_filesystem_for_path(path, mounts_file, statvfs_):
36
path = os.path.realpath(path)
37
path_segments = path.split("/")
38
for info in get_mount_info(mounts_file, statvfs_):
39
mount_segments = info["mount-point"].split("/")
40
if path.startswith(info["mount-point"]):
42
or path_segments[:len(mount_segments)] == mount_segments):