From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1GcMSn-0002dP-SL for mharc-grub-devel@gnu.org; Tue, 24 Oct 2006 09:37:05 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1GcMSl-0002Zp-UO for grub-devel@gnu.org; Tue, 24 Oct 2006 09:37:03 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1GcMSh-0002Qf-5L for grub-devel@gnu.org; Tue, 24 Oct 2006 09:37:03 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GcMSg-0002QO-SO for grub-devel@gnu.org; Tue, 24 Oct 2006 09:36:58 -0400 Received: from [195.54.107.79] (helo=mxfep04.bredband.com) by monty-python.gnu.org with esmtp (Exim 4.52) id 1GcMSg-0004ec-J6 for grub-devel@gnu.org; Tue, 24 Oct 2006 09:36:59 -0400 Received: from ironport2.bredband.com ([195.54.107.84] [195.54.107.84]) by mxfep04.bredband.com with ESMTP id <20061024133657.VSHW8360.mxfep04.bredband.com@ironport2.bredband.com> for ; Tue, 24 Oct 2006 15:36:57 +0200 Received: from c-e8df71d5.029-19-73746f13.cust.bredbandsbolaget.se (HELO localhost.localdomain) ([213.113.223.232]) by ironport2.bredband.com with ESMTP; 24 Oct 2006 15:36:57 +0200 From: Johan Rydberg To: The development of GRUB 2 References: <453DBE9A.7040300@intel.com> <87fydd3ll4.fsf@night.trouble.net> Date: Tue, 24 Oct 2006 16:05:56 +0200 In-Reply-To: <87fydd3ll4.fsf@night.trouble.net> (Johan Rydberg's message of "Tue, 24 Oct 2006 15:11:19 +0200") Message-ID: <877iyp3j23.fsf@night.trouble.net> User-Agent: Gnus/5.110004 (No Gnus v0.4) Emacs/21.4 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" Subject: Re: [PATCH 3/3] grub EFI disk device enumberating X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 Oct 2006 13:37:04 -0000 --=-=-= Content-Transfer-Encoding: quoted-printable Johan Rydberg writes: > This code can be shorter; you only have to compare the lengths. If > they match, you can do a memcmp on the whole device path.=20=20 It could look something like this; /* Returns zero if device path SUBPATH is a subpath of device path PATH. */ static int compare_subpath (const grub_efi_device_path_t *subpath, const grub_efi_device_path_t *path) { if (! subpath || ! path) return 1; while (1) { int len, ret; if (GRUB_EFI_END_ENTIRE_DEVICE_PATH (subpath)) return 0; else if (GRUB_EFI_END_ENTIRE_DEVICE_PATH (path)) return 1; if (GRUB_EFI_DEVICE_PATH_LENGTH (subpath) !=3D GRUB_EFI_DEVICE_PATH_LENGTH (path)) return ((int) GRUB_EFI_DEVICE_PATH_LENGTH (subpath) - (int) GRUB_EFI_DEVICE_PATH_LENGTH (path)); len =3D GRUB_EFI_DEVICE_PATH_LENGTH (path); ret =3D grub_memcmp (subpath, path, len); if (ret) return ret; path =3D (grub_efi_device_path_t *) ((char *) path + len); subpath =3D (grub_efi_device_path_t *) ((char *) subpath + len); } } I guess that should work at least, it is not tested. In gnufi I have a device_path_iterate function that could be used for these kind of things. Maybe we should bring it in to GRUB2. /* Iterate nodes of the device path. *PATHP should be set to point to the path that is to be iterated. NULL will be returned when the end of the path has been reached. */ efi_device_path_t * efi_device_path_iterate (efi_device_path_t **pathp) { efi_device_path_t *p =3D *pathp; if (EFI_END_ENTIRE_DEVICE_PATH (p)) return NULL; else { efi_uint_t len =3D EFI_DEVICE_PATH_LENGTH (p); *pathp =3D (efi_device_path_t *) (((char *) p) + len); return p; } } ~j --=-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.2 (GNU/Linux) iD8DBQBFPh3R3CqIy3K3X2ERAjs4AJ45Q028B+ni0X4yjWmvXD/kCdcmngCgiWzc ZnyVqUs8yMJkJVFTRJH5ZgU= =Ib7A -----END PGP SIGNATURE----- --=-=-=--