[CDG5] Pure Python HFS implementation

Elliot Nunn elliotnunn at fastmail.com
Fri Oct 12 22:10:32 AWST 2018


Good question!

First, I think it is pretty clear that we need software that can run on
modern machines, and read and write disk images in a format native to
the Classic Mac OS. This includes access to Mac-specific metadata,
particularly resource forks and type/creator codes.

Until now I have used Robert Leslie's hfsutils package in this role. It
is a C implementation of HFS with several Tcl wrapper programs. My
experience with empw (https://github.com/elliotnunn/empw) showed that
the Tcl wrapper programs are very tedious to use in automated fashion.
My very slow solution requires (deprecated features of) a recent macOS
version, a non-stock version of rsync, deprecated Xcode command line
tools, etc, etc.

So I wrote some Python to expose the low-level "libhfs" part of
hfsutils. This works well enough but really wants an object-oriented
wrapper. Going through the libhfs code I realised that, although it is
pretty well structured for C code, it makes some assumptions about its
host that are no longer correct or helpful. In particular, it assumes
that a filesystem is too big to fit in the process address space and so
must be kept on disk and manipulated incrementally using IO calls, with
all the inconvenience and complexity that that entails. As a result the
code is quite long (~4700 lines excluding headers) and, to me, nearly
inscrutable.

So a wrote a Python implementation that just serialises and deserialises
disk images in memory, leaving all the hard work of maintaining
low-level data structures to Python's builtins. Currently it is 490
lines long. `import machfs` away!

> On 11 Oct 2018, at 11:25 pm, Max Poliakovski <maximumspatium at googlemail.com> wrote:
> 
> Hi Elliot,
> 
> thank you for keeping us updated and for your impressive work on HFS in Python.
> 
> Could you elaborate the reason why do you need to maintain your own HFS implementation? Is there nothing we can reuse/improve?



More information about the cdg5 mailing list