xref: /titanic_52/usr/src/uts/common/sys/lofi.h (revision bdfc6d18da790deeec2e0eb09c625902defe2498)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 
28 #ifndef	_SYS_LOFI_H
29 #define	_SYS_LOFI_H
30 
31 #pragma ident	"%Z%%M%	%I%	%E% SMI"
32 
33 #include <sys/types.h>
34 #include <sys/time.h>
35 #include <sys/taskq.h>
36 #include <sys/vtoc.h>
37 #include <sys/dkio.h>
38 #include <sys/vnode.h>
39 
40 #ifdef	__cplusplus
41 extern "C" {
42 #endif
43 
44 /*
45  * /dev names:
46  *	/dev/lofictl	- master control device
47  *	/dev/lofi	- block devices, named by minor number
48  *	/dev/rlofi	- character devices, named by minor number
49  */
50 #define	LOFI_DRIVER_NAME	"lofi"
51 #define	LOFI_CTL_NODE		"ctl"
52 #define	LOFI_CTL_NAME		LOFI_DRIVER_NAME LOFI_CTL_NODE
53 #define	LOFI_BLOCK_NAME		LOFI_DRIVER_NAME
54 #define	LOFI_CHAR_NAME		"r" LOFI_DRIVER_NAME
55 
56 /*
57  *
58  * Use is:
59  *	ld = open("/dev/lofictl", O_RDWR | O_EXCL);
60  *
61  * lofi must be opened exclusively. Access is controlled by permissions on
62  * the device, which is 644 by default. Write-access is required for ioctls
63  * that change state, but only read-access is required for the ioctls that
64  * return information. Basically, only root can add and remove files, but
65  * non-root can look at the current lists.
66  *
67  * ioctl usage:
68  *
69  * kernel ioctls
70  *
71  *	strcpy(li.li_filename, "somefilename");
72  *	ioctl(ld, LOFI_MAP_FILE, &li);
73  *	newminor = li.li_minor;
74  *
75  *	strcpy(li.li_filename, "somefilename");
76  *	ioctl(ld, LOFI_UNMAP_FILE, &li);
77  *
78  *	strcpy(li.li_filename, "somefilename");
79  *	li.li_minor = minor_number;
80  *	ioctl(ld, LOFI_MAP_FILE_MINOR, &li);
81  *
82  *	li.li_minor = minor_number;
83  *	ioctl(ld, LOFI_UNMAP_FILE_MINOR, &li);
84  *
85  *	li.li_minor = minor_number;
86  *	ioctl(ld, LOFI_GET_FILENAME, &li);
87  *
88  *	strcpy(li.li_filename, "somefilename");
89  *	ioctl(ld, LOFI_GET_MINOR, &li);
90  *
91  *	li.li_minor = 0;
92  *	ioctl(ld, LOFI_GET_MAXMINOR, &li);
93  *	maxminor = li.li_minor;
94  *
95  * Oh, and last but not least: these ioctls are totally private and only
96  * for use by lofiadm(1M).
97  *
98  */
99 
100 struct lofi_ioctl {
101 	uint32_t li_minor;
102 	char	li_filename[MAXPATHLEN + 1];
103 };
104 
105 #define	LOFI_IOC_BASE		(('L' << 16) | ('F' << 8))
106 
107 #define	LOFI_MAP_FILE		(LOFI_IOC_BASE | 0x01)
108 #define	LOFI_MAP_FILE_MINOR	(LOFI_IOC_BASE | 0x02)
109 #define	LOFI_UNMAP_FILE		(LOFI_IOC_BASE | 0x03)
110 #define	LOFI_UNMAP_FILE_MINOR	(LOFI_IOC_BASE | 0x04)
111 #define	LOFI_GET_FILENAME	(LOFI_IOC_BASE | 0x05)
112 #define	LOFI_GET_MINOR		(LOFI_IOC_BASE | 0x06)
113 #define	LOFI_GET_MAXMINOR	(LOFI_IOC_BASE | 0x07)
114 
115 /*
116  * file types that might be usable with lofi, maybe. Only regular
117  * files are documented though.
118  */
119 #define	S_ISLOFIABLE(mode) \
120 	(S_ISREG(mode) || S_ISBLK(mode) || S_ISCHR(mode))
121 
122 #if defined(_KERNEL)
123 
124 /*
125  * We limit the maximum number of active lofi devices to 128, which seems very
126  * large. You can tune this by changing lofi_max_files in /etc/system.
127  * If you change it dynamically, which you probably shouldn't do, make sure
128  * to only _increase_ it.
129  */
130 #define	LOFI_MAX_FILES	128
131 extern uint32_t lofi_max_files;
132 
133 #define	V_ISLOFIABLE(vtype) \
134 	((vtype == VREG) || (vtype == VBLK) || (vtype == VCHR))
135 
136 struct lofi_state {
137 	char	*ls_filename;	/* filename to open */
138 	size_t	ls_filename_sz;
139 	struct vnode	*ls_vp; /* open vnode */
140 	u_offset_t	ls_vp_size;
141 	uint32_t	ls_blk_open;
142 	uint32_t	ls_chr_open;
143 	uint32_t	ls_lyr_open_count;
144 	int		ls_openflag;
145 	taskq_t		*ls_taskq;
146 	kstat_t		*ls_kstat;
147 	kmutex_t	ls_kstat_lock;
148 	struct dk_geom	ls_dkg;
149 	struct vtoc	ls_vtoc;
150 	struct dk_cinfo	ls_ci;
151 };
152 
153 #endif
154 
155 #ifdef	__cplusplus
156 }
157 #endif
158 
159 #endif	/* _SYS_LOFI_H */
160