1 /* $NetBSD: refuse_compat.c,v 1.3 2022/01/23 21:07:28 rillig Exp $ */
2
3 /*
4 * Copyright (c) 2021 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote
16 * products derived from this software without specific prior written
17 * permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
20 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
25 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include <sys/cdefs.h>
33 #if !defined(lint)
34 __RCSID("$NetBSD: refuse_compat.c,v 1.3 2022/01/23 21:07:28 rillig Exp $");
35 #endif /* !lint */
36
37 #include <fuse_internal.h>
38 #include <string.h>
39
40 /*
41 * Compatibility symbols that had existed in old versions of
42 * librefuse.
43 */
44
45 struct fuse_cmdline_opts_rev0 {
46 int singlethread;
47 int foreground;
48 int debug;
49 int nodefault_fsname;
50 char *mountpoint;
51 int show_version;
52 int show_help;
53 };
54
55 int fuse_daemonize_rev0(struct fuse* fuse) __RENAME(fuse_daemonize);
56 int fuse_mount(struct fuse *fuse, const char *mountpoint);
57 int fuse_main_real(int argc, char **argv, const struct fuse_operations_v26 *op,
58 size_t size, void *user_data);
59 struct fuse *fuse_new(struct fuse_args *args, const void *op, size_t op_size,
60 void *user_data);
61 void fuse_destroy(struct fuse* fuse);
62 int fuse_parse_cmdline(struct fuse_args *args, struct fuse_cmdline_opts_rev0 *opts);
63 void fuse_unmount(struct fuse* fuse);
64 void fuse_unmount_compat22(const char *mountpoint);
65
66 /* librefuse once had a function fuse_daemonize() with an incompatible
67 * prototype with that of FUSE. We keep ABI compatibility with
68 * executables compiled against old librefuse by having this shim
69 * function as a symbol "fuse_daemonize". However, we can NOT keep API
70 * compatibility with old code expecting the wrong prototype. The only
71 * way to work around the problem is to put "#if FUSE_H_ < 20211204"
72 * into old user code. pho@ really regrets this mistake... */
73 __warn_references(
74 fuse_daemonize,
75 "warning: reference to compatibility fuse_daemonize();"
76 " include <fuse.h> for correct reference")
77 int
fuse_daemonize_rev0(struct fuse * fuse)78 fuse_daemonize_rev0(struct fuse* fuse __attribute__((__unused__))) {
79 return fuse_daemonize(1);
80 }
81
82 /* librefuse once had a function fuse_main_real() which was specific
83 * to FUSE 2.6 API. */
84 __warn_references(
85 fuse_main_real,
86 "warning: reference to compatibility fuse_main_real();"
87 " include <fuse.h> for correct reference")
88 int
fuse_main_real(int argc,char ** argv,const struct fuse_operations_v26 * op,size_t size,void * user_data)89 fuse_main_real(int argc, char **argv, const struct fuse_operations_v26 *op,
90 size_t size __attribute__((__unused__)), void *user_data) {
91 return __fuse_main(argc, argv, op, 26, user_data);
92 }
93
94 /* librefuse once had a function fuse_mount() for FUSE 3.0 but without
95 * a version postfix. */
96 __warn_references(
97 fuse_mount,
98 "warning: reference to compatibility fuse_mount();"
99 " include <fuse.h> for correct reference")
100 int
fuse_mount(struct fuse * fuse,const char * mountpoint)101 fuse_mount(struct fuse *fuse, const char *mountpoint) {
102 return fuse_mount_v30(fuse, mountpoint);
103 }
104
105 /* librefuse once had a function fuse_new() for FUSE 3.0 but without a
106 * version postfix. */
107 __warn_references(
108 fuse_new,
109 "warning: reference to compatibility fuse_new();"
110 " include <fuse.h> for correct reference")
111 struct fuse *
fuse_new(struct fuse_args * args,const void * op,size_t op_size,void * user_data)112 fuse_new(struct fuse_args *args, const void *op,
113 size_t op_size __attribute__((__unused__)),
114 void *user_data) {
115 return fuse_new_v30(args, op, 30, user_data);
116 }
117
118 /* librefuse once had a function fuse_destroy() for FUSE 3.0 but
119 * without a version postfix. */
120 __warn_references(
121 fuse_new,
122 "warning: reference to compatibility fuse_destroy();"
123 " include <fuse.h> for correct reference")
124 void
fuse_destroy(struct fuse * fuse)125 fuse_destroy(struct fuse *fuse) {
126 fuse_destroy_v30(fuse);
127 }
128
129 /* librefuse once had a function fuse_parse_cmdline() for FUSE 3.0 but
130 * without a version postfix. It expected an old definition of struct
131 * fuse_cmdline_opts too. */
132 __warn_references(
133 fuse_parse_cmdline,
134 "warning: reference to compatibility fuse_parse_cmdline();"
135 " include <fuse.h> for correct reference")
136 int
fuse_parse_cmdline(struct fuse_args * args,struct fuse_cmdline_opts_rev0 * opts)137 fuse_parse_cmdline(struct fuse_args *args, struct fuse_cmdline_opts_rev0 *opts) {
138 struct fuse_cmdline_opts tmp;
139
140 if (fuse_parse_cmdline_v30(args, &tmp) != 0)
141 return -1;
142
143 memcpy(opts, &tmp, sizeof(*opts));
144 return 0;
145 }
146
147 /* librefuse once had a function fuse_unmount() for FUSE 3.0 but
148 * without a version postfix. */
149 __warn_references(
150 fuse_unmount,
151 "warning: reference to compatibility fuse_unmount();"
152 " include <fuse.h> for correct reference")
153 void
fuse_unmount(struct fuse * fuse)154 fuse_unmount(struct fuse* fuse) {
155 fuse_unmount_v30(fuse);
156 }
157
158 /* librefuse once had a function fuse_unmount_compat22() which was an
159 * implementation of fuse_unmount() to be used when FUSE_USE_VERSION
160 * was set to 22 or below. The function was actually a no-op. */
161 void
fuse_unmount_compat22(const char * mountpoint)162 fuse_unmount_compat22(const char *mountpoint) {
163 fuse_unmount_v11(mountpoint);
164 }
165