Skip to main content

Library for reading and writing Macintosh HFS volumes

Project description

This is a library for creating and inspecting HFS-format disk images. Mac-specific concepts like resource forks and type/creator codes are first-class citizens.

Python interface

The Python API is simple. The contents of a Volume or a Folder are accessed using the index operator []. While working on a filesystem, its entire high-level contents are stored in memory as a Python object.

from machfs import Volume, Folder, File

v = Volume()

v['Folder'] = Folder()

v['Folder']['File'] = File()
v['Folder']['File'].data = b'Hello from Python!\r'
v['Folder']['File'].rsrc = b'' # Use the macresources library to work with resource forks
v['Folder']['File'].type = b'TEXT'
v['Folder']['File'].creator = b'ttxt' # Teach Text/SimpleText

with open('FloppyImage.dsk', 'wb') as f:
    flat = v.write(
        size=1440*1024, # "High Density" floppy
        align=512, # Allocation block alignment modulus (2048 for CDs)
        desktopdb=True, # Create a dummy Desktop Database to prevent a rebuild on boot
        bootable=True, # This requires a folder with a ZSYS and a FNDR file
        startapp=('Folder','File'), # Path (as tuple) to an app to open at boot
    )
    f.write(flat)

with open('FloppyImage.dsk', 'rb') as f:
    flat = f.read()
    v = Volume()
    v.read(flat) # And you can read an image back!

Command-line interface

This package also installs the MakeHFS and DumpHFS utilities, for working with folders on your native filesystem. Briefly, resource forks are stored in Rez-formatted .rdump files, and type and creator codes are stored in 8-byte .idump files. Admittedly this method of storage is not pretty, but it exposes changes to resource files without requiring Mac-specific software. For example, Git can track the addition and removal of resources. Files with a TEXT type are assumed to be UTF-8 encoded with Unix-style (LF) line endings, and are converted to Mac OS Roman encoding with Mac-style (CR) line endings.

Both commands have a --help argument to display their options.

Why?

I want an automated, reproducible way to compile legacy MacOS software. Without any current operating system fully supporting HFS, libhfs/hfsutils (a C library and command-line wrapper) is the most capable implementation. The implementor chose to emulate POSIX I/O on a fake "mounted" filesystem. While this is important for machines with very limited RAM, the maintenance of consistent HFS data structures across incremental operations is a complicated task requiring a large amount of low-level code. Frequent I/O to the real filesystem also occurs. Current machines have memory and cycles to burn, so an in-memory implementation in a high-level programming language seemed like a reasonable tradeoff. As a result, machfs has nearly an order of magnitude fewer lines than libhfs, and is more maintainable, at a nearly negligible cost in performance.

Changes

1.3

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

machfs-1.3.tar.gz (18.9 kB view details)

Uploaded Source

Built Distribution

machfs-1.3-py2.py3-none-any.whl (19.4 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file machfs-1.3.tar.gz.

File metadata

  • Download URL: machfs-1.3.tar.gz
  • Upload date:
  • Size: 18.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.2

File hashes

Hashes for machfs-1.3.tar.gz
Algorithm Hash digest
SHA256 89201818ca16c2385be234b5bfe90946cf80e8141dfa4ed42a54dfa164690389
MD5 64c763007d89332ccfdef1709a4e4b1d
BLAKE2b-256 7f5e04d568847e2632f18908636f4e688835292643f5c5cdf93fb764323a6940

See more details on using hashes here.

File details

Details for the file machfs-1.3-py2.py3-none-any.whl.

File metadata

  • Download URL: machfs-1.3-py2.py3-none-any.whl
  • Upload date:
  • Size: 19.4 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.2

File hashes

Hashes for machfs-1.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 17a87350c46d4542c74f1d7e2045201ff90d73906e2021b3864a4f9a7f8e8ff7
MD5 6ab988e8be915e4dd02f23bcc6c56c4d
BLAKE2b-256 bc9c3c6e7f389327857c8258e863e0dddf352307c97f005cedd64d3b62929636

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page