summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoel Andres Granados <jgranado@redhat.com>2008-10-23 16:24:15 +0200
committerJoel Andres Granados <jgranado@redhat.com>2008-10-24 15:01:13 +0200
commit2a433d8bbe31ff16156f5d2864f0435e9fc440ed (patch)
tree15b7d161f0e9e9706c9d514dc0907f9e588314e7
parent1615b70e2fdd6e36d4050ee9c55aaf15a0501a6f (diff)
downloadfirstaidkit-2a433d8bbe31ff16156f5d2864f0435e9fc440ed.tar.gz
firstaidkit-2a433d8bbe31ff16156f5d2864f0435e9fc440ed.tar.xz
firstaidkit-2a433d8bbe31ff16156f5d2864f0435e9fc440ed.zip
Create the revert function for the grub plugin.
-rw-r--r--plugins/grub/grub.py30
-rw-r--r--plugins/grub/grubUtils.py4
2 files changed, 29 insertions, 5 deletions
diff --git a/plugins/grub/grub.py b/plugins/grub/grub.py
index 7fcb586..3a4f247 100644
--- a/plugins/grub/grub.py
+++ b/plugins/grub/grub.py
@@ -41,7 +41,29 @@ class Grub(Plugin):
@classmethod
def revert(cls, backup, report):
- report.info("Executing revert", origin = Grub)
+ """ Use the backup object to replace the first 446 bytes in all devs.
+ """
+ report.info("Entering revert...", origin = Grub)
+ firstblockdict = backup.restoreValue("firstblockdict")
+ for (dev, val) in firstblockdict.iteritems():
+ devpath = val[1].path()
+ first446bytes = val[0]
+ report.info("Reverting changes for device %s." % devpath, \
+ origin = Grub)
+ try:
+ fd = os.open(devpath, os.O_WRONLY)
+ first446btemp = os.write(fd, 446)
+ os.close(fd)
+ except IOError, ie:
+ report.debug("There was an error writing to %s, It is very " \
+ "probable that this device is in an invalid state." \
+ "Error: %s" % (devpath, ie), origin = Grub)
+ except Exception, e:
+ report.debug("There was an unexpected error: %s" % e, \
+ origin = Grub)
+
+ report.info("Successfully reverted changes to device %s." % devpath, \
+ origin = Grub)
def __init__(self, *args, **kwargs):
Plugin.__init__(self, *args, **kwargs)
@@ -220,14 +242,16 @@ class Grub(Plugin):
# devices, we will backup all of them.
self._reporting.info("Going to backup all the first 446 bytes of " \
"all storage devices in the system.", origin = self)
+ firstblockdict = {}
for (device, partitions) in self.devices.iteritems():
fd = os.open(Dname.asPath(device), os.O_RDONLY)
first446btemp = os.read(fd, 446)
os.close(fd)
- self.backupSpace.backupValue(first446btemp, Dname.asName(device))
+ firstblockdict[Dname.asName(device)] = [first446btemp, \
+ Dname(device)]
+ self.backupSpace.backupValue( firstblockdict, "firstblockdict")
self._result = ReturnSuccess
-
def fix(self):
# We ar to fail if there is no dirs.
if len(self.grub_dir_parts) == 0:
diff --git a/plugins/grub/grubUtils.py b/plugins/grub/grubUtils.py
index 1519d72..b390518 100644
--- a/plugins/grub/grubUtils.py
+++ b/plugins/grub/grubUtils.py
@@ -444,7 +444,7 @@ class Dname:
def grubName(self, parenthesis = False):
"""Change the kernel device name to something that grub understands
- It returns a string of the form hd[devicd],[partition]
+ It returns a string of the form hd[device],[partition]
"""
# First we search for the number that ends the device string.
@@ -469,7 +469,7 @@ class Dname:
raise Exception("The conversion from kernel device scheme to " \
"grub scheme failed.")
- # Decide weather to return with or withoug parenthesis.
+ # Decide weather to return with or without parenthesis.
if parenthesis:
openpar = "("
closepar = ")"