annotate python/iso9660.py @ 283:c9781c73e7e2

Added first kernel files
author Windel Bouwman
date Fri, 15 Nov 2013 12:26:50 +0100
parents
children 1c7c1e619be8
rev   line source
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
1
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
2 import argparse
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
3
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
4 """
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
5 ISO 9660 filesystem utility.
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
6 """
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
7
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
8 def read_vol_desc(f):
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
9 s = f.read(2048)
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
10 ty = s[0]
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
11 Id = s[1:6]
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
12 assert Id == 'CD001'.encode('ascii')
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
13 ver = s[6]
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
14 assert ver == 1
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
15 data = s[7:]
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
16 assert len(data) == 2041
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
17 return ty, Id, s
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
18
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
19 def parse_boot_record(sec):
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
20 boot_sys_id = sec[7:39]
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
21 boot_id = sec[39:71]
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
22 print(boot_sys_id)
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
23 print(boot_id)
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
24
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
25 def parse_primary_volume(sec):
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
26 sys_id = sec[8:40]
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
27 vol_id = sec[40:72]
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
28 print(sys_id)
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
29 print(vol_id)
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
30
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
31 def read_iso(f):
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
32 # System area
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
33 system = f.read(16 * 2048)
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
34 while True:
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
35 ty, Id, dat = read_vol_desc(f)
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
36 print(ty, Id)
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
37 if ty == 255:
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
38 break
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
39 elif ty == 0:
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
40 parse_boot_record(dat)
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
41 elif ty == 1:
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
42 parse_primary_volume(dat)
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
43
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
44
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
45 if __name__ == '__main__':
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
46 with open('mikeos.iso', 'rb') as f:
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
47 read_iso(f)
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
48
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
49