Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src librefuse: Preparation of a proper API versioning; no more #...



details:   https://anonhg.NetBSD.org/src/rev/c5869b431ff9
branches:  trunk
changeset: 1026647:c5869b431ff9
user:      pho <pho%NetBSD.org@localhost>
date:      Sat Dec 04 06:42:39 2021 +0000

description:
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).

diffstat:

 lib/librefuse/Makefile             |   4 +-
 lib/librefuse/fuse.h               |  34 +++++++++++++++++++----------
 lib/librefuse/fuse_internal.h      |  42 ++++++++++++++++++++++++++++++++++++++
 lib/librefuse/refuse.c             |  12 +++++++---
 lib/librefuse/refuse_lowlevel.c    |   6 ++--
 lib/librefuse/refuse_opt.c         |   4 +-
 sbin/mount_qemufwcfg/Makefile      |   4 +--
 sbin/mount_qemufwcfg/fwcfg.c       |   6 +++-
 tests/lib/librefuse/t_refuse_opt.c |   6 ++--
 usr.sbin/perfused/perfused.h       |   3 +-
 10 files changed, 88 insertions(+), 33 deletions(-)

diffs (276 lines):

diff -r bf337b66a1fe -r c5869b431ff9 lib/librefuse/Makefile
--- a/lib/librefuse/Makefile    Sat Dec 04 00:01:24 2021 +0000
+++ b/lib/librefuse/Makefile    Sat Dec 04 06:42:39 2021 +0000
@@ -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 @@
 .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
diff -r bf337b66a1fe -r c5869b431ff9 lib/librefuse/fuse.h
--- a/lib/librefuse/fuse.h      Sat Dec 04 00:01:24 2021 +0000
+++ b/lib/librefuse/fuse.h      Sat Dec 04 06:42:39 2021 +0000
@@ -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 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
diff -r bf337b66a1fe -r c5869b431ff9 lib/librefuse/fuse_internal.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/librefuse/fuse_internal.h     Sat Dec 04 06:42:39 2021 +0000
@@ -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
diff -r bf337b66a1fe -r c5869b431ff9 lib/librefuse/refuse.c
--- a/lib/librefuse/refuse.c    Sat Dec 04 00:01:24 2021 +0000
+++ b/lib/librefuse/refuse.c    Sat Dec 04 06:42:39 2021 +0000
@@ -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>
diff -r bf337b66a1fe -r c5869b431ff9 lib/librefuse/refuse_lowlevel.c
--- a/lib/librefuse/refuse_lowlevel.c   Sat Dec 04 00:01:24 2021 +0000
+++ b/lib/librefuse/refuse_lowlevel.c   Sat Dec 04 06:42:39 2021 +0000
@@ -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>
diff -r bf337b66a1fe -r c5869b431ff9 lib/librefuse/refuse_opt.c
--- a/lib/librefuse/refuse_opt.c        Sat Dec 04 00:01:24 2021 +0000
+++ b/lib/librefuse/refuse_opt.c        Sat Dec 04 06:42:39 2021 +0000
@@ -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>
diff -r bf337b66a1fe -r c5869b431ff9 sbin/mount_qemufwcfg/Makefile
--- a/sbin/mount_qemufwcfg/Makefile     Sat Dec 04 00:01:24 2021 +0000
+++ b/sbin/mount_qemufwcfg/Makefile     Sat Dec 04 06:42:39 2021 +0000
@@ -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 @@
 LDADD= -lrefuse -lpuffs -lutil
 MAN=   mount_qemufwcfg.8
 
-CPPFLAGS+=     -D_KERNTYPES
-
 .include <bsd.prog.mk>
diff -r bf337b66a1fe -r c5869b431ff9 sbin/mount_qemufwcfg/fwcfg.c
--- a/sbin/mount_qemufwcfg/fwcfg.c      Sat Dec 04 00:01:24 2021 +0000
+++ b/sbin/mount_qemufwcfg/fwcfg.c      Sat Dec 04 06:42:39 2021 +0000
@@ -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 <jmcneill%invisible.ca@localhost>
@@ -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>
 
diff -r bf337b66a1fe -r c5869b431ff9 tests/lib/librefuse/t_refuse_opt.c
--- a/tests/lib/librefuse/t_refuse_opt.c        Sat Dec 04 00:01:24 2021 +0000
+++ b/tests/lib/librefuse/t_refuse_opt.c        Sat Dec 04 06:42:39 2021 +0000
@@ -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"
diff -r bf337b66a1fe -r c5869b431ff9 usr.sbin/perfused/perfused.h
--- a/usr.sbin/perfused/perfused.h      Sat Dec 04 00:01:24 2021 +0000
+++ b/usr.sbin/perfused/perfused.h      Sat Dec 04 06:42:39 2021 +0000
@@ -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
 



Home | Main Index | Thread Index | Old Index