xref: /netbsd-src/lib/librefuse/refuse_compat.c (revision 5d27a0722d9589b3c3fcf4a9b4943259b71c09ff)
1*5d27a072Srillig /* $NetBSD: refuse_compat.c,v 1.3 2022/01/23 21:07:28 rillig Exp $ */
29733de66Spho 
39733de66Spho /*
49733de66Spho  * Copyright (c) 2021 The NetBSD Foundation, Inc.
59733de66Spho  * All rights reserved.
69733de66Spho  *
79733de66Spho  * Redistribution and use in source and binary forms, with or without
89733de66Spho  * modification, are permitted provided that the following conditions
99733de66Spho  * are met:
109733de66Spho  * 1. Redistributions of source code must retain the above copyright
119733de66Spho  *    notice, this list of conditions and the following disclaimer.
129733de66Spho  * 2. Redistributions in binary form must reproduce the above copyright
139733de66Spho  *    notice, this list of conditions and the following disclaimer in the
149733de66Spho  *    documentation and/or other materials provided with the distribution.
159733de66Spho  * 3. The name of the author may not be used to endorse or promote
169733de66Spho  *    products derived from this software without specific prior written
179733de66Spho  *    permission.
189733de66Spho  *
199733de66Spho  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
209733de66Spho  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
219733de66Spho  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
229733de66Spho  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
239733de66Spho  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
249733de66Spho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
259733de66Spho  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
269733de66Spho  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
279733de66Spho  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
289733de66Spho  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
299733de66Spho  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
309733de66Spho  */
319733de66Spho 
329733de66Spho #include <sys/cdefs.h>
339733de66Spho #if !defined(lint)
34*5d27a072Srillig __RCSID("$NetBSD: refuse_compat.c,v 1.3 2022/01/23 21:07:28 rillig Exp $");
359733de66Spho #endif /* !lint */
369733de66Spho 
379733de66Spho #include <fuse_internal.h>
38ec9afb42Spho #include <string.h>
399733de66Spho 
409733de66Spho /*
419733de66Spho  * Compatibility symbols that had existed in old versions of
429733de66Spho  * librefuse.
439733de66Spho  */
449733de66Spho 
45ec9afb42Spho struct fuse_cmdline_opts_rev0 {
46ec9afb42Spho 	int singlethread;
47ec9afb42Spho 	int foreground;
48ec9afb42Spho 	int debug;
49ec9afb42Spho 	int nodefault_fsname;
50ec9afb42Spho 	char *mountpoint;
51ec9afb42Spho 	int show_version;
52ec9afb42Spho 	int show_help;
53ec9afb42Spho };
54ec9afb42Spho 
559733de66Spho int fuse_daemonize_rev0(struct fuse* fuse) __RENAME(fuse_daemonize);
56ec9afb42Spho int fuse_mount(struct fuse *fuse, const char *mountpoint);
57ec9afb42Spho int fuse_main_real(int argc, char **argv, const struct fuse_operations_v26 *op,
58ec9afb42Spho                    size_t size, void *user_data);
59ec9afb42Spho struct fuse *fuse_new(struct fuse_args *args, const void *op, size_t op_size,
60ec9afb42Spho                       void *user_data);
61ec9afb42Spho void fuse_destroy(struct fuse* fuse);
62ec9afb42Spho int fuse_parse_cmdline(struct fuse_args *args, struct fuse_cmdline_opts_rev0 *opts);
63ec9afb42Spho void fuse_unmount(struct fuse* fuse);
64ec9afb42Spho void fuse_unmount_compat22(const char *mountpoint);
659733de66Spho 
669733de66Spho /* librefuse once had a function fuse_daemonize() with an incompatible
679733de66Spho  * prototype with that of FUSE. We keep ABI compatibility with
689733de66Spho  * executables compiled against old librefuse by having this shim
699733de66Spho  * function as a symbol "fuse_daemonize". However, we can NOT keep API
709733de66Spho  * compatibility with old code expecting the wrong prototype. The only
719733de66Spho  * way to work around the problem is to put "#if FUSE_H_ < 20211204"
729733de66Spho  * into old user code. pho@ really regrets this mistake... */
739733de66Spho __warn_references(
749733de66Spho     fuse_daemonize,
759733de66Spho     "warning: reference to compatibility fuse_daemonize();"
769733de66Spho     " include <fuse.h> for correct reference")
779733de66Spho int
fuse_daemonize_rev0(struct fuse * fuse)789733de66Spho fuse_daemonize_rev0(struct fuse* fuse __attribute__((__unused__))) {
799733de66Spho     return fuse_daemonize(1);
809733de66Spho }
81ec9afb42Spho 
82ec9afb42Spho /* librefuse once had a function fuse_main_real() which was specific
83ec9afb42Spho  * to FUSE 2.6 API. */
84ec9afb42Spho __warn_references(
85ec9afb42Spho     fuse_main_real,
86ec9afb42Spho     "warning: reference to compatibility fuse_main_real();"
87ec9afb42Spho     " include <fuse.h> for correct reference")
88ec9afb42Spho int
fuse_main_real(int argc,char ** argv,const struct fuse_operations_v26 * op,size_t size,void * user_data)89ec9afb42Spho fuse_main_real(int argc, char **argv, const struct fuse_operations_v26 *op,
90ec9afb42Spho                size_t size __attribute__((__unused__)), void *user_data) {
91ec9afb42Spho     return __fuse_main(argc, argv, op, 26, user_data);
92ec9afb42Spho }
93ec9afb42Spho 
94ec9afb42Spho /* librefuse once had a function fuse_mount() for FUSE 3.0 but without
95ec9afb42Spho  * a version postfix. */
96ec9afb42Spho __warn_references(
97ec9afb42Spho     fuse_mount,
98ec9afb42Spho     "warning: reference to compatibility fuse_mount();"
99ec9afb42Spho     " include <fuse.h> for correct reference")
100ec9afb42Spho int
fuse_mount(struct fuse * fuse,const char * mountpoint)101ec9afb42Spho fuse_mount(struct fuse *fuse, const char *mountpoint) {
102ec9afb42Spho     return fuse_mount_v30(fuse, mountpoint);
103ec9afb42Spho }
104ec9afb42Spho 
105ec9afb42Spho /* librefuse once had a function fuse_new() for FUSE 3.0 but without a
106ec9afb42Spho  * version postfix. */
107ec9afb42Spho __warn_references(
108ec9afb42Spho     fuse_new,
109ec9afb42Spho     "warning: reference to compatibility fuse_new();"
110ec9afb42Spho     " include <fuse.h> for correct reference")
111ec9afb42Spho struct fuse *
fuse_new(struct fuse_args * args,const void * op,size_t op_size,void * user_data)112ec9afb42Spho fuse_new(struct fuse_args *args, const void *op,
113ec9afb42Spho          size_t op_size __attribute__((__unused__)),
114ec9afb42Spho          void *user_data) {
115ec9afb42Spho     return fuse_new_v30(args, op, 30, user_data);
116ec9afb42Spho }
117ec9afb42Spho 
118ec9afb42Spho /* librefuse once had a function fuse_destroy() for FUSE 3.0 but
119ec9afb42Spho  * without a version postfix. */
120ec9afb42Spho __warn_references(
121ec9afb42Spho     fuse_new,
122ec9afb42Spho     "warning: reference to compatibility fuse_destroy();"
123ec9afb42Spho     " include <fuse.h> for correct reference")
124ec9afb42Spho void
fuse_destroy(struct fuse * fuse)125ec9afb42Spho fuse_destroy(struct fuse *fuse) {
126ec9afb42Spho     fuse_destroy_v30(fuse);
127ec9afb42Spho }
128ec9afb42Spho 
129ec9afb42Spho /* librefuse once had a function fuse_parse_cmdline() for FUSE 3.0 but
130ec9afb42Spho  * without a version postfix. It expected an old definition of struct
131ec9afb42Spho  * fuse_cmdline_opts too. */
132ec9afb42Spho __warn_references(
133ec9afb42Spho     fuse_parse_cmdline,
134ec9afb42Spho     "warning: reference to compatibility fuse_parse_cmdline();"
135ec9afb42Spho     " include <fuse.h> for correct reference")
136ec9afb42Spho int
fuse_parse_cmdline(struct fuse_args * args,struct fuse_cmdline_opts_rev0 * opts)137ec9afb42Spho fuse_parse_cmdline(struct fuse_args *args, struct fuse_cmdline_opts_rev0 *opts) {
138ec9afb42Spho     struct fuse_cmdline_opts tmp;
139ec9afb42Spho 
140ec9afb42Spho     if (fuse_parse_cmdline_v30(args, &tmp) != 0)
141ec9afb42Spho         return -1;
142ec9afb42Spho 
143ec9afb42Spho     memcpy(opts, &tmp, sizeof(*opts));
144ec9afb42Spho     return 0;
145ec9afb42Spho }
146ec9afb42Spho 
147ec9afb42Spho /* librefuse once had a function fuse_unmount() for FUSE 3.0 but
148ec9afb42Spho  * without a version postfix. */
149ec9afb42Spho __warn_references(
150ec9afb42Spho     fuse_unmount,
151ec9afb42Spho     "warning: reference to compatibility fuse_unmount();"
152ec9afb42Spho     " include <fuse.h> for correct reference")
153ec9afb42Spho void
fuse_unmount(struct fuse * fuse)154ec9afb42Spho fuse_unmount(struct fuse* fuse) {
155*5d27a072Srillig     fuse_unmount_v30(fuse);
156ec9afb42Spho }
157ec9afb42Spho 
158ec9afb42Spho /* librefuse once had a function fuse_unmount_compat22() which was an
159ec9afb42Spho  * implementation of fuse_unmount() to be used when FUSE_USE_VERSION
160ec9afb42Spho  * was set to 22 or below. The function was actually a no-op. */
161ec9afb42Spho void
fuse_unmount_compat22(const char * mountpoint)162ec9afb42Spho fuse_unmount_compat22(const char *mountpoint) {
163ec9afb42Spho     fuse_unmount_v11(mountpoint);
164ec9afb42Spho }
165