Skip to contentSkip to conversation

off-spec-ness of HFS+ image from apple, hfsplus 2nd volume header, and mount options

DISCUSSION Hin-Tak Leung 2 participants 4 messages Aug 3, 2012 – Aug 6, 2012 VFS

lore
Share & tools
lore
#0 lore raw
Quoted 20 lines · Vyacheslav Dubeyko

Hi,

Quoted 1 line · Hin-Tak Leung

I did not make those volumes - they were downloaded

them from Apple's developer web site (http://developer.apple.com/xcode/ - sorry, free registration required). Some of them have additional
compression built-in - there are 3rd-party tools on linux
for decompressing them - but these 4 appear to be plain disk
images, of sorts (I have a small random selection, from
helping Mac-user friends to set up their dev environment
from time to time).

Quoted 1 line

Could you share dump of the first and secondary volume headers from one
of these volumes, offset of secondary ones in bytes from volume begin
and output any utilities with size of the partition?

Quoted 5 lines

I think that from file system points of view all can be OK (without
anomaly). But partition map can have some different value of volume
size.

I know parition map can have different ideas about volume sizes. I was talking about the HFS+ volume header itself - located on the 3rd 512-byte, and *supposedly* located on the 2nd 512-byte from the "end" - the "end" being the size declared by multiplying the blocksize with blockcount in the HFS+ header, and counting from 1024 byte before the primary header.

The smaller set of files also have blockcount way over the image size itself, and the 2nd header is located at the beginning of the last used 4k block.

Here they are:

dd if=xcode_4.3.3_for_lion.dmg of=/tmp/header1 count=3 skip=65 dd if=xcode_4.3.3_for_lion.dmg of=/tmp/header2 count=1 skip=3858241

("header1" includes the 2x512 bytes before the primary volume header, hence count=3).
The HFS+ header says 482273 blocks of 4 KiB, which means the 2nd header sould be located at 65 + 482273 * 8 - 2, i.e. at skip 3858247 instead of 3858241 as above.

Quoted 143 lines

It is possible to talk about anomaly after real reproduction of the
problem on real hardware, from my point of view.

With the best regards,
Vyacheslav Dubeyko.

Quoted 6 lines

cltools_lion_latemarch12.dmg
command_line_tools_for_xcode.dmg
xcode_4.3.1_for_lion.dmg
xcode_4.3.3_for_lion.dmg

These have an Apple partition map, an empty ATA driver

partition and and HFS+ partition. The HFS+ partition's header says it uses block size 4k, and the 2nd volume header is located at 4k from the end of the HFS+ partition rather than 1024 byte from the end. The two command_line_tools* also have an extra issue - its HFS+ header says it is about 400MB in total, half of that free, but the actual size is only 180MB and the secondary volume header is located on the last 4k block (i.e. freespace is not included), and not 1024 byte from the end.

Quoted 2 lines

These are the "official" Apple development tool

distributions, and quite obviously millions of Apple-centric developers are using them without problem. when they are slightly off-spec, I think one should interpret this as Apple extending/changing/adjusting the HFS+ format, relaxing/changing some of the constraints in the case of disk images.

Quoted 2 lines

The "sizelimit" I wrote in the redhat bug report is

modified to fool the linux kernel into finding the 2nd volume header in its "expected" place to loop-back mount that image i.e. the true end of the HFS+ volume is 3072 bytes further, from the HFS+ header. (the redhat bug report is about sizelimit not working from mount -o, but need to be specified separately on losetup).

Quoted 2 lines
Quoted 2 lines

On Fri, 2012-08-03 at 05:21 +0100, Hin-Tak Leung

Quoted 1 line · wrote:
Quoted 1 line
Quoted 1 line

I think I found another small bug in the

kernel's

Quoted 1 line
Quoted 1 line

hfsplus support, or more properly, a difference

between how

Quoted 1 line
Quoted 1 line

the linux kernel deal with HFS+ images versus how

Mac OS X

Quoted 3 lines
Quoted 3 lines

does it.

Quoted 2 lines

Some of the necessary/boring details are in

the bug

Quoted 2 lines
Quoted 2 lines

report https://bugzilla.redhat.com/show_bug.cgi?id=845419
(which isn't about this bug, but some other issues

about

Quoted 3 lines
Quoted 3 lines

mount options).

Quoted 2 lines

According to Apple's TN1150 technote (the

HFS+

Quoted 1 line
Quoted 1 line

specification), the primary volume header is at

1024 bytes

Quoted 1 line
Quoted 1 line

into an image, while a duplicate back-up version

of it, the

Quoted 1 line
Quoted 1 line

secondary volume header, is at 1024 bytes counting

from the

Quoted 1 line
Quoted 1 line

end of the image/storage. (or for 512-sector

devices, the

Quoted 1 line
Quoted 1 line

3rd sector from the beginning and the 2nd sector

from the

Quoted 3 lines
Quoted 3 lines

last).

Quoted 2 lines

Apple's xcode images (I just happen to have

those in my

Quoted 1 line
Quoted 1 line

hard disc, as I am looking at any/every HFS+ disk

images I

Quoted 1 line
Quoted 1 line

might have), and all the apple tools images I

have, have an

Quoted 1 line
Quoted 1 line

anomaly: the secondary volume header is located

one logical

Quoted 1 line
Quoted 1 line

block (a logical block being 4k in this case from

the HFS+

Quoted 3 lines
Quoted 3 lines

header) from the end.

Quoted 2 lines

Indeed, apple's own fsck.hfsplus itself

complains about

Quoted 1 line
Quoted 1 line

the xcode image not of the right size, if you set

up the

Quoted 1 line
Quoted 1 line

loopback device as I wrote in the bug report.

OTOH, since

Quoted 1 line
Quoted 1 line

Apple developers all over the world download the

xcode

Quoted 1 line
Quoted 1 line

images and access them as virtual disk images on

their

Quoted 1 line
Quoted 1 line

computers on a daily basis, and Apple can change

what is

Quoted 1 line
Quoted 1 line

considered "correct behavior" about HFS+ without

notice,

Quoted 3 lines
Quoted 3 lines

this anomaly probably should be supported.

Quoted 2 lines

The wording of TN1150 is also a bit ambiguous

about the

Quoted 1 line
Quoted 1 line

2nd volume header - it says it is for disk repair

utilities

Quoted 3 lines
Quoted 3 lines

only, and may not be where it said it is.

Quoted 2 lines

So I am wondering whether the linux kernel

should as it

Quoted 1 line
Quoted 1 line

currently does, enforce the 2nd volume header

being at 1024

Quoted 1 line
Quoted 1 line

bytes from the end and agree with the primary

volume header,

Quoted 1 line
Quoted 1 line

and refuse to mount, as correct. It also seems

unnecessary

Quoted 1 line
Quoted 1 line

for read-only mounts, or image-loop-back mounts. I

have two

Quoted 3 lines
Quoted 3 lines

suggestions:

Quoted 2 lines

- for read-only/look-back mounts, allows the

2nd volume

Quoted 1 line
Quoted 1 line

header to not agree with the primary, with a

warning.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

- or, for read-only/look-back mounts, allows

the 2nd

Quoted 1 line
Quoted 1 line

volume header to locate one logical block from the

end

Quoted 1 line
Quoted 1 line

rather than 2 x 512-sectors from the end, if the

logical

Quoted 1 line
Quoted 1 line

block according to the HFS+ header is larger than

or

Quoted 7 lines
Quoted 5 lines

different from 512.

Quoted 1 line

--
To unsubscribe from this list: send the line

"unsubscribe linux-fsdevel" in

Quoted 2 lines

the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

#1 lore raw

Hi Hin-Tak,

Quoted 5 lines · Hin-Tak Leung

I know parition map can have different ideas about volume sizes. I was talking about the HFS+ volume header itself - located on the 3rd 512-byte, and *supposedly* located on the 2nd 512-byte from the "end" - the "end" being the size declared by multiplying the blocksize with blockcount in the HFS+ header, and counting from 1024 byte before the primary header.

The smaller set of files also have blockcount way over the image size itself, and the 2nd header is located at the beginning of the last used 4k block.

Quoted 8 lines

Here they are:

dd if=xcode_4.3.3_for_lion.dmg of=/tmp/header1 count=3 skip=65 dd if=xcode_4.3.3_for_lion.dmg of=/tmp/header2 count=1 skip=3858241

("header1" includes the 2x512 bytes before the primary volume header, hence count=3).
The HFS+ header says 482273 blocks of 4 KiB, which means the 2nd header sould be located at 65 + 482273 * 8 - 2, i.e. at skip 3858247 instead of 3858241 as above.

I made some experiments with creation of hfs+ volumes under Mac OS X (10.6.8) Snow Leopard. I can't detect such anomaly in the case of my version of Mac OS. For example, I created partition with size of 2097155 sectors (sector is 512 bytes in size) and I can see second volume header in the 2097153 sector. It means that second volume header is located on the distance in 1024 bytes from partition's end. In volume header I can see volume size in 0x40000 blocks (block is 4096 bytes) or 2097152 sectors. The detected position of second volume header is coincided with Apple's technical specification.

Unfortunately, I haven't any Apple hardware with installed Mac OS X Lion. So, I think that maybe reported by you anomaly is take place under only Lion. Maybe, it was made as optimization efforts for SSD case. Do you have opportunity to make similar experiments under Lion?

With the best regards,
Vyacheslav Dubeyko.

#2 lore raw
Quoted 42 lines · Vyacheslav Dubeyko

Hi Hin-Tak,

Quoted 2 lines · Hin-Tak Leung

I know parition map can have different ideas about

volume sizes. I was talking about the HFS+ volume header itself - located on the 3rd 512-byte, and *supposedly* located on the 2nd 512-byte from the "end" - the "end" being the size declared by multiplying the blocksize with blockcount in the HFS+ header, and counting from 1024 byte before the primary header.

Quoted 2 lines

The smaller set of files also have blockcount way over

the image size itself, and the 2nd header is located at the beginning of the last used 4k block.

Quoted 4 lines

Here they are:

dd if=xcode_4.3.3_for_lion.dmg of=/tmp/header1 count=3

skip=65

Quoted 1 line

dd if=xcode_4.3.3_for_lion.dmg of=/tmp/header2 count=1

skip=3858241

Quoted 2 lines

("header1" includes the 2x512 bytes before the primary

volume header, hence count=3).

Quoted 1 line

The HFS+ header says 482273 blocks of 4 KiB, which

means the 2nd header sould be located at 65 + 482273 * 8 - 2, i.e. at skip 3858247 instead of 3858241 as above.

Quoted 1 line

I made some experiments with creation of hfs+ volumes under Mac OS X (10.6.8) Snow Leopard. I can't detect such anomaly in the case of my version of Mac OS. For example, I created  partition with size of 2097155 sectors (sector is 512 bytes in size) and I can see second volume header in the 2097153 sector. It means that second volume header is located on the distance in 1024 bytes from partition's end. In volume header I can see volume size in 0x40000 blocks (block is 4096 bytes) or 2097152 sectors. The detected position of second volume header is coincided with Apple's technical specification.

Quoted 5 lines

Unfortunately, I haven't any Apple hardware with installed Mac OS X Lion. So, I think that maybe reported by you anomaly is take place under only Lion. Maybe, it was made as optimization efforts for SSD case.  Do you have opportunity to make similar experiments under Lion?

Those images did mount and worked on Lion (as I mentioned I was helping a Mac-user friend to set up his dev environment in March). I can try downloading some of the earlier xcode images (or other dev material images) from Apple's to see if earlier Mac OS'es are supposed to be able to cope with that anomaly.

I should point out again that I did not make those images, nor know how they were made - they are "freely" available on apple's web site. They are the updates/installers of their standard dev tools (contain Apple's patched version of gcc, binutils, autoconf, etc) on Mac OS X, and Mac OS X [some version] obviously have no problem loop-back mounting them, even when they are off-spec.

It is free registration, and apple doesn't really try to bombard one with more info/offers, so everybody is free to take a look around, if interested. --
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw
In reply to Hin-Tak Leung

Hi Hin-Tak,

Quoted 5 lines · Hin-Tak Leung

I know parition map can have different ideas about volume sizes. I was talking about the HFS+ volume header itself - located on the 3rd 512-byte, and *supposedly* located on the 2nd 512-byte from the "end" - the "end" being the size declared by multiplying the blocksize with blockcount in the HFS+ header, and counting from 1024 byte before the primary header.

The smaller set of files also have blockcount way over the image size itself, and the 2nd header is located at the beginning of the last used 4k block.

Quoted 8 lines

Here they are:

dd if=xcode_4.3.3_for_lion.dmg of=/tmp/header1 count=3 skip=65 dd if=xcode_4.3.3_for_lion.dmg of=/tmp/header2 count=1 skip=3858241

("header1" includes the 2x512 bytes before the primary volume header, hence count=3).
The HFS+ header says 482273 blocks of 4 KiB, which means the 2nd header sould be located at 65 + 482273 * 8 - 2, i.e. at skip 3858247 instead of 3858241 as above.

I made some experiments with creation of hfs+ volumes under Mac OS X (10.6.8) Snow Leopard. I can't detect such anomaly in the case of my version of Mac OS. For example, I created partition with size of 2097155 sectors (sector is 512 bytes in size) and I can see second volume header in the 2097153 sector. It means that second volume header is located on the distance in 1024 bytes from partition's end. In volume header I can see volume size in 0x40000 blocks (block is 4096 bytes) or 2097152 sectors. The detected position of second volume header is coincided with Apple's technical specification.

Unfortunately, I haven't any Apple hardware with installed Mac OS X Lion. So, I think that maybe reported by you anomaly is take place under only Lion. Maybe, it was made as optimization efforts for SSD case. Do you have opportunity to make similar experiments under Lion?

With the best regards,
Vyacheslav Dubeyko.