HFS+ wrapper support
PATCH 1/1 HFS+ wrapper support
This patch (sent mostly for Marco) adds HFS wrapper support to the HFS+ code. All Apple-created HFS+ partitions are contained in an HFS wrapper for some backwards compatibility. The code is based on information found at http://developer.apple.com/technotes/tn/tn1150.html#HFSWrapper .
I only moved the minimum HFS code and structures into hfs.h. More could go there if desired.
When I tested this patch, an embedded filesystem was recognized as HFS+, but the HFS+ code itself did not discover any files, so there is probably still something wrong.
-Hollis
Index: fs/hfs.c
===================================================================
RCS file: /cvsroot/grub/grub2/fs/hfs.c,v
retrieving revision 1.4
hfs.c +13 -33
@@ -18,6 +18,9 @@* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +/* HFS is documented at +http://developer.apple.com/documentation/mac/Files/Files-2.html */ +#include <grub/err.h> #include <grub/file.h> #include <grub/mm.h>
@@ -25,9 +28,10 @@#include <grub/disk.h> #include <grub/dl.h> #include <grub/types.h> +#include <grub/hfs.h> #define GRUB_HFS_SBLOCK 2 -#define GRUB_HFS_MAGIC 0x4244 +#define GRUB_HFS_EMBED_HFSPLUS_SIG 0x482B#define GRUB_HFS_BLKS (data->blksz >> 9)
@@ -40,37 +44,6 @@ enumGRUB_HFS_FILETYPE_FILE =2 }; -/* A single extent. A file consists of suchs extents. */ -struct grub_hfs_extent -{ -/* The first physical block. */ -grub_uint16_t first_block; -grub_uint16_t count; -}; - -/* HFS stores extents in groups of 3. */ -typedef struct grub_hfs_extent grub_hfs_datarecord_t [3 ]; - -/* The HFS superblock (The official name is `Master Directory -Block'). */ -struct grub_hfs_sblock -{ -grub_uint16_t magic; -grub_uint8_t unused[18 ]; -grub_uint32_t blksz; -grub_uint8_t unused2[4 ]; -grub_uint16_t first_block; -grub_uint8_t unused4[6 ]; - -/* A pascal style string that holds the volumename. */ -grub_uint8_t volname[28 ]; - -grub_uint8_t unused5[70 ]; -grub_hfs_datarecord_t extent_recs; -grub_uint32_t catalog_size; -grub_hfs_datarecord_t catalog_recs; -} __attribute__ ((packed)); -/* A node desciptor. This is the header of every node. */ struct grub_hfs_node {
@@ -345,7 +318,14 @@ grub_hfs_mount (grub_disk_t disk)/* Check if this is a HFS filesystem. */ if (grub_be_to_cpu16 (data->sblock.magic) !=GRUB_HFS_MAGIC ) { -grub_error (GRUB_ERR_BAD_FS ,"not a hfs filesystem" ); +grub_error (GRUB_ERR_BAD_FS ,"not an HFS filesystem" ); + goto fail; + } + +/* Check if this is an embedded HFS+ filesystem. */ +if (grub_be_to_cpu16 (data->sblock.embed_sig) ==GRUB_HFS_EMBED_HFSPLUS_SIG ) + { +grub_error (GRUB_ERR_BAD_FS ,"embedded HFS+ filesystem" ); goto fail; }
Index: fs/hfsplus.c
===================================================================
RCS file: /cvsroot/grub/grub2/fs/hfsplus.c,v
retrieving revision 1.1
hfsplus.c +50 -7
108 lines not on this page · raw message
Index: include/grub/hfs.h
===================================================================
RCS file: include/grub/hfs.h
grub/hfs.h new file +61 -0
61 lines not on this page · raw message
Quoted 5 lines · Hollis Blanchard
This patch (sent mostly for Marco) adds HFS wrapper support to the HFS+ code. All Apple-created HFS+ partitions are contained in an HFS wrapper for some backwards compatibility. The code is based on information found at
http://developer.apple.com/technotes/tn/tn1150.html#HFSWrapper .
That's the information I used to implement HFS+ support.
Quoted 2 lines
I only moved the minimum HFS code and structures into
hfs.h. More could go there if desired.
Right, it seems sane to me.
Quoted 3 lines
When I tested this patch, an embedded filesystem was recognized as HFS+, but the HFS+ code itself did not discover any files, so there is probably still something wrong.
Perhaps it is just my code that is wrong, who knows. :-)
Can you extract the HFS+ filesystem using `dd' to see if that works?
hfsplus.c struct grub_hfsplus_data · line 226
Quoted 3 lines
hfsplus.c +3
-0+/* This is the offset into the physical disk for an embedded HFS+ filesystem +* (one inside a plain HFS wrapper). */ +static int embedded_offset =0 ;
This should be moved into grub_hfsplus_data. In case multiple HFS+ partitions are accessed things can go wrong here.
Quoted 1 line
+
embedded_offset=ablk_start+extent_start* (ablk_size/ 512);
Better to use ablk_size >> GRUB_DISK_SECTOR_BITS here.
hfsplus.c grub_hfsplus_mount (grub_disk_t disk) · line 392
Quoted 2 lines
hfsplus.c +2
-0+if ((volheader.hfsplus.magic !=GRUB_HFSPLUS_MAGIC ) + && (volheader.hfsplus.magic !=GRUB_HFSPLUSX_MAGIC ))
You could keep the existing check. But if you prefer checking it as integers, make sure the endianess is fixed.
Thanks,
Marco
Quoted 5 lines · Hollis Blanchard
This patch (sent mostly for Marco) adds HFS wrapper support to the HFS+ code. All Apple-created HFS+ partitions are contained in an HFS wrapper for some backwards compatibility. The code is based on information found at
http://developer.apple.com/technotes/tn/tn1150.html#HFSWrapper .
This patch was committed, I changed a few things so it also works on little endian. I've also committed a patch to fix endianess of apple partition maps on non big endian.
Now HFS+ partitions with a HFS wrapper should work. Hopefully that means we will have a working macos loaders soon. :-)
Thanks,
Marco