diff options
author | Ludovic Pouzenc <lpouzenc@gmail.com> | 2015-07-04 16:56:48 +0200 |
---|---|---|
committer | Ludovic Pouzenc <lpouzenc@gmail.com> | 2015-07-04 16:56:48 +0200 |
commit | 32d4e844404295546e5623251037c09f83130981 (patch) | |
tree | 299370b69840462ad36ed7069897714b36930c7f | |
parent | d16af666b5fc165d1f231a04ce6c1609563b7e74 (diff) | |
download | raidguessfs-32d4e844404295546e5623251037c09f83130981.tar.gz raidguessfs-32d4e844404295546e5623251037c09f83130981.tar.bz2 raidguessfs-32d4e844404295546e5623251037c09f83130981.zip |
Tasks : implement the first one : find_bootsect
task_kill does not work, stale python process stays after umount.
Should use state as initialisation vector too (start / kill / restart)
-rw-r--r-- | mytasks.py | 46 | ||||
-rwxr-xr-x | raidguessfs.py | 2 |
2 files changed, 42 insertions, 6 deletions
@@ -18,15 +18,51 @@ # You should have received a copy of the GNU General Public License # along with RaidGuessFS. If not, see <http://www.gnu.org/licenses/> -import multiprocessing, logging +import multiprocessing, binascii, logging import mydisks def do_find_files(d,state): - state['TODO'] = 'Not yet implemented' + logging.info("Enter do_find_files()") + try: + state['TODO'] = 'Not yet implemented' + state['progress'] = 100 + except Exception as e: + logging.exception(e) + logging.info("Exit. do_find_files()") def do_find_bootsect(d,state): - state['TODO'] = 'Not yet implemented' + logging.info("Enter do_find_bootsect()") + try: + ref_sig = binascii.unhexlify('55AA') + + start = 0 + end = min(d.disks_size) + one_percent = (end - start) / 100 + one_percent = one_percent + ( (-one_percent)%512 ) + logging.debug("start/end/1pc : %i / %i / %i"%(start,end,one_percent)) + + state['found'] = [] + state['progress'] = 0 + for offset in range(start, end, 512): + for disk_no in range(d.disk_count): + d.disks[disk_no].seek(offset) + data = d.disks[disk_no].read(512) + sig = data[510:] + if sig == ref_sig: + f = state['found'] + if len(f) < 200: + f.append((disk_no,offset)) + state['found'] = f + else: + raise Exception('Aborting after too many matches') + + if offset % one_percent == 0: + state['progress'] = state['progress'] + 1 + state['progress'] = 100 + except Exception as e: + logging.exception(e) + logging.info("Exit. do_find_bootsect()") @@ -84,11 +120,11 @@ class MyTasks(): if self.find_bootsect_process == None: return 'This task has never been started\n' else: - return 'TODO\n%s\n'%self.find_bootsect_state + return '%s\n'%self.find_bootsect_state def read_find_files(self): if self.find_files_process == None: return 'This task has never been started\n' else: - return 'TODO\n%s\n'%self.find_files_state + return '%s\n'%self.find_files_state diff --git a/raidguessfs.py b/raidguessfs.py index 5aa8347..409ef0c 100755 --- a/raidguessfs.py +++ b/raidguessfs.py @@ -241,7 +241,7 @@ class RaidGuessFS(fuse.Fuse): } self.fattr.update( { - '/tasks/%s'%s: self.st.make_fake_file(512) for s in self.tasks.TASK_NAMES + '/tasks/%s'%s: self.st.make_fake_file(4096) for s in self.tasks.TASK_NAMES }) for raid_type in myraid.MyRaid.RAID_TYPES: |