On 03/15/2009 08:57 AM, Eric Sandeen wrote:
David Lehman wrote:
On Fri, 2009-03-13 at 18:09 -1000, David Cantrell wrote:
The _getExistingSize() method in class FS will using the filesystem
info/dump utility to figure out the size of the filesystem. Each
filesystem must define _infofs, _defaultInfoOptions, and
_existingSizeFields.
Looks okay to me. This is kind of scary stuff, but I think that's just
how it is when you have to parse output like this.
Why not just do a temporary mount somewhere (if not already mounted) and
run statfs on it? Wouldn't that be simpler?</hand_wave>
It would be. Attached is a new patch. I didn't know we could call
statvfs() from Python (nor did I ever bother to look, but whatever).
--
David Cantrell <dcantrell@xxxxxxxxxx>
Red Hat / Honolulu, HI
>From 1dc02267ae81b6f5bf88db361a3cfd543efa310d Mon Sep 17 00:00:00 2001
From: David Cantrell <dcantrell@xxxxxxxxxx>
Date: Fri, 13 Mar 2009 18:03:22 -1000
Subject: [PATCH 03/10] Use os.statvfs() to get existing filesystem size.
Mount the filesystem in a temporary location, call os.statvfs(),
compute filesystem size in megabytes.
---
storage/formats/fs.py | 27 +++++++++++++++++++++++++++
1 files changed, 27 insertions(+), 0 deletions(-)
diff --git a/storage/formats/fs.py b/storage/formats/fs.py
index f467852..40215cf 100644
--- a/storage/formats/fs.py
+++ b/storage/formats/fs.py
@@ -18,6 +18,7 @@
# Red Hat, Inc.
#
# Red Hat Author(s): Dave Lehman <dlehman@xxxxxxxxxx>
+# David Cantrell <dcantrell@xxxxxxxxxx>
#
""" Filesystem classes for use by anaconda.
@@ -27,6 +28,7 @@
- bug 472127: allow creation of tmpfs filesystems (/tmp, /var/tmp, &c)
"""
import os
+import tempfile
import isys
from ..errors import *
@@ -150,8 +152,12 @@ class FS(DeviceFormat):
self.mountpoint = kwargs.get("mountpoint")
self.mountopts = kwargs.get("mountopts")
self.label = kwargs.get("label")
+
# filesystem size does not necessarily equal device size
self._size = kwargs.get("size")
+ if self.exists:
+ self._size = self._getExistingSize()
+
self._targetSize = self._size
self._mountpoint = None # the current mountpoint when mounted
@@ -187,6 +193,27 @@ class FS(DeviceFormat):
size = property(_getSize, doc="This filesystem's size, accounting "
"for pending changes")
+ def _getExistingSize(self):
+ """ Determine the size of this filesystem. Filesystem must
+ exist.
+ """
+ size = 0
+
+ if self.mountable:
+ origMountPoint = self._mountpoint
+
+ (f, tmppath) = tempfile.mkdtemp(prefix='getsize', dir='/tmp')
+ self.mount(mountpoint=tmppath)
+ buf = os.statvfs(tmppath)
+ self.unmount()
+ os.rmdir(tmppath)
+
+ self._mountpoint = origMountPoint
+
+ size = (buf.f_frsize * buf.f_blocks) / 1024.0 / 1024.0
+
+ return size
+
@property
def currentSize(self):
""" The filesystem's current actual size. """
--
1.6.2
_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list