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