summaryrefslogtreecommitdiff
path: root/mydisks.py
diff options
context:
space:
mode:
Diffstat (limited to 'mydisks.py')
-rw-r--r--mydisks.py28
1 files changed, 11 insertions, 17 deletions
diff --git a/mydisks.py b/mydisks.py
index 070c188..624e3a0 100644
--- a/mydisks.py
+++ b/mydisks.py
@@ -23,27 +23,16 @@ import os, sys, logging
class MyDisks():
"""Auxiliary class, managing disk layer"""
- def __init__(self, *args, **kwargs):
+ def __init__(self):
self.disks = []
- self.disk_paths = []
self.sector_size = 512
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"""
- 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):
+ def open_disks(self, base_path, new_disk_count):
"""(re)open all disks"""
logging.debug("Enter open_disks()")
for fh in self.disks:
@@ -51,13 +40,16 @@ class MyDisks():
fh.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]
+ self.disk_count = 0
+ self.disks = [ None for d in range(new_disk_count) ]
+ self.disks_size = [ 0 for d in range(new_disk_count) ]
+
+ for d in range(new_disk_count):
+ path = '%s/disk%02d.img'%(base_path,d)
logging.debug("Try to open disk #%2d"%d)
try:
+ # TODO : follow symlinks
fh = open(path, "rb")
self.disks_size[d] = os.lseek(fh.fileno(), 0, os.SEEK_END)
self.disks[d] = fh
@@ -70,6 +62,7 @@ class MyDisks():
logging.error("Can't open disk #%2d ('%s') : unhandled exception"%(d, path))
self.disks_size[d] = 0
logging.exception(e)
+ self.disk_count += 1
logging.debug("Exit. open_disks()")
@@ -80,6 +73,7 @@ class MyDisks():
#return random.randint(0,100) > 1 # FIXME : implement this (parse ddrescue log files)
def read(self,disk_no,offset,size):
+ # XXX : Consider pread() ?
self.disks[disk_no].seek(offset)
return self.disks[disk_no].read(size)