From a045b4fd1a97882bfee6820f3707c21cc1a83ffc Mon Sep 17 00:00:00 2001 From: pho Date: Sat, 22 Jan 2022 08:01:12 +0000 Subject: [PATCH] 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. --- lib/librefuse/fuse.h | 46 ++++++++++++++++++++++++++++------- lib/librefuse/fuse_internal.h | 6 ++--- lib/librefuse/refuse.c | 11 +++------ 3 files changed, 43 insertions(+), 20 deletions(-) diff --git a/lib/librefuse/fuse.h b/lib/librefuse/fuse.h index 3b25d92a2a8a..bdf51f843398 100644 --- a/lib/librefuse/fuse.h +++ b/lib/librefuse/fuse.h @@ -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 #include -/* 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 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 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 --git a/lib/librefuse/fuse_internal.h b/lib/librefuse/fuse_internal.h index 533bb11b7899..dc8003d7b627 100644 --- a/lib/librefuse/fuse_internal.h +++ b/lib/librefuse/fuse_internal.h @@ -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 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 #include diff --git a/lib/librefuse/refuse.c b/lib/librefuse/refuse.c index e9504493968a..91dede7998da 100644 --- a/lib/librefuse/refuse.c +++ b/lib/librefuse/refuse.c @@ -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 #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 without - * defining FUSE_USE_VERSION. Define it here, or otherwise we'll be - * warned too. */ -#define FUSE_USE_VERSION FUSE_VERSION - #include #include @@ -1417,7 +1412,7 @@ fuse_invalidate_path(struct fuse *fuse __attribute__((__unused__)), int fuse_version(void) { - return FUSE_VERSION; + return _REFUSE_VERSION_; } /* This is a legacy function that has been removed from the FUSE API,