1 /* $FreeBSD$ */ 2 /*- 3 * Copyright (c) 2014-2022 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 (1 << 12) /* bytes */ 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 128UL /* units */ 38 #define CUSE_ALLOC_UNIT_SHIFT 24 /* bits */ 39 /* All memory allocations must be less than the following limit */ 40 #define CUSE_ALLOC_BYTES_MAX \ 41 (CUSE_ALLOC_UNIT_MAX << CUSE_ALLOC_UNIT_SHIFT) /* bytes */ 42 43 struct cuse_dev; 44 45 struct cuse_data_chunk { 46 uintptr_t local_ptr; 47 uintptr_t peer_ptr; 48 unsigned long length; 49 }; 50 51 struct cuse_alloc_info { 52 unsigned long page_count; 53 unsigned long alloc_nr; 54 }; 55 56 struct cuse_command { 57 struct cuse_dev *dev; 58 unsigned long fflags; 59 uintptr_t per_file_handle; 60 uintptr_t data_pointer; 61 unsigned long argument; 62 unsigned long command; /* see CUSE_CMD_XXX */ 63 }; 64 65 struct cuse_create_dev { 66 struct cuse_dev *dev; 67 uid_t user_id; 68 gid_t group_id; 69 int permissions; 70 char devname[80]; /* /dev/xxxxx */ 71 }; 72 73 /* Definition of internal IOCTLs for /dev/cuse */ 74 75 #define CUSE_IOCTL_GET_COMMAND _IOR('C', 0, struct cuse_command) 76 #define CUSE_IOCTL_WRITE_DATA _IOW('C', 1, struct cuse_data_chunk) 77 #define CUSE_IOCTL_READ_DATA _IOW('C', 2, struct cuse_data_chunk) 78 #define CUSE_IOCTL_SYNC_COMMAND _IOW('C', 3, int) 79 #define CUSE_IOCTL_GET_SIG _IOR('C', 4, int) 80 #define CUSE_IOCTL_ALLOC_MEMORY _IOW('C', 5, struct cuse_alloc_info) 81 #define CUSE_IOCTL_FREE_MEMORY _IOW('C', 6, struct cuse_alloc_info) 82 #define CUSE_IOCTL_SET_PFH _IOW('C', 7, uintptr_t) 83 #define CUSE_IOCTL_CREATE_DEV _IOW('C', 8, struct cuse_create_dev) 84 #define CUSE_IOCTL_DESTROY_DEV _IOW('C', 9, struct cuse_dev *) 85 #define CUSE_IOCTL_ALLOC_UNIT _IOR('C',10, int) 86 #define CUSE_IOCTL_FREE_UNIT _IOW('C',11, int) 87 #define CUSE_IOCTL_SELWAKEUP _IOW('C',12, int) 88 #define CUSE_IOCTL_ALLOC_UNIT_BY_ID _IOWR('C',13, int) 89 #define CUSE_IOCTL_FREE_UNIT_BY_ID _IOWR('C',14, int) 90 91 #endif /* _CUSE_IOCTL_H_ */ 92