[elbe-devel] [PATCH v2 3/9] fstab: factor out hdpart from fstabentry
Torben Hohn
torben.hohn at linutronix.de
Tue Dec 15 17:33:13 CET 2020
the partition geometry is currently saved into attributes of
an fstab label entry.
Prepare to be able to losetup() binary partitions, which do not
have an fstabentry by splitting the losetup() stuff into a base class.
Signed-off-by: Torben Hohn <torben.hohn at linutronix.de>
Reviewed-by: Bastian Germann <bage at linutronix.de>
---
elbepack/fstab.py | 76 +++++++++++++++++++++++++----------------------
1 file changed, 40 insertions(+), 36 deletions(-)
diff --git a/elbepack/fstab.py b/elbepack/fstab.py
index f3e0f5757..6b89b3990 100644
--- a/elbepack/fstab.py
+++ b/elbepack/fstab.py
@@ -71,14 +71,53 @@ class mountpoint_dict (dict):
return [self[x] for x in mplist]
+class hdpart:
+ def __init__(self):
+ # These attributes are filled later
+ # using set_geometry()
+ self.size = 0
+ self.offset = 0
+ self.filename = ''
+ self.partnum = 0
+ self.number = ''
+
+ def set_geometry(self, ppart, disk):
+ sector_size = 512
+ self.offset = ppart.geometry.start * sector_size
+ self.size = ppart.getLength() * sector_size
+ self.filename = disk.device.path
+ self.partnum = ppart.number
+ self.number = '{}{}'.format(disk.type, ppart.number)
+
+ def losetup(self):
+
+ cmd = ('losetup --offset %d --sizelimit %d --find --show "%s"' %
+ (self.offset, self.size, self.filename))
+
+ while True:
+
+ try:
+ loopdev = get_command_out(cmd)
+ except CommandError as e:
+ if e.returncode != 1:
+ raise
+ do('sync')
+ time.sleep(1)
+ else:
+ break
+
+ return loopdev.decode().rstrip('\n')
+
# TODO:py3 Remove object inheritance
# pylint: disable=useless-object-inheritance
-class fstabentry(object):
+class fstabentry(hdpart):
# pylint: disable=too-many-instance-attributes
def __init__(self, xml, entry, fsid=0):
+ super().__init__()
+
if entry.has("source"):
self.source = entry.text("source")
else:
@@ -95,14 +134,6 @@ class fstabentry(object):
self.passno = entry.text("fs/passno", default="0")
self.tune = entry.text("fs/tune2fs", default=None)
- # These attributes are filled later
- # using set_geometry()
- self.size = 0
- self.offset = 0
- self.filename = ''
- self.partnum = 0
- self.number = ''
-
self.id = str(fsid)
def get_str(self):
@@ -126,33 +157,6 @@ class fstabentry(object):
return "-n " + self.label
return ""
- def set_geometry(self, ppart, disk):
- sector_size = 512
- self.offset = ppart.geometry.start * sector_size
- self.size = ppart.getLength() * sector_size
- self.filename = disk.device.path
- self.partnum = ppart.number
- self.number = '{}{}'.format(disk.type, ppart.number)
-
- def losetup(self):
-
- cmd = ('losetup --offset %d --sizelimit %d --find --show "%s"' %
- (self.offset, self.size, self.filename))
-
- while True:
-
- try:
- loopdev = get_command_out(cmd)
- except CommandError as e:
- if e.returncode != 1:
- raise
- do('sync')
- time.sleep(1)
- else:
- break
-
- return loopdev.decode().rstrip('\n')
-
def tuning(self, loopdev):
if self.tune:
do('tune2fs %s %s' % (self.tune, loopdev))
--
2.20.1
More information about the elbe-devel
mailing list