1*fa0f6e62SHans Petter Selasky /* $FreeBSD$ */ 2*fa0f6e62SHans Petter Selasky /*- 3*fa0f6e62SHans Petter Selasky * Copyright (c) 2014 Hans Petter Selasky. All rights reserved. 4*fa0f6e62SHans Petter Selasky * 5*fa0f6e62SHans Petter Selasky * Redistribution and use in source and binary forms, with or without 6*fa0f6e62SHans Petter Selasky * modification, are permitted provided that the following conditions 7*fa0f6e62SHans Petter Selasky * are met: 8*fa0f6e62SHans Petter Selasky * 1. Redistributions of source code must retain the above copyright 9*fa0f6e62SHans Petter Selasky * notice, this list of conditions and the following disclaimer. 10*fa0f6e62SHans Petter Selasky * 2. Redistributions in binary form must reproduce the above copyright 11*fa0f6e62SHans Petter Selasky * notice, this list of conditions and the following disclaimer in the 12*fa0f6e62SHans Petter Selasky * documentation and/or other materials provided with the distribution. 13*fa0f6e62SHans Petter Selasky * 14*fa0f6e62SHans Petter Selasky * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15*fa0f6e62SHans Petter Selasky * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16*fa0f6e62SHans Petter Selasky * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17*fa0f6e62SHans Petter Selasky * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18*fa0f6e62SHans Petter Selasky * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19*fa0f6e62SHans Petter Selasky * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20*fa0f6e62SHans Petter Selasky * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21*fa0f6e62SHans Petter Selasky * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22*fa0f6e62SHans Petter Selasky * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23*fa0f6e62SHans Petter Selasky * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24*fa0f6e62SHans Petter Selasky * SUCH DAMAGE. 25*fa0f6e62SHans Petter Selasky */ 26*fa0f6e62SHans Petter Selasky 27*fa0f6e62SHans Petter Selasky #ifndef _CUSE_H_ 28*fa0f6e62SHans Petter Selasky #define _CUSE_H_ 29*fa0f6e62SHans Petter Selasky 30*fa0f6e62SHans Petter Selasky #ifdef __cplusplus 31*fa0f6e62SHans Petter Selasky extern "C" { 32*fa0f6e62SHans Petter Selasky #endif 33*fa0f6e62SHans Petter Selasky 34*fa0f6e62SHans Petter Selasky #include <fs/cuse/cuse_defs.h> 35*fa0f6e62SHans Petter Selasky 36*fa0f6e62SHans Petter Selasky struct cuse_dev; 37*fa0f6e62SHans Petter Selasky 38*fa0f6e62SHans Petter Selasky typedef int (cuse_open_t)(struct cuse_dev *, int fflags); 39*fa0f6e62SHans Petter Selasky typedef int (cuse_close_t)(struct cuse_dev *, int fflags); 40*fa0f6e62SHans Petter Selasky typedef int (cuse_read_t)(struct cuse_dev *, int fflags, void *user_ptr, int len); 41*fa0f6e62SHans Petter Selasky typedef int (cuse_write_t)(struct cuse_dev *, int fflags, const void *user_ptr, int len); 42*fa0f6e62SHans Petter Selasky typedef int (cuse_ioctl_t)(struct cuse_dev *, int fflags, unsigned long cmd, void *user_data); 43*fa0f6e62SHans Petter Selasky typedef int (cuse_poll_t)(struct cuse_dev *, int fflags, int events); 44*fa0f6e62SHans Petter Selasky 45*fa0f6e62SHans Petter Selasky struct cuse_methods { 46*fa0f6e62SHans Petter Selasky cuse_open_t *cm_open; 47*fa0f6e62SHans Petter Selasky cuse_close_t *cm_close; 48*fa0f6e62SHans Petter Selasky cuse_read_t *cm_read; 49*fa0f6e62SHans Petter Selasky cuse_write_t *cm_write; 50*fa0f6e62SHans Petter Selasky cuse_ioctl_t *cm_ioctl; 51*fa0f6e62SHans Petter Selasky cuse_poll_t *cm_poll; 52*fa0f6e62SHans Petter Selasky }; 53*fa0f6e62SHans Petter Selasky 54*fa0f6e62SHans Petter Selasky int cuse_init(void); 55*fa0f6e62SHans Petter Selasky int cuse_uninit(void); 56*fa0f6e62SHans Petter Selasky 57*fa0f6e62SHans Petter Selasky void *cuse_vmalloc(int); 58*fa0f6e62SHans Petter Selasky int cuse_is_vmalloc_addr(void *); 59*fa0f6e62SHans Petter Selasky void cuse_vmfree(void *); 60*fa0f6e62SHans Petter Selasky unsigned long cuse_vmoffset(void *ptr); 61*fa0f6e62SHans Petter Selasky 62*fa0f6e62SHans Petter Selasky int cuse_alloc_unit_number_by_id(int *, int); 63*fa0f6e62SHans Petter Selasky int cuse_free_unit_number_by_id(int, int); 64*fa0f6e62SHans Petter Selasky int cuse_alloc_unit_number(int *); 65*fa0f6e62SHans Petter Selasky int cuse_free_unit_number(int); 66*fa0f6e62SHans Petter Selasky 67*fa0f6e62SHans Petter Selasky struct cuse_dev *cuse_dev_create(const struct cuse_methods *, void *, void *, uid_t, gid_t, int, const char *,...); 68*fa0f6e62SHans Petter Selasky void cuse_dev_destroy(struct cuse_dev *); 69*fa0f6e62SHans Petter Selasky 70*fa0f6e62SHans Petter Selasky void *cuse_dev_get_priv0(struct cuse_dev *); 71*fa0f6e62SHans Petter Selasky void *cuse_dev_get_priv1(struct cuse_dev *); 72*fa0f6e62SHans Petter Selasky 73*fa0f6e62SHans Petter Selasky void cuse_dev_set_priv0(struct cuse_dev *, void *); 74*fa0f6e62SHans Petter Selasky void cuse_dev_set_priv1(struct cuse_dev *, void *); 75*fa0f6e62SHans Petter Selasky 76*fa0f6e62SHans Petter Selasky void cuse_set_local(int); 77*fa0f6e62SHans Petter Selasky int cuse_get_local(void); 78*fa0f6e62SHans Petter Selasky 79*fa0f6e62SHans Petter Selasky int cuse_wait_and_process(void); 80*fa0f6e62SHans Petter Selasky 81*fa0f6e62SHans Petter Selasky void cuse_dev_set_per_file_handle(struct cuse_dev *, void *); 82*fa0f6e62SHans Petter Selasky void *cuse_dev_get_per_file_handle(struct cuse_dev *); 83*fa0f6e62SHans Petter Selasky 84*fa0f6e62SHans Petter Selasky int cuse_copy_out(const void *src, void *user_dst, int len); 85*fa0f6e62SHans Petter Selasky int cuse_copy_in(const void *user_src, void *dst, int len); 86*fa0f6e62SHans Petter Selasky int cuse_got_peer_signal(void); 87*fa0f6e62SHans Petter Selasky void cuse_poll_wakeup(void); 88*fa0f6e62SHans Petter Selasky 89*fa0f6e62SHans Petter Selasky struct cuse_dev *cuse_dev_get_current(int *); 90*fa0f6e62SHans Petter Selasky 91*fa0f6e62SHans Petter Selasky extern int cuse_debug_level; 92*fa0f6e62SHans Petter Selasky 93*fa0f6e62SHans Petter Selasky #ifdef __cplusplus 94*fa0f6e62SHans Petter Selasky } 95*fa0f6e62SHans Petter Selasky #endif 96*fa0f6e62SHans Petter Selasky 97*fa0f6e62SHans Petter Selasky #endif /* _CUSE_H_ */ 98