Reputation: 29
I have a image which is FAT (16 bit), I want to parser the image to file, so that i can get the files in image.
Upvotes: 0
Views: 2078
Reputation: 75
Actually, I was in a similar situation, where I needed FAT12/16/32 support in Python. Searching the web you can find various implementations (such as maxpat78/FATtools, em-/grasso or hisahi/PyFAT12).
None of those libraries were available via PyPI at the time or were lacking features I needed so (full disclosure) I decided to write my own but I'll try to sum it up as objectively as possible:
pyfatfs supports FAT12, FAT16 as well as FAT32 including VFAT (long file names) and can be installed via pip as a pure Python package (no native dependencies such as mtools needed and/or included). It implements functionality for PyFilesystem2, a framework for basic file operations across different filesystem implementations (SSH, AWS S3, OSFS host directory pass-through, …). Aside from that pyfatfs can also be used standalone (without PyFilesystem2) in case you need to make more low-level operations (manipulating directory/file entries, changing disk attributes, formatting disks/images, manipulating FAT, etc.).
For instance, to copy files from a diskette image to your host via PyFilesystem2:
import fs
fat_fs = fs.open_fs("fat://my_diskette.img") # Open disk image
host_fs = fs.open_fs("osfs:///tmp") # Open '/tmp' directory on host
fs.copy.copy_dir(fat_fs, "/", host_fs, "/") # Copy all files from the disk image to the host_fs filesystem (/tmp directory on host)
Upvotes: 0
Reputation: 494
As far as reading a FAT32 filesystem image in Python goes, the Wikipedia page has all the detail you need to write a read-only implementation.
Construct may be of some use. Looks like they have an example for FAT16 (https://github.com/construct/construct/blob/master/construct/examples/formats/filesystem/fat16.py) which you could try extending.
Upvotes: 1