[PATCH 4/8] On existing ext2/ext3 filesystems, init size and targetSize.

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

 



On existing ext2 and ext3 filesystems, initialize our size property
to the size of the filesystem in megabytes.  Initialize targetSize
to the size in megabytes of the used space.  Use dumpe2fs to collect
size information as the size does not necessarily match with the
underlying StorageDevice this format sits on.
---
 storage/formats/fs.py |   35 +++++++++++++++++++++++++++++++++++
 1 files changed, 35 insertions(+), 0 deletions(-)

diff --git a/storage/formats/fs.py b/storage/formats/fs.py
index 0c66d38..7579122 100644
--- a/storage/formats/fs.py
+++ b/storage/formats/fs.py
@@ -26,6 +26,7 @@
         - migration
         - bug 472127: allow creation of tmpfs filesystems (/tmp, /var/tmp, &c)
 """
+import math
 import os
 import isys
 
@@ -704,6 +705,40 @@ class Ext2FS(FS):
     _migratefs = "tune2fs"
     _defaultMigrateOptions = ["-j"]
 
+    def __init__(self, *args, **kwargs):
+        FS.__init__(self, *args, **kwargs)
+
+        # get size of existing filesystem
+        if self.exists:
+            blockCount = None
+            blockSize = None
+            freeBlocks = None
+
+            buf = iutil.execWithCapture('dumpe2fs', ['-h', self.device],
+                                        stderr="/dev/tty5")
+
+            for line in buf.splitlines():
+                tmp = line.split(' ')
+
+                if line.startswith('Block count:'):
+                    blockCount = long(tmp[len(tmp) - 1])
+                elif line.startswith('Block size:'):
+                    blockSize = long(tmp[len(tmp) - 1])
+                elif line.startswith('Free blocks:'):
+                    freeBlocks = long(tmp[len(tmp) - 1])
+
+                if blockCount and blockSize and freeBlocks:
+                    break
+
+            total = blockCount * blockSize
+            free = freeBlocks * blockSize
+
+            # report current size as megabytes
+            self._size = total / 1024.0 / 1024.0
+
+            # set target size to used space
+            self.targetSize = math.ceil(total - free) / 1024.0 / 1024.0
+
     @property
     def minSize(self):
         """ Minimum size for this filesystem in MB. """
-- 
1.6.1.3

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux