Skip to main content

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.

Release files for machfs 1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for machfs 1.2
File Size Uploaded
machfs-1.2.tar.gz 15.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for machfs 1.2
File Interpreter ABI Platform
machfs-1.2-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 32.7 kB

Release files / machfs-1.2.tar.gz

Download URL machfs-1.2.tar.gz
Size 15.9 kB
Tags Source
SHA-256 checksum
How to use checksums
e334a867e6a94af2c5540125aa76b1792a15fdf7c38dc2bb5f44a3d7c30720c9
BLAKE2b-256 checksum
How to use checksums
52e2fc7b689fb67b9665f996a99f26b5bdbcbbf21f90aa8af7f7175a7ff87a61
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0

Release files / machfs-1.2-py2.py3-none-any.whl

Download URL machfs-1.2-py2.py3-none-any.whl
Size 16.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
eaca1c278c267c0de8d247fc8f304cee820d2ad91be29e80597c78aea23ea83d
BLAKE2b-256 checksum
How to use checksums
de3067ba1c8cca4e457629b6dfb82263c0b6e744afb882fd5427c29119521bf1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page