Module Name: src Committed By: pho Date: Sat Dec 4 06:42:39 UTC 2021
Modified Files: src/lib/librefuse: Makefile fuse.h refuse.c refuse_lowlevel.c refuse_opt.c src/sbin/mount_qemufwcfg: Makefile fwcfg.c src/tests/lib/librefuse: t_refuse_opt.c src/usr.sbin/perfused: perfused.h Added Files: src/lib/librefuse: fuse_internal.h Log Message: librefuse: Preparation of a proper API versioning; no more #ifdef woes in user code The goal is to fully support FUSE API version 3.0 while maintaining API/ABI compatibility with code written for 2.6 (or even older). * <fuse.h> now emits a compiler warning if it's included without defining FUSE_USE_VERSION. It had been silently defaulted to the latest supported version prior to this change. This is permissive compared to the original FUSE, as it emits an error instead. * <fuse.h> now emits a warning if FUSE_USE_VERSION is higher than what can be provided. * Added a macro FUSE_MAKE_VERSION(maj, min). It was missing from librefuse <fuse.h>. No actual API updates have been made (yet). To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 src/lib/librefuse/Makefile cvs rdiff -u -r1.23 -r1.24 src/lib/librefuse/fuse.h cvs rdiff -u -r0 -r1.1 src/lib/librefuse/fuse_internal.h cvs rdiff -u -r1.102 -r1.103 src/lib/librefuse/refuse.c cvs rdiff -u -r1.1 -r1.2 src/lib/librefuse/refuse_lowlevel.c cvs rdiff -u -r1.21 -r1.22 src/lib/librefuse/refuse_opt.c cvs rdiff -u -r1.4 -r1.5 src/sbin/mount_qemufwcfg/Makefile cvs rdiff -u -r1.5 -r1.6 src/sbin/mount_qemufwcfg/fwcfg.c cvs rdiff -u -r1.8 -r1.9 src/tests/lib/librefuse/t_refuse_opt.c cvs rdiff -u -r1.10 -r1.11 src/usr.sbin/perfused/perfused.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/lib/librefuse/Makefile diff -u src/lib/librefuse/Makefile:1.11 src/lib/librefuse/Makefile:1.12 --- src/lib/librefuse/Makefile:1.11 Sun Nov 20 13:26:28 2016 +++ src/lib/librefuse/Makefile Sat Dec 4 06:42:39 2021 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.11 2016/11/20 13:26:28 pho Exp $ +# $NetBSD: Makefile,v 1.12 2021/12/04 06:42:39 pho Exp $ USE_FORT?= yes # data driven bugs? @@ -11,7 +11,7 @@ FUSE_OPT_DEBUG_FLAGS= -g -DFUSE_OPT_DEBU .endif CFLAGS+= ${FUSE_OPT_DEBUG_FLAGS} -CPPFLAGS+= -I${.CURDIR} -D_KERNTYPES +CPPFLAGS+= -I${.CURDIR} SRCS= refuse.c refuse_opt.c refuse_lowlevel.c MAN= refuse.3 WARNS?= 5 Index: src/lib/librefuse/fuse.h diff -u src/lib/librefuse/fuse.h:1.23 src/lib/librefuse/fuse.h:1.24 --- src/lib/librefuse/fuse.h:1.23 Wed Apr 10 21:38:02 2019 +++ src/lib/librefuse/fuse.h Sat Dec 4 06:42:39 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: fuse.h,v 1.23 2019/04/10 21:38:02 maya Exp $ */ +/* $NetBSD: fuse.h,v 1.24 2021/12/04 06:42:39 pho Exp $ */ /* * Copyright © 2007 Alistair Crooks. All rights reserved. @@ -28,19 +28,33 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef FUSE_H_ -#define FUSE_H_ 20070123 - -/* set the default version to use for the fuse interface */ -/* this value determines the API to be used */ -#ifndef FUSE_USE_VERSION -#define FUSE_USE_VERSION 26 -#endif +#define FUSE_H_ 20211204 #include <sys/types.h> #include <puffs.h> #include <utime.h> +/* The latest version of FUSE API currently provided by refuse. */ +#define FUSE_MAJOR_VERSION 2 +#define FUSE_MINOR_VERSION 6 + +#define FUSE_MAKE_VERSION(maj, min) ((maj) * 10 + (min)) +#define FUSE_VERSION FUSE_MAKE_VERSION(FUSE_MAJOR_VERSION, FUSE_MINOR_VERSION) + +/* FUSE_USE_VERSION is expected to be defined by user code to + * determine the API to be used. Although defining this macro is + * mandatory in the original FUSE implementation, refuse hasn't + * required this so we only emit a warning if it's undefined. */ +#if defined(FUSE_USE_VERSION) +# if FUSE_USE_VERSION > FUSE_VERSION +# warning "The requested API version is higher than the latest one supported by refuse." +# endif +#else +# warning "User code including <fuse.h> should define FUSE_USE_VERSION before including this header. Defaulting to the latest version." +# define FUSE_USE_VERSION FUSE_VERSION +#endif + #ifdef __cplusplus extern "C" { #endif @@ -97,10 +111,6 @@ typedef struct puffs_fuse_dirh *fuse_dir typedef int (*fuse_fill_dir_t)(void *, const char *, const struct stat *, off_t); typedef int (*fuse_dirfil_t)(fuse_dirh_t, const char *, int, ino_t); -#define FUSE_VERSION 26 -#define FUSE_MAJOR_VERSION 2 -#define FUSE_MINOR_VERSION 6 - /* * These operations shadow those in puffs_usermount, and are used * as a table of callbacks to make when file system requests come Index: src/lib/librefuse/refuse.c diff -u src/lib/librefuse/refuse.c:1.102 src/lib/librefuse/refuse.c:1.103 --- src/lib/librefuse/refuse.c:1.102 Tue Nov 30 12:13:12 2021 +++ src/lib/librefuse/refuse.c Sat Dec 4 06:42:39 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: refuse.c,v 1.102 2021/11/30 12:13:12 pho Exp $ */ +/* $NetBSD: refuse.c,v 1.103 2021/12/04 06:42:39 pho Exp $ */ /* * Copyright © 2007 Alistair Crooks. All rights reserved. @@ -31,16 +31,20 @@ #include <sys/cdefs.h> #if !defined(lint) -__RCSID("$NetBSD: refuse.c,v 1.102 2021/11/30 12:13:12 pho Exp $"); +__RCSID("$NetBSD: refuse.c,v 1.103 2021/12/04 06:42:39 pho Exp $"); #endif /* !lint */ +/* We emit a compiler warning for anyone including <fuse.h> without + * defining FUSE_USE_VERSION. Define it here, or otherwise we'll be + * warned too. */ +#define FUSE_USE_VERSION FUSE_VERSION + #include <sys/types.h> #include <assert.h> #include <err.h> #include <errno.h> -#include <fuse.h> -#include <fuse_lowlevel.h> +#include <fuse_internal.h> #include <fuse_opt.h> #include <paths.h> #include <stddef.h> Index: src/lib/librefuse/refuse_lowlevel.c diff -u src/lib/librefuse/refuse_lowlevel.c:1.1 src/lib/librefuse/refuse_lowlevel.c:1.2 --- src/lib/librefuse/refuse_lowlevel.c:1.1 Sun Nov 20 13:26:28 2016 +++ src/lib/librefuse/refuse_lowlevel.c Sat Dec 4 06:42:39 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: refuse_lowlevel.c,v 1.1 2016/11/20 13:26:28 pho Exp $ */ +/* $NetBSD: refuse_lowlevel.c,v 1.2 2021/12/04 06:42:39 pho Exp $ */ /* * Copyright (c) 2016 The NetBSD Foundation, Inc. @@ -31,10 +31,10 @@ #include <sys/cdefs.h> #if !defined(lint) -__RCSID("$NetBSD: refuse_lowlevel.c,v 1.1 2016/11/20 13:26:28 pho Exp $"); +__RCSID("$NetBSD: refuse_lowlevel.c,v 1.2 2021/12/04 06:42:39 pho Exp $"); #endif /* !lint */ -#include <fuse_lowlevel.h> +#include <fuse_internal.h> #include <fuse_opt.h> #include <stddef.h> #include <stdio.h> Index: src/lib/librefuse/refuse_opt.c diff -u src/lib/librefuse/refuse_opt.c:1.21 src/lib/librefuse/refuse_opt.c:1.22 --- src/lib/librefuse/refuse_opt.c:1.21 Wed Dec 1 14:17:50 2021 +++ src/lib/librefuse/refuse_opt.c Sat Dec 4 06:42:39 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: refuse_opt.c,v 1.21 2021/12/01 14:17:50 pho Exp $ */ +/* $NetBSD: refuse_opt.c,v 1.22 2021/12/04 06:42:39 pho Exp $ */ /*- * Copyright (c) 2007 Juan Romero Pardines. @@ -28,7 +28,7 @@ #include <sys/types.h> #include <err.h> -#include <fuse.h> +#include <fuse_internal.h> #include <fuse_opt.h> #include <stdbool.h> #include <stdio.h> Index: src/sbin/mount_qemufwcfg/Makefile diff -u src/sbin/mount_qemufwcfg/Makefile:1.4 src/sbin/mount_qemufwcfg/Makefile:1.5 --- src/sbin/mount_qemufwcfg/Makefile:1.4 Wed Oct 3 13:34:44 2018 +++ src/sbin/mount_qemufwcfg/Makefile Sat Dec 4 06:42:39 2021 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.4 2018/10/03 13:34:44 jmcneill Exp $ +# $NetBSD: Makefile,v 1.5 2021/12/04 06:42:39 pho Exp $ WARNS= 6 @@ -8,6 +8,4 @@ DPADD+= ${LIBREFUSE} ${LIBPUFFS} ${LIBUT LDADD= -lrefuse -lpuffs -lutil MAN= mount_qemufwcfg.8 -CPPFLAGS+= -D_KERNTYPES - .include <bsd.prog.mk> Index: src/sbin/mount_qemufwcfg/fwcfg.c diff -u src/sbin/mount_qemufwcfg/fwcfg.c:1.5 src/sbin/mount_qemufwcfg/fwcfg.c:1.6 --- src/sbin/mount_qemufwcfg/fwcfg.c:1.5 Thu Nov 30 15:42:18 2017 +++ src/sbin/mount_qemufwcfg/fwcfg.c Sat Dec 4 06:42:39 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: fwcfg.c,v 1.5 2017/11/30 15:42:18 wiz Exp $ */ +/* $NetBSD: fwcfg.c,v 1.6 2021/12/04 06:42:39 pho Exp $ */ /*- * Copyright (c) 2017 Jared McNeill <jmcne...@invisible.ca> @@ -27,7 +27,9 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: fwcfg.c,v 1.5 2017/11/30 15:42:18 wiz Exp $"); +__RCSID("$NetBSD: fwcfg.c,v 1.6 2021/12/04 06:42:39 pho Exp $"); + +#define FUSE_USE_VERSION FUSE_MAKE_VERSION(2, 6) #include <sys/ioctl.h> Index: src/tests/lib/librefuse/t_refuse_opt.c diff -u src/tests/lib/librefuse/t_refuse_opt.c:1.8 src/tests/lib/librefuse/t_refuse_opt.c:1.9 --- src/tests/lib/librefuse/t_refuse_opt.c:1.8 Fri Jan 13 21:30:41 2017 +++ src/tests/lib/librefuse/t_refuse_opt.c Sat Dec 4 06:42:39 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: t_refuse_opt.c,v 1.8 2017/01/13 21:30:41 christos Exp $ */ +/* $NetBSD: t_refuse_opt.c,v 1.9 2021/12/04 06:42:39 pho Exp $ */ /*- * Copyright (c) 2016 The NetBSD Foundation, Inc. @@ -26,13 +26,13 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include <sys/cdefs.h> -__RCSID("$NetBSD: t_refuse_opt.c,v 1.8 2017/01/13 21:30:41 christos Exp $"); +__RCSID("$NetBSD: t_refuse_opt.c,v 1.9 2021/12/04 06:42:39 pho Exp $"); -#define _KERNTYPES #include <sys/types.h> #include <atf-c.h> +#define FUSE_USE_VERSION FUSE_MAKE_VERSION(2, 6) #include <fuse.h> #include "h_macros.h" Index: src/usr.sbin/perfused/perfused.h diff -u src/usr.sbin/perfused/perfused.h:1.10 src/usr.sbin/perfused/perfused.h:1.11 --- src/usr.sbin/perfused/perfused.h:1.10 Sat Feb 4 18:36:30 2012 +++ src/usr.sbin/perfused/perfused.h Sat Dec 4 06:42:39 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: perfused.h,v 1.10 2012/02/04 18:36:30 joerg Exp $ */ +/* $NetBSD: perfused.h,v 1.11 2021/12/04 06:42:39 pho Exp $ */ /*- * Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved. @@ -30,7 +30,6 @@ #include <puffs.h> #include "../../lib/libperfuse/perfuse_if.h" -#include "fuse.h" #define PERFUSE_MSG_T struct puffs_framebuf Added files: Index: src/lib/librefuse/fuse_internal.h diff -u /dev/null src/lib/librefuse/fuse_internal.h:1.1 --- /dev/null Sat Dec 4 06:42:39 2021 +++ src/lib/librefuse/fuse_internal.h Sat Dec 4 06:42:39 2021 @@ -0,0 +1,42 @@ +/* $NetBSD: fuse_internal.h,v 1.1 2021/12/04 06:42:39 pho Exp $ */ + +/* + * Copyright (c) 2021 The NetBSD Foundation, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#if !defined(FUSE_INTERNAL_H) +#define FUSE_INTERNAL_H + +/* We emit a compiler warning for anyone including <fuse.h> without + * defining FUSE_USE_VERSION. Define it here, or otherwise we'll be + * warned too. */ +#define FUSE_USE_VERSION FUSE_VERSION + +#include <fuse.h> +#include <fuse_lowlevel.h> + +#endif