summaryrefslogtreecommitdiff
path: root/mydisks.py
diff options
context:
space:
mode:
authorLudovic Pouzenc <lpouzenc@lud-GB1>2015-06-12 08:34:26 +0200
committerLudovic Pouzenc <lpouzenc@lud-GB1>2015-06-12 08:34:26 +0200
commit5943acb92ce0159e9f482748e4fa4aadddae6851 (patch)
treee4fc66dabda439f8a98535f10287018e871c2e41 /mydisks.py
parent49c830d2d70547c31cab1b1f0bc9f26d77d62a7e (diff)
downloadraidguessfs-5943acb92ce0159e9f482748e4fa4aadddae6851.tar.gz
raidguessfs-5943acb92ce0159e9f482748e4fa4aadddae6851.tar.bz2
raidguessfs-5943acb92ce0159e9f482748e4fa4aadddae6851.zip
Initial import.
RAID 5 xor parity checking is working, data reading on left-assymetric RAID 5 is working. Nothing done on other RAID types.
Diffstat (limited to 'mydisks.py')
-rw-r--r--mydisks.py75
1 files changed, 75 insertions, 0 deletions
diff --git a/mydisks.py b/mydisks.py
new file mode 100644
index 0000000..c3b7716
--- /dev/null
+++ b/mydisks.py
@@ -0,0 +1,75 @@
+#!/usr/bin/env python
+
+# RaidGuessFS, a FUSE pseudo-filesystem to guess RAID parameters of a damaged device
+# Copyright (C) 2015 Ludovic Pouzenc <ludovic@pouzenc.fr>
+#
+# This file is part of RaidGuessFS.
+#
+# RaidGuessFS is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# RaidGuessFS is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with RaidGuessFS. If not, see <http://www.gnu.org/licenses/>
+
+import os, sys, logging
+
+class MyDisks():
+ """Auxiliary class, managing disk layer"""
+
+ def __init__(self, *args, **kwargs):
+ self.disks = []
+ self.disk_paths = []
+ self.disk_count = 0
+ self.disks_size = [0]
+ self.max_disks = 16
+
+ def get_disk_count(self):
+ return self.disk_count
+
+ def set_disks_path(self,disk_path_list):
+ """Set the list of real filepath to disks or images and (re)open them"""
+ self.disk_paths = disk_path_list
+
+ def set_disk_count(self,new_disk_count):
+ """Update the number of attached disks on the fly"""
+ self.disk_count = min(new_disk_count,self.max_disks)
+ logging.info("MyDisks.set_disk_count(%d) : setting disk_count to %d" % (new_disk_count, self.disk_count))
+
+ def open_disks(self):
+ """(re)open all disks"""
+ logging.debug("Enter open_disks()")
+ for fd in self.disks:
+ try:
+ fd.close()
+ except:
+ pass
+ self.disks = [ None for d in range(self.disk_count) ]
+ self.disks_size = [ 0 for d in range(self.disk_count) ]
+
+ for d in range(self.disk_count):
+ path = self.disk_paths[d]
+ logging.debug("Try to open disk #%2d"%d)
+ try:
+ self.disks[d] = open(path, "r")
+ self.disks_size[d] = os.lstat(path).st_size
+ logging.debug("Opened disk #%2d"%d)
+ except IOError as e:
+ logging.error("Can't open disk #%2d ('%s') : %s"%(d, path, e.strerror))
+ self.disks_size[d] = 0
+ except:
+ logging.error("Can't open disk #%2d ('%s') : unhandled exception"%(d, path))
+ self.disks_size[d] = 0
+ logging.debug("Exit. open_disks()")
+
+ def read(self,disk_no,offset,size):
+ self.disks[disk_no].seek(offset)
+ return self.disks[disk_no].read(size)
+
+