17270962aSWarner Losh /*- 27270962aSWarner Losh * Copyright (c) 2017 Netflix, Inc. 37270962aSWarner Losh * 47270962aSWarner Losh * Redistribution and use in source and binary forms, with or without 57270962aSWarner Losh * modification, are permitted provided that the following conditions 67270962aSWarner Losh * are met: 77270962aSWarner Losh * 1. Redistributions of source code must retain the above copyright 8*6decf2ccSEd Maste * notice, this list of conditions and the following disclaimer. 97270962aSWarner Losh * 2. Redistributions in binary form must reproduce the above copyright 107270962aSWarner Losh * notice, this list of conditions and the following disclaimer in the 117270962aSWarner Losh * documentation and/or other materials provided with the distribution. 127270962aSWarner Losh * 13*6decf2ccSEd Maste * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14*6decf2ccSEd Maste * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15*6decf2ccSEd Maste * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16*6decf2ccSEd Maste * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17*6decf2ccSEd Maste * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18*6decf2ccSEd Maste * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19*6decf2ccSEd Maste * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20*6decf2ccSEd Maste * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21*6decf2ccSEd Maste * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22*6decf2ccSEd Maste * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23*6decf2ccSEd Maste * SUCH DAMAGE. 247270962aSWarner Losh */ 257270962aSWarner Losh 267270962aSWarner Losh #ifndef _EFIVAR_DP_H_ 277270962aSWarner Losh #define _EFIVAR_DP_H_ 287270962aSWarner Losh 297270962aSWarner Losh /* 307270962aSWarner Losh * "Linux compatible" efivar-dp.h header. At the moment, it's really a 317270962aSWarner Losh * very thin, minimal interface. 327270962aSWarner Losh */ 337270962aSWarner Losh 347270962aSWarner Losh /* 357270962aSWarner Losh * Generic EFI_DEVICE_PATH, spelled the Linux way. We use this 367270962aSWarner Losh * interface to the outside world and type-pun to the EFI EDK2 code 377270962aSWarner Losh * we use to implement it. 387270962aSWarner Losh */ 397270962aSWarner Losh typedef struct { 407270962aSWarner Losh uint8_t type; 417270962aSWarner Losh uint8_t subtype; 427270962aSWarner Losh uint16_t length; 437270962aSWarner Losh } __packed efidp_header; 447270962aSWarner Losh 457270962aSWarner Losh /* NB: Linux has shadow types for all dp type */ 467270962aSWarner Losh 477270962aSWarner Losh typedef union { 487270962aSWarner Losh efidp_header header; 497270962aSWarner Losh } efidp_data; 507270962aSWarner Losh typedef efidp_data *efidp; 517270962aSWarner Losh typedef const efidp_data *const_efidp; 527270962aSWarner Losh 537270962aSWarner Losh /** format a device path into UEFI standard conforming output. 547270962aSWarner Losh * 557270962aSWarner Losh * NB: FreeBSD's implementation is taken from EDK2, while Linux's 567270962aSWarner Losh * was hand-rolled. There may be differences as a result. 577270962aSWarner Losh */ 587270962aSWarner Losh ssize_t efidp_format_device_path(char *buf, size_t len, const_efidp dp, 597270962aSWarner Losh ssize_t max); 6009ee5d8aSWarner Losh ssize_t efidp_format_device_path_node(char *buf, size_t len, const_efidp dp); 617270962aSWarner Losh ssize_t efidp_parse_device_path(char *path, efidp out, size_t max); 6209ee5d8aSWarner Losh char * efidp_extract_file_path(const_efidp dp); 637270962aSWarner Losh 641028a2d4SWarner Losh size_t efidp_size(const_efidp); 651028a2d4SWarner Losh 6609ee5d8aSWarner Losh int efivar_device_path_to_unix_path(const_efidp dp, char **dev, char **relpath, char **abspath); 6709ee5d8aSWarner Losh int efivar_unix_path_to_device_path(const char *path, efidp *dp); 6809ee5d8aSWarner Losh 697270962aSWarner Losh #endif /* _EFIVAR_DP_H_ */ 70