mount_point = find_mount_point(path)
+ candidates = []
+
with open('/proc/mounts', 'rt') as file_handle:
for line in file_handle:
parts = line.split()
new_mount = MountPoint()
for field_name, value in matches.groupdict().items():
setattr(new_mount, field_name, value)
- return new_mount
+ candidates.append(new_mount)
+
+ if not candidates:
+ raise NotImplementedError('impossible: mount point not found in '
+ 'fstab!')
+ elif len(candidates) == 1:
+ return candidates[0]
+
+ # decide which candidates to use: return first that is a "real"
+ # filesystem (e.g. prefer ext4 before rootfs for '/')
+ for candidate in candidates:
+ print(candidate.vfstype)
+ if candidate.vfstype in REAL_FILESYSTEMS_TYPE and \
+ candidate.spec not in NOT_REAL_FILESYSTEMS_SPEC:
+ return candidate
+
+ # otherwise just return first
+ return candidates[0]
- raise NotImplementedError('impossible: mount point not found in fstab!')
def find_mount_point(path):