diff options
author | Bernd Schubert <bernd.schubert@fastmail.fm> | 2024-05-13 12:32:06 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-13 12:32:06 +0200 |
commit | 58f85bfa9b7dca9a216cd0bb4e38e9cdf4b661da (patch) | |
tree | 6b731982629b96315c70bca87280141e3240fcd7 /include | |
parent | 2bdec0bc22ce39b307e299ee9ec19d1c58b640de (diff) | |
download | libfuse-58f85bfa9b7dca9a216cd0bb4e38e9cdf4b661da.tar.gz |
Add in the libfuse version a program was compiled with (#942)
The API stays the same, the libfuse version comes from
inlined functions, which are defined fuse_lowlevel.h
and fuse.h. As these inlined functions are defined in the header
files they get added into the application, similar as if these
were preprocessor macros.
Macro vs inlined function is then just a style issue - I personally
prefer the latter.
fuse_session_new() -> static inlinei, in the application
_fuse_session_new -> inside of libfuse
fuse_new() -> static inline, in the application
_fuse_new() -> inside of libfuse
Note: Entirely untested is the fuse 30 api - we need a test
for it. And we do not have any ABI tests at all.
Signed-off-by: Bernd Schubert <bernd.schubert@fastmail.fm>
Diffstat (limited to 'include')
-rw-r--r-- | include/fuse.h | 108 | ||||
-rw-r--r-- | include/fuse_common.h | 12 | ||||
-rw-r--r-- | include/fuse_lowlevel.h | 50 |
3 files changed, 143 insertions, 27 deletions
diff --git a/include/fuse.h b/include/fuse.h index 90ee4bb..a3549cb 100644 --- a/include/fuse.h +++ b/include/fuse.h @@ -854,6 +854,22 @@ struct fuse_context { mode_t umask; }; +#if (defined(LIBFUSE_BUILT_WITH_VERSIONED_SYMBOLS)) +/** + * The real main function + * + * Do not call this directly, use fuse_main() + */ +int fuse_main_real(int argc, char *argv[], const struct fuse_operations *op, + size_t op_size, struct libfuse_version *version, + void *user_data); +#else +int fuse_main_real_317(int argc, char *argv[], const struct fuse_operations *op, + size_t op_size, struct libfuse_version *version, void *user_data); +#define fuse_main_real(argc, argv, op, op_size, version, user_data) \ + fuse_main_real_317(argc, argv, op, op_size, version, user_data); +#endif + /** * Main function of FUSE. * @@ -908,12 +924,19 @@ struct fuse_context { * * Example usage, see hello.c */ -/* - int fuse_main(int argc, char *argv[], const struct fuse_operations *op, - void *private_data); -*/ -#define fuse_main(argc, argv, op, private_data) \ - fuse_main_real(argc, argv, op, sizeof(*(op)), private_data) +static inline int +fuse_main(int argc, char *argv[], const struct fuse_operations *op, + void *user_data) +{ + struct libfuse_version version = { + .major = FUSE_MAJOR_VERSION, + .minor = FUSE_MINOR_VERSION, + .hotfix = FUSE_HOTFIX_VERSION, + .padding = 0 + }; + return fuse_main_real(argc, argv, op, sizeof(*(op)), &version, + user_data); +} /* ----------------------------------------------------------- * * More detailed API * @@ -932,6 +955,11 @@ struct fuse_context { */ void fuse_lib_help(struct fuse_args *args); +struct fuse *_fuse_new(struct fuse_args *args, + const struct fuse_operations *op, + size_t op_size, struct libfuse_version *version, + void *user_data); + /** * Create a new FUSE filesystem. * @@ -960,18 +988,60 @@ void fuse_lib_help(struct fuse_args *args); * @return the created FUSE handle */ #if FUSE_USE_VERSION == 30 -struct fuse *fuse_new_30(struct fuse_args *args, const struct fuse_operations *op, - size_t op_size, void *private_data); -#define fuse_new(args, op, size, data) fuse_new_30(args, op, size, data) +struct fuse *_fuse_new_30(struct fuse_args *args, + const struct fuse_operations *op, + size_t op_size, void *user_data); +static inline struct fuse * +fuse_new(struct fuse_args *args, + const struct fuse_operations *op, size_t op_size, + void *user_data) +{ + struct libfuse_version version = { + .major = FUSE_MAJOR_VERSION, + .minor = FUSE_MINOR_VERSION, + .hotfix = FUSE_HOTFIX_VERSION, + .padding = 0 + }; + + return _fuse_new_30(args, op, op_size, &version, user_data); +} #else #if (defined(LIBFUSE_BUILT_WITH_VERSIONED_SYMBOLS)) -struct fuse *fuse_new(struct fuse_args *args, const struct fuse_operations *op, - size_t op_size, void *private_data); +static inline struct fuse * +fuse_new(struct fuse_args *args, + const struct fuse_operations *op, size_t op_size, + void *user_data) +{ + struct libfuse_version version = { + .major = FUSE_MAJOR_VERSION, + .minor = FUSE_MINOR_VERSION, + .hotfix = FUSE_HOTFIX_VERSION, + .padding = 0 + }; + + return _fuse_new(args, op, op_size, &version, user_data); +} #else /* LIBFUSE_BUILT_WITH_VERSIONED_SYMBOLS */ -struct fuse *fuse_new_31(struct fuse_args *args, - const struct fuse_operations *op, - size_t op_size, void *private_data); -#define fuse_new(args, op, size, data) fuse_new_31(args, op, size, data) +struct fuse *_fuse_new_317(struct fuse_args *args, + const struct fuse_operations *op, size_t op_size, + struct libfuse_version *version, + void *private_data); +#define _fuse_new(args, op, size, version, data) \ + _fuse_new_317(args, op, size, version, data) +static inline struct fuse * +fuse_new(struct fuse_args *args, + const struct fuse_operations *op, size_t op_size, + void *user_data) +{ + struct libfuse_version version = { + .major = FUSE_MAJOR_VERSION, + .minor = FUSE_MINOR_VERSION, + .hotfix = FUSE_HOTFIX_VERSION, + .padding = 0 + }; + + return _fuse_new(args, op, op_size, &version, user_data); +} #endif /* LIBFUSE_BUILT_WITH_VERSIONED_SYMBOLS */ #endif @@ -1128,14 +1198,6 @@ int fuse_interrupted(void); int fuse_invalidate_path(struct fuse *f, const char *path); /** - * The real main function - * - * Do not call this directly, use fuse_main() - */ -int fuse_main_real(int argc, char *argv[], const struct fuse_operations *op, - size_t op_size, void *private_data); - -/** * Start the cleanup thread when using option "remember". * * This is done automatically by fuse_loop_mt() diff --git a/include/fuse_common.h b/include/fuse_common.h index 8803b68..a614fb0 100644 --- a/include/fuse_common.h +++ b/include/fuse_common.h @@ -836,6 +836,18 @@ struct fuse_bufvec { struct fuse_buf buf[1]; }; +/** + * libfuse version a file system was compiled with. Should be filled in from + * defines in 'libfuse_config.h' + */ +struct libfuse_version +{ + int major; + int minor; + int hotfix; + int padding; +}; + /* Initialize bufvec with a single buffer of given size */ #define FUSE_BUFVEC_INIT(size__) \ ((struct fuse_bufvec) { \ diff --git a/include/fuse_lowlevel.h b/include/fuse_lowlevel.h index 8ff111a..2ada62b 100644 --- a/include/fuse_lowlevel.h +++ b/include/fuse_lowlevel.h @@ -2005,6 +2005,36 @@ int fuse_parse_cmdline_312(struct fuse_args *args, #endif #endif +/* + * This should mostly not be called directly, but instead the fuse_session_new() + * macro should be used, which fills in the libfuse version compilation + * is done against automatically. + */ +struct fuse_session *_fuse_session_new_317(struct fuse_args *args, + const struct fuse_lowlevel_ops *op, + size_t op_size, + struct libfuse_version *version, + void *userdata); + +/* Do not call this directly, but only through fuse_session_new() */ +#if (defined(LIBFUSE_BUILT_WITH_VERSIONED_SYMBOLS)) +struct fuse_session * +_fuse_session_new(struct fuse_args *args, + const struct fuse_lowlevel_ops *op, + size_t op_size, + struct libfuse_version *version, + void *userdata); +#else +struct fuse_session * +_fuse_session_new_317(struct fuse_args *args, + const struct fuse_lowlevel_ops *op, + size_t op_size, + struct libfuse_version *version, + void *userdata); +#define _fuse_session_new(args, op, op_size, version, userdata) \ + _fuse_session_new_317(args, op, op_size, version, userdata) +#endif + /** * Create a low level session. * @@ -2029,13 +2059,25 @@ int fuse_parse_cmdline_312(struct fuse_args *args, * @param args argument vector * @param op the (low-level) filesystem operations * @param op_size sizeof(struct fuse_lowlevel_ops) + * @param version the libfuse version a file system server was compiled against * @param userdata user data - * * @return the fuse session on success, NULL on failure **/ -struct fuse_session *fuse_session_new(struct fuse_args *args, - const struct fuse_lowlevel_ops *op, - size_t op_size, void *userdata); +static inline struct fuse_session * +fuse_session_new(struct fuse_args *args, + const struct fuse_lowlevel_ops *op, + size_t op_size, + void *userdata) +{ + struct libfuse_version version = { + .major = FUSE_MAJOR_VERSION, + .minor = FUSE_MINOR_VERSION, + .hotfix = FUSE_HOTFIX_VERSION, + .padding = 0 + }; + + return _fuse_session_new(args, op, op_size, &version, userdata); +} /** * Set a file descriptor for the session. |