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