From: Mike Brudevold Date: Thu, 15 Apr 2010 13:42:24 +0000 Subject: Re: [PATCH] Fix cdrom profile enumeration. Message-Id: List-Id: References: <1271214432-30088-1-git-send-email-mike@brudevold.com> In-Reply-To: <1271214432-30088-1-git-send-email-mike@brudevold.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable To: linux-hotplug@vger.kernel.org On Thu, Apr 15, 2010 at 1:43 AM, Martin Pitt wrote: > Hello Mike, > > mike@brudevold.com [2010-04-14 20:38 -0500]: >> - =A0 =A0 for (i =3D 12; i < profiles[11]; i +=3D 4) { >> + =A0 =A0 profiles_end =3D 12 + profiles[11]; >> + =A0 =A0 for (i =3D 12; i < profiles_end; i +=3D 4) { > > (This could just be written as "i < 12 + profiles[11]" for simplicity) I started with that, but GCC was giving me a warning, so I changed it to what is currently in the patch. The profiles array is an array of bytes, so we just needed to either store or cast it as something larger. > > Do you have some pointers which document this structure, in particular > whether it's really the count and not the last offset? I searched for > some minutes, but didn't find anything. It would be nice to add a > reference to the spec to the code. > The document I referenced was [1]. Section 10.6.2.1 states that the "Additional Length field shall be set to ((number of Profile Descriptors) * 4)." The size of the feature header is 8 bytes, and we assume that feature 0 (the profile list) directly follows this. This adds 4 bytes, which is how you get the 12 byte start. You can see that the size of each profile descriptor is 4 bytes, so it follows that this is an offset from 12. In my testing, the git version would not enumerate all available profiles, whereas this patch would. I think this went unnoticed because there is a second set of code (cd_capability_compat) that checks for what types of media the drive supports, so the information was still available. Mike [1] http://www.t10.org/ftp/t10/document.97/97-263r0.pdf