xref: /freebsd/sys/fs/cuse/cuse_ioctl.h (revision 1c05a6ea6b849ff95e539c31adea887c644a6a01)
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_IOCTL_H_
28 #define	_CUSE_IOCTL_H_
29 
30 #include <sys/ioccom.h>
31 #include <sys/types.h>
32 
33 #define	CUSE_BUFFER_MAX		PAGE_SIZE
34 #define	CUSE_DEVICES_MAX	64	/* units */
35 #define	CUSE_BUF_MIN_PTR	0x10000UL
36 #define	CUSE_BUF_MAX_PTR	0x20000UL
37 #define	CUSE_ALLOC_UNIT_MAX	128	/* units */
38 #define	CUSE_ALLOC_PAGES_MAX	(((16UL * 1024UL * 1024UL) + PAGE_SIZE - 1) / PAGE_SIZE)
39 
40 struct cuse_dev;
41 
42 struct cuse_data_chunk {
43 	uintptr_t local_ptr;
44 	uintptr_t peer_ptr;
45 	unsigned long length;
46 };
47 
48 struct cuse_alloc_info {
49 	unsigned long page_count;
50 	unsigned long alloc_nr;
51 };
52 
53 struct cuse_command {
54 	struct cuse_dev *dev;
55 	unsigned long fflags;
56 	uintptr_t per_file_handle;
57 	uintptr_t data_pointer;
58 	unsigned long argument;
59 	unsigned long command;		/* see CUSE_CMD_XXX */
60 };
61 
62 struct cuse_create_dev {
63 	struct cuse_dev *dev;
64 	uid_t	user_id;
65 	gid_t	group_id;
66 	int	permissions;
67 	char	devname[80];		/* /dev/xxxxx */
68 };
69 
70 /* Definition of internal IOCTLs for /dev/cuse */
71 
72 #define	CUSE_IOCTL_GET_COMMAND		_IOR('C', 0, struct cuse_command)
73 #define	CUSE_IOCTL_WRITE_DATA		_IOW('C', 1, struct cuse_data_chunk)
74 #define	CUSE_IOCTL_READ_DATA		_IOW('C', 2, struct cuse_data_chunk)
75 #define	CUSE_IOCTL_SYNC_COMMAND		_IOW('C', 3, int)
76 #define	CUSE_IOCTL_GET_SIG		_IOR('C', 4, int)
77 #define	CUSE_IOCTL_ALLOC_MEMORY		_IOW('C', 5, struct cuse_alloc_info)
78 #define	CUSE_IOCTL_FREE_MEMORY		_IOW('C', 6, struct cuse_alloc_info)
79 #define	CUSE_IOCTL_SET_PFH		_IOW('C', 7, uintptr_t)
80 #define	CUSE_IOCTL_CREATE_DEV		_IOW('C', 8, struct cuse_create_dev)
81 #define	CUSE_IOCTL_DESTROY_DEV		_IOW('C', 9, struct cuse_dev *)
82 #define	CUSE_IOCTL_ALLOC_UNIT		_IOR('C',10, int)
83 #define	CUSE_IOCTL_FREE_UNIT		_IOW('C',11, int)
84 #define	CUSE_IOCTL_SELWAKEUP		_IOW('C',12, int)
85 #define	CUSE_IOCTL_ALLOC_UNIT_BY_ID	_IOWR('C',13, int)
86 #define	CUSE_IOCTL_FREE_UNIT_BY_ID	_IOWR('C',14, int)
87 
88 #endif			/* _CUSE_IOCTL_H_ */
89