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