From owner-svn-src-head@freebsd.org Fri Oct 6 12:20:25 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 6E54EE35C2A; Fri, 6 Oct 2017 12:20:25 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 3B9F780DB3; Fri, 6 Oct 2017 12:20:25 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v96CKOja044722; Fri, 6 Oct 2017 12:20:24 GMT (envelope-from imp@FreeBSD.org) Received: (from imp@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v96CKOtt044720; Fri, 6 Oct 2017 12:20:24 GMT (envelope-from imp@FreeBSD.org) Message-Id: <201710061220.v96CKOtt044720@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: imp set sender to imp@FreeBSD.org using -f From: Warner Losh Date: Fri, 6 Oct 2017 12:20:24 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r324359 - in head/sys/boot/efi: include libefi X-SVN-Group: head X-SVN-Commit-Author: imp X-SVN-Commit-Paths: in head/sys/boot/efi: include libefi X-SVN-Commit-Revision: 324359 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 06 Oct 2017 12:20:25 -0000 Author: imp Date: Fri Oct 6 12:20:24 2017 New Revision: 324359 URL: https://svnweb.freebsd.org/changeset/base/324359 Log: Add efi_devpath_is_prefix efi_devpath_is_prefix determines if a path matches a passed-in prefix. Differential Revision: https://reviews.freebsd.org/D12564 Submitted by: Eric McCorkle Modified: head/sys/boot/efi/include/efilib.h head/sys/boot/efi/libefi/devpath.c Modified: head/sys/boot/efi/include/efilib.h ============================================================================== --- head/sys/boot/efi/include/efilib.h Fri Oct 6 11:48:09 2017 (r324358) +++ head/sys/boot/efi/include/efilib.h Fri Oct 6 12:20:24 2017 (r324359) @@ -82,6 +82,7 @@ EFI_HANDLE efi_devpath_handle(EFI_DEVICE_PATH *); EFI_DEVICE_PATH *efi_devpath_last_node(EFI_DEVICE_PATH *); EFI_DEVICE_PATH *efi_devpath_trim(EFI_DEVICE_PATH *); bool efi_devpath_match(EFI_DEVICE_PATH *, EFI_DEVICE_PATH *); +int efi_devpath_is_prefix(EFI_DEVICE_PATH *, EFI_DEVICE_PATH *); CHAR16 *efi_devpath_name(EFI_DEVICE_PATH *); void efi_free_devpath_name(CHAR16 *); Modified: head/sys/boot/efi/libefi/devpath.c ============================================================================== --- head/sys/boot/efi/libefi/devpath.c Fri Oct 6 11:48:09 2017 (r324358) +++ head/sys/boot/efi/libefi/devpath.c Fri Oct 6 12:20:24 2017 (r324359) @@ -166,3 +166,32 @@ efi_devpath_match(EFI_DEVICE_PATH *devpath1, EFI_DEVIC } return (true); } + +int +efi_devpath_is_prefix(EFI_DEVICE_PATH *prefix, EFI_DEVICE_PATH *path) +{ + int len; + + if (prefix == NULL || path == NULL) + return (0); + + while (1) { + if (IsDevicePathEnd(prefix)) + break; + + if (DevicePathType(prefix) != DevicePathType(path) || + DevicePathSubType(prefix) != DevicePathSubType(path)) + return (0); + + len = DevicePathNodeLength(prefix); + if (len != DevicePathNodeLength(path)) + return (0); + + if (memcmp(prefix, path, (size_t)len) != 0) + return (0); + + prefix = NextDevicePathNode(prefix); + path = NextDevicePathNode(path); + } + return (1); +}