From: Hin-Tak Leung Subject: Re: off-spec-ness of HFS+ image from apple, hfsplus 2nd volume header, and mount options Date: Fri, 3 Aug 2012 09:40:34 +0100 (BST) Message-ID: <1343983234.31736.YahooMailClassic@web29405.mail.ird.yahoo.com> Reply-To: htl10@users.sourceforge.net Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="1426553645-239962902-1343983234=:31736" Cc: linux-fsdevel@vger.kernel.org, Till Kamppeter , Naohiro Aota , Matthew Garrett , Karel Zak To: Vyacheslav Dubeyko Return-path: Received: from nm2-vm0.bullet.mail.ird.yahoo.com ([77.238.189.199]:42978 "HELO nm2-vm0.bullet.mail.ird.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1753110Ab2HCIkg (ORCPT ); Fri, 3 Aug 2012 04:40:36 -0400 Sender: linux-fsdevel-owner@vger.kernel.org List-ID: --1426553645-239962902-1343983234=:31736 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable --- On Fri, 3/8/12, Vyacheslav Dubeyko wrote:=0A=0A> Hi= ,=0A> =0A> On Fri, 2012-08-03 at 09:01 +0100, Hin-Tak Leung wrote:=0A> =0A= > > I did not make those volumes - they were downloaded=0A> them from Apple= 's developer web site (http://developer.apple.com/xcode/ - sorry, free=0A> = registration required). Some of them have additional=0A> compression built-= in - there are 3rd-party tools on linux=0A> for decompressing them - but th= ese 4 appear to be plain disk=0A> images, of sorts (I have a small random s= election, from=0A> helping Mac-user friends to set up their dev environment= =0A> from time to time).=0A> > =0A> =0A> Could you share dump of the first = and secondary volume=0A> headers from one=0A> of these volumes, offset of s= econdary ones in bytes from=0A> volume begin=0A> and output any utilities w= ith size of the partition?=0A> =0A> I think that from file system points of= view all can be OK=0A> (without=0A> anomaly). But partition map can have s= ome different value of=0A> volume=0A> size.=0A=0AI know parition map can ha= ve different ideas about volume sizes. I was talking about the HFS+ volume = header itself - located on the 3rd 512-byte, and *supposedly* located on th= e 2nd 512-byte from the "end" - the "end" being the size declared by multip= lying the blocksize with blockcount in the HFS+ header, and counting from 1= 024 byte before the primary header. =0A=0AThe smaller set of files also hav= e blockcount way over the image size itself, and the 2nd header is located = at the beginning of the last used 4k block.=0A=0AHere they are:=0A=0Add if= =3Dxcode_4.3.3_for_lion.dmg of=3D/tmp/header1 count=3D3 skip=3D65=0Add if= =3Dxcode_4.3.3_for_lion.dmg of=3D/tmp/header2 count=3D1 skip=3D3858241=0A= =0A("header1" includes the 2x512 bytes before the primary volume header, he= nce count=3D3).=0AThe 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 385824= 7 instead of 3858241 as above.=0A=0A> It is possible to talk about anomaly = after real reproduction=0A> of the=0A> problem on real hardware, from my po= int of view.=0A> =0A> With the best regards,=0A> Vyacheslav Dubeyko. =0A> = =0A> =0A> > cltools_lion_latemarch12.dmg=0A> > command_line_tools_for_xcode= .dmg=0A> > xcode_4.3.1_for_lion.dmg=0A> > xcode_4.3.3_for_lion.dmg=0A> > = =0A> > These have an Apple partition map, an empty ATA driver=0A> partition= and and HFS+ partition. The HFS+ partition's=0A> header says it uses block= size 4k, and the 2nd volume header=0A> is located at 4k from the end of th= e HFS+ partition rather=0A> than 1024 byte from the end. The two command_li= ne_tools*=0A> also have an extra issue - its HFS+ header says it is about= =0A> 400MB in total, half of that free, but the actual size is=0A> only 180= MB and the secondary volume header is located on the=0A> last 4k block (i.e= . freespace is not included), and not 1024=0A> byte from the end.=0A> > =0A= > > These are the "official" Apple development tool=0A> distributions, and = quite obviously millions of Apple-centric=0A> developers are using them wit= hout problem. when they are=0A> slightly off-spec, I think one should inter= pret this as=0A> Apple extending/changing/adjusting the HFS+ format,=0A> re= laxing/changing some of the constraints in the case of=0A> disk images.=0A>= > =0A> > The "sizelimit" I wrote in the redhat bug report is=0A> modified = to fool the linux kernel into finding the 2nd=0A> volume header in its "exp= ected" place to loop-back mount=0A> that image i.e. the true end of the HFS= + volume is 3072=0A> bytes further, from the HFS+ header. (the redhat bug r= eport=0A> is about sizelimit not working from mount -o, but need to be=0A> = specified separately on losetup).=0A> > =0A> > > On Fri, 2012-08-03 at 05:2= 1 +0100, Hin-Tak Leung=0A> wrote:=0A> > > > I think I found another small b= ug in the=0A> kernel's=0A> > > hfsplus support, or more properly, a differe= nce=0A> between how=0A> > > the linux kernel deal with HFS+ images versus h= ow=0A> Mac OS X=0A> > > does it.=0A> > > > =0A> > > > Some of the necessary= /boring details are in=0A> the bug=0A> > > report https://bugzilla.redhat.c= om/show_bug.cgi?id=3D845419=0A> > > (which isn't about this bug, but some o= ther issues=0A> about=0A> > > mount options).=0A> > > > =0A> > > > Accordin= g to Apple's TN1150 technote (the=0A> HFS+=0A> > > specification), the prim= ary volume header is at=0A> 1024 bytes=0A> > > into an image, while a dupli= cate back-up version=0A> of it, the=0A> > > secondary volume header, is at = 1024 bytes counting=0A> from the=0A> > > end of the image/storage. (or for = 512-sector=0A> devices, the=0A> > > 3rd sector from the beginning and the 2= nd sector=0A> from the=0A> > > last).=0A> > > > =0A> > > > Apple's xcode im= ages (I just happen to have=0A> those in my=0A> > > hard disc, as I am look= ing at any/every HFS+ disk=0A> images I=0A> > > might have), and all the ap= ple tools images I=0A> have, have an=0A> > > anomaly: the secondary volume = header is located=0A> one logical=0A> > > block (a logical block being 4k i= n this case from=0A> the HFS+=0A> > > header) from the end.=0A> > > > =0A> = > > > Indeed, apple's own fsck.hfsplus itself=0A> complains about=0A> > > t= he xcode image not of the right size, if you set=0A> up the=0A> > > loopbac= k device as I wrote in the bug report.=0A> OTOH, since=0A> > > Apple develo= pers all over the world download the=0A> xcode=0A> > > images and access th= em as virtual disk images on=0A> their=0A> > > computers on a daily basis, = and Apple can change=0A> what is=0A> > > considered "correct behavior" abou= t HFS+ without=0A> notice,=0A> > > this anomaly probably should be supporte= d.=0A> > > > =0A> > > > The wording of TN1150 is also a bit ambiguous=0A> a= bout the=0A> > > 2nd volume header - it says it is for disk repair=0A> util= ities=0A> > > only, and may not be where it said it is.=0A> > > > =0A> > > = > So I am wondering whether the linux kernel=0A> should as it=0A> > > curre= ntly does, enforce the 2nd volume header=0A> being at 1024=0A> > > bytes fr= om the end and agree with the primary=0A> volume header,=0A> > > and refuse= to mount, as correct. It also seems=0A> unnecessary=0A> > > for read-only = mounts, or image-loop-back mounts. I=0A> have two=0A> > > suggestions:=0A> = > > > =0A> > > > - for read-only/look-back mounts, allows the=0A> 2nd volum= e=0A> > > header to not agree with the primary, with a=0A> warning.=0A> > >= > =0A> > > > - or, for read-only/look-back mounts, allows=0A> the 2nd=0A> = > > volume header to locate one logical block from the=0A> end=0A> > > rath= er than 2 x 512-sectors from the end, if the=0A> logical=0A> > > block acco= rding to the HFS+ header is larger than=0A> or=0A> > > different from 512.= =0A> > > > =0A> > > =0A> > > =0A> > > =0A> > --=0A> > To unsubscribe from t= his list: send the line=0A> "unsubscribe linux-fsdevel" in=0A> > the body o= f a message to majordomo@vger.kernel.org=0A> > More majordomo info at=A0 ht= tp://vger.kernel.org/majordomo-info.html=0A> =0A> =0A> --1426553645-239962902-1343983234=:31736 Content-Type: application/octet-stream; name=header1 Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename=header1 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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AEAAAABAAAAATfnAAB55AAAAAAAAAABAAAAAAAAAAAAAAACAAAAAAAAAAAA AAAAmN8l4FDHwJoAAAAAAAQAAAAA8AAAAABAAAAAAQAAAEAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAQAAAAEAAAAAABAAAAABBAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHgAAAA QAAAAAAeAAAARkEAAAwAAABuUgAABgAABOHlAAAGAAAF1s0AAAYAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA2AAAABAAAAAADYAAAAE QQAADAAAABDeAAAGAAAAJIcAAAYAAABeywAABgAAAqu9AAAGAAAD7aoAAAYA AAWY9gAABgAABd9sAAAGAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAA --1426553645-239962902-1343983234=:31736 Content-Type: application/octet-stream; name=header2 Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename=header2 SCsABIAAAQAxMC4wAAAAAMvqd97L6t+MAAAAAMvq2k4AAPaoAABBAwAAEAAA B1vhAAAAAAAAiEEAAQAAAAEAAAABN+cAAHnjAAAAAAAAAAEAAAAAAAAAAAAA AAIAAAAAAAAAAAAAAACY3yXgUMfAmgAAAAAABAAAAADwAAAAAEAAAAABAAAA QAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAABAAAAAQAAAAAAEAAAAAEEAAAQAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAeAAAABAAAAAAB4AAABGQQAADAAAAG5SAAAGAAAE4eUAAAYAAAXW zQAABgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADYAAA AEAAAAAANgAAAARBAAAMAAAAEN4AAAYAAAAkhwAABgAAAF7LAAAGAAACq70A AAYAAAPtqgAABgAABZj2AAAGAAAF32wAAAYAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAA= --1426553645-239962902-1343983234=:31736--