python-adfs
changeset 30:5c97b1f04969
Returned to the method of scanning for each file number individually when
it is required.
| author | David Boddie <david@boddie.org.uk> |
|---|---|
| date | Sat Mar 29 23:02:07 2003 +0100 |
| parents | b74f65e160ed |
| children | 00351d2c0d09 |
| files | ADFSlib.py |
| diffstat | 1 files changed, 75 insertions(+), 102 deletions(-) [+] |
line diff
1.1 --- a/ADFSlib.py Sat Mar 29 22:31:38 2003 +0100 1.2 +++ b/ADFSlib.py Sat Mar 29 23:02:07 2003 +0100 1.3 @@ -466,6 +466,25 @@ 1.4 return map 1.5 1.6 1.7 + def find_address_from_map(self, addr, begin, entry): 1.8 + 1.9 + if self.disc_type == 'adE': 1.10 + 1.11 + address = ((addr - begin) * self.sector_size) 1.12 + 1.13 + elif self.disc_type == 'adEbig': 1.14 + 1.15 + upper = (entry & 0x7f00) >> 8 1.16 + 1.17 + if upper > 1: 1.18 + upper = upper - 1 1.19 + if upper > 3: 1.20 + upper = 3 1.21 + 1.22 + address = ((addr - begin) - (upper * 0xc8)) * 0x200 1.23 + 1.24 + return address 1.25 + 1.26 def find_in_new_map(self, begin, end, file_no): 1.27 1.28 #print "File number:", hex(file_no) 1.29 @@ -474,146 +493,100 @@ 1.30 1.31 return [] 1.32 1.33 - # Check that the file number exists in the disc map by checking the 1.34 - # map summary created by the scan_new_map method. 1.35 - if not self.disc_map.has_key(file_no): 1.36 - 1.37 - return [] 1.38 - 1.39 a = begin 1.40 1.41 + # Create a list containing the start and end addresses of the 1.42 + # file/directory associated with this file number. 1.43 pieces = [] 1.44 1.45 - in_piece = 0 1.46 - 1.47 - # Retrieve the list of possible starting addresses for this file 1.48 - # number. 1.49 - pairs = self.disc_map[file_no] 1.50 - 1.51 - for start, finish in pairs: 1.52 - 1.53 - if self.disc_type == 'adE': 1.54 - 1.55 - start_address = ((start - begin) * self.sector_size) 1.56 - finish_address = ((finish - begin) * self.sector_size) 1.57 - 1.58 - elif self.disc_type == 'adEbig': 1.59 - 1.60 - upper = (file_no & 0x7f00) >> 8 1.61 - 1.62 - if upper > 1: 1.63 - upper = upper - 1 1.64 - if upper > 3: 1.65 - upper = 3 1.66 - 1.67 - start_address = ((start - begin) - (upper * 0xc8)) * 0x200 1.68 - finish_address = ((finish - begin) - (upper * 0xc8)) * 0x200 1.69 - 1.70 - # Add a list containing the start address of the 1.71 - # file/directory to the list of objects associated 1.72 - # with this file number. 1.73 - pieces.append( [start_address, finish_address] ) 1.74 - 1.75 - return pieces 1.76 - 1.77 - """ 1.78 - in_starts = 0 1.79 - 1.80 - #print "Map scan:", map(hex, starts) 1.81 + current_piece = None 1.82 + current_start = 0 1.83 1.84 while a < end: 1.85 1.86 - if in_piece == 0 and in_starts < len(starts): 1.87 - 1.88 - a = starts[in_starts] 1.89 - in_starts = in_starts + 1 1.90 - 1.91 - entry = self.str2num(2, self.sectors[a:a+2]) 1.92 - 1.93 # The next entry to be read will occur one byte after this one 1.94 # unless one of the following checks override this behaviour. 1.95 next = a + 1 1.96 1.97 - if (entry & 0x7fff) == file_no: 1.98 + if current_piece is None: 1.99 1.100 - if self.disc_type == 'adE': 1.101 + value = self.str2num(2, self.sectors[a:a+2]) 1.102 1.103 - address = ((a - begin) * self.sector_size) 1.104 + entry = value & 0x7fff 1.105 1.106 - elif self.disc_type == 'adEbig': 1.107 + if entry == file_no: 1.108 1.109 - upper = (entry & 0x7f00) >> 8 1.110 + next = a + 2 1.111 1.112 - if upper > 1: 1.113 - upper = upper - 1 1.114 - if upper > 3: 1.115 - upper = 3 1.116 + if (value & 0x8000) == 0: 1.117 1.118 - address = ((a - begin) - (upper * 0xc8)) * 0x200 1.119 + current_piece = entry 1.120 + current_start = a 1.121 + 1.122 + else: 1.123 + 1.124 + # Add the block to the list of pieces found. 1.125 + pieces.append( 1.126 + [ self.find_address_from_map(a, begin, entry), 1.127 + self.find_address_from_map(next, begin, entry) 1.128 + ] ) 1.129 1.130 - # Add a list containing the start address of the 1.131 - # file/directory to the list of objects associated 1.132 - # with this file number. 1.133 - pieces.append( [address] ) 1.134 + else: 1.135 1.136 - in_piece = 1 1.137 + # Search for a valid file number. 1.138 + next = a + 1 1.139 1.140 - next = a + 1 1.141 + else: 1.142 1.143 - if in_piece == 1 and (entry & 0x8000) != 0: 1.144 - 1.145 - if self.disc_type == 'adE': 1.146 + # In a piece being read. 1.147 1.148 - address = ((a + 2 - begin) * self.sector_size) 1.149 + value = ord(self.sectors[a]) 1.150 1.151 - elif self.disc_type == 'adEbig': 1.152 + if value == 0: 1.153 1.154 - upper = (entry & 0x7f00) >> 8 1.155 + # Still in the block. 1.156 + next = a + 1 1.157 + 1.158 + elif value == 0x80: 1.159 + 1.160 + # At the end of the block. 1.161 + next = a + 1 1.162 1.163 - if upper > 1: 1.164 - upper = upper - 1 1.165 - if upper > 3: 1.166 - upper = 3 1.167 + # Add the block to the list of pieces found. 1.168 + pieces.append( 1.169 + [ self.find_address_from_map( 1.170 + current_start, begin, current_piece 1.171 + ), 1.172 + self.find_address_from_map( 1.173 + next, begin, current_piece 1.174 + ) 1.175 + ] ) 1.176 1.177 - address = ((a + 2 - begin) - (upper * 0xc8)) * 0x200 1.178 + current_piece = None 1.179 1.180 - # This is the end of the current entry. Modify the latest 1.181 - # address to indicate a range of addresses. 1.182 - pieces[-1].append(address) 1.183 + else: 1.184 1.185 - in_piece = 0 1.186 - 1.187 - next = a + 2 1.188 + # The byte found was unexpected - backtrack to the 1.189 + # byte after the start of this block and try again. 1.190 + next = current_start + 1 1.191 + current_piece = None 1.192 1.193 a = next 1.194 1.195 # If the last piece is incomplete then use the end of the map as 1.196 # the end of the piece. 1.197 - if len(pieces[-1]) != 2: 1.198 + if current_piece is not None: 1.199 1.200 - if self.disc_type == 'adE': 1.201 - 1.202 - address = ((end - begin) * self.sector_size) 1.203 - 1.204 - elif self.disc_type == 'adEbig': 1.205 - 1.206 - upper = (entry & 0x7f00) >> 8 1.207 - 1.208 - if upper > 1: 1.209 - upper = upper - 1 1.210 - if upper > 3: 1.211 - upper = 3 1.212 - 1.213 - address = ((end - begin) - (upper * 0xc8)) * 0x200 1.214 - 1.215 - # This is the end of the current entry. Modify the latest 1.216 - # address to indicate a range of addresses. 1.217 - pieces[-1].append(address) 1.218 + pieces.append( 1.219 + [ self.find_address_from_map( 1.220 + current_start, begin, current_piece 1.221 + ), 1.222 + self.find_address_from_map(end, begin, current_piece) 1.223 + ] ) 1.224 1.225 #print "Pieces:", map(lambda x: map(hex, x), pieces) 1.226 1.227 return pieces 1.228 - """ 1.229 1.230 def read_tracks(self, f, inter): 1.231
