Johan Rydberg <[EMAIL PROTECTED]> 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.
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) != GRUB_EFI_DEVICE_PATH_LENGTH (path)) return ((int) GRUB_EFI_DEVICE_PATH_LENGTH (subpath) - (int) GRUB_EFI_DEVICE_PATH_LENGTH (path)); len = GRUB_EFI_DEVICE_PATH_LENGTH (path); ret = grub_memcmp (subpath, path, len); if (ret) return ret; path = (grub_efi_device_path_t *) ((char *) path + len); subpath = (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 = *pathp; if (EFI_END_ENTIRE_DEVICE_PATH (p)) return NULL; else { efi_uint_t len = EFI_DEVICE_PATH_LENGTH (p); *pathp = (efi_device_path_t *) (((char *) p) + len); return p; } } ~j
pgpfuh7RNvMft.pgp
Description: PGP signature
_______________________________________________ Grub-devel mailing list Grub-devel@gnu.org http://lists.gnu.org/mailman/listinfo/grub-devel