-
Notifications
You must be signed in to change notification settings - Fork 0
/
ADFSlib.py
1741 lines (1174 loc) · 57.2 KB
/
ADFSlib.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python
"""
ADFSlib.py, a library for reading ADFS disc images.
Copyright (c) 2003-2011, David Boddie <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
__author__ = "David Boddie <[email protected]>"
__date__ = "Sun 29th August 2010"
__version__ = "0.42"
__license__ = "GNU General Public License (version 3)"
import os, string, struct, time
INFORM = 0
WARNING = 1
ERROR = 2
# Find the number of centiseconds between 1900 and 1970.
between_epochs = ((365 * 70) + 17) * 24 * 360000L
class Utilities:
# Little endian reading
def _read_signed_word(self, s):
return struct.unpack("<i", s)[0]
def _read_unsigned_word(self, s):
return struct.unpack("<I", s)[0]
def _read_signed_byte(self, s):
return struct.unpack("<b", s)[0]
def _read_unsigned_byte(self, s):
return struct.unpack("<B", s)[0]
def _read_unsigned_half_word(self, s):
return struct.unpack("<H", s)[0]
def _read_signed_half_word(self, s):
return struct.unpack("<h", s)[0]
def _str2num(self, size, s):
i = 0
n = 0
while i < size:
n = n | (ord(s[i]) << (i*8))
i = i + 1
return n
def _binary(self, size, n):
new = ""
while (n != 0) & (size > 0):
if (n & 1)==1:
new = "1" + new
else:
new = "0" + new
n = n >> 1
size = size - 1
if size > 0:
new = ("0"*size) + new
return new
def _safe(self, s, with_space = 0):
new = ""
if with_space == 1:
lower = 31
else:
lower = 32
for i in s:
if ord(i) <= lower:
break
if ord(i) >= 128:
c = ord(i)^128
if c > 32:
new = new + chr(c)
else:
new = new + i
return new
def _plural(self, msg, values, words):
"""Returns a message which takes into account the plural form of
words in the original message, assuming that the appropriate
form for negative numbers of items is the same as that for
more than one item.
values is a list of numeric values referenced in the message.
words is a list of sequences of words to substitute into the
message. This takes the form
[ word_to_use_for_zero_items,
word_to_use_for_one_item,
word_to_use_for_two_or_more_items ]
The length of the values and words lists must be equal.
"""
substitutions = []
for i in range(0, len(values)):
n = values[i]
# Each number must be mapped to a value in the range [0, 2].
if n > 1: n = 2
elif n < 0: n = 2
substitutions.append(values[i])
substitutions.append(words[i][n])
return msg % tuple(substitutions)
def _create_directory(self, path, name = None):
elements = []
while not os.path.exists(path) and path != "":
path, file = os.path.split(path)
elements.insert(0, file)
if path != "":
elements.insert(0, path)
if name is not None:
elements.append(name)
# Remove any empty list elements or those containing a $ character.
elements = filter(lambda x: x != '' and x != "$", elements)
try:
built = ""
for element in elements:
built = os.path.join(built, element)
if not os.path.exists(built):
# This element of the directory does not exist.
# Create a directory here.
os.mkdir(built)
print 'Created directory:', built
elif not os.path.isdir(built):
# This element of the directory already exists
# but is not a directory.
print 'A file exists which prevents a ' + \
'directory from being created: %s' % built
return ""
except OSError:
print 'Directory could not be created: %s' % \
string.join(elements, os.sep)
return ""
# Success
return built
def _convert_name(self, old_name, convert_dict):
# Use the conversion dictionary to convert any forbidden
# characters to accepted local substitutes.
name = ""
for c in old_name:
if c in convert_dict.keys():
name = name + convert_dict[c]
else:
name = name + c
if self.verify and old_name != name:
self.verify_log.append(
( WARNING,
"Changed %s to %s" % (old_name, name) )
)
return name
class ADFS_exception(Exception):
pass
class ADFSdirectory:
"""directory = ADFSdirectory(name, files)
The directory created contains name and files attributes containing the
directory name and the objects it contains.
"""
def __init__(self, name, files):
self.name = name
self.files = files
def __repr__(self):
return '<%s instance, "%s", at %x>' % (self.__class__, self.name, id(self))
class ADFSfile:
"""file = ADFSfile(name, data, load_address, execution_address, length)
"""
def __init__(self, name, data, load_address, execution_address, length):
self.name = name
self.data = data
self.load_address = load_address
self.execution_address = execution_address
self.length = length
def __repr__(self):
return '<%s instance, "%s", at %x>' % (self.__class__, self.name, id(self))
def has_filetype(self):
"""Returns True if the file's meta-data contains filetype information."""
return self.load_address & 0xfff00000 == 0xfff00000
def filetype(self):
"""Returns the meta-data containing the filetype information.
Note that a filetype can be obtained for all files, though it may not
necessarily be valid. Use has_filetype() to determine whether the file
is likely to have a valid filetype."""
return "%03x" % ((self.load_address >> 8) & 0xfff)
def time_stamp(self):
"""Returns the time stamp for the file as a tuple of values containing
the local time, or an empty tuple if the file does not have a time stamp."""
# RISC OS time is given as a five byte block containing the
# number of centiseconds since 1900 (presumably 1st January 1900).
# Convert the time to the time elapsed since the Epoch (assuming
# 1970 for this value).
date_num = struct.unpack("<Q",
struct.pack("<IBxxx", self.execution_address, self.load_address & 0xff))[0]
centiseconds = date_num - between_epochs
# Convert this to a value in seconds and return a time tuple.
try:
return time.localtime(centiseconds / 100.0)
except ValueError:
return ()
class ADFSmap(Utilities):
def __getitem__(self, index):
return self.disc_map[index]
def has_key(self, key):
return self.disc_map.has_key(key)
class ADFSnewMap(ADFSmap):
dir_markers = ('Hugo', 'Nick')
root_dir_address = 0x800
def __init__(self, header, begin, end, sectors, sector_size, record):
self.header = header
self.begin = begin
self.end = end
self.sectors = sectors
self.sector_size = sector_size
self.record = record
self.free_space = self._read_free_space()
self.disc_map = self._read_disc_map()
def _read_disc_map(self):
# See ADFS/EMaps.htm, ADFS/EFormat.htm and ADFS/DiscMap.htm for details.
### TODO: This needs to take into account multiple zones.
disc_map = {}
a = self.begin
current_piece = None
current_start = 0
next_zone = self.header + self.sector_size
# Copy the free space map.
free_space = self.free_space[:]
while a < self.end:
# The next entry to be read will occur one byte after this one
# unless one of the following checks override this behaviour.
next = a + 1
if (a % self.sector_size) < 4:
# In a zone header. Not the first zone header as this
# was already skipped when we started reading.
next = a + 4 - (a % self.sector_size)
# Set the next zone offset.
next_zone = next_zone + self.sector_size
# Reset the current piece and starting offset.
current_piece = None
current_start = 0
elif free_space != [] and a >= free_space[0][0]:
# In the next free space entry. Go to the entry following
# it and discard this free space entry.
next = free_space[0][1]
free_space.pop(0)
# Reset the current piece and starting offset.
current_piece = None
current_start = 0
elif current_piece is None and (next_zone - a) >= 2:
# If there is enough space left in this zone to allow
# further fragments then read the next two bytes.
value = self._read_unsigned_half_word(self.sectors[a:a+2])
entry = value & 0x7fff
# See ADFS/EAddrs.htm document for restriction on
# the disc address and hence the file number.
# i.e.the top bit of the file number cannot be set.
if entry >= 1:
# Defects (1), files or directories (greater than 1)
next = a + 2
# Define a new entry.
#print "Begin:", hex(entry), hex(a)
if not disc_map.has_key(entry):
# Create a new map entry if none exists.
disc_map[entry] = []
if (value & 0x8000) == 0:
# Record the file number and start of this fragment.
current_piece = entry
current_start = a
else:
# For an immediately terminated fragment, add the
# extents of the block to the list of pieces found
# and implicitly finish reading this fragment
# (current_piece remains None).
start_addr = self.find_address_from_map(
a, self.begin, entry
)
end_addr = self.find_address_from_map(
next, self.begin, entry
)
if [start_addr, end_addr] not in disc_map[entry]:
disc_map[entry].append((start_addr, end_addr))
else:
# Search for a valid file number.
# Should probably stop looking in this zone.
next = a + 1
elif current_piece is not None:
# In a piece being read.
value = ord(self.sectors[a])
if value == 0:
# Still in the block.
next = a + 1
elif value == 0x80:
# At the end of the block.
next = a + 1
# For relevant entries add the block to the list of
# pieces found.
start_addr = self.find_address_from_map(
current_start, self.begin, current_piece
)
end_addr = self.find_address_from_map(
next, self.begin, current_piece
)
if [start_addr, end_addr] not in disc_map[current_piece]:
disc_map[current_piece].append(
(start_addr, end_addr)
)
# Look for a new fragment.
current_piece = None
else:
# The byte found was unexpected - backtrack to the
# byte after the start of this block and try again.
#print "Backtrack from %s to %s" % (hex(a), hex(current_start+1))
next = current_start + 1
current_piece = None
# Move to the next relevant byte.
a = next
return disc_map
def _read_free_space(self):
free_space = []
a = self.header
while a < self.end:
# The next zone starts a sector after this one.
next_zone = a + self.sector_size
a = a + 1
# Start by reading the offset in bits from the start of the header
# of the first item of free space in the map.
offset = self._read_unsigned_half_word(self.sectors[a:a+2])
# The top bit is apparently always set, so mask it off and convert
# the result into bytes. * Not sure if this is the case for
# entries in the map. *
next = ((offset & 0x7fff) >> 3)
if next == 0:
# No more free space in this zone. Look at the free
# space field in the next zone.
a = next_zone
continue
# Update the offset to point to the free space in this zone.
a = a + next
while a < next_zone:
# Read the offset to the next free fragment in this zone.
offset = self._read_unsigned_half_word(self.sectors[a:a+2])
# Convert this to a byte offset.
next = ((offset & 0x7fff) >> 3)
# Find the end of the free space.
b = a + 1
while b < next_zone:
c = b + 1
value = self._read_unsigned_byte(self.sectors[b])
if (value & 0x80) != 0:
break
b = c
# Record the offset into the map of this item of free space
# and the offset of the byte after it ends.
free_space.append((a, c))
if next == 0:
break
# Move to the next free space entry.
a = a + next
# Whether we are at the end of the zone or not, move to the
# beginning of the next zone.
a = next_zone
# Return the free space list.
return free_space
def read_catalogue(self, base):
head = base
p = 0
dir_seq = self.sectors[head + p]
dir_start = self.sectors[head+p+1:head+p+5]
if dir_start not in self.dir_markers:
if self.verify:
self.verify_log.append(
(WARNING, 'Not a directory: %s' % hex(head))
)
return '', []
p = p + 5
files = []
while ord(self.sectors[head+p]) != 0:
old_name = self.sectors[head+p:head+p+10]
top_set = 0
counter = 1
for i in old_name:
if (ord(i) & 128) != 0:
top_set = counter
counter = counter + 1
name = self._safe(self.sectors[head+p:head+p+10])
load = self._read_unsigned_word(self.sectors[head+p+10:head+p+14])
exe = self._read_unsigned_word(self.sectors[head+p+14:head+p+18])
length = self._read_unsigned_word(self.sectors[head+p+18:head+p+22])
inddiscadd = self._read_new_address(
self.sectors[head+p+22:head+p+25]
)
newdiratts = self._read_unsigned_byte(self.sectors[head+p+25])
if inddiscadd == -1:
if (newdiratts & 0x8) != 0:
if self.verify:
self.verify_log.append(
(WARNING, "Couldn't find directory: %s" % name)
)
self.verify_log.append(
(WARNING, " at: %x" % (head+p+22))
)
self.verify_log.append( (
WARNING, " file details: %x" % \
self._str2num(3, self.sectors[head+p+22:head+p+25])
) )
self.verify_log.append(
(WARNING, " atts: %x" % newdiratts)
)
elif length != 0:
if self.verify:
self.verify_log.append(
(WARNING, "Couldn't find file: %s" % name)
)
self.verify_log.append(
(WARNING, " at: %x" % (head+p+22))
)
self.verify_log.append( (
WARNING,
" file details: %x" % \
self._str2num(3, self.sectors[head+p+22:head+p+25])
) )
self.verify_log.append(
(WARNING, " atts: %x" % newdiratts)
)
else:
# Store a zero length file. This appears to be the
# standard behaviour for storing empty files.
files.append(ADFSfile(name, "", load, exe, length))
else:
if (newdiratts & 0x8) != 0:
# Remember that inddiscadd will be a sequence of
# pairs of addresses.
for start, end in inddiscadd:
# Try to interpret the data at the referenced address
# as a directory.
lower_dir_name, lower_files = \
self.read_catalogue(start)
# Store the directory name and file found therein.
files.append(ADFSdirectory(name, lower_files))
else:
# Remember that inddiscadd will be a sequence of
# pairs of addresses.
file = ""
remaining = length
for start, end in inddiscadd:
amount = min(remaining, end - start)
file = file + self.sectors[start : (start + amount)]
remaining = remaining - amount
file_obj = ADFSfile(name, file, load, exe, length)
# Store the SIN (System Internal Number) for debugging.
file_obj.addr = self._str2num(3, self.sectors[head+p+22:head+p+25])
files.append(file_obj)
p = p + 26
# Go to tail of directory structure (0x800 -- 0xc00)
tail = head + self.sector_size
dir_end = self.sectors[tail+self.sector_size-5:tail+self.sector_size-1]
if dir_end not in self.dir_markers:
if self.verify:
self.verify_log.append(
( WARNING,
'Discrepancy in directory structure: [%x, %x]' % \
( head, tail ) )
)
return '', files
dir_name = self._safe(
self.sectors[tail+self.sector_size-16:tail+self.sector_size-6]
)
parent = \
self.sectors[tail+self.sector_size-38:tail+self.sector_size-35]
dir_title = \
self.sectors[tail+self.sector_size-35:tail+self.sector_size-16]
if head == self.root_dir_address:
dir_name = '$'
endseq = self.sectors[tail+self.sector_size-6]
if endseq != dir_seq:
if self.verify:
self.verify_log.append(
( WARNING,
'Broken directory: %s at [%x, %x]' % \
(dir_title, head, tail) )
)
return dir_name, files
return dir_name, files
def _read_new_address(self, s):
# From the three character string passed, determine the address on the
# disc.
value = self._str2num(3, s)
# This is a SIN (System Internal Number)
# The bottom 8 bits are the sector offset + 1
offset = value & 0xff
if offset != 0:
address = (offset - 1) * self.sector_size
else:
address = 0
# The top 16 bits are the file number
file_no = value >> 8
# The pieces of the object are returned as a list of pairs of
# addresses.
pieces = self._find_in_new_map(file_no)
if pieces == []:
return -1
# Ensure that the first piece of data is read from the appropriate
# point in the relevant sector.
pieces = pieces[:]
pieces[0] = (pieces[0][0] + address, pieces[0][1])
return pieces
def _find_in_new_map(self, file_no):
try:
return self.disc_map[file_no]
except KeyError:
return []
def find_address_from_map(self, addr, begin, entry):
return ((addr - begin) * self.sector_size)
class ADFSbigNewMap(ADFSnewMap):
dir_markers = ('Nick',)
root_dir_address = 0xc8800
def find_address_from_map(self, addr, begin, entry):
# I can't remember where the rationale for this calculation
# came from or where the necessary information was obtained.
# It probably came from one of the WSS files, such as
# Formats.htm or Formats2.htm which imply that the F format
# uses 512 byte sectors (see the 0x200 value below) and
# indicate that F format uses 4 zones rather than 1.
upper = (entry & 0x7f00) >> 8
if upper > 1:
upper = upper - 1
if upper > 3:
upper = 3
return ((addr - begin) - (upper * 0xc8)) * 0x200
class ADFSoldMap(ADFSmap):
def _read_free_space(self):
# Currently unused
base = 0
free_space = []
p = 0
while self.sectors[base+p] != 0:
free.append(self._str2num(3, self.sectors[base+p:base+p+3]))
name = self.sectors[self.sector_size-9:self.sector_size-4]
disc_size = self._str2num(
3, self.sectors[self.sector_size-4:self.sector_size-1]
)
checksum0 = self._read_unsigned_byte(self.sectors[self.sector_size-1])
base = self.sector_size
p = 0
while self.sectors[base+p] != 0:
free.append(self._str2num(3, self.sectors[base+p:base+p+3]))
name = name + \
self.sectors[base+self.sector_size-10:base+self.sector_size-5]
disc_id = self._str2num(
2, self.sectors[base+self.sector_size-5:base+self.sector_size-3]
)
boot = self._read_unsigned_byte(self.sectors[base+self.sector_size-3])
checksum1 = self._read_unsigned_byte(self.sectors[base+self.sector_size-1])
return free_space
class ADFSdisc(Utilities):
"""disc = ADFSdisc(file_handle, verify = 0)
Represents an ADFS disc image stored in the file with the specified file
handle. The image is not verified by default; pass True or another
non-False value to request automatic verification of the disc format.
If the disc image specified cannot be read successfully, an ADFS_exception
is raised.
The disc's name is recorded in the disc_name attribute; its type is
recorded in the disc_type attribute. To obtain a human-readable description
of the disc format call the disc_format() method.
Once an ADFSdisc instance has been created, it can be used to access the
contents of the disc image. The files attribute contains a list of objects
from the disc's catalogue, including both directories and files,
represented by ADFSdirectory and ADFSfile instances respectively.
The contents of the disc can be extracted to a directory structure in the
user's filing system with the extract_files() method.
For debugging purposes, the print_catalogue() method prints the contents of
the disc's catalogue to the console. Similarly, the print_log() method
prints the disc verification log and can be used to show any disc errors
that have been found.
"""
_format_names = {"ads": "ADFS S format",
"adm": "ADFS M format",
"adl": "ADFS L format",
"adD": "ADFS D format",
"adE": "ADFS E format",
"adEbig": "ADFS F format"}
def __init__(self, adf, verify = 0):
# Log problems if the verify flag is set.
self.verify = verify
self.verify_log = []
# Check the properties using the length of the file
adf.seek(0,2)
length = adf.tell()
adf.seek(0,0)
if length == 163840:
self.ntracks = 40
self.nsectors = 16
self.sector_size = 256
interleave = 0
self.disc_type = 'ads'
self.dir_markers = ('Hugo',)
elif length == 327680:
self.ntracks = 80
self.nsectors = 16
self.sector_size = 256
interleave = 0
self.disc_type = 'adm'
self.dir_markers = ('Hugo',)
elif length == 655360:
self.ntracks = 160
self.nsectors = 16 # per track
self.sector_size = 256 # in bytes
# Most L format discs are interleaved, but at least one is
# sequenced.
interleave = 1
self.disc_type = 'adl'
self.dir_markers = ('Hugo',)
elif length == 819200:
self.ntracks = 80
self.nsectors = 10
self.sector_size = 1024
interleave = 0
self.dir_markers = ('Hugo', 'Nick')
format = self._identify_format(adf)
if format == 'D':
self.disc_type = 'adD'
elif format == 'E':
self.disc_type = 'adE'
else:
raise ADFS_exception, \
'Please supply a .adf, .adl or .adD file.'
elif length == 1638400:
self.ntracks = 80
self.nsectors = 20
self.sector_size = 1024
interleave = 0
self.disc_type = 'adEbig'
self.dir_markers = ('Nick',)
else:
raise ADFS_exception, 'Please supply a .adf, .adl or .adD file.'
# Read tracks
self.sectors = self._read_tracks(adf, interleave)
# Close the ADF file
adf.close()
# Set the default disc name.
self.disc_name = 'Untitled'
# Read the files on the disc.
if self.disc_type == 'adD':
# Find the root directory name and all the files and directories
# contained within it.
self.root_name, self.files = self._read_old_catalogue(0x400)
elif self.disc_type == 'adE':
# Read the disc name and map
self.disc_name = self._safe(self._read_disc_info(), with_space = 1)
# Find the root directory name and all the files and directories
# contained within it.
self.root_name, self.files = self.disc_map.read_catalogue(2*self.sector_size)
elif self.disc_type == 'adEbig':
# Read the disc name and map
self.disc_name = self._safe(self._read_disc_info(), with_space = 1)
# Find the root directory name and all the files and directories
# contained within it. The
self.root_name, self.files = self.disc_map.read_catalogue((self.ntracks * self.nsectors/2 + 2) * self.sector_size)
else:
# Find the root directory name and all the files and directories
# contained within it.
self.root_name, self.files = self._read_old_catalogue(2*self.sector_size)
def _identify_format(self, adf):
"""Returns a string containing the disc format for the disc image
accessed by the file object, adf. This method is used to determine the
format for 800K disc images (either D or E format).
"""