[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Fedora-livecd-list] [PATCH 4/7] anaconda: livecd.py: use dumpe2fs for getLiveSizeMB



even if turboLiveInst/genMinInstDelta didn't depend on this, it is a good idea anyway for anaconda's livecd backend to use dumpe2fs to determine the size of data to copy during install, rather than looking at the size of the block device holding the filesystem.


diff -Naur anaconda.0.bugfix_selinux/livecd.py anaconda.4.getLiveSizeMB_use_dumpe2fs/livecd.py
--- anaconda.0.bugfix_selinux/livecd.py	2007-09-17 17:03:50.000000000 +0000
+++ anaconda.4.getLiveSizeMB_use_dumpe2fs/livecd.py	2007-09-17 17:02:18.000000000 +0000
@@ -133,25 +133,24 @@
     def getLiveBlockDevice(self):
         return self.osimg
 
-    def getLiveSizeMB(self):
-        lnk = os.readlink(self.osimg)
-        if lnk[0] != "/":
-            lnk = os.path.join(os.path.dirname(self.osimg), lnk)
-        blk = os.path.basename(lnk)
-
-        if not os.path.exists("/sys/block/%s/size" %(blk,)):
-            log.debug("Unable to determine the actual size of the live image")
-            return 0
-
-        size = open("/sys/block/%s/size" %(blk,), "r").read()
-        try:
-            size = int(size)
-        except ValueError:
-            log.debug("Unable to handle live size conversion: %s" %(size,))
-            return 0
+    def parseField(self, output, field):
+        for line in output.split("\n"):
+            if line.startswith(field + ":"):
+                return line[len(field) + 1:].strip()
+        
+        raise KeyError("Failed to find field '%s' in output" % field)
 
-        return (size * 512) / 1024 / 1024
+    def getSectorCountOfExt2FS(self, filesystem):
+        output = subprocess.Popen(['/sbin/dumpe2fs', '-h', filesystem],
+                                  stdout=subprocess.PIPE,
+                                  stderr=open('/dev/null', 'w')
+                                  ).communicate()[0]
         
+        return (int(self.parseField(output, "Block count")) *
+                int(self.parseField(output, "Block size")) / 512)
+
+    def getLiveSizeMB(self):
+        return (self.getSectorCountOfExt2FS(self.osimg) * 512) / 1024 / 1024
 
 class LiveCDCopyBackend(backend.AnacondaBackend):
     def __init__(self, method, instPath):

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]