Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1jC5If-0002Gf-3I for mharc-grub-devel@gnu.org; Wed, 11 Mar 2020 13:37:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33335) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jC5Ic-0002DK-Cq for grub-devel@gnu.org; Wed, 11 Mar 2020 13:37:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jC5Ib-0008UY-De for grub-devel@gnu.org; Wed, 11 Mar 2020 13:37:42 -0400 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]:45950) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jC5Ib-0008TK-89 for grub-devel@gnu.org; Wed, 11 Mar 2020 13:37:41 -0400 Received: by mail-pl1-x642.google.com with SMTP id b22so1409852pls.12 for ; Wed, 11 Mar 2020 10:37:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=delphix.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7XS1AyuWO1LeWn89uyinT4ON+owL/rhISOka+HTK5xM=; b=Lq0FwhbmMLEba6CKdasQZrnm3j9Iz6D40tGaMwXHIGAjxlulm3cUmFiaOK+G3a6M9B /4ekkD7LixvV3gfRVdHCI7EHCreFkf+u/+p/w+wgauI3VoKKCgfHSysaaja+LJIqM1Ca n/PcQhKmsvE/hq+DT6qfSmdlcpLMuCIcVgJZw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7XS1AyuWO1LeWn89uyinT4ON+owL/rhISOka+HTK5xM=; b=A0Hl8i2x8O1Ug66KpgIPK6f1HAxTwtSkAuJcaVoEUk8n2Ihrgfx1NAS+JLpg7mN5Oq 81OKbG+aKgL5AXGs839q9xjUxYbPUNMg7QaoHiZ2aueg/AjXcxPnEJqXH/ZUYdkTCbNv s+Q5U59pwm9vjp1D8TCGtI7ZN9Q3YOR6n9hBxWHYySw4WktKNbc2SAlzK5oOfYK/PUm7 8z/Oym6BPchR9DwzsH/3mc2HJxtANmxrBQqM0o+E6opGP4mTTSz3/MWUHJ2+JoRaurhy 63AYtUC2a8wmOWlirVwV0cxCCT/RQs5CzdSYwwB0Z+Feqc4fAgIqt5vbI0yN9T7IgW3f BZYg== X-Gm-Message-State: ANhLgQ3j4Wc2mo2FHkqomBnTE0NUahWZNinzqI21yhctIqmkhYeHpi30 AqCMPuFq7/+/G8vR0eYVWVzJ59WZmOQvGavxK9uP6XSWP0F84UcHPUDGgm3QQBFQIbY5fDx/LsN XgMXMlV7p1P6rWgt/kHD1UQzzJfcYSAFRYA5koVQbnPrswe0afKO8xA== X-Google-Smtp-Source: ADFU+vvn6L4FJcKagWvPXc4ifBtxkat9eZV+Fyp/6WQfiET+Iw1aUnycnSzjb1Fq2jZ+osEy/hmIvw== X-Received: by 2002:a17:90b:3888:: with SMTP id mu8mr4362389pjb.33.1583948259242; Wed, 11 Mar 2020 10:37:39 -0700 (PDT) Received: from localhost.localdomain (c-73-162-153-225.hsd1.ca.comcast.net. [73.162.153.225]) by smtp.gmail.com with ESMTPSA id b3sm6342060pjq.38.2020.03.11.10.37.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Mar 2020 10:37:38 -0700 (PDT) From: Paul Dagnelie To: grub-devel@gnu.org Cc: mahrens@delphix.com, behlendorf1@llnl.gov, george.wilson@delphix.com, sebastien.roy@delphix.com, Paul Dagnelie Subject: [PATCH 1/7] Factor out file filter function for reuse Date: Wed, 11 Mar 2020 10:37:09 -0700 Message-Id: <20200311173715.22274-2-pcd@delphix.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20200311173715.22274-1-pcd@delphix.com> References: <20200311173715.22274-1-pcd@delphix.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::642 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Mar 2020 17:37:43 -0000 This patch refactors out the logic that applies filters to files for reuse in other code. Signed-off-by: Paul Dagnelie --- grub-core/kern/file.c | 46 +++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/grub-core/kern/file.c b/grub-core/kern/file.c index 58454458c..75eb5e2fa 100644 --- a/grub-core/kern/file.c +++ b/grub-core/kern/file.c @@ -57,14 +57,37 @@ grub_file_get_device_name (const char *name) return 0; } +static grub_file_t +grub_apply_file_filters (grub_file_t file, enum grub_file_type type, const char *name) +{ + grub_file_filter_id_t filter; + grub_file_t last_file = NULL; + + for (filter = 0; file && filter < ARRAY_SIZE (grub_file_filters); + filter++) + if (grub_file_filters[filter]) + { + last_file = file; + file = grub_file_filters[filter] (file, type); + if (file && file != last_file) + { + file->name = grub_strdup (name); + grub_errno = GRUB_ERR_NONE; + } + } + if (!file) + grub_file_close (last_file); + + return file; +} + grub_file_t grub_file_open (const char *name, enum grub_file_type type) { - grub_device_t device = 0; - grub_file_t file = 0, last_file = 0; + grub_device_t device = NULL; + grub_file_t file = NULL; char *device_name; const char *file_name; - grub_file_filter_id_t filter; device_name = grub_file_get_device_name (name); if (grub_errno) @@ -113,22 +136,7 @@ grub_file_open (const char *name, enum grub_file_type type) file->name = grub_strdup (name); grub_errno = GRUB_ERR_NONE; - for (filter = 0; file && filter < ARRAY_SIZE (grub_file_filters); - filter++) - if (grub_file_filters[filter]) - { - last_file = file; - file = grub_file_filters[filter] (file, type); - if (file && file != last_file) - { - file->name = grub_strdup (name); - grub_errno = GRUB_ERR_NONE; - } - } - if (!file) - grub_file_close (last_file); - - return file; + return grub_apply_file_filters(file, type, name); fail: if (device) -- 2.19.0