1*ec9afb42Spho /* $NetBSD: v25.c,v 1.1 2022/01/22 08:09:40 pho Exp $ */
2*ec9afb42Spho
3*ec9afb42Spho /*
4*ec9afb42Spho * Copyright (c) 2021 The NetBSD Foundation, Inc.
5*ec9afb42Spho * All rights reserved.
6*ec9afb42Spho *
7*ec9afb42Spho * Redistribution and use in source and binary forms, with or without
8*ec9afb42Spho * modification, are permitted provided that the following conditions
9*ec9afb42Spho * are met:
10*ec9afb42Spho * 1. Redistributions of source code must retain the above copyright
11*ec9afb42Spho * notice, this list of conditions and the following disclaimer.
12*ec9afb42Spho * 2. Redistributions in binary form must reproduce the above copyright
13*ec9afb42Spho * notice, this list of conditions and the following disclaimer in the
14*ec9afb42Spho * documentation and/or other materials provided with the distribution.
15*ec9afb42Spho * 3. The name of the author may not be used to endorse or promote
16*ec9afb42Spho * products derived from this software without specific prior written
17*ec9afb42Spho * permission.
18*ec9afb42Spho *
19*ec9afb42Spho * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
20*ec9afb42Spho * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21*ec9afb42Spho * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22*ec9afb42Spho * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
23*ec9afb42Spho * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24*ec9afb42Spho * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
25*ec9afb42Spho * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26*ec9afb42Spho * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27*ec9afb42Spho * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28*ec9afb42Spho * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29*ec9afb42Spho * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30*ec9afb42Spho */
31*ec9afb42Spho
32*ec9afb42Spho #include <sys/cdefs.h>
33*ec9afb42Spho #if !defined(lint)
34*ec9afb42Spho __RCSID("$NetBSD: v25.c,v 1.1 2022/01/22 08:09:40 pho Exp $");
35*ec9afb42Spho #endif /* !lint */
36*ec9afb42Spho
37*ec9afb42Spho #include <err.h>
38*ec9afb42Spho #include <fuse_internal.h>
39*ec9afb42Spho #include <stdbool.h>
40*ec9afb42Spho #include <string.h>
41*ec9afb42Spho
42*ec9afb42Spho int
fuse_mount_v25(const char * mountpoint,struct fuse_args * args)43*ec9afb42Spho fuse_mount_v25(const char *mountpoint, struct fuse_args *args) {
44*ec9afb42Spho struct fuse_chan* chan;
45*ec9afb42Spho
46*ec9afb42Spho /* Of course we cannot accurately emulate the semantics, so we
47*ec9afb42Spho * save arguments and use them later in fuse_new(). */
48*ec9afb42Spho chan = fuse_chan_new(mountpoint, args);
49*ec9afb42Spho if (!chan)
50*ec9afb42Spho return -1;
51*ec9afb42Spho
52*ec9afb42Spho /* But, the return type of this function is just an int which is
53*ec9afb42Spho * supposed to be a file descriptor. It's too narrow to store a
54*ec9afb42Spho * pointer ofc, so... */
55*ec9afb42Spho return fuse_chan_stash(chan);
56*ec9afb42Spho }
57*ec9afb42Spho
58*ec9afb42Spho int
fuse_parse_cmdline_v25(struct fuse_args * args,char ** mountpoint,int * multithreaded,int * foreground)59*ec9afb42Spho fuse_parse_cmdline_v25(struct fuse_args *args, char **mountpoint,
60*ec9afb42Spho int *multithreaded, int *foreground) {
61*ec9afb42Spho struct fuse_cmdline_opts opts;
62*ec9afb42Spho
63*ec9afb42Spho if (fuse_parse_cmdline_v30(args, &opts) != 0)
64*ec9afb42Spho return -1;
65*ec9afb42Spho
66*ec9afb42Spho *mountpoint = opts.mountpoint; /* Transfer the ownership of the string. */
67*ec9afb42Spho *multithreaded = !opts.singlethread;
68*ec9afb42Spho *foreground = opts.foreground;
69*ec9afb42Spho return 0;
70*ec9afb42Spho }
71*ec9afb42Spho
72*ec9afb42Spho /* The interface of fuse_mount() and fuse_new() became even stranger
73*ec9afb42Spho * in FUSE 2.5. Now they both take "struct fuse_args" which are
74*ec9afb42Spho * expected to be identical between those two calls (which isn't
75*ec9afb42Spho * explained clearly in the documentation). Our implementation just
76*ec9afb42Spho * assume they are identical, because we can't recover from situations
77*ec9afb42Spho * where they differ, as there is no obvious way to merge them
78*ec9afb42Spho * together. */
79*ec9afb42Spho struct fuse *
fuse_new_v25(int fd,struct fuse_args * args,const void * op,int op_version,void * user_data)80*ec9afb42Spho fuse_new_v25(int fd, struct fuse_args *args, const void *op,
81*ec9afb42Spho int op_version, void *user_data) {
82*ec9afb42Spho struct fuse_chan* chan;
83*ec9afb42Spho struct fuse_args* mount_args;
84*ec9afb42Spho bool args_differ = false;
85*ec9afb42Spho
86*ec9afb42Spho /* But at least we can emit a warning when they differ... */
87*ec9afb42Spho chan = fuse_chan_peek(fd);
88*ec9afb42Spho if (!chan) {
89*ec9afb42Spho warnx("%s: invalid channel: %d", __func__, fd);
90*ec9afb42Spho return NULL;
91*ec9afb42Spho }
92*ec9afb42Spho
93*ec9afb42Spho mount_args = fuse_chan_args(chan);
94*ec9afb42Spho
95*ec9afb42Spho if (mount_args->argc != args->argc) {
96*ec9afb42Spho args_differ = true;
97*ec9afb42Spho }
98*ec9afb42Spho else {
99*ec9afb42Spho int i;
100*ec9afb42Spho
101*ec9afb42Spho for (i = 0; i < args->argc; i++) {
102*ec9afb42Spho if (strcmp(mount_args->argv[i], args->argv[i]) != 0) {
103*ec9afb42Spho args_differ = true;
104*ec9afb42Spho break;
105*ec9afb42Spho }
106*ec9afb42Spho }
107*ec9afb42Spho }
108*ec9afb42Spho
109*ec9afb42Spho if (args_differ) {
110*ec9afb42Spho warnx("%s: the argument vector differs from "
111*ec9afb42Spho "that were passed to fuse_mount()", __func__);
112*ec9afb42Spho }
113*ec9afb42Spho
114*ec9afb42Spho return fuse_new_v21(fd, NULL, op, op_version, user_data);
115*ec9afb42Spho }
116