HFS access on modern Macs

Continuing the discussion from External Disk Reformatting:

That worked! I didn’t even check to see if the modules existed when cat /proc/filesystems didn’t show them. But after sudo modprobe hfs and sudo modprobe hfsplus, they appeared.

I was able to mount a floppy disk pretty easily. I connected a USB floppy drive, which appeared in Linux as /dev/sdf. In then inserted an HFS floppy and typed

sudo mount -t hfs /dev/sdf /mnt/tmp

And it mounted.

CD-ROMs were a bit trickier. Apple’s CD-ROMs are what appear to be images of hard drives. So they use 512 byte blocks and have an APM-scheme partition table.

If you try to just blindly mount an HFS CD (at least any of my old Apple Developer CDs), you just get an error:

$ sudo mount -t hfs /dev/cdrom /mnt/tmp
mount: /mnt/tmp: wrong fs type, bad option, bad superblock on /dev/sr0, missing codepage or helper program, or other error.

If this would have been a hard drive, then the Linux kernel would see the partition table, create per-partition devices, and you would just mount one of them. But CD-ROMs don’t work that way. Fortunately, the HFS driver has a workaround - specify the partition in the mount command. But that also failed:

$ sudo mount -t hfs -o part=1 /dev/cdrom /mnt/tmp
mount: /mnt/tmp: wrong fs type, bad option, bad superblock on /dev/sr0, missing codepage or helper program, or other error.

But after reviewing the system log (/var/log/syslog), it shows a message when trying to mount that:

... kernel: [...] hfs: unable to set blocksize to 512

After some web searching, I found a known bug. The driver, like all file system drivers, must work with the hardware’s block size. And CD-ROMs always have a block size of 2K. So when the file system driver tries to set its block size to 512 (to match the HFS file system), it fails.

Fortunately, there’s a workaround for that. The “loopback” mount option. This tells the system to pretend the device is actually a file (just a big stream of bytes with no particular associated hardware) and mount that. This is normally used for mounting disk images, but it appears you can also use it on a physical device to ignore all block-device issues. And that worked:

$ mount -t hfs -o part=1,loop /dev/cdrom /mnt/tmp

And I was able to see the contents of the CD, in all of its HFS glory.

Of course, that’s only the first step. Since Linux doesn’t know a thing about resource forks, and quite a lot of the files on developer CDs need them. So I’d still need to use something like hfstools to copy the files to something like MacBinary format, which can be used to transport the content to a Mac for (hopefully) being able to open them.

But for extracting things that don’t involve resources (like system disk images, suitable for installing old OS releases onto emulators), it looks like it can get the job done.

I still think for actually using HFS media, some solution other than Linux will be necessary, but at least I’ve got that workaround working.

5 Likes