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