Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1iPlWz-00040x-P9 for mharc-grub-devel@gnu.org; Wed, 30 Oct 2019 06:48:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45196) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iPlWx-0003yl-9c for grub-devel@gnu.org; Wed, 30 Oct 2019 06:48:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iPlWv-0004Ys-W6 for grub-devel@gnu.org; Wed, 30 Oct 2019 06:48:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58888) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iPlWv-0004WS-Nz for grub-devel@gnu.org; Wed, 30 Oct 2019 06:48:45 -0400 Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.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 4B5DFA0510 for ; Wed, 30 Oct 2019 10:48:43 +0000 (UTC) Received: by mail-wr1-f72.google.com with SMTP id b4so1095147wrn.8 for ; Wed, 30 Oct 2019 03:48:43 -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=Mm0uIyZlMm+AvVaPO27L37SHMCH3ramwriMppj/+onE=; b=mzeYRmjY7QlecN3z0/HlKCMulcU0gRa6PgSMH5qumwbduz1ctdVVd8psWgtGcJ7u8g eyeIkKrDRa1eF5IekC60LhTp7w8N87sgy3yzUI7UAQxwxTeMYzSeDKipa1V3GM/pwqrj n134dBGPiCGG1ozWLGhJ0V1wmr0FXClvB1BX3xquFBngl8a0Cysf80o4RCYqtkt9AbSr 4jYKl2SJhgeEH3H9CTcCLIQQ9n/xMWcBnirUtLwrW69GNX2QY4W8DHRAKPjutLkACz9f m2GtZZj/ZyveKMdEdOqbSz84dVwGjTMpJ6mjqxAbnMqdKMBfhu8poCm/0mEimR3NRIyn XWfQ== X-Gm-Message-State: APjAAAXDaBRyERYbApRpS2RbeyBld4PjbiQHLArwjriCC4XgGd6yJt7o Uokbu4dgAIjrK8kGhcrZ7gO8ClsqvlzWqxh7tCM3RQ3WfeBxjy7lThagP2T8GTpWjwFqX+WkFjq 8vNu+Y4/p9oo= X-Received: by 2002:adf:ee10:: with SMTP id y16mr23690419wrn.67.1572432521560; Wed, 30 Oct 2019 03:48:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqzeFt1vCjhtWd0feFCMHKfXx2whgjTNLC0YLYRRh3VpvpJca0MqgdKf8YKxFz8X7n46G+DsAA== X-Received: by 2002:adf:ee10:: with SMTP id y16mr23690402wrn.67.1572432521360; Wed, 30 Oct 2019 03:48:41 -0700 (PDT) Received: from minerva.redhat.com ([90.168.169.92]) by smtp.gmail.com with ESMTPSA id b3sm323341wma.13.2019.10.30.03.48.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Oct 2019 03:48:40 -0700 (PDT) From: Javier Martinez Canillas To: grub-devel@gnu.org Cc: Peter Jones , Adam Jackson , Javier Martinez Canillas , Daniel Kiper Subject: [PATCH v3 1/2] Add grub_util_readlink() Date: Wed, 30 Oct 2019 11:48:13 +0100 Message-Id: <20191030104815.25837-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: Wed, 30 Oct 2019 10:48:48 -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 v3: None 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