Source-Changes-HG archive

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

[src/trunk]: src/lib/librefuse Change the way how FUSE_*_VERSION are handled



details:   https://anonhg.NetBSD.org/src/rev/d08bff569aae
branches:  trunk
changeset: 359765:d08bff569aae
user:      pho <pho%NetBSD.org@localhost>
date:      Sat Jan 22 08:01:12 2022 +0000

description:
Change the way how FUSE_*_VERSION are handled

* FUSE_MAKE_VERSION(maj, min) now generates a 3-digits number if the
  version is higher than 3.9. This is needed to support FUSE 3.10 API.

* FUSE_{MAJOR,MINOR}_VERSION no longer have a fixed value but are
  derived from FUSE_USE_VERSION specified by the user code. This is
  needed to support more FUSE filesystems in the wild.

diffstat:

 lib/librefuse/fuse.h          |  46 ++++++++++++++++++++++++++++++++++--------
 lib/librefuse/fuse_internal.h |   6 ++--
 lib/librefuse/refuse.c        |  11 ++-------
 3 files changed, 43 insertions(+), 20 deletions(-)

diffs (125 lines):

diff -r dbbea3fd7882 -r d08bff569aae lib/librefuse/fuse.h
--- a/lib/librefuse/fuse.h      Sat Jan 22 08:00:17 2022 +0000
+++ b/lib/librefuse/fuse.h      Sat Jan 22 08:01:12 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fuse.h,v 1.28 2022/01/22 07:57:30 pho Exp $ */
+/* $NetBSD: fuse.h,v 1.29 2022/01/22 08:01:12 pho Exp $ */
 
 /*
  * Copyright © 2007 Alistair Crooks.  All rights reserved.
@@ -40,24 +40,52 @@
 #include <sys/types.h>
 #include <utime.h>
 
-/* The latest version of FUSE API currently provided by refuse. */
-#define FUSE_MAJOR_VERSION     2
-#define FUSE_MINOR_VERSION     6
+/* This used to be (maj) * 10 + (min) until FUSE 3.10, and then
+ * changed to (maj) * 100 + (min). We can't just use the "newer"
+ * definition because filesystems in the wild still use the older one
+ * in their FUSE_USE_VERSION request. */
+#define FUSE_MAKE_VERSION(maj, min)                                    \
+       (((maj) > 3 || ((maj) == 3 && (min) >= 10))                     \
+       ? (maj) * 100 + (min)                                           \
+       : (maj) *  10 + (min))
 
-#define FUSE_MAKE_VERSION(maj, min)    ((maj) * 10 + (min))
-#define FUSE_VERSION   FUSE_MAKE_VERSION(FUSE_MAJOR_VERSION, FUSE_MINOR_VERSION)
+/* The latest version of FUSE API currently provided by ReFUSE. This
+ * is an implementation detail. User code should not rely on this
+ * constant. */
+#define _REFUSE_MAJOR_VERSION_ 2
+#define _REFUSE_MINOR_VERSION_ 6
+
+#define _REFUSE_VERSION_       FUSE_MAKE_VERSION(_REFUSE_MAJOR_VERSION_, _REFUSE_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
+#      if FUSE_USE_VERSION > _REFUSE_VERSION_
 #              warning "The requested API version is higher than the latest one supported by refuse."
+#      elif FUSE_USE_VERSION < 11
+#              warning "The requested API version is lower than the oldest 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
+#      if !defined(_REFUSE_IMPLEMENTATION_)
+#              warning "User code including <fuse.h> should define FUSE_USE_VERSION before including this header. Defaulting to the latest version."
+#              define FUSE_USE_VERSION _REFUSE_VERSION_
+#      endif
+#endif
+
+/* FUSE_VERSION is supposed to be the latest version of FUSE API
+ * supported by the library. However, due to the way how original FUSE
+ * is implemented, some filesystems set FUSE_USE_VERSION to some old
+ * one and then expect the actual API version exposed by the library
+ * to be something newer if FUSE_VERSION is higher than that. ReFUSE
+ * doesn't work that way, so this has to be always identical to
+ * FUSE_USE_VERSION.
+ */
+#if defined(FUSE_USE_VERSION)
+#      define FUSE_VERSION             FUSE_USE_VERSION
+#      define FUSE_MAJOR_VERSION       (FUSE_VERSION / 10)
+#      define FUSE_MINOR_VERSION       (FUSE_VERSION % 10)
 #endif
 
 #ifdef __cplusplus
diff -r dbbea3fd7882 -r d08bff569aae lib/librefuse/fuse_internal.h
--- a/lib/librefuse/fuse_internal.h     Sat Jan 22 08:00:17 2022 +0000
+++ b/lib/librefuse/fuse_internal.h     Sat Jan 22 08:01:12 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fuse_internal.h,v 1.2 2022/01/22 07:53:06 pho Exp $ */
+/* $NetBSD: fuse_internal.h,v 1.3 2022/01/22 08:01:12 pho Exp $ */
 
 /*
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -32,9 +32,9 @@
 #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
+ * defining FUSE_USE_VERSION. Exempt ourselves here, or we'll be
  * warned too. */
-#define FUSE_USE_VERSION       FUSE_VERSION
+#define _REFUSE_IMPLEMENTATION_
 
 #include <fuse.h>
 #include <fuse_lowlevel.h>
diff -r dbbea3fd7882 -r d08bff569aae lib/librefuse/refuse.c
--- a/lib/librefuse/refuse.c    Sat Jan 22 08:00:17 2022 +0000
+++ b/lib/librefuse/refuse.c    Sat Jan 22 08:01:12 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: refuse.c,v 1.108 2022/01/22 08:00:17 pho Exp $ */
+/*     $NetBSD: refuse.c,v 1.109 2022/01/22 08:01:12 pho Exp $ */
 
 /*
  * Copyright © 2007 Alistair Crooks.  All rights reserved.
@@ -31,14 +31,9 @@
 
 #include <sys/cdefs.h>
 #if !defined(lint)
-__RCSID("$NetBSD: refuse.c,v 1.108 2022/01/22 08:00:17 pho Exp $");
+__RCSID("$NetBSD: refuse.c,v 1.109 2022/01/22 08:01:12 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>
@@ -1417,7 +1412,7 @@
 int
 fuse_version(void)
 {
-       return FUSE_VERSION;
+       return _REFUSE_VERSION_;
 }
 
 /* This is a legacy function that has been removed from the FUSE API,



Home | Main Index | Thread Index | Old Index