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