Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1iP4nq-0007Og-EN for mharc-grub-devel@gnu.org; Mon, 28 Oct 2019 09:11:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57480) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iP4nl-0007Gl-Q1 for grub-devel@gnu.org; Mon, 28 Oct 2019 09:11:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iP4nk-000555-FH for grub-devel@gnu.org; Mon, 28 Oct 2019 09:11:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47316) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iP4nk-00054P-6h for grub-devel@gnu.org; Mon, 28 Oct 2019 09:11:16 -0400 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 216463DD9E for ; Mon, 28 Oct 2019 13:11:15 +0000 (UTC) Received: by mail-wm1-f72.google.com with SMTP id g13so3806946wme.0 for ; Mon, 28 Oct 2019 06:11:15 -0700 (PDT) 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:mime-version :content-transfer-encoding; bh=vR2Q5EMGMJK+APsbG9pL0tKE51VpaMrNR0ogPiMek4k=; b=d9ENOTrlT5tpaHG4C0erRodURMTFobUo0SEjjfoTeyhyuUwa4Ufcxnw1PAroT88u8z su9Yp5DuR/XCnt1gBjPpicV5xdMc60m8Fv1epyiewBhjYXFHSRMzJT81ce5tyDZQiCaD yD3in9wkhQtK2M7JfM0DzKm86b7iKLsTs3Dwc8IHXZQ5Q64Ycxrw9+lb54ihCMHmCBEh EvHdvQSoiQb0yF3UItUxBGmt8OyqcbnZ439iS1TX5fSSVUqjlKx701am4hU/G3jUhLpO 0EHmuVLs6mFEAwmOhexrKMHKCFWpnXhBkB8/zZC8Xtnq3dKAQXh6gQb8HD0hVI2Tl/ZR J4Tw== X-Gm-Message-State: APjAAAXgapTFDcO2q4gNRsiKA0TXg1FTozL7jGtPf2e3JUwHKb4aBduB Q5dLFBLUFoKv4qT9MoumSjATIbbBvQ6WojB2vmUQg3YxjZ4nJ/v3CY3NQ2+ui29F+ZAB7RuoyGB VZ56PUxJfSq0= X-Received: by 2002:a5d:4d0f:: with SMTP id z15mr14392094wrt.195.1572268273347; Mon, 28 Oct 2019 06:11:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqwUmqEYJmQBmMKcLxtF0/ZdsuENEuG4Oopcqe16TF2LAVlR+igf5XN7fN+Xnox7kwxucM+paA== X-Received: by 2002:a5d:4d0f:: with SMTP id z15mr14392071wrt.195.1572268273145; Mon, 28 Oct 2019 06:11:13 -0700 (PDT) Received: from minerva.redhat.com ([90.168.169.92]) by smtp.gmail.com with ESMTPSA id i18sm11679082wrx.14.2019.10.28.06.11.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2019 06:11:12 -0700 (PDT) From: Javier Martinez Canillas To: grub-devel@gnu.org Cc: Peter Jones , Adam Jackson , Javier Martinez Canillas , Daniel Kiper Subject: [PATCH v2 1/2] Add grub_util_readlink() Date: Mon, 28 Oct 2019 14:11:09 +0100 Message-Id: <20191028131110.17464-1-javierm@redhat.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 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: Mon, 28 Oct 2019 13:11:20 -0000 From: Peter Jones Currently grub-editenv and related tools are not able to follow symbolic links when finding their config file. For example the grub-editenv create command will wrongly overwrite a symlink in /boot/grub2/grubenv with a ne= w regular file, instead of creating a file in the path the symlink points t= o. A following patch will change that and add support in grub-editenv to follow symbolic links when finding the grub environment variables file. Add a grub_util_readlink() helper function that is just a wrapper around the platform specific function to read the value of a symbolic link. This helper function will be used by the following patch for grub-editenv. Signed-off-by: Peter Jones Reviewed-by: Adam Jackson Signed-off-by: Javier Martinez Canillas Reviewed-by: Daniel Kiper --- Changes in v2: - Add a better commit message explaining why the change is needed. - Add Reviewed-by tag from Daniel Kiper. grub-core/osdep/windows/hostdisk.c | 6 ++++++ include/grub/osdep/hostfile_aros.h | 6 ++++++ include/grub/osdep/hostfile_unix.h | 6 ++++++ include/grub/osdep/hostfile_windows.h | 2 ++ 4 files changed, 20 insertions(+) diff --git grub-core/osdep/windows/hostdisk.c grub-core/osdep/windows/hos= tdisk.c index 355100789a7..87a106c9b82 100644 --- grub-core/osdep/windows/hostdisk.c +++ grub-core/osdep/windows/hostdisk.c @@ -365,6 +365,12 @@ grub_util_mkdir (const char *dir) free (windows_name); } =20 +ssize_t +grub_util_readlink (const char *name, char *buf, size_t bufsize) +{ + return readlink(name, buf, bufsize); +} + int grub_util_rename (const char *from, const char *to) { diff --git include/grub/osdep/hostfile_aros.h include/grub/osdep/hostfile= _aros.h index a059c0fa40a..161fbb7bdfd 100644 --- include/grub/osdep/hostfile_aros.h +++ include/grub/osdep/hostfile_aros.h @@ -68,6 +68,12 @@ grub_util_rename (const char *from, const char *to) return rename (from, to); } =20 +static inline ssize_t +grub_util_readlink (const char *name, char *buf, size_t bufsize) +{ + return readlink(name, buf, bufsize); +} + #define grub_util_mkdir(a) mkdir ((a), 0755) =20 struct grub_util_fd diff --git include/grub/osdep/hostfile_unix.h include/grub/osdep/hostfile= _unix.h index 9ffe46fa3ca..17cd3aa8b30 100644 --- include/grub/osdep/hostfile_unix.h +++ include/grub/osdep/hostfile_unix.h @@ -71,6 +71,12 @@ grub_util_rename (const char *from, const char *to) return rename (from, to); } =20 +static inline ssize_t +grub_util_readlink (const char *name, char *buf, size_t bufsize) +{ + return readlink(name, buf, bufsize); +} + #define grub_util_mkdir(a) mkdir ((a), 0755) =20 #if defined (__NetBSD__) diff --git include/grub/osdep/hostfile_windows.h include/grub/osdep/hostf= ile_windows.h index bf6451b6db4..8c92d0591bb 100644 --- include/grub/osdep/hostfile_windows.h +++ include/grub/osdep/hostfile_windows.h @@ -41,6 +41,8 @@ typedef struct grub_util_fd_dir *grub_util_fd_dir_t; =20 int grub_util_rename (const char *from, const char *to); +ssize_t +grub_util_readlink (const char *name, char *buf, size_t bufsize); int grub_util_unlink (const char *name); void --=20 2.21.0