summaryrefslogtreecommitdiff
path: root/usr/src/uts/common/sys/ctfs_impl.h
blob: 77e491a550592ab492302966a23af5cf2a418b90 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#ifndef	_SYS_CTFS_IMPL_H
#define	_SYS_CTFS_IMPL_H

#pragma ident	"%Z%%M%	%I%	%E% SMI"

#include <sys/contract.h>
#include <sys/gfs.h>

#ifdef	__cplusplus
extern "C" {
#endif

/*
 * Inode numbers
 */

/*
 * Root inode:
 * ---------------------------------------------------
 * |                       0                         |
 * ---------------------------------------------------
 * 63						     0
 */

#define	CTFS_INO_ROOT 0

/*
 * Contract-specific file:
 * ---------------------------------------------------
 * |1|    file (62:32)     |   contract id (31:0)    |
 * ---------------------------------------------------
 * 63						     0
 *	file = 0 : directory
 *	file = 1 : "all" directory symlink
 *	file > 1 : special files ("ctl", "status", etc.)
 */

#define	CTFS_INO_CT_SHIFT	32
#define	CTFS_INO_CT(ctid, file)	\
	((1ULL << 63) | \
	((unsigned long long)(file) << CTFS_INO_CT_SHIFT) | \
	(ctid))
#define	CTFS_INO_CT_DIR(ctid)		CTFS_INO_CT((ctid), 0)
#define	CTFS_INO_CT_LINK(ctid)		CTFS_INO_CT((ctid), 1)
#define	CTFS_INO_CT_FILE(ctid, file)	CTFS_INO_CT((ctid), (file) + 2)

/*
 * Type-specific file:
 * ---------------------------------------------------
 * |          0         | type (31:16) | file (15:0) |
 * ---------------------------------------------------
 * 63						     0
 *	type = 0 : invalid
 *	type > 0 : contract type index + 1 ("all" is #types + 1)
 *	file = 0 : directory
 *	file > 0 : special files ("template", "latest", etc.)
 */

#define	CTFS_INO_TYPE_SHIFT	16
#define	CTFS_INO_TYPE(type, file)	\
	(((type) + 1) << CTFS_INO_TYPE_SHIFT | (file))
#define	CTFS_INO_TYPE_DIR(type)		CTFS_INO_TYPE((type), 0)
#define	CTFS_INO_TYPE_FILE(type, file)	CTFS_INO_TYPE((type), (file) + 1)

/*
 * Other constants
 */
#define	CTFS_NAME_MAX		32

/*
 * Possible values for ctfs_endpt_flags, below.
 */
#define	CTFS_ENDPT_SETUP	0x1
#define	CTFS_ENDPT_NBLOCK	0x2

/*
 * Common endpoint object.
 */
typedef struct ctfs_endpoint {
	kmutex_t	ctfs_endpt_lock;
	ct_listener_t	ctfs_endpt_listener;
	uint_t		ctfs_endpt_flags;
} ctfs_endpoint_t;

/*
 * root directory data
 */
typedef gfs_dir_t	ctfs_rootnode_t;

/*
 * /all directory data
 */
typedef gfs_dir_t	ctfs_adirnode_t;

/*
 * /all symlink data
 */
typedef struct ctfs_symnode {
	gfs_file_t	ctfs_sn_file;		/* gfs file */
	contract_t	*ctfs_sn_contract;	/* target contract */
	char		*ctfs_sn_string;	/* target path */
	size_t		ctfs_sn_size;		/* length of target path */
} ctfs_symnode_t;

/*
 * contract type directory data
 */
typedef	gfs_dir_t	ctfs_tdirnode_t;

/*
 * contract directory data
 */
typedef struct ctfs_cdirnode {
	gfs_dir_t	ctfs_cn_dir;		/* directory contents */
	contract_t	*ctfs_cn_contract;	/* contract pointer */
	contract_vnode_t ctfs_cn_linkage;	/* contract vnode list node */
} ctfs_cdirnode_t;

/*
 * template file data
 */
typedef struct ctfs_tmplnode {
	gfs_file_t	ctfs_tmn_file;		/* gfs file */
	ct_template_t	*ctfs_tmn_tmpl;		/* template pointer */
} ctfs_tmplnode_t;

/*
 * ctl and status file data
 */
typedef struct ctfs_ctlnode {
	gfs_file_t	ctfs_ctl_file;		/* gfs file */
	contract_t	*ctfs_ctl_contract;	/* contract pointer */
} ctfs_ctlnode_t;

/*
 * latest file data
 */
typedef gfs_dir_t	ctfs_latenode_t;

/*
 * events file data
 */
typedef struct ctfs_evnode {
	gfs_file_t	ctfs_ev_file;		/* gfs file */
	contract_t	*ctfs_ev_contract;	/* contract we're watching */
	ctfs_endpoint_t	ctfs_ev_listener;	/* common endpoint data */
} ctfs_evnode_t;

/*
 * bundle and pbundle file data
 */
typedef struct ctfs_bunode {
	gfs_file_t	ctfs_bu_file;		/* gfs file */
	ct_equeue_t	*ctfs_bu_queue;		/* queue we're watching */
	ctfs_endpoint_t	ctfs_bu_listener;	/* common endpoint data */
} ctfs_bunode_t;

/*
 * VFS data object
 */
typedef struct ctfs_vfs {
	vnode_t	*ctvfs_root;		/* root vnode pointer */
} ctfs_vfs_t;

/*
 * vnode creation routines
 */
extern vnode_t *ctfs_create_tdirnode(vnode_t *);
extern vnode_t *ctfs_create_tmplnode(vnode_t *);
extern vnode_t *ctfs_create_latenode(vnode_t *);
extern vnode_t *ctfs_create_pbundle(vnode_t *);
extern vnode_t *ctfs_create_bundle(vnode_t *);
extern vnode_t *ctfs_create_ctlnode(vnode_t *);
extern vnode_t *ctfs_create_statnode(vnode_t *);
extern vnode_t *ctfs_create_evnode(vnode_t *);
extern vnode_t *ctfs_create_adirnode(vnode_t *);
extern vnode_t *ctfs_create_cdirnode(vnode_t *, contract_t *);
extern vnode_t *ctfs_create_symnode(vnode_t *, contract_t *);

/*
 * common ctfs routines
 */
extern void ctfs_common_getattr(vnode_t *, vattr_t *);
extern int ctfs_close(vnode_t *, int, int, offset_t, cred_t *,
		caller_context_t *);
extern int ctfs_access_dir(vnode_t *, int, int, cred_t *,
		caller_context_t *);
extern int ctfs_access_readonly(vnode_t *, int, int, cred_t *,
		caller_context_t *);
extern int ctfs_access_readwrite(vnode_t *, int, int, cred_t *,
		caller_context_t *);
extern int ctfs_open(vnode_t **, int, cred_t *,
		caller_context_t *);

/*
 * vnode ops vector templates
 */
extern vnodeops_t *ctfs_ops_root;
extern vnodeops_t *ctfs_ops_adir;
extern vnodeops_t *ctfs_ops_sym;
extern vnodeops_t *ctfs_ops_tdir;
extern vnodeops_t *ctfs_ops_tmpl;
extern vnodeops_t *ctfs_ops_cdir;
extern vnodeops_t *ctfs_ops_ctl;
extern vnodeops_t *ctfs_ops_stat;
extern vnodeops_t *ctfs_ops_event;
extern vnodeops_t *ctfs_ops_bundle;
extern vnodeops_t *ctfs_ops_latest;

#ifdef	__cplusplus
}
#endif

#endif	/* _SYS_CTFS_IMPL_H */