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]
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>
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>
40 #include <sys/ctfs_impl.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.
54 ctfs_create_tmplnode(vnode_t
*pvp
)
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();
70 * ctfs_tmpl_open - fop_open entry point
72 * Just ensures the right mode bits are set.
76 ctfs_tmpl_open(vnode_t
**vpp
, int flag
, cred_t
*cr
, caller_context_t
*ct
)
78 if (flag
!= (FREAD
| FWRITE
))
85 * ctfs_tmpl_getattr - fop_getattr entry point
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
);
109 * ctfs_tmpl_ioctl - fop_ioctl entry point
111 * All the ct_tmpl_*(3contract) interfaces point here.
122 caller_context_t
*ct
)
124 ctfs_tmplnode_t
*tmplnode
= vp
->v_data
;
126 ct_param_t
*param
= &kparam
.param
;
132 ASSERT(tmplnode
->ctfs_tmn_tmpl
!= NULL
);
133 ctmpl_activate(tmplnode
->ctfs_tmn_tmpl
);
136 ASSERT(tmplnode
->ctfs_tmn_tmpl
!= NULL
);
137 ctmpl_clear(tmplnode
->ctfs_tmn_tmpl
);
140 ASSERT(tmplnode
->ctfs_tmn_tmpl
!= NULL
);
141 error
= ctmpl_create(tmplnode
->ctfs_tmn_tmpl
, &ctid
);
147 error
= ctparam_copyin((void *)arg
, &kparam
, flag
, cmd
);
150 error
= ctmpl_set(tmplnode
->ctfs_tmn_tmpl
, &kparam
, cr
);
151 kmem_free(kparam
.ctpm_kbuf
, param
->ctpm_size
);
155 error
= ctparam_copyin((void *)arg
, &kparam
, flag
, cmd
);
158 error
= ctmpl_get(tmplnode
->ctfs_tmn_tmpl
, &kparam
);
160 kmem_free(kparam
.ctpm_kbuf
, param
->ctpm_size
);
162 error
= ctparam_copyout(&kparam
, (void *)arg
, flag
);
174 * ctfs_tmpl_inactive - fop_inactive entry point
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
,