xref: /titanic_41/usr/src/uts/common/sys/ctfs_impl.h (revision da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SYS_CTFS_IMPL_H
27 #define	_SYS_CTFS_IMPL_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <sys/contract.h>
32 #include <sys/gfs.h>
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 /*
39  * Inode numbers
40  */
41 
42 /*
43  * Root inode:
44  * ---------------------------------------------------
45  * |                       0                         |
46  * ---------------------------------------------------
47  * 63						     0
48  */
49 
50 #define	CTFS_INO_ROOT 0
51 
52 /*
53  * Contract-specific file:
54  * ---------------------------------------------------
55  * |1|    file (62:32)     |   contract id (31:0)    |
56  * ---------------------------------------------------
57  * 63						     0
58  *	file = 0 : directory
59  *	file = 1 : "all" directory symlink
60  *	file > 1 : special files ("ctl", "status", etc.)
61  */
62 
63 #define	CTFS_INO_CT_SHIFT	32
64 #define	CTFS_INO_CT(ctid, file)	\
65 	((1ULL << 63) | \
66 	((unsigned long long)(file) << CTFS_INO_CT_SHIFT) | \
67 	(ctid))
68 #define	CTFS_INO_CT_DIR(ctid)		CTFS_INO_CT((ctid), 0)
69 #define	CTFS_INO_CT_LINK(ctid)		CTFS_INO_CT((ctid), 1)
70 #define	CTFS_INO_CT_FILE(ctid, file)	CTFS_INO_CT((ctid), (file) + 2)
71 
72 /*
73  * Type-specific file:
74  * ---------------------------------------------------
75  * |          0         | type (31:16) | file (15:0) |
76  * ---------------------------------------------------
77  * 63						     0
78  *	type = 0 : invalid
79  *	type > 0 : contract type index + 1 ("all" is #types + 1)
80  *	file = 0 : directory
81  *	file > 0 : special files ("template", "latest", etc.)
82  */
83 
84 #define	CTFS_INO_TYPE_SHIFT	16
85 #define	CTFS_INO_TYPE(type, file)	\
86 	(((type) + 1) << CTFS_INO_TYPE_SHIFT | (file))
87 #define	CTFS_INO_TYPE_DIR(type)		CTFS_INO_TYPE((type), 0)
88 #define	CTFS_INO_TYPE_FILE(type, file)	CTFS_INO_TYPE((type), (file) + 1)
89 
90 /*
91  * Other constants
92  */
93 #define	CTFS_NAME_MAX		32
94 
95 /*
96  * Possible values for ctfs_endpt_flags, below.
97  */
98 #define	CTFS_ENDPT_SETUP	0x1
99 #define	CTFS_ENDPT_NBLOCK	0x2
100 
101 /*
102  * Common endpoint object.
103  */
104 typedef struct ctfs_endpoint {
105 	kmutex_t	ctfs_endpt_lock;
106 	ct_listener_t	ctfs_endpt_listener;
107 	uint_t		ctfs_endpt_flags;
108 } ctfs_endpoint_t;
109 
110 /*
111  * root directory data
112  */
113 typedef gfs_dir_t	ctfs_rootnode_t;
114 
115 /*
116  * /all directory data
117  */
118 typedef gfs_dir_t	ctfs_adirnode_t;
119 
120 /*
121  * /all symlink data
122  */
123 typedef struct ctfs_symnode {
124 	gfs_file_t	ctfs_sn_file;		/* gfs file */
125 	contract_t	*ctfs_sn_contract;	/* target contract */
126 	char		*ctfs_sn_string;	/* target path */
127 	size_t		ctfs_sn_size;		/* length of target path */
128 } ctfs_symnode_t;
129 
130 /*
131  * contract type directory data
132  */
133 typedef	gfs_dir_t	ctfs_tdirnode_t;
134 
135 /*
136  * contract directory data
137  */
138 typedef struct ctfs_cdirnode {
139 	gfs_dir_t	ctfs_cn_dir;		/* directory contents */
140 	contract_t	*ctfs_cn_contract;	/* contract pointer */
141 	contract_vnode_t ctfs_cn_linkage;	/* contract vnode list node */
142 } ctfs_cdirnode_t;
143 
144 /*
145  * template file data
146  */
147 typedef struct ctfs_tmplnode {
148 	gfs_file_t	ctfs_tmn_file;		/* gfs file */
149 	ct_template_t	*ctfs_tmn_tmpl;		/* template pointer */
150 } ctfs_tmplnode_t;
151 
152 /*
153  * ctl and status file data
154  */
155 typedef struct ctfs_ctlnode {
156 	gfs_file_t	ctfs_ctl_file;		/* gfs file */
157 	contract_t	*ctfs_ctl_contract;	/* contract pointer */
158 } ctfs_ctlnode_t;
159 
160 /*
161  * latest file data
162  */
163 typedef gfs_dir_t	ctfs_latenode_t;
164 
165 /*
166  * events file data
167  */
168 typedef struct ctfs_evnode {
169 	gfs_file_t	ctfs_ev_file;		/* gfs file */
170 	contract_t	*ctfs_ev_contract;	/* contract we're watching */
171 	ctfs_endpoint_t	ctfs_ev_listener;	/* common endpoint data */
172 } ctfs_evnode_t;
173 
174 /*
175  * bundle and pbundle file data
176  */
177 typedef struct ctfs_bunode {
178 	gfs_file_t	ctfs_bu_file;		/* gfs file */
179 	ct_equeue_t	*ctfs_bu_queue;		/* queue we're watching */
180 	ctfs_endpoint_t	ctfs_bu_listener;	/* common endpoint data */
181 } ctfs_bunode_t;
182 
183 /*
184  * VFS data object
185  */
186 typedef struct ctfs_vfs {
187 	vnode_t	*ctvfs_root;		/* root vnode pointer */
188 } ctfs_vfs_t;
189 
190 /*
191  * vnode creation routines
192  */
193 extern vnode_t *ctfs_create_tdirnode(vnode_t *);
194 extern vnode_t *ctfs_create_tmplnode(vnode_t *);
195 extern vnode_t *ctfs_create_latenode(vnode_t *);
196 extern vnode_t *ctfs_create_pbundle(vnode_t *);
197 extern vnode_t *ctfs_create_bundle(vnode_t *);
198 extern vnode_t *ctfs_create_ctlnode(vnode_t *);
199 extern vnode_t *ctfs_create_statnode(vnode_t *);
200 extern vnode_t *ctfs_create_evnode(vnode_t *);
201 extern vnode_t *ctfs_create_adirnode(vnode_t *);
202 extern vnode_t *ctfs_create_cdirnode(vnode_t *, contract_t *);
203 extern vnode_t *ctfs_create_symnode(vnode_t *, contract_t *);
204 
205 /*
206  * common ctfs routines
207  */
208 extern void ctfs_common_getattr(vnode_t *, vattr_t *);
209 extern int ctfs_close(vnode_t *, int, int, offset_t, cred_t *,
210 		caller_context_t *);
211 extern int ctfs_access_dir(vnode_t *, int, int, cred_t *,
212 		caller_context_t *);
213 extern int ctfs_access_readonly(vnode_t *, int, int, cred_t *,
214 		caller_context_t *);
215 extern int ctfs_access_readwrite(vnode_t *, int, int, cred_t *,
216 		caller_context_t *);
217 extern int ctfs_open(vnode_t **, int, cred_t *,
218 		caller_context_t *);
219 
220 /*
221  * vnode ops vector templates
222  */
223 extern vnodeops_t *ctfs_ops_root;
224 extern vnodeops_t *ctfs_ops_adir;
225 extern vnodeops_t *ctfs_ops_sym;
226 extern vnodeops_t *ctfs_ops_tdir;
227 extern vnodeops_t *ctfs_ops_tmpl;
228 extern vnodeops_t *ctfs_ops_cdir;
229 extern vnodeops_t *ctfs_ops_ctl;
230 extern vnodeops_t *ctfs_ops_stat;
231 extern vnodeops_t *ctfs_ops_event;
232 extern vnodeops_t *ctfs_ops_bundle;
233 extern vnodeops_t *ctfs_ops_latest;
234 
235 #ifdef	__cplusplus
236 }
237 #endif
238 
239 #endif	/* _SYS_CTFS_IMPL_H */
240