5

I need to write a program to extract the information from a disk using 512KB blocks. The disk image file is in raw format.

Russel
  • 73
  • 2
  • 7
  • 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 Answers1

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