1 /* $NetBSD: efidev.c,v 1.1 2018/03/08 10:34:33 nonaka Exp $ */ 2 /* $OpenBSD: efiboot.c,v 1.28 2017/11/25 19:02:07 patrick Exp $ */ 3 4 /* 5 * Copyright (c) 2015 YASUOKA Masahiko <yasuoka@yasuoka.net> 6 * 7 * Permission to use, copy, modify, and distribute this software for any 8 * purpose with or without fee is hereby granted, provided that the above 9 * copyright notice and this permission notice appear in all copies. 10 * 11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 */ 19 20 #include "efiboot.h" 21 22 /* 23 * Determine the number of nodes up to, but not including, the first 24 * node of the specified type. 25 */ 26 int 27 efi_device_path_depth(EFI_DEVICE_PATH *dp, int dptype) 28 { 29 int i; 30 31 for (i = 0; !IsDevicePathEnd(dp); dp = NextDevicePathNode(dp), i++) { 32 if (DevicePathType(dp) == dptype) 33 return (i); 34 } 35 36 return (-1); 37 } 38 39 int 40 efi_device_path_ncmp(EFI_DEVICE_PATH *dpa, EFI_DEVICE_PATH *dpb, int deptn) 41 { 42 int i, cmp; 43 44 for (i = 0; i < deptn; i++) { 45 if (IsDevicePathEnd(dpa) || IsDevicePathEnd(dpb)) 46 return ((IsDevicePathEnd(dpa) && IsDevicePathEnd(dpb)) 47 ? 0 : (IsDevicePathEnd(dpa))? -1 : 1); 48 cmp = DevicePathNodeLength(dpa) - DevicePathNodeLength(dpb); 49 if (cmp) 50 return (cmp); 51 cmp = memcmp(dpa, dpb, DevicePathNodeLength(dpa)); 52 if (cmp) 53 return (cmp); 54 dpa = NextDevicePathNode(dpa); 55 dpb = NextDevicePathNode(dpb); 56 } 57 58 return (0); 59 } 60