1*ec9afb42Spho /* $NetBSD: v26.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: v26.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 <stdlib.h>
40*ec9afb42Spho #include <string.h>
41*ec9afb42Spho
42*ec9afb42Spho struct fuse_chan *
fuse_mount_v26(const char * mountpoint,struct fuse_args * args)43*ec9afb42Spho fuse_mount_v26(const char *mountpoint, struct fuse_args *args) {
44*ec9afb42Spho int nominal_fd;
45*ec9afb42Spho
46*ec9afb42Spho /* fuse_mount() in FUSE 2.6 returns a fuse_chan instead of fd. We
47*ec9afb42Spho * still need to store the channel in the global list, because
48*ec9afb42Spho * users may call fuse_destroy() before fuse_unmount().
49*ec9afb42Spho */
50*ec9afb42Spho nominal_fd = fuse_mount_v25(mountpoint, args);
51*ec9afb42Spho if (nominal_fd == -1)
52*ec9afb42Spho return NULL;
53*ec9afb42Spho
54*ec9afb42Spho return fuse_chan_peek(nominal_fd);
55*ec9afb42Spho }
56*ec9afb42Spho
57*ec9afb42Spho static bool
is_same_channel(struct fuse_chan * chan,void * priv)58*ec9afb42Spho is_same_channel(struct fuse_chan* chan, void* priv) {
59*ec9afb42Spho return chan == (struct fuse_chan*)priv;
60*ec9afb42Spho }
61*ec9afb42Spho
62*ec9afb42Spho void
fuse_unmount_v26(const char * mountpoint,struct fuse_chan * ch)63*ec9afb42Spho fuse_unmount_v26(const char *mountpoint, struct fuse_chan *ch) {
64*ec9afb42Spho /* Although the API documentation doesn't say so, fuse_unmount()
65*ec9afb42Spho * from FUSE >= 2.6 < 3.0 in fact allows "ch" to be NULL. */
66*ec9afb42Spho if (ch)
67*ec9afb42Spho if (strcmp(mountpoint, fuse_chan_mountpoint(ch)) != 0)
68*ec9afb42Spho warnx("%s: mountpoint `%s' differs from that was passed to fuse_mount(): %s",
69*ec9afb42Spho __func__, mountpoint, fuse_chan_mountpoint(ch));
70*ec9afb42Spho
71*ec9afb42Spho /* Ask fuse_unmount_v11() to find the channel object that is
72*ec9afb42Spho * already in our hand. We are going to need to know its index in
73*ec9afb42Spho * the global list anyway. */
74*ec9afb42Spho fuse_unmount_v11(mountpoint);
75*ec9afb42Spho }
76*ec9afb42Spho
77*ec9afb42Spho struct fuse *
fuse_new_v26(struct fuse_chan * ch,struct fuse_args * args,const void * op,int op_version,void * user_data)78*ec9afb42Spho fuse_new_v26(struct fuse_chan *ch, struct fuse_args *args,
79*ec9afb42Spho const void *op, int op_version,
80*ec9afb42Spho void *user_data) {
81*ec9afb42Spho int idx;
82*ec9afb42Spho
83*ec9afb42Spho /* Although the fuse_chan object is already in our hand, we need
84*ec9afb42Spho * to know its index in the global list because that's what
85*ec9afb42Spho * fuse_new_v25() wants. */
86*ec9afb42Spho if (fuse_chan_find(is_same_channel, &idx, ch) == NULL)
87*ec9afb42Spho errx(EXIT_FAILURE, "%s: cannot find the channel index", __func__);
88*ec9afb42Spho
89*ec9afb42Spho return fuse_new_v25(idx, args, op, op_version, user_data);
90*ec9afb42Spho }
91*ec9afb42Spho
92*ec9afb42Spho struct fuse *
fuse_setup_v26(int argc,char * argv[],const void * op,int op_version,char ** mountpoint,int * multithreaded,void * user_data)93*ec9afb42Spho fuse_setup_v26(int argc, char *argv[],
94*ec9afb42Spho const void *op, int op_version,
95*ec9afb42Spho char **mountpoint, int *multithreaded,
96*ec9afb42Spho void *user_data) {
97*ec9afb42Spho struct fuse* fuse;
98*ec9afb42Spho struct fuse_cmdline_opts opts;
99*ec9afb42Spho
100*ec9afb42Spho fuse = __fuse_setup(argc, argv, op, op_version, user_data, &opts);
101*ec9afb42Spho if (fuse == NULL)
102*ec9afb42Spho return NULL;
103*ec9afb42Spho
104*ec9afb42Spho *mountpoint = opts.mountpoint; /* Transfer the ownership of the string. */
105*ec9afb42Spho *multithreaded = !opts.singlethread;
106*ec9afb42Spho return fuse;
107*ec9afb42Spho }
108*ec9afb42Spho
109*ec9afb42Spho void
fuse_teardown_v26(struct fuse * fuse,char * mountpoint)110*ec9afb42Spho fuse_teardown_v26(struct fuse *fuse,
111*ec9afb42Spho char *mountpoint __attribute__((__unused__))) {
112*ec9afb42Spho __fuse_teardown(fuse);
113*ec9afb42Spho }
114