Example #1
0
 def scan_root(self):
   """Step 2: scan root block.
      Try to determine root block from boot block or guess number.
      Returns True if the root block could be decoded.
   """
   if self.boot != None:
     # retrieve root block number from boot block
     root_blk_num = self.boot.got_root_blk
     # check root block number
     if root_blk_num == 0:
       new_root = self.blkdev.num_blocks // 2
       self.log.msg(Log.INFO,"Boot contains not Root blk. Using default: %d" % new_root,root_blk_num)
       root_blk_num = new_root      
     elif root_blk_num < self.blkdev.reserved or root_blk_num > self.blkdev.num_blocks:
       new_root = self.blkdev.num_blocks // 2
       self.log.msg(Log.INFO,"Invalid root block number: given %d using guess %d" % (root_blk_num, new_root),root_blk_num)
       root_blk_num = new_root
   else:
     # guess root block number
     root_blk_num = self.blkdev.num_blocks // 2
     self.log.msg(Log.INFO,"Guessed root block number",root_blk_num)
   # read root block
   root = RootBlock(self.blkdev, root_blk_num)
   root.read()
   if not root.valid:
     self.log.msg(Log.INFO,"Root block is not valid -> No file system",root_blk_num)      
     self.root = None # mode without root
     return False
   else:
     self.root = root
     return True
 def scan_root(self):
   """Step 2: scan root block.
      Try to determine root block from boot block or guess number.
      Returns True if the root block could be decoded.
   """
   if self.boot != None:
     # retrieve root block number from boot block
     root_blk_num = self.boot.got_root_blk
     # check root block number
     if root_blk_num == 0:
       new_root = self.blkdev.num_blocks / 2
       self.log.msg(Log.INFO,"Boot contains not Root blk. Using default: %d" % new_root,root_blk_num)
       root_blk_num = new_root      
     elif root_blk_num < self.blkdev.reserved or root_blk_num > self.blkdev.num_blocks:
       new_root = self.blkdev.num_blocks / 2
       self.log.msg(Log.INFO,"Invalid root block number: given %d using guess %d" % (root_blk_num, new_root),root_blk_num)
       root_blk_num = new_root
   else:
     # guess root block number
     root_blk_num = self.blkdev.num_blocks / 2
     self.log.msg(Log.INFO,"Guessed root block number",root_blk_num)
   # read root block
   root = RootBlock(self.blkdev, root_blk_num)
   root.read()
   if not root.valid:
     self.log.msg(Log.INFO,"Root block is not valid -> No file system",root_blk_num)      
     self.root = None # mode without root
     return False
   else:
     self.root = root
     return True
Example #3
0
    def read_block(self, blk_num, is_bm=False, is_bm_ext=False):
        """read block from device, decode it, and return block info instance"""
        try:
            # read block from device
            if is_bm:
                blk = BitmapBlock(self.blkdev, blk_num)
            elif is_bm_ext:
                blk = BitmapExtBlock(self.blkdev, blk_num)
            else:
                blk = Block(self.blkdev, blk_num)
            blk.read()
            data = blk.data
            # create block info
            bi = BlockInfo(blk_num)
            # --- classify block ---
            if blk.valid:
                # block is valid AmigaDOS
                bi.blk_status = self.BS_VALID
                # --- bitmap block ---
                if is_bm:
                    bi.blk_type = self.BT_BITMAP
                    bi.blk_status = self.BS_TYPE
                    bi.bitmap = blk.get_bitmap_data()
                # --- bitmap ext block ---
                elif is_bm_ext:
                    bi.blk_type = self.BT_BITMAP_EXT
                    bi.blk_status = self.BS_TYPE
                    bi.bitmap_ptrs = blk.bitmap_ptrs
                    bi.next_blk = blk.bitmap_ext_blk
                # --- root block ---
                elif blk.is_root_block():
                    bi.blk_type = self.BT_ROOT
                    bi.blk_status = self.BS_TYPE
                    root = RootBlock(self.blkdev, blk_num)
                    root.set(data)
                    bi.name = root.name
                    bi.hash_table = root.hash_table
                    bi.parent_blk = 0
                    self.log.msg(Log.DEBUG, "Found Root: '%s'" % bi.name,
                                 blk_num)
                    # chech hash size
                    nht = len(root.hash_table)
                    if root.hash_size != nht:
                        self.log.msg(Log.ERROR,
                                     "Root block hash table size mismatch",
                                     blk_num)
                    eht = self.blkdev.block_longs - 56
                    if nht != eht:
                        self.log.msg(
                            Log.WARN,
                            "Root block does not have normal hash size: %d != %d"
                            % (nht, eht),
                            blk_num,
                        )
                # --- user dir block ---
                elif blk.is_user_dir_block():
                    bi.blk_type = self.BT_DIR
                    bi.blk_status = self.BS_TYPE
                    user = UserDirBlock(self.blkdev, blk_num,
                                        DosType.is_longname(self.dos_type))
                    user.set(data)
                    bi.name = user.name
                    bi.parent_blk = user.parent
                    bi.next_blk = user.hash_chain
                    bi.hash_table = user.hash_table
                    bi.own_key = user.own_key
                    self.log.msg(Log.DEBUG, "Found Dir : '%s'" % bi.name,
                                 blk_num)
                # --- filter header block ---
                elif blk.is_file_header_block():
                    bi.blk_type = self.BT_FILE_HDR
                    bi.blk_status = self.BS_TYPE
                    fh = FileHeaderBlock(self.blkdev, blk_num,
                                         DosType.is_longname(self.dos_type))
                    fh.set(data)
                    bi.name = fh.name
                    bi.parent_blk = fh.parent
                    bi.next_blk = fh.hash_chain
                    bi.own_key = fh.own_key
                    bi.byte_size = fh.byte_size
                    bi.data_blocks = fh.data_blocks
                    bi.extension = fh.extension
                    self.log.msg(Log.DEBUG, "Found File: '%s'" % bi.name,
                                 blk_num)
                # --- file list block ---
                elif blk.is_file_list_block():
                    bi.blk_type = self.BT_FILE_LIST
                    fl = FileListBlock(self.blkdev, blk_num)
                    fl.set(data)
                    bi.blk_status = self.BS_TYPE
                    bi.ext_blk = fl.extension
                    bi.blk_list = fl.data_blocks
                    bi.own_key = fl.own_key
                    bi.data_blocks = fl.data_blocks
                    bi.extension = fl.extension
                    bi.parent_blk = fl.parent
                # --- file data block (OFS) ---
                elif blk.is_file_data_block():
                    bi.blk_type = self.BT_FILE_DATA
                    bi.blk_status = self.BS_TYPE
                    fd = FileDataBlock(self.blkdev, blk_num)
                    fd.set(data)
                    bi.data_size = fd.data_size
                    bi.hdr_key = fd.hdr_key
                    bi.seq_num = fd.seq_num
                elif blk.is_comment_block():
                    bi.blk_type = self.BT_COMMENT
                    bi.blk_status = self.BS_TYPE
                    cblk = CommentBlock(self.blkdev, blk_num)
                    bi.hdr_key = cblk.hdr_key
                    bi.own_key = cblk.own_key

        except IOError as e:
            self.log.msg(Log.ERROR, "Can't read block", blk_num)
            bi = BlockInfo(blk_num)
            bi.blk_status = BS_READ_ERROR

        # sort block info into map and arrays assigned by status/type
        self.block_map[blk_num] = bi
        self.map_status[bi.blk_status].append(bi)
        self.map_type[bi.blk_type].append(bi)
        return bi
Example #4
0
 def read_block(self, blk_num, is_bm=False, is_bm_ext=False):
   """read block from device, decode it, and return block info instance"""
   try:
     # read block from device
     if is_bm:
       blk = BitmapBlock(self.blkdev, blk_num)
     elif is_bm_ext:
       blk = BitmapExtBlock(self.blkdev, blk_num)
     else:
       blk = Block(self.blkdev, blk_num)
     blk.read()
     data = blk.data
     # create block info
     bi = BlockInfo(blk_num)
     # --- classify block ---
     if blk.valid:
       # block is valid AmigaDOS
       bi.blk_status = self.BS_VALID
       # --- bitmap block ---
       if is_bm:
         bi.blk_type = self.BT_BITMAP
         bi.blk_status = self.BS_TYPE
         bi.bitmap = blk.get_bitmap_data()
       # --- bitmap ext block ---
       elif is_bm_ext:
         bi.blk_type = self.BT_BITMAP_EXT
         bi.blk_status = self.BS_TYPE
         bi.bitmap_ptrs = blk.bitmap_ptrs
         bi.next_blk = blk.bitmap_ext_blk
       # --- root block ---
       elif blk.is_root_block():
         bi.blk_type = self.BT_ROOT
         bi.blk_status = self.BS_TYPE
         root = RootBlock(self.blkdev, blk_num)
         root.set(data)
         bi.name = FSString(root.name)
         bi.hash_table = root.hash_table
         bi.parent_blk = 0
         self.log.msg(Log.DEBUG, "Found Root: '%s'" % bi.name, blk_num)
         # chech hash size
         nht = len(root.hash_table)
         if root.hash_size != nht:
           self.log.msg(Log.ERROR, "Root block hash table size mismatch", blk_num)
         eht = self.blkdev.block_longs - 56
         if nht != eht:
           self.log.msg(Log.WARN, "Root block does not have normal hash size: %d != %d" % (nht, eht), blk_num)
       # --- user dir block ---
       elif blk.is_user_dir_block():
         bi.blk_type = self.BT_DIR
         bi.blk_status = self.BS_TYPE
         user = UserDirBlock(self.blkdev, blk_num)
         user.set(data)
         bi.name = FSString(user.name)
         bi.parent_blk = user.parent
         bi.next_blk = user.hash_chain
         bi.hash_table = user.hash_table
         bi.own_key = user.own_key
         self.log.msg(Log.DEBUG, "Found Dir : '%s'" % bi.name, blk_num)
       # --- filter header block ---
       elif blk.is_file_header_block():
         bi.blk_type = self.BT_FILE_HDR
         bi.blk_status = self.BS_TYPE
         fh = FileHeaderBlock(self.blkdev, blk_num)
         fh.set(data)
         bi.name = FSString(fh.name)
         bi.parent_blk = fh.parent
         bi.next_blk = fh.hash_chain
         bi.own_key = fh.own_key
         bi.byte_size = fh.byte_size
         bi.data_blocks = fh.data_blocks
         bi.extension = fh.extension
         self.log.msg(Log.DEBUG, "Found File: '%s'" % bi.name, blk_num)
       # --- file list block ---
       elif blk.is_file_list_block():
         bi.blk_type = self.BT_FILE_LIST
         fl = FileListBlock(self.blkdev, blk_num)
         fl.set(data)
         bi.blk_status = self.BS_TYPE
         bi.ext_blk = fl.extension
         bi.blk_list = fl.data_blocks
         bi.own_key = fl.own_key
         bi.data_blocks = fl.data_blocks
         bi.extension = fl.extension
         bi.parent_blk = fl.parent
       # --- file data block (OFS) ---
       elif blk.is_file_data_block():
         bi.blk_type = self.BT_FILE_DATA
         bi.blk_status = self.BS_TYPE
         fd = FileDataBlock(self.blkdev, blk_num)
         fd.set(data)
         bi.data_size = fd.data_size
         bi.hdr_key = fd.hdr_key
         bi.seq_num = fd.seq_num
             
   except IOError,e:
     self.log.msg(Log.ERROR, "Can't read block", blk_num)
     bi = BlockInfo(blk_num)
     bi.blk_status = BS_READ_ERROR