From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1n9T5r-0006NA-81 for mharc-grub-devel@gnu.org; Mon, 17 Jan 2022 09:34:47 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57732) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n9T5p-0006G6-Dn for grub-devel@gnu.org; Mon, 17 Jan 2022 09:34:45 -0500 Received: from smtp-out2.suse.de ([195.135.220.29]:38152) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n9T5k-0005rp-Q0 for grub-devel@gnu.org; Mon, 17 Jan 2022 09:34:44 -0500 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 0A5661F385 for ; Mon, 17 Jan 2022 14:34:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1642430078; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DbG+UkWguDkBYMn5d4i4qDrSYf/WFj6C80PviPFvcOo=; b=k+lzwcYq4CN72v9NOHVR/7kLlXYIX7Flc5mBu5kIzPUd1gvTi+zCZPTbvrnxJhvq3w+87e 1+klfw0a/BOpG3gQGzC93RtX3VXHOX33+WAS5tJ/8hYfxPqtGJYxO07SNTiyclhIivLev9 Wl1ZACcuc44qHPqcFYfe6+Mq5m1ln5A= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1642430078; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DbG+UkWguDkBYMn5d4i4qDrSYf/WFj6C80PviPFvcOo=; b=KbQYcg0D8KbpjgoE96U3hyxZ0JWGWXqM+u25KATzlesGA+sKyzaD1TP28A4XlFduQY30// AEBvZWbZJkc2X9DA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id DFE8F13C0E for ; Mon, 17 Jan 2022 14:34:37 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id OPd0NH1+5WGGHAAAMHmgww (envelope-from ) for ; Mon, 17 Jan 2022 14:34:37 +0000 From: Fabian Vogt To: grub-devel@gnu.org Subject: [PATCH v2] grub-mount: Support libfuse 3 Date: Mon, 17 Jan 2022 15:34:37 +0100 Message-ID: <7205494.90HXkBHot5@linux-e202.suse.de> In-Reply-To: <11406490.S1saASi1EY@linux-e202.suse.de> References: <11406490.S1saASi1EY@linux-e202.suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Received-SPF: pass client-ip=195.135.220.29; envelope-from=fvogt@suse.de; helo=smtp-out2.suse.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 17 Jan 2022 14:34:45 -0000 libfuse 3.0.0 got released in 2016, with some API changes compared to 2.x. This commit introduces support for 3.x while keeping it compatible with 2.6 as a fallback still. To detect fuse3, switch configure over to use pkg-config, which is simpler yet more reliable than looking for library and header manually. Also set FUSE_USE_VERSION that way, as it depends on the used libfuse version. Now that the CFLAGS are read from pkg-config, use just , which works with 2.x as well as 3.x and is recommended by libfuse upstream. One behaviour change of libfuse3 is that FUSE_ATOMIC_O_TRUNC is set by default, which means that open with O_TRUNC is passed as-is instead of calling the truncate operation. With libfuse2, truncate failed with -ENOSYS and that was returned to the application. To make O_TRUNC fail with libfuse3, return -EROFS explicitly if writing was requested. Signed-off-by: Fabian Vogt --- v2: add __attribute__ ((unused)) Makefile.util.def | 4 +++- configure.ac | 16 +++++----------- util/grub-mount.c | 25 ++++++++++++++++++++++--- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/Makefile.util.def b/Makefile.util.def index f8b356cc1..e92c1f346 100644 --- a/Makefile.util.def +++ b/Makefile.util.def @@ -309,11 +309,13 @@ program = { common = grub-core/disk/host.c; common = grub-core/osdep/init.c; + cflags = '$(FUSE_CFLAGS)'; + ldadd = libgrubmods.a; ldadd = libgrubgcry.a; ldadd = libgrubkern.a; ldadd = grub-core/lib/gnulib/libgnu.a; - ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM) -lfuse'; + ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM) $(FUSE_LIBS)'; condition = COND_GRUB_MOUNT; }; diff --git a/configure.ac b/configure.ac index 4f649edaf..1d40f9560 100644 --- a/configure.ac +++ b/configure.ac @@ -1787,17 +1787,11 @@ if test x"$enable_grub_mount" = xno ; then fi if test x"$grub_mount_excuse" = x ; then - AC_CHECK_LIB([fuse], [fuse_main_real], [], - [grub_mount_excuse="need FUSE library"]) -fi - -if test x"$grub_mount_excuse" = x ; then - # Check for fuse headers. - SAVED_CPPFLAGS="$CPPFLAGS" - CPPFLAGS="$CPPFLAGS -DFUSE_USE_VERSION=26" - AC_CHECK_HEADERS([fuse/fuse.h], [], - [grub_mount_excuse=["need FUSE headers"]]) - CPPFLAGS="$SAVED_CPPFLAGS" + PKG_CHECK_MODULES([FUSE], [fuse3], [FUSE_CFLAGS="$FUSE_CFLAGS -DFUSE_USE_VERSION=32"], [ + PKG_CHECK_MODULES([FUSE], [fuse], [FUSE_CFLAGS="$FUSE_CFLAGS -DFUSE_USE_VERSION=26"], [ + grub_mount_excuse="need fuse or fuse3 libraries" + ]) + ]) fi if test x"$enable_grub_mount" = xyes && test x"$grub_mount_excuse" != x ; then diff --git a/util/grub-mount.c b/util/grub-mount.c index d7be2a427..6df835df2 100644 --- a/util/grub-mount.c +++ b/util/grub-mount.c @@ -16,7 +16,6 @@ * You should have received a copy of the GNU General Public License * along with GRUB. If not, see . */ -#define FUSE_USE_VERSION 26 #include #include #include @@ -34,7 +33,7 @@ #include #include #include -#include +#include #include #include @@ -146,8 +145,14 @@ fuse_getattr_find_file (const char *cur_filename, return 0; } +#if FUSE_USE_VERSION < 30 static int fuse_getattr (const char *path, struct stat *st) +#else +static int +fuse_getattr (const char *path, struct stat *st, + struct fuse_file_info *fi __attribute__ ((unused))) +#endif { struct fuse_getattr_ctx ctx; char *pathname, *path2; @@ -241,8 +246,11 @@ static grub_file_t files[65536]; static int first_fd = 1; static int -fuse_open (const char *path, struct fuse_file_info *fi __attribute__ ((unused))) +fuse_open (const char *path, struct fuse_file_info *fi) { + if ((fi->flags & O_ACCMODE) != O_RDONLY) + return -EROFS; + grub_file_t file; file = grub_file_open (path, GRUB_FILE_TYPE_MOUNT); if (! file) @@ -330,13 +338,24 @@ fuse_readdir_call_fill (const char *filename, st.st_blocks = (st.st_size + 511) >> 9; st.st_atime = st.st_mtime = st.st_ctime = info->mtimeset ? info->mtime : 0; +#if FUSE_USE_VERSION < 30 ctx->fill (ctx->buf, filename, &st, 0); +#else + ctx->fill (ctx->buf, filename, &st, 0, 0); +#endif return 0; } +#if FUSE_USE_VERSION < 30 static int fuse_readdir (const char *path, void *buf, fuse_fill_dir_t fill, off_t off, struct fuse_file_info *fi) +#else +static int +fuse_readdir (const char *path, void *buf, + fuse_fill_dir_t fill, off_t off, struct fuse_file_info *fi, + enum fuse_readdir_flags flags __attribute__ ((unused))) +#endif { struct fuse_readdir_ctx ctx = { .path = path, -- 2.34.1