python-adfs
changeset 28:0a693a7f220e
Introduced a more complex scanning algorithm to try and identify the start
of blocks in the map.
| author | David Boddie <david@boddie.org.uk> |
|---|---|
| date | Sat Mar 29 03:28:43 2003 +0100 |
| parents | 7da34e35f9ef |
| children | b74f65e160ed |
| files | ADFSlib.py |
| diffstat | 1 files changed, 84 insertions(+), 71 deletions(-) [+] |
line diff
1.1 --- a/ADFSlib.py Sat Mar 29 01:40:13 2003 +0100 1.2 +++ b/ADFSlib.py Sat Mar 29 03:28:43 2003 +0100 1.3 @@ -352,101 +352,114 @@ 1.4 1.5 a = begin 1.6 1.7 - in_block = 0 1.8 - block_no = None 1.9 - terminated = 1 1.10 + current = None 1.11 + action = "read ID" 1.12 1.13 while a < end: 1.14 1.15 - value = ord(self.sectors[a]) 1.16 + if action == "read ID": 1.17 1.18 - if not in_block: 1.19 - 1.20 - if value > 1: 1.21 + # At the start of a block. 1.22 1.23 - if terminated: 1.24 + value = self.str2num(2, self.sectors[a:a+2]) 1.25 + 1.26 + entry = value & 0x7fff 1.27 + 1.28 + if entry > 1: 1.29 + 1.30 + #print hex(entry), hex(a) 1.31 + if not map.has_key(entry): 1.32 1.33 - # A file number was found. Read its value and begin to 1.34 - # read its length. 1.35 - value = self.str2num(2, self.sectors[a:a+2]) 1.36 + # Create a new map entry corresponding to this value in 1.37 + # which the address of this entry is stored. 1.38 + map[entry] = [[a]] 1.39 + 1.40 + else: 1.41 + 1.42 + # Add this address to the map dictionary. 1.43 + map[entry].append([a]) 1.44 + 1.45 + # Check whether this block finishes immediately. 1.46 + if (value & 0x8000) != 0: 1.47 + 1.48 + print " immediate end at", hex(a) 1.49 1.50 - entry = value & 0x7fff 1.51 - print hex(entry), hex(a) 1.52 + map[entry][-1].append(a + 2) 1.53 1.54 - if not map.has_key(entry): 1.55 - 1.56 - # Create a new map entry corresponding to this value in 1.57 - # which the address of this entry is stored. 1.58 - map[entry] = [[a]] 1.59 - 1.60 - else: 1.61 - 1.62 - # Add this address to the map dictionary. 1.63 - map[entry].append([a]) 1.64 - 1.65 - # Check whether this block finishes immediately. 1.66 - if (value & 0x8000) != 0: 1.67 - 1.68 - terminated = 1 1.69 - in_block = 0 1.70 - block_number = None 1.71 - next = a + 2 1.72 - 1.73 - print " immediate end at", hex(a) 1.74 - 1.75 - map[entry][-1].append(a + 2) 1.76 - 1.77 - else: 1.78 - 1.79 - terminated = 0 1.80 - in_block = 1 1.81 - block_number = entry 1.82 - next = a + 2 1.83 + next = a + 2 1.84 + action = "read ID" 1.85 + current = None 1.86 1.87 - elif not terminated: 1.88 + else: 1.89 1.90 - # An object was found outside the file blocks but 1.91 - # was not expected. 1.92 - 1.93 - if self.verify: 1.94 - 1.95 - self.verify_log.append( 1.96 - "An object was found but was not expected:" + \ 1.97 - " %x" % (a + begin) 1.98 - ) 1.99 - 1.100 - next = a + 1 1.101 + next = a + 2 1.102 + action = "find end marker" 1.103 + current = entry 1.104 1.105 - elif value <= 1: 1.106 + else: 1.107 1.108 - # Defects or free space found outside blocks. 1.109 + # Space or defect 1.110 next = a + 1 1.111 1.112 - elif in_block: 1.113 + elif action == "find end marker": 1.114 1.115 - if value != 0: 1.116 + # In a block. 1.117 1.118 - # The end of a block has been found. 1.119 - terminated = 1 1.120 - in_block = 0 1.121 - block_number = None 1.122 + value = ord(self.sectors[a]) 1.123 + 1.124 + if value == 0x80: 1.125 + 1.126 + # The next block should start immediately after this 1.127 + # byte. 1.128 + if current is not None: 1.129 + 1.130 + map[current][-1].append(a + 1) 1.131 + 1.132 next = a + 1 1.133 - 1.134 - print "end at", hex(a) 1.135 - 1.136 - map[entry][-1].append(a + 1) 1.137 + action = "read ID" 1.138 + current = None 1.139 1.140 elif value == 0: 1.141 1.142 - # Continue reading until an end marker is found. 1.143 + # Continue reading the block. 1.144 next = a + 1 1.145 1.146 - else: 1.147 + else: 1.148 + 1.149 + # Unknown data - search for a new block. 1.150 + if current is not None: 1.151 + 1.152 + map[current][-1].append(a) 1.153 + 1.154 + next = a + 1 1.155 + action = "find ID" 1.156 + current = None 1.157 1.158 - # Space or defects. 1.159 + elif action == "find ID": 1.160 + 1.161 + # Possibly in a block, but still looking for the end. 1.162 1.163 - # Keep scanning the map for a new block. 1.164 - next = a + 1 1.165 + value = ord(self.sectors[a]) 1.166 + 1.167 + if value == 0x80: 1.168 + 1.169 + # End of block marker - go back two bytes and look for 1.170 + # a block ID. 1.171 + next = max(begin, a - 2) 1.172 + 1.173 + action = "read ID" 1.174 + 1.175 + elif value == 0: 1.176 + 1.177 + # Space - go back two bytes and look for a block ID. 1.178 + next = max(begin, a - 2) 1.179 + 1.180 + action = "read ID" 1.181 + 1.182 + else: 1.183 + 1.184 + # Other data - keep looking. 1.185 + next = a + 1 1.186 1.187 a = next 1.188
