python-adfs

changeset 27:7da34e35f9ef

Continued work on the map decoding method "scan_new_map".
author David Boddie <david@boddie.org.uk>
date Sat Mar 29 01:40:13 2003 +0100
parents bcc1701ee79d
children 0a693a7f220e
files ADFSlib.py
diffstat 1 files changed, 70 insertions(+), 109 deletions(-) [+]
line diff
     1.1 --- a/ADFSlib.py	Fri Mar 28 22:34:07 2003 +0100
     1.2 +++ b/ADFSlib.py	Sat Mar 29 01:40:13 2003 +0100
     1.3 @@ -346,79 +346,6 @@
     1.4          return map
     1.5      
     1.6      
     1.7 -    def _scan_new_map(self, begin, end):
     1.8 -    
     1.9 -        map = {}
    1.10 -    
    1.11 -        a = begin
    1.12 -        
    1.13 -        in_block = 0
    1.14 -        block_no = None
    1.15 -        
    1.16 -        while a < end:
    1.17 -        
    1.18 -            value = ord(self.sectors[a])
    1.19 -            
    1.20 -            if not in_block and value > 1:
    1.21 -            
    1.22 -                # A file number was found. Read its value and begin to
    1.23 -                # read its length.
    1.24 -                value = self.str2num(2, self.sectors[a:a+2])
    1.25 -                
    1.26 -                entry = value & 0x7fff
    1.27 -                print hex(entry), hex(a)
    1.28 -                
    1.29 -                if not map.has_key(entry):
    1.30 -                
    1.31 -                    # Create a new map entry corresponding to this value in
    1.32 -                    # which the address of this entry is stored.
    1.33 -                    map[entry] = [[a]]
    1.34 -                
    1.35 -                else:
    1.36 -                
    1.37 -                    # Add this address to the map dictionary.
    1.38 -                    map[entry].append([a])
    1.39 -                
    1.40 -                # Check whether this block finishes immediately.
    1.41 -                if (value & 0x8000) != 0:
    1.42 -                    
    1.43 -                    in_block = 0
    1.44 -                    block_number = None
    1.45 -                    next = a + 2
    1.46 -                    
    1.47 -                    print " immediate end at", hex(a)
    1.48 -                    
    1.49 -                    map[entry][-1].append(a + 2)
    1.50 -                
    1.51 -                else:
    1.52 -                
    1.53 -                    in_block = 1
    1.54 -                    block_number = entry
    1.55 -                    next = a + 2
    1.56 -            
    1.57 -            elif in_block and value != 0:
    1.58 -            
    1.59 -                # The end of a block has been found.
    1.60 -                in_block = 0
    1.61 -                block_number = None
    1.62 -                next = a + 1
    1.63 -                
    1.64 -                print "end at", hex(a)
    1.65 -                
    1.66 -                map[entry][-1].append(a + 1)
    1.67 -                
    1.68 -            else:
    1.69 -            
    1.70 -                # Space or defects.
    1.71 -                
    1.72 -                # Keep scanning the map for a new block.
    1.73 -                next = a + 1
    1.74 -            
    1.75 -            a = next
    1.76 -        
    1.77 -        return map
    1.78 -    
    1.79 -    
    1.80      def scan_new_map(self, begin, end):
    1.81      
    1.82          map = {}
    1.83 @@ -427,58 +354,92 @@
    1.84          
    1.85          in_block = 0
    1.86          block_no = None
    1.87 +        terminated = 1
    1.88          
    1.89          while a < end:
    1.90          
    1.91              value = ord(self.sectors[a])
    1.92              
    1.93 -            if not in_block and value > 1:
    1.94 +            if not in_block:
    1.95              
    1.96 -                # A file number was found. Read its value and begin to
    1.97 -                # read its length.
    1.98 -                value = self.str2num(2, self.sectors[a:a+2])
    1.99 +                if value > 1:
   1.100                  
   1.101 -                entry = value & 0x7fff
   1.102 -                print hex(entry), hex(a)
   1.103 +                    if terminated:
   1.104 +                    
   1.105 +                        # A file number was found. Read its value and begin to
   1.106 +                        # read its length.
   1.107 +                        value = self.str2num(2, self.sectors[a:a+2])
   1.108 +                        
   1.109 +                        entry = value & 0x7fff
   1.110 +                        print hex(entry), hex(a)
   1.111 +                        
   1.112 +                        if not map.has_key(entry):
   1.113 +                        
   1.114 +                            # Create a new map entry corresponding to this value in
   1.115 +                            # which the address of this entry is stored.
   1.116 +                            map[entry] = [[a]]
   1.117 +                        
   1.118 +                        else:
   1.119 +                        
   1.120 +                            # Add this address to the map dictionary.
   1.121 +                            map[entry].append([a])
   1.122 +                        
   1.123 +                        # Check whether this block finishes immediately.
   1.124 +                        if (value & 0x8000) != 0:
   1.125 +                        
   1.126 +                            terminated = 1
   1.127 +                            in_block = 0
   1.128 +                            block_number = None
   1.129 +                            next = a + 2
   1.130 +                            
   1.131 +                            print " immediate end at", hex(a)
   1.132 +                            
   1.133 +                            map[entry][-1].append(a + 2)
   1.134 +                        
   1.135 +                        else:
   1.136 +                        
   1.137 +                            terminated = 0
   1.138 +                            in_block = 1
   1.139 +                            block_number = entry
   1.140 +                            next = a + 2
   1.141 +                    
   1.142 +                    elif not terminated:
   1.143 +                    
   1.144 +                        # An object was found outside the file blocks but
   1.145 +                        # was not expected.
   1.146 +                        
   1.147 +                        if self.verify:
   1.148 +                        
   1.149 +                            self.verify_log.append(
   1.150 +                                "An object was found but was not expected:" + \
   1.151 +                                " %x" % (a + begin)
   1.152 +                                )
   1.153 +                        
   1.154 +                        next = a + 1
   1.155                  
   1.156 -                if not map.has_key(entry):
   1.157 +                elif value <= 1:
   1.158                  
   1.159 -                    # Create a new map entry corresponding to this value in
   1.160 -                    # which the address of this entry is stored.
   1.161 -                    map[entry] = [[a]]
   1.162 +                    # Defects or free space found outside blocks.
   1.163 +                    next = a + 1
   1.164 +            
   1.165 +            elif in_block:
   1.166 +            
   1.167 +                if value != 0:
   1.168                  
   1.169 -                else:
   1.170 -                
   1.171 -                    # Add this address to the map dictionary.
   1.172 -                    map[entry].append([a])
   1.173 -                
   1.174 -                # Check whether this block finishes immediately.
   1.175 -                if (value & 0x8000) != 0:
   1.176 -                    
   1.177 +                    # The end of a block has been found.
   1.178 +                    terminated = 1
   1.179                      in_block = 0
   1.180                      block_number = None
   1.181 -                    next = a + 2
   1.182 +                    next = a + 1
   1.183                      
   1.184 -                    print " immediate end at", hex(a)
   1.185 +                    print "end at", hex(a)
   1.186                      
   1.187 -                    map[entry][-1].append(a + 2)
   1.188 +                    map[entry][-1].append(a + 1)
   1.189                  
   1.190 -                else:
   1.191 +                elif value == 0:
   1.192                  
   1.193 -                    in_block = 1
   1.194 -                    block_number = entry
   1.195 -                    next = a + 2
   1.196 -            
   1.197 -            elif in_block and value != 0:
   1.198 -            
   1.199 -                # The end of a block has been found.
   1.200 -                in_block = 0
   1.201 -                block_number = None
   1.202 -                next = a + 1
   1.203 -                
   1.204 -                print "end at", hex(a)
   1.205 -                
   1.206 -                map[entry][-1].append(a + 1)
   1.207 +                    # Continue reading until an end marker is found.
   1.208 +                    next = a + 1
   1.209                  
   1.210              else:
   1.211