kill FOFFMAX / O_LARGEFILE
[unleashed/lotheac.git] / kernel / fs / ctfs / ctfs_tmpl.c
blobee0c985f5245f6dbf0818094c63e5495490e6f18
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #include <sys/types.h>
27 #include <sys/param.h>
28 #include <sys/time.h>
29 #include <sys/cred.h>
30 #include <sys/vfs.h>
31 #include <sys/gfs.h>
32 #include <sys/vnode.h>
33 #include <sys/systm.h>
34 #include <sys/errno.h>
35 #include <sys/sysmacros.h>
36 #include <sys/fs_subr.h>
37 #include <sys/contract.h>
38 #include <sys/contract_impl.h>
39 #include <sys/ctfs.h>
40 #include <sys/ctfs_impl.h>
41 #include <sys/file.h>
42 #include <sys/model.h>
45 * CTFS routines for the /system/contract/<type>/template vnode.
49 * ctfs_create_tmplnode
51 * Creates a new template and tdirnode, and returns the tdirnode.
53 vnode_t *
54 ctfs_create_tmplnode(vnode_t *pvp)
56 vnode_t *vp;
57 ctfs_tmplnode_t *tmplnode;
59 ASSERT(gfs_file_index(pvp) < ct_ntypes);
61 vp = gfs_file_create(sizeof (ctfs_tmplnode_t), pvp, &ctfs_ops_tmpl);
62 tmplnode = vp->v_data;
63 tmplnode->ctfs_tmn_tmpl =
64 ct_types[gfs_file_index(pvp)]->ct_type_default();
66 return (vp);
70 * ctfs_tmpl_open - fop_open entry point
72 * Just ensures the right mode bits are set.
74 /* ARGSUSED */
75 static int
76 ctfs_tmpl_open(vnode_t **vpp, int flag, cred_t *cr, caller_context_t *ct)
78 if (flag != (FREAD | FWRITE))
79 return (EINVAL);
81 return (0);
85 * ctfs_tmpl_getattr - fop_getattr entry point
87 /* ARGSUSED */
88 static int
89 ctfs_tmpl_getattr(
90 vnode_t *vp,
91 vattr_t *vap,
92 int flags,
93 cred_t *cr,
94 caller_context_t *ct)
96 vap->va_type = VREG;
97 vap->va_mode = 0666;
98 vap->va_nlink = 1;
99 vap->va_size = 0;
100 vap->va_ctime.tv_sec = vp->v_vfsp->vfs_mtime;
101 vap->va_ctime.tv_nsec = 0;
102 vap->va_atime = vap->va_mtime = vap->va_ctime;
103 ctfs_common_getattr(vp, vap);
105 return (0);
109 * ctfs_tmpl_ioctl - fop_ioctl entry point
111 * All the ct_tmpl_*(3contract) interfaces point here.
113 /* ARGSUSED */
114 static int
115 ctfs_tmpl_ioctl(
116 vnode_t *vp,
117 int cmd,
118 intptr_t arg,
119 int flag,
120 cred_t *cr,
121 int *rvalp,
122 caller_context_t *ct)
124 ctfs_tmplnode_t *tmplnode = vp->v_data;
125 ct_kparam_t kparam;
126 ct_param_t *param = &kparam.param;
127 ctid_t ctid;
128 int error;
130 switch (cmd) {
131 case CT_TACTIVATE:
132 ASSERT(tmplnode->ctfs_tmn_tmpl != NULL);
133 ctmpl_activate(tmplnode->ctfs_tmn_tmpl);
134 break;
135 case CT_TCLEAR:
136 ASSERT(tmplnode->ctfs_tmn_tmpl != NULL);
137 ctmpl_clear(tmplnode->ctfs_tmn_tmpl);
138 break;
139 case CT_TCREATE:
140 ASSERT(tmplnode->ctfs_tmn_tmpl != NULL);
141 error = ctmpl_create(tmplnode->ctfs_tmn_tmpl, &ctid);
142 if (error)
143 return (error);
144 *rvalp = ctid;
145 break;
146 case CT_TSET:
147 error = ctparam_copyin((void *)arg, &kparam, flag, cmd);
148 if (error != 0)
149 return (error);
150 error = ctmpl_set(tmplnode->ctfs_tmn_tmpl, &kparam, cr);
151 kmem_free(kparam.ctpm_kbuf, param->ctpm_size);
153 return (error);
154 case CT_TGET:
155 error = ctparam_copyin((void *)arg, &kparam, flag, cmd);
156 if (error != 0)
157 return (error);
158 error = ctmpl_get(tmplnode->ctfs_tmn_tmpl, &kparam);
159 if (error != 0) {
160 kmem_free(kparam.ctpm_kbuf, param->ctpm_size);
161 } else {
162 error = ctparam_copyout(&kparam, (void *)arg, flag);
165 return (error);
166 default:
167 return (EINVAL);
170 return (0);
174 * ctfs_tmpl_inactive - fop_inactive entry point
176 /* ARGSUSED */
177 static void
178 ctfs_tmpl_inactive(vnode_t *vp, cred_t *cr, caller_context_t *ct)
180 ctfs_tmplnode_t *tmplnode;
182 if ((tmplnode = gfs_file_inactive(vp)) != NULL) {
183 ctmpl_free(tmplnode->ctfs_tmn_tmpl);
184 kmem_free(tmplnode, sizeof (ctfs_tmplnode_t));
188 const struct vnodeops ctfs_ops_tmpl = {
189 .vnop_name = "ctfs template file",
190 .vop_open = ctfs_tmpl_open,
191 .vop_close = ctfs_close,
192 .vop_ioctl = ctfs_tmpl_ioctl,
193 .vop_getattr = ctfs_tmpl_getattr,
194 .vop_access = ctfs_access_readwrite,
195 .vop_readdir = fs_notdir,
196 .vop_lookup = fs_notdir,
197 .vop_inactive = ctfs_tmpl_inactive,