I need to write a program to extract the information from a disk using 512KB blocks. The disk image file is in raw format.
Asked
Active
Viewed 4,274 times
5
-
What does "extract the information" mean? You want to read logical files? If so you'll need to specify what filesystem(s) you want to support. Why not just mount the image file using some regular mounter and then read it using Python's usual `open("filename").readlines()` or whatever? – John Zwinck Apr 14 '13 at 06:34
-
I have one image file of a disk in .raw format. Now I want to get the data from there and find out what are the types. Is it possible? – Russel Apr 14 '13 at 22:17
1 Answers
6
Open the file with 'rb'
flags to read bytes and read
your stuff with a size argument of 512 * 2^10 (or 512000, depending on whether your size is in KB or KiB.
with open('filename', 'rb') as f:
block = f.read(512 * 2**10)
while block != "":
# Do stuff with a block
block = f.read(512 * 2**10)

Igonato
- 10,175
- 3
- 35
- 64
-
@WingTangWong no, at the end of a file `read` will return an empty string and `block != ""` condition will fail. – Igonato Apr 14 '13 at 06:43
-
1