From patchwork Wed Nov 20 02:42:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Kerr X-Patchwork-Id: 1197785 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47Hngz6LTXz9sPV for ; Wed, 20 Nov 2019 14:08:15 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="HYOv69+t"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47Hngz5TJszDqxl for ; Wed, 20 Nov 2019 14:08:15 +1100 (AEDT) X-Original-To: petitboot@lists.ozlabs.org Delivered-To: petitboot@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47Hn9W3PzRzDqHl for ; Wed, 20 Nov 2019 13:45:19 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="HYOv69+t"; dkim-atps=neutral Received: by ozlabs.org (Postfix, from userid 1023) id 47Hn9W1Kshz9sPW; Wed, 20 Nov 2019 13:45:19 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1574217919; bh=Y3QuwFuVlIis2jf2S0K7XvCMtpCBbIVy9QIQNckIS9Y=; h=From:To:Subject:Date:In-Reply-To:References:From; b=HYOv69+tv0tvtfVUERnxmbxqN+aIvhQtRW7DzTiZHJaZfl6zar39vXcFG7GPfd3B9 BWalKdYsKcigWfHIZHZrxml7gW5/mEE/H0b2R517f90/Yf1MleWD6lgZUC/GTQvJou ECoaAl95Omo7QuB6uvmRXOh0ITYODFeNUc4/p24JwVU+OBPO9RHmig7rT2vwB5pAZ9 aDKqUWs3F+6ZjAiPLh2CpjhEP9qPv9RhbZr4r3K4bkGuj3LcAJZnbB+FYGdK3VTMXO mXcdKu6//nddcwb7IvowjgyN/K2UtYd+bQrGlXQMp1gFQaKvUfAeFgsUpJGDtht+ML gs80I7kf2OrqQ== From: Jeremy Kerr To: petitboot@lists.ozlabs.org Subject: [PATCH 05/14] discover/grub2: expose a struct for grub2 file references Date: Wed, 20 Nov 2019 10:42:57 +0800 Message-Id: <20191120024306.16526-6-jk@ozlabs.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191120024306.16526-1-jk@ozlabs.org> References: <20191120024306.16526-1-jk@ozlabs.org> MIME-Version: 1.0 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" Currently, we have struct grub2_resource_info to keep references to boot payloads that may be returned in boot options, and be (conditionally) resolved by the parser. We'd also like to use the same semantics for other file references in the grub2 parser, for arbitrary usage in scripts - where files are also referenced by a path and an optional device. To do this, this change moves struct grub2_resource_info to grub2.h, and renames to struct grub2_file. Future changes will use this for script-internal file handling. Signed-off-by: Jeremy Kerr --- discover/grub2/grub2.c | 24 +++++++++--------------- discover/grub2/grub2.h | 8 ++++++++ 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/discover/grub2/grub2.c b/discover/grub2/grub2.c index f62ccdd..412298b 100644 --- a/discover/grub2/grub2.c +++ b/discover/grub2/grub2.c @@ -33,17 +33,12 @@ static const char *const grub2_conf_files[] = { NULL }; -struct grub2_resource_info { - char *root; - char *path; -}; - /* we use slightly different resources for grub2 */ struct resource *create_grub2_resource(struct discover_boot_option *opt, struct discover_device *orig_device, const char *root, const char *path) { - struct grub2_resource_info *info; + struct grub2_file *file; struct resource *res; if (strstr(path, "://")) { @@ -55,13 +50,12 @@ struct resource *create_grub2_resource(struct discover_boot_option *opt, res = talloc(opt, struct resource); if (root) { - info = talloc(res, struct grub2_resource_info); - talloc_reference(info, root); - info->root = talloc_strdup(info, root); - info->path = talloc_strdup(info, path); + file = talloc(res, struct grub2_file); + file->dev = talloc_strdup(file, root); + file->path = talloc_strdup(file, path); res->resolved = false; - res->info = info; + res->info = file; } else resolve_resource_against_device(res, orig_device, path); @@ -72,18 +66,18 @@ struct resource *create_grub2_resource(struct discover_boot_option *opt, bool resolve_grub2_resource(struct device_handler *handler, struct resource *res) { - struct grub2_resource_info *info = res->info; + struct grub2_file *file = res->info; struct discover_device *dev; assert(!res->resolved); - dev = device_lookup_by_uuid(handler, info->root); + dev = device_lookup_by_uuid(handler, file->dev); if (!dev) return false; - resolve_resource_against_device(res, dev, info->path); - talloc_free(info); + resolve_resource_against_device(res, dev, file->path); + talloc_free(file); return true; } diff --git a/discover/grub2/grub2.h b/discover/grub2/grub2.h index 68176fb..73d91b2 100644 --- a/discover/grub2/grub2.h +++ b/discover/grub2/grub2.h @@ -107,6 +107,14 @@ struct grub2_parser { bool inter_word; }; +/* References to files in grub2 consist of an optional device and a path + * (specified here by UUID). If the dev is unspecified, we fall back to a + * default - usually the 'root' environment variable. */ +struct grub2_file { + char *dev; + char *path; +}; + /* type for builtin functions */ typedef int (*grub2_function)(struct grub2_script *script, void *data, int argc, char *argv[]);