1*9f391507Spho /* $NetBSD: session.c,v 1.1 2022/01/22 07:53:06 pho Exp $ */
2*9f391507Spho
3*9f391507Spho /*
4*9f391507Spho * Copyright (c) 2021 The NetBSD Foundation, Inc.
5*9f391507Spho * All rights reserved.
6*9f391507Spho *
7*9f391507Spho * Redistribution and use in source and binary forms, with or without
8*9f391507Spho * modification, are permitted provided that the following conditions
9*9f391507Spho * are met:
10*9f391507Spho * 1. Redistributions of source code must retain the above copyright
11*9f391507Spho * notice, this list of conditions and the following disclaimer.
12*9f391507Spho * 2. Redistributions in binary form must reproduce the above copyright
13*9f391507Spho * notice, this list of conditions and the following disclaimer in the
14*9f391507Spho * documentation and/or other materials provided with the distribution.
15*9f391507Spho * 3. The name of the author may not be used to endorse or promote
16*9f391507Spho * products derived from this software without specific prior written
17*9f391507Spho * permission.
18*9f391507Spho *
19*9f391507Spho * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
20*9f391507Spho * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21*9f391507Spho * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22*9f391507Spho * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
23*9f391507Spho * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24*9f391507Spho * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
25*9f391507Spho * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26*9f391507Spho * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27*9f391507Spho * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28*9f391507Spho * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29*9f391507Spho * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30*9f391507Spho */
31*9f391507Spho
32*9f391507Spho #include <sys/cdefs.h>
33*9f391507Spho #if !defined(lint)
34*9f391507Spho __RCSID("$NetBSD: session.c,v 1.1 2022/01/22 07:53:06 pho Exp $");
35*9f391507Spho #endif /* !lint */
36*9f391507Spho
37*9f391507Spho #include <err.h>
38*9f391507Spho #include <fuse_internal.h>
39*9f391507Spho #include <puffs.h>
40*9f391507Spho
41*9f391507Spho /* The documentation for FUSE is not clear as to what "struct fuse_session" is,
42*9f391507Spho * why it exists, or how it's different from "struct fuse". For now we leave it
43*9f391507Spho * undefined (i.e. an incomplete type) and treat "struct fuse_session *" as
44*9f391507Spho * being identical to "struct fuse *". */
45*9f391507Spho
46*9f391507Spho struct fuse_session *
fuse_get_session(struct fuse * f)47*9f391507Spho fuse_get_session(struct fuse *f) {
48*9f391507Spho return (struct fuse_session*)f;
49*9f391507Spho }
50*9f391507Spho
51*9f391507Spho int
fuse_session_fd(struct fuse_session * se)52*9f391507Spho fuse_session_fd(struct fuse_session *se) {
53*9f391507Spho struct fuse* fuse = (struct fuse*)se;
54*9f391507Spho
55*9f391507Spho /* We don't want to expose this to users, but filesystems in the wild often
56*9f391507Spho * wants to set FD_CLOEXEC on it. Hope they don't assume it's the real
57*9f391507Spho * /dev/fuse, because it's actually /dev/puffs in our implementation. */
58*9f391507Spho return puffs_getselectable(fuse->pu);
59*9f391507Spho }
60*9f391507Spho
61*9f391507Spho int
fuse_set_signal_handlers(struct fuse_session * se)62*9f391507Spho fuse_set_signal_handlers(struct fuse_session *se) {
63*9f391507Spho return __fuse_set_signal_handlers((struct fuse*)se);
64*9f391507Spho }
65*9f391507Spho
66*9f391507Spho void
fuse_remove_signal_handlers(struct fuse_session * se)67*9f391507Spho fuse_remove_signal_handlers(struct fuse_session *se) {
68*9f391507Spho if (__fuse_remove_signal_handlers((struct fuse*)se) == -1)
69*9f391507Spho warn("%s: failed to remove signal handlers", __func__);
70*9f391507Spho }
71