151369649SPedro F. Giffuni /*- 251369649SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause 351369649SPedro F. Giffuni * 45fe58019SAttilio Rao * Copyright (c) 2007-2009 Google Inc. and Amit Singh 55fe58019SAttilio Rao * All rights reserved. 65fe58019SAttilio Rao * 75fe58019SAttilio Rao * Redistribution and use in source and binary forms, with or without 85fe58019SAttilio Rao * modification, are permitted provided that the following conditions are 95fe58019SAttilio Rao * met: 105fe58019SAttilio Rao * 115fe58019SAttilio Rao * * Redistributions of source code must retain the above copyright 125fe58019SAttilio Rao * notice, this list of conditions and the following disclaimer. 135fe58019SAttilio Rao * * Redistributions in binary form must reproduce the above 145fe58019SAttilio Rao * copyright notice, this list of conditions and the following disclaimer 155fe58019SAttilio Rao * in the documentation and/or other materials provided with the 165fe58019SAttilio Rao * distribution. 175fe58019SAttilio Rao * * Neither the name of Google Inc. nor the names of its 185fe58019SAttilio Rao * contributors may be used to endorse or promote products derived from 195fe58019SAttilio Rao * this software without specific prior written permission. 205fe58019SAttilio Rao * 215fe58019SAttilio Rao * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 225fe58019SAttilio Rao * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 235fe58019SAttilio Rao * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 245fe58019SAttilio Rao * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 255fe58019SAttilio Rao * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 265fe58019SAttilio Rao * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 275fe58019SAttilio Rao * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 285fe58019SAttilio Rao * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 295fe58019SAttilio Rao * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 305fe58019SAttilio Rao * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 315fe58019SAttilio Rao * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 325fe58019SAttilio Rao * 335fe58019SAttilio Rao * Copyright (C) 2005 Csaba Henk. 345fe58019SAttilio Rao * All rights reserved. 355fe58019SAttilio Rao * 365fe58019SAttilio Rao * Redistribution and use in source and binary forms, with or without 375fe58019SAttilio Rao * modification, are permitted provided that the following conditions 385fe58019SAttilio Rao * are met: 395fe58019SAttilio Rao * 1. Redistributions of source code must retain the above copyright 405fe58019SAttilio Rao * notice, this list of conditions and the following disclaimer. 415fe58019SAttilio Rao * 2. Redistributions in binary form must reproduce the above copyright 425fe58019SAttilio Rao * notice, this list of conditions and the following disclaimer in the 435fe58019SAttilio Rao * documentation and/or other materials provided with the distribution. 445fe58019SAttilio Rao * 455fe58019SAttilio Rao * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND 465fe58019SAttilio Rao * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 475fe58019SAttilio Rao * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 485fe58019SAttilio Rao * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 495fe58019SAttilio Rao * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 505fe58019SAttilio Rao * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 515fe58019SAttilio Rao * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 525fe58019SAttilio Rao * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 535fe58019SAttilio Rao * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 545fe58019SAttilio Rao * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 555fe58019SAttilio Rao * SUCH DAMAGE. 565fe58019SAttilio Rao * 575fe58019SAttilio Rao * $FreeBSD$ 585fe58019SAttilio Rao */ 595fe58019SAttilio Rao 605fe58019SAttilio Rao #ifndef _FUSE_IPC_H_ 615fe58019SAttilio Rao #define _FUSE_IPC_H_ 625fe58019SAttilio Rao 635fe58019SAttilio Rao #include <sys/param.h> 645fe58019SAttilio Rao #include <sys/refcount.h> 655fe58019SAttilio Rao 665fe58019SAttilio Rao struct fuse_iov { 675fe58019SAttilio Rao void *base; 685fe58019SAttilio Rao size_t len; 695fe58019SAttilio Rao size_t allocated_size; 705fe58019SAttilio Rao int credit; 715fe58019SAttilio Rao }; 725fe58019SAttilio Rao 735fe58019SAttilio Rao void fiov_init(struct fuse_iov *fiov, size_t size); 745fe58019SAttilio Rao void fiov_teardown(struct fuse_iov *fiov); 755fe58019SAttilio Rao void fiov_refresh(struct fuse_iov *fiov); 765fe58019SAttilio Rao void fiov_adjust(struct fuse_iov *fiov, size_t size); 775fe58019SAttilio Rao 78*02295cafSConrad Meyer #define FUSE_DIMALLOC(fiov, spc1, spc2, amnt) do { \ 795fe58019SAttilio Rao fiov_adjust(fiov, (sizeof(*(spc1)) + (amnt))); \ 805fe58019SAttilio Rao (spc1) = (fiov)->base; \ 815fe58019SAttilio Rao (spc2) = (char *)(fiov)->base + (sizeof(*(spc1))); \ 825fe58019SAttilio Rao } while (0) 835fe58019SAttilio Rao 845fe58019SAttilio Rao #define FU_AT_LEAST(siz) max((siz), 160) 855fe58019SAttilio Rao 865fe58019SAttilio Rao #define FUSE_ASSERT_AW_DONE(ftick) \ 875fe58019SAttilio Rao KASSERT((ftick)->tk_aw_link.tqe_next == NULL && \ 885fe58019SAttilio Rao (ftick)->tk_aw_link.tqe_prev == NULL, \ 89*02295cafSConrad Meyer ("FUSE: ticket still on answer delivery list %p", (ftick))) 905fe58019SAttilio Rao 915fe58019SAttilio Rao #define FUSE_ASSERT_MS_DONE(ftick) \ 925fe58019SAttilio Rao KASSERT((ftick)->tk_ms_link.stqe_next == NULL, \ 935fe58019SAttilio Rao ("FUSE: ticket still on message list %p", (ftick))) 945fe58019SAttilio Rao 955fe58019SAttilio Rao struct fuse_ticket; 965fe58019SAttilio Rao struct fuse_data; 975fe58019SAttilio Rao 985fe58019SAttilio Rao typedef int fuse_handler_t(struct fuse_ticket *ftick, struct uio *uio); 995fe58019SAttilio Rao 1005fe58019SAttilio Rao struct fuse_ticket { 1015fe58019SAttilio Rao /* fields giving the identity of the ticket */ 1025fe58019SAttilio Rao uint64_t tk_unique; 1035fe58019SAttilio Rao struct fuse_data *tk_data; 1045fe58019SAttilio Rao int tk_flag; 1055fe58019SAttilio Rao u_int tk_refcount; 1065fe58019SAttilio Rao 1075fe58019SAttilio Rao /* fields for initiating an upgoing message */ 1085fe58019SAttilio Rao struct fuse_iov tk_ms_fiov; 1095fe58019SAttilio Rao void *tk_ms_bufdata; 1105fe58019SAttilio Rao size_t tk_ms_bufsize; 1115fe58019SAttilio Rao enum { FT_M_FIOV, FT_M_BUF } tk_ms_type; 1125fe58019SAttilio Rao STAILQ_ENTRY(fuse_ticket) tk_ms_link; 1135fe58019SAttilio Rao 1145fe58019SAttilio Rao /* fields for handling answers coming from userspace */ 1155fe58019SAttilio Rao struct fuse_iov tk_aw_fiov; 1165fe58019SAttilio Rao void *tk_aw_bufdata; 1175fe58019SAttilio Rao size_t tk_aw_bufsize; 1185fe58019SAttilio Rao enum { FT_A_FIOV, FT_A_BUF } tk_aw_type; 1195fe58019SAttilio Rao 1205fe58019SAttilio Rao struct fuse_out_header tk_aw_ohead; 1215fe58019SAttilio Rao int tk_aw_errno; 1225fe58019SAttilio Rao struct mtx tk_aw_mtx; 1235fe58019SAttilio Rao fuse_handler_t *tk_aw_handler; 1245fe58019SAttilio Rao TAILQ_ENTRY(fuse_ticket) tk_aw_link; 1255fe58019SAttilio Rao }; 1265fe58019SAttilio Rao 1275fe58019SAttilio Rao #define FT_ANSW 0x01 /* request of ticket has already been answered */ 1285fe58019SAttilio Rao #define FT_DIRTY 0x04 /* ticket has been used */ 1295fe58019SAttilio Rao 130*02295cafSConrad Meyer static inline struct fuse_iov * 1315fe58019SAttilio Rao fticket_resp(struct fuse_ticket *ftick) 1325fe58019SAttilio Rao { 1335fe58019SAttilio Rao return (&ftick->tk_aw_fiov); 1345fe58019SAttilio Rao } 1355fe58019SAttilio Rao 136*02295cafSConrad Meyer static inline bool 1375fe58019SAttilio Rao fticket_answered(struct fuse_ticket *ftick) 1385fe58019SAttilio Rao { 1395fe58019SAttilio Rao DEBUGX(FUSE_DEBUG_IPC, "-> ftick=%p\n", ftick); 1405fe58019SAttilio Rao mtx_assert(&ftick->tk_aw_mtx, MA_OWNED); 1415fe58019SAttilio Rao return (ftick->tk_flag & FT_ANSW); 1425fe58019SAttilio Rao } 1435fe58019SAttilio Rao 144*02295cafSConrad Meyer static inline void 1455fe58019SAttilio Rao fticket_set_answered(struct fuse_ticket *ftick) 1465fe58019SAttilio Rao { 1475fe58019SAttilio Rao DEBUGX(FUSE_DEBUG_IPC, "-> ftick=%p\n", ftick); 1485fe58019SAttilio Rao mtx_assert(&ftick->tk_aw_mtx, MA_OWNED); 1495fe58019SAttilio Rao ftick->tk_flag |= FT_ANSW; 1505fe58019SAttilio Rao } 1515fe58019SAttilio Rao 152*02295cafSConrad Meyer static inline enum fuse_opcode 1535fe58019SAttilio Rao fticket_opcode(struct fuse_ticket *ftick) 1545fe58019SAttilio Rao { 1555fe58019SAttilio Rao DEBUGX(FUSE_DEBUG_IPC, "-> ftick=%p\n", ftick); 1565fe58019SAttilio Rao return (((struct fuse_in_header *)(ftick->tk_ms_fiov.base))->opcode); 1575fe58019SAttilio Rao } 1585fe58019SAttilio Rao 1595fe58019SAttilio Rao int fticket_pull(struct fuse_ticket *ftick, struct uio *uio); 1605fe58019SAttilio Rao 1615fe58019SAttilio Rao enum mountpri { FM_NOMOUNTED, FM_PRIMARY, FM_SECONDARY }; 1625fe58019SAttilio Rao 1635fe58019SAttilio Rao /* 1645fe58019SAttilio Rao * The data representing a FUSE session. 1655fe58019SAttilio Rao */ 1665fe58019SAttilio Rao struct fuse_data { 1675fe58019SAttilio Rao struct cdev *fdev; 1685fe58019SAttilio Rao struct mount *mp; 1695fe58019SAttilio Rao struct vnode *vroot; 1705fe58019SAttilio Rao struct ucred *daemoncred; 1715fe58019SAttilio Rao int dataflags; 1725fe58019SAttilio Rao int ref; 1735fe58019SAttilio Rao 1745fe58019SAttilio Rao struct mtx ms_mtx; 1755fe58019SAttilio Rao STAILQ_HEAD(, fuse_ticket) ms_head; 1765fe58019SAttilio Rao 1775fe58019SAttilio Rao struct mtx aw_mtx; 1785fe58019SAttilio Rao TAILQ_HEAD(, fuse_ticket) aw_head; 1795fe58019SAttilio Rao 1805fe58019SAttilio Rao u_long ticketer; 1815fe58019SAttilio Rao 1825fe58019SAttilio Rao struct sx rename_lock; 1835fe58019SAttilio Rao 1845fe58019SAttilio Rao uint32_t fuse_libabi_major; 1855fe58019SAttilio Rao uint32_t fuse_libabi_minor; 1865fe58019SAttilio Rao 1875fe58019SAttilio Rao uint32_t max_write; 1885fe58019SAttilio Rao uint32_t max_read; 1895fe58019SAttilio Rao uint32_t subtype; 1905fe58019SAttilio Rao char volname[MAXPATHLEN]; 1915fe58019SAttilio Rao 1925fe58019SAttilio Rao struct selinfo ks_rsel; 1935fe58019SAttilio Rao 1945fe58019SAttilio Rao int daemon_timeout; 1955fe58019SAttilio Rao uint64_t notimpl; 1965fe58019SAttilio Rao }; 1975fe58019SAttilio Rao 1985fe58019SAttilio Rao #define FSESS_DEAD 0x0001 /* session is to be closed */ 1995fe58019SAttilio Rao #define FSESS_UNUSED0 0x0002 /* unused */ 2005fe58019SAttilio Rao #define FSESS_INITED 0x0004 /* session has been inited */ 2015fe58019SAttilio Rao #define FSESS_DAEMON_CAN_SPY 0x0010 /* let non-owners access this fs */ 2025fe58019SAttilio Rao /* (and being observed by the daemon) */ 2035fe58019SAttilio Rao #define FSESS_PUSH_SYMLINKS_IN 0x0020 /* prefix absolute symlinks with mp */ 2045fe58019SAttilio Rao #define FSESS_DEFAULT_PERMISSIONS 0x0040 /* kernel does permission checking */ 2055fe58019SAttilio Rao #define FSESS_NO_ATTRCACHE 0x0080 /* no attribute caching */ 2065fe58019SAttilio Rao #define FSESS_NO_READAHEAD 0x0100 /* no readaheads */ 2075fe58019SAttilio Rao #define FSESS_NO_DATACACHE 0x0200 /* disable buffer cache */ 2085fe58019SAttilio Rao #define FSESS_NO_NAMECACHE 0x0400 /* disable name cache */ 2095fe58019SAttilio Rao #define FSESS_NO_MMAP 0x0800 /* disable mmap */ 2105fe58019SAttilio Rao #define FSESS_BROKENIO 0x1000 /* fix broken io */ 2115fe58019SAttilio Rao 212c4af8b17SConrad Meyer enum fuse_data_cache_mode { 213c4af8b17SConrad Meyer FUSE_CACHE_UC, 214c4af8b17SConrad Meyer FUSE_CACHE_WT, 215c4af8b17SConrad Meyer FUSE_CACHE_WB, 216c4af8b17SConrad Meyer }; 217c4af8b17SConrad Meyer 218c4af8b17SConrad Meyer extern int fuse_data_cache_mode; 2195fe58019SAttilio Rao extern int fuse_data_cache_invalidate; 2205fe58019SAttilio Rao extern int fuse_mmap_enable; 2215fe58019SAttilio Rao extern int fuse_sync_resize; 2225fe58019SAttilio Rao extern int fuse_fix_broken_io; 2235fe58019SAttilio Rao 224*02295cafSConrad Meyer static inline struct fuse_data * 2255fe58019SAttilio Rao fuse_get_mpdata(struct mount *mp) 2265fe58019SAttilio Rao { 2275fe58019SAttilio Rao return mp->mnt_data; 2285fe58019SAttilio Rao } 2295fe58019SAttilio Rao 230*02295cafSConrad Meyer static inline bool 2315fe58019SAttilio Rao fsess_isimpl(struct mount *mp, int opcode) 2325fe58019SAttilio Rao { 2335fe58019SAttilio Rao struct fuse_data *data = fuse_get_mpdata(mp); 2345fe58019SAttilio Rao 235*02295cafSConrad Meyer return ((data->notimpl & (1ULL << opcode)) == 0); 2365fe58019SAttilio Rao 2375fe58019SAttilio Rao } 238*02295cafSConrad Meyer static inline void 2395fe58019SAttilio Rao fsess_set_notimpl(struct mount *mp, int opcode) 2405fe58019SAttilio Rao { 2415fe58019SAttilio Rao struct fuse_data *data = fuse_get_mpdata(mp); 2425fe58019SAttilio Rao 2435fe58019SAttilio Rao data->notimpl |= (1ULL << opcode); 2445fe58019SAttilio Rao } 2455fe58019SAttilio Rao 246*02295cafSConrad Meyer static inline bool 2475fe58019SAttilio Rao fsess_opt_datacache(struct mount *mp) 2485fe58019SAttilio Rao { 2495fe58019SAttilio Rao struct fuse_data *data = fuse_get_mpdata(mp); 2505fe58019SAttilio Rao 251c4af8b17SConrad Meyer return (fuse_data_cache_mode != FUSE_CACHE_UC && 2525fe58019SAttilio Rao (data->dataflags & FSESS_NO_DATACACHE) == 0); 2535fe58019SAttilio Rao } 2545fe58019SAttilio Rao 255*02295cafSConrad Meyer static inline bool 2565fe58019SAttilio Rao fsess_opt_mmap(struct mount *mp) 2575fe58019SAttilio Rao { 2585fe58019SAttilio Rao struct fuse_data *data = fuse_get_mpdata(mp); 2595fe58019SAttilio Rao 260c4af8b17SConrad Meyer if (!fuse_mmap_enable || fuse_data_cache_mode == FUSE_CACHE_UC) 261*02295cafSConrad Meyer return (false); 2625fe58019SAttilio Rao return ((data->dataflags & (FSESS_NO_DATACACHE | FSESS_NO_MMAP)) == 0); 2635fe58019SAttilio Rao } 2645fe58019SAttilio Rao 265*02295cafSConrad Meyer static inline bool 2665fe58019SAttilio Rao fsess_opt_brokenio(struct mount *mp) 2675fe58019SAttilio Rao { 2685fe58019SAttilio Rao struct fuse_data *data = fuse_get_mpdata(mp); 2695fe58019SAttilio Rao 2705fe58019SAttilio Rao return (fuse_fix_broken_io || (data->dataflags & FSESS_BROKENIO)); 2715fe58019SAttilio Rao } 2725fe58019SAttilio Rao 273*02295cafSConrad Meyer static inline void 2745fe58019SAttilio Rao fuse_ms_push(struct fuse_ticket *ftick) 2755fe58019SAttilio Rao { 276*02295cafSConrad Meyer DEBUGX(FUSE_DEBUG_IPC, "ftick=%p refcount=%d\n", ftick, 277*02295cafSConrad Meyer ftick->tk_refcount + 1); 2785fe58019SAttilio Rao mtx_assert(&ftick->tk_data->ms_mtx, MA_OWNED); 2795fe58019SAttilio Rao refcount_acquire(&ftick->tk_refcount); 2805fe58019SAttilio Rao STAILQ_INSERT_TAIL(&ftick->tk_data->ms_head, ftick, tk_ms_link); 2815fe58019SAttilio Rao } 2825fe58019SAttilio Rao 283*02295cafSConrad Meyer static inline struct fuse_ticket * 2845fe58019SAttilio Rao fuse_ms_pop(struct fuse_data *data) 2855fe58019SAttilio Rao { 2865fe58019SAttilio Rao struct fuse_ticket *ftick = NULL; 2875fe58019SAttilio Rao 2885fe58019SAttilio Rao mtx_assert(&data->ms_mtx, MA_OWNED); 2895fe58019SAttilio Rao 2905fe58019SAttilio Rao if ((ftick = STAILQ_FIRST(&data->ms_head))) { 2915fe58019SAttilio Rao STAILQ_REMOVE_HEAD(&data->ms_head, tk_ms_link); 2925fe58019SAttilio Rao #ifdef INVARIANTS 2935fe58019SAttilio Rao ftick->tk_ms_link.stqe_next = NULL; 2945fe58019SAttilio Rao #endif 2955fe58019SAttilio Rao } 296*02295cafSConrad Meyer DEBUGX(FUSE_DEBUG_IPC, "ftick=%p refcount=%d\n", ftick, 297*02295cafSConrad Meyer ftick ? ftick->tk_refcount : -1); 2985fe58019SAttilio Rao 299*02295cafSConrad Meyer return (ftick); 3005fe58019SAttilio Rao } 3015fe58019SAttilio Rao 302*02295cafSConrad Meyer static inline void 3035fe58019SAttilio Rao fuse_aw_push(struct fuse_ticket *ftick) 3045fe58019SAttilio Rao { 305*02295cafSConrad Meyer DEBUGX(FUSE_DEBUG_IPC, "ftick=%p refcount=%d\n", ftick, 306*02295cafSConrad Meyer ftick->tk_refcount + 1); 3075fe58019SAttilio Rao mtx_assert(&ftick->tk_data->aw_mtx, MA_OWNED); 3085fe58019SAttilio Rao refcount_acquire(&ftick->tk_refcount); 3095fe58019SAttilio Rao TAILQ_INSERT_TAIL(&ftick->tk_data->aw_head, ftick, tk_aw_link); 3105fe58019SAttilio Rao } 3115fe58019SAttilio Rao 312*02295cafSConrad Meyer static inline void 3135fe58019SAttilio Rao fuse_aw_remove(struct fuse_ticket *ftick) 3145fe58019SAttilio Rao { 3155fe58019SAttilio Rao DEBUGX(FUSE_DEBUG_IPC, "ftick=%p refcount=%d\n", 3165fe58019SAttilio Rao ftick, ftick->tk_refcount); 3175fe58019SAttilio Rao mtx_assert(&ftick->tk_data->aw_mtx, MA_OWNED); 3185fe58019SAttilio Rao TAILQ_REMOVE(&ftick->tk_data->aw_head, ftick, tk_aw_link); 3195fe58019SAttilio Rao #ifdef INVARIANTS 3205fe58019SAttilio Rao ftick->tk_aw_link.tqe_next = NULL; 3215fe58019SAttilio Rao ftick->tk_aw_link.tqe_prev = NULL; 3225fe58019SAttilio Rao #endif 3235fe58019SAttilio Rao } 3245fe58019SAttilio Rao 325*02295cafSConrad Meyer static inline struct fuse_ticket * 3265fe58019SAttilio Rao fuse_aw_pop(struct fuse_data *data) 3275fe58019SAttilio Rao { 328*02295cafSConrad Meyer struct fuse_ticket *ftick; 3295fe58019SAttilio Rao 3305fe58019SAttilio Rao mtx_assert(&data->aw_mtx, MA_OWNED); 3315fe58019SAttilio Rao 332*02295cafSConrad Meyer if ((ftick = TAILQ_FIRST(&data->aw_head)) != NULL) 3335fe58019SAttilio Rao fuse_aw_remove(ftick); 334*02295cafSConrad Meyer DEBUGX(FUSE_DEBUG_IPC, "ftick=%p refcount=%d\n", ftick, 335*02295cafSConrad Meyer ftick ? ftick->tk_refcount : -1); 3365fe58019SAttilio Rao 337*02295cafSConrad Meyer return (ftick); 3385fe58019SAttilio Rao } 3395fe58019SAttilio Rao 3405fe58019SAttilio Rao struct fuse_ticket *fuse_ticket_fetch(struct fuse_data *data); 3415fe58019SAttilio Rao int fuse_ticket_drop(struct fuse_ticket *ftick); 3425fe58019SAttilio Rao void fuse_insert_callback(struct fuse_ticket *ftick, fuse_handler_t *handler); 3435fe58019SAttilio Rao void fuse_insert_message(struct fuse_ticket *ftick); 3445fe58019SAttilio Rao 345*02295cafSConrad Meyer static inline bool 3465fe58019SAttilio Rao fuse_libabi_geq(struct fuse_data *data, uint32_t abi_maj, uint32_t abi_min) 3475fe58019SAttilio Rao { 3485fe58019SAttilio Rao return (data->fuse_libabi_major > abi_maj || 349*02295cafSConrad Meyer (data->fuse_libabi_major == abi_maj && 350*02295cafSConrad Meyer data->fuse_libabi_minor >= abi_min)); 3515fe58019SAttilio Rao } 3525fe58019SAttilio Rao 3535fe58019SAttilio Rao struct fuse_data *fdata_alloc(struct cdev *dev, struct ucred *cred); 3545fe58019SAttilio Rao void fdata_trydestroy(struct fuse_data *data); 3555fe58019SAttilio Rao void fdata_set_dead(struct fuse_data *data); 3565fe58019SAttilio Rao 357*02295cafSConrad Meyer static inline bool 3585fe58019SAttilio Rao fdata_get_dead(struct fuse_data *data) 3595fe58019SAttilio Rao { 3605fe58019SAttilio Rao return (data->dataflags & FSESS_DEAD); 3615fe58019SAttilio Rao } 3625fe58019SAttilio Rao 3635fe58019SAttilio Rao struct fuse_dispatcher { 3645fe58019SAttilio Rao struct fuse_ticket *tick; 3655fe58019SAttilio Rao struct fuse_in_header *finh; 3665fe58019SAttilio Rao 3675fe58019SAttilio Rao void *indata; 3685fe58019SAttilio Rao size_t iosize; 3695fe58019SAttilio Rao uint64_t nodeid; 3705fe58019SAttilio Rao int answ_stat; 3715fe58019SAttilio Rao void *answ; 3725fe58019SAttilio Rao }; 3735fe58019SAttilio Rao 374*02295cafSConrad Meyer static inline void 3755fe58019SAttilio Rao fdisp_init(struct fuse_dispatcher *fdisp, size_t iosize) 3765fe58019SAttilio Rao { 3775fe58019SAttilio Rao DEBUGX(FUSE_DEBUG_IPC, "-> fdisp=%p, iosize=%zx\n", fdisp, iosize); 3785fe58019SAttilio Rao fdisp->iosize = iosize; 3795fe58019SAttilio Rao fdisp->tick = NULL; 3805fe58019SAttilio Rao } 3815fe58019SAttilio Rao 382*02295cafSConrad Meyer static inline void 3835fe58019SAttilio Rao fdisp_destroy(struct fuse_dispatcher *fdisp) 3845fe58019SAttilio Rao { 3855fe58019SAttilio Rao DEBUGX(FUSE_DEBUG_IPC, "-> fdisp=%p, ftick=%p\n", fdisp, fdisp->tick); 3865fe58019SAttilio Rao fuse_ticket_drop(fdisp->tick); 3875fe58019SAttilio Rao #ifdef INVARIANTS 3885fe58019SAttilio Rao fdisp->tick = NULL; 3895fe58019SAttilio Rao #endif 3905fe58019SAttilio Rao } 3915fe58019SAttilio Rao 3925fe58019SAttilio Rao void fdisp_make(struct fuse_dispatcher *fdip, enum fuse_opcode op, 393*02295cafSConrad Meyer struct mount *mp, uint64_t nid, struct thread *td, struct ucred *cred); 3945fe58019SAttilio Rao 3955fe58019SAttilio Rao void fdisp_make_pid(struct fuse_dispatcher *fdip, enum fuse_opcode op, 396*02295cafSConrad Meyer struct mount *mp, uint64_t nid, pid_t pid, struct ucred *cred); 3975fe58019SAttilio Rao 3985fe58019SAttilio Rao void fdisp_make_vp(struct fuse_dispatcher *fdip, enum fuse_opcode op, 3995fe58019SAttilio Rao struct vnode *vp, struct thread *td, struct ucred *cred); 4005fe58019SAttilio Rao 4015fe58019SAttilio Rao int fdisp_wait_answ(struct fuse_dispatcher *fdip); 4025fe58019SAttilio Rao 403*02295cafSConrad Meyer static inline int 4045fe58019SAttilio Rao fdisp_simple_putget_vp(struct fuse_dispatcher *fdip, enum fuse_opcode op, 4055fe58019SAttilio Rao struct vnode *vp, struct thread *td, struct ucred *cred) 4065fe58019SAttilio Rao { 4075fe58019SAttilio Rao DEBUGX(FUSE_DEBUG_IPC, "-> fdip=%p, opcode=%d, vp=%p\n", fdip, op, vp); 4085fe58019SAttilio Rao fdisp_make_vp(fdip, op, vp, td, cred); 409*02295cafSConrad Meyer return (fdisp_wait_answ(fdip)); 4105fe58019SAttilio Rao } 4115fe58019SAttilio Rao 4125fe58019SAttilio Rao #endif /* _FUSE_IPC_H_ */ 413