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