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