#!/usr/bin/env python # RaidGuessFS, a FUSE pseudo-filesystem to guess RAID parameters of a damaged device # Copyright (C) 2015 Ludovic Pouzenc # # 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 import logging, numpy class MyRaid(): """Auxiliary class, managing RAID layer""" def __init__(self, *args, **kwargs): self.raid_start = 0 self.raid_end = 0 self.raid_sector_size = 512 self.raid_chunk_size = 65536 self.raid_disk_order = [] self.raid_disk_count = 0 self.raid_types = [ '0', '1', '5', '5+0' ] def get_raid_start(self): return self.raid_start def get_raid_chunk_size(self): return self.raid_chunk_size def get_raid_disk_order(self): return self.raid_disk_order def get_raid_disk_order_str(self): return ' '.join(map(str,self.raid_disk_order)) def set_raid_start(self, new_raid_start): """Update the start offset of raid data on underlying disks""" self.raid_start = new_raid_start def set_raid_end(self, new_raid_end): """Update the end offset of raid data on underlying disks""" self.raid_end = new_raid_end def set_raid_chunk_size(self, new_raid_chunk_size): """Update the size of chucks of data (or slice size)""" self.raid_chunk_size = new_raid_chunk_size def set_raid_disk_order(self, new_raid_disk_order): """Update the raid logical disk order""" card=len(new_raid_disk_order) check=[0]*card for item in new_raid_disk_order: d = int(item) if not 0 <= d < card: raise ValueError('Value out of range : %i [0,%i]'%(d,card-1)) check[d]=check[d]+1 for d in range(card): if check[d]!=1: raise ValueError('Disk %i appears %i times (must be 1)'%(d,check[d])) self.raid_disk_order = new_raid_disk_order self.raid_disk_count = len(new_raid_disk_order) def sizeof_raid_result(self, raid_type): size = self.raid_end - self.raid_start if size <= 0 : return 0 else: return { '0' : size * self.raid_disk_count, '1' : size, '5' : size * (self.raid_disk_count - 1) if self.raid_disk_count >= 3 else 0, '5+0': size * (self.raid_disk_count - 2) if self.raid_disk_count >= 6 and self.raid_disk_count % 2 == 0 else 0, }[raid_type] def sizeof_disk_parity(self, raid_type): return self.sizeof_disk_xor(raid_type) / self.raid_sector_size * 16 def sizeof_disk_xor(self, raid_type): size = self.raid_end - self.raid_start if size <= 0: return 0 else: return { '0' : 0, # TODO Could contain some plain text error message '1' : size, '5' : size if self.raid_disk_count >= 3 else 0, '5+0': size if self.raid_disk_count >= 6 and self.raid_disk_count % 2 == 0 else 0, }[raid_type] def xor_blocks(self,fd_list, offset, size): """TODO""" logging.info("Enter xor_blocks(fd_list,%d,%d)"%(offset, size)) assert(size % 8 == 0), "Size must be multiple of 8" dt = numpy.dtype('