Skip to content

Instantly share code, notes, and snippets.

@devilholk
Created September 25, 2020 12:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devilholk/19ff0123e2f3f819b60d30492ad59cd7 to your computer and use it in GitHub Desktop.
Save devilholk/19ff0123e2f3f819b60d30492ad59cd7 to your computer and use it in GitHub Desktop.
Read /etc/mtab to a table
#some person on the internet: https://stackoverflow.com/a/9290177
#That is, /etc/mtab should be the convention
class MountTableRow:
def __init__(self, node, mount_point, fs_type, fs_options, fs_dump, fs_pass):
self.node = node
self.mount_point = mount_point
self.fs_type = fs_type
self.fs_options = fs_options
self.fs_dump = fs_dump
self.fs_pass = fs_pass
class MountTable:
def __init__(self):
self.table = list()
self.by_node = dict()
self.by_mount_point = dict()
def parse_line(self, line):
row = MountTableRow(*line.split())
self.table.append(row)
self.by_node[row.node] = row
self.by_mount_point[row.mount_point] = row
def is_mounted(self, node):
return node in self.by_node
def get_mount_table():
result = MountTable()
with open('/etc/mtab', 'r') as infile:
for line in infile:
result.parse_line(line)
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment