xref: /illumos-gate/usr/src/uts/common/fs/ctfs/ctfs_ctl.c (revision 2d6eb4a5)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5aa59c4cbSrsb  * Common Development and Distribution License (the "License").
6aa59c4cbSrsb  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22aa59c4cbSrsb  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #include <sys/types.h>
277c478bd9Sstevel@tonic-gate #include <sys/param.h>
287c478bd9Sstevel@tonic-gate #include <sys/time.h>
297c478bd9Sstevel@tonic-gate #include <sys/cred.h>
307c478bd9Sstevel@tonic-gate #include <sys/vfs.h>
31aa59c4cbSrsb #include <sys/vfs_opreg.h>
327c478bd9Sstevel@tonic-gate #include <sys/gfs.h>
337c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
347c478bd9Sstevel@tonic-gate #include <sys/systm.h>
357c478bd9Sstevel@tonic-gate #include <sys/errno.h>
367c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
377c478bd9Sstevel@tonic-gate #include <fs/fs_subr.h>
387c478bd9Sstevel@tonic-gate #include <sys/contract.h>
397c478bd9Sstevel@tonic-gate #include <sys/contract_impl.h>
407c478bd9Sstevel@tonic-gate #include <sys/ctfs.h>
417c478bd9Sstevel@tonic-gate #include <sys/ctfs_impl.h>
427c478bd9Sstevel@tonic-gate #include <sys/file.h>
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate /*
457c478bd9Sstevel@tonic-gate  * CTFS routines for the /system/contract/<type>/<ctid>/ctl vnode.
467c478bd9Sstevel@tonic-gate  * CTFS routines for the /system/contract/<type>/<ctid>/status vnode.
477c478bd9Sstevel@tonic-gate  */
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate /*
507c478bd9Sstevel@tonic-gate  * ctfs_create_ctlnode
517c478bd9Sstevel@tonic-gate  *
527c478bd9Sstevel@tonic-gate  * If necessary, creates a ctlnode for a ctl file and inserts it into
537c478bd9Sstevel@tonic-gate  * the specified cdirnode's gfs_dir_t.  Returns either the existing
547c478bd9Sstevel@tonic-gate  * vnode or the new one.
557c478bd9Sstevel@tonic-gate  */
567c478bd9Sstevel@tonic-gate vnode_t *
ctfs_create_ctlnode(vnode_t * pvp)577c478bd9Sstevel@tonic-gate ctfs_create_ctlnode(vnode_t *pvp)
587c478bd9Sstevel@tonic-gate {
597c478bd9Sstevel@tonic-gate 	ctfs_ctlnode_t *ctlnode;
607c478bd9Sstevel@tonic-gate 	ctfs_cdirnode_t *cdirnode = pvp->v_data;
617c478bd9Sstevel@tonic-gate 	vnode_t *vp;
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate 	vp = gfs_file_create(sizeof (ctfs_ctlnode_t), pvp, ctfs_ops_ctl);
647c478bd9Sstevel@tonic-gate 	ctlnode = vp->v_data;
657c478bd9Sstevel@tonic-gate 	/*
667c478bd9Sstevel@tonic-gate 	 * We transitively have a hold on the contract through our
677c478bd9Sstevel@tonic-gate 	 * parent directory.
687c478bd9Sstevel@tonic-gate 	 */
697c478bd9Sstevel@tonic-gate 	ctlnode->ctfs_ctl_contract = cdirnode->ctfs_cn_contract;
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate 	return (vp);
727c478bd9Sstevel@tonic-gate }
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate /*
757c478bd9Sstevel@tonic-gate  * ctfs_ctl_access - VOP_ACCESS entry point
767c478bd9Sstevel@tonic-gate  *
777c478bd9Sstevel@tonic-gate  * You only get to access ctl files for contracts you own or were
787c478bd9Sstevel@tonic-gate  * abandoned and inherited by your containing process contract.
797c478bd9Sstevel@tonic-gate  */
807c478bd9Sstevel@tonic-gate /* ARGSUSED */
817c478bd9Sstevel@tonic-gate static int
ctfs_ctl_access(vnode_t * vp,int mode,int flags,cred_t * cr,caller_context_t * cct)82*da6c28aaSamw ctfs_ctl_access(
83*da6c28aaSamw 	vnode_t *vp,
84*da6c28aaSamw 	int mode,
85*da6c28aaSamw 	int flags,
86*da6c28aaSamw 	cred_t *cr,
87*da6c28aaSamw 	caller_context_t *cct)
887c478bd9Sstevel@tonic-gate {
897c478bd9Sstevel@tonic-gate 	ctfs_ctlnode_t *ctlnode = vp->v_data;
907c478bd9Sstevel@tonic-gate 	contract_t *ct = ctlnode->ctfs_ctl_contract;
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate 	if (mode & (VEXEC | VREAD))
937c478bd9Sstevel@tonic-gate 		return (EACCES);
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate 	mutex_enter(&ct->ct_lock);
967c478bd9Sstevel@tonic-gate 	if ((curproc == ct->ct_owner) ||
977c478bd9Sstevel@tonic-gate 	    (ct->ct_owner == NULL && ct->ct_regent != NULL &&
987c478bd9Sstevel@tonic-gate 	    ct->ct_regent->ct_data == curproc->p_ct_process)) {
997c478bd9Sstevel@tonic-gate 		mutex_exit(&ct->ct_lock);
1007c478bd9Sstevel@tonic-gate 		return (0);
1017c478bd9Sstevel@tonic-gate 	}
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate 	mutex_exit(&ct->ct_lock);
1047c478bd9Sstevel@tonic-gate 	return (EACCES);
1057c478bd9Sstevel@tonic-gate }
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate /*
1087c478bd9Sstevel@tonic-gate  * ctfs_ctl_open - VOP_OPEN entry point
1097c478bd9Sstevel@tonic-gate  *
1107c478bd9Sstevel@tonic-gate  * Just checks to make sure the mode bits are set, and that the
1117c478bd9Sstevel@tonic-gate  * constraints imposed by ctfs_ctl_access are met.
1127c478bd9Sstevel@tonic-gate  */
1137c478bd9Sstevel@tonic-gate static int
ctfs_ctl_open(vnode_t ** vpp,int flag,cred_t * cr,caller_context_t * ct)114*da6c28aaSamw ctfs_ctl_open(vnode_t **vpp, int flag, cred_t *cr, caller_context_t *ct)
1157c478bd9Sstevel@tonic-gate {
1167c478bd9Sstevel@tonic-gate 	if (flag != (FWRITE | FOFFMAX))
1177c478bd9Sstevel@tonic-gate 		return (EINVAL);
1187c478bd9Sstevel@tonic-gate 
119*da6c28aaSamw 	return (ctfs_ctl_access(*vpp, VWRITE, 0, cr, ct));
1207c478bd9Sstevel@tonic-gate }
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate /*
123567faccaSacruz  * ctfs_ctl_common_getattr
124*da6c28aaSamw  * Implements functionality common to ctl and status ctfs VOP_GETATTR
125567faccaSacruz  * entry points. It assumes vp->v_data is set
1267c478bd9Sstevel@tonic-gate  */
1277c478bd9Sstevel@tonic-gate static int
ctfs_ctl_common_getattr(vnode_t * vp,vattr_t * vap)128964da2a9Sacruz ctfs_ctl_common_getattr(vnode_t *vp, vattr_t *vap)
1297c478bd9Sstevel@tonic-gate {
1307c478bd9Sstevel@tonic-gate 	ctfs_ctlnode_t *ctlnode = vp->v_data;
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate 	vap->va_type = VREG;
1337c478bd9Sstevel@tonic-gate 	vap->va_nlink = 1;
1347c478bd9Sstevel@tonic-gate 	vap->va_size = 0;
1357c478bd9Sstevel@tonic-gate 	vap->va_ctime = ctlnode->ctfs_ctl_contract->ct_ctime;
1367c478bd9Sstevel@tonic-gate 	mutex_enter(&ctlnode->ctfs_ctl_contract->ct_events.ctq_lock);
1377c478bd9Sstevel@tonic-gate 	vap->va_atime = vap->va_mtime =
1387c478bd9Sstevel@tonic-gate 	    ctlnode->ctfs_ctl_contract->ct_events.ctq_atime;
1397c478bd9Sstevel@tonic-gate 	mutex_exit(&ctlnode->ctfs_ctl_contract->ct_events.ctq_lock);
1407c478bd9Sstevel@tonic-gate 	ctfs_common_getattr(vp, vap);
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate 	return (0);
1437c478bd9Sstevel@tonic-gate }
1447c478bd9Sstevel@tonic-gate 
145567faccaSacruz /*
146567faccaSacruz  * ctfs_ctl_getattr - VOP_GETATTR entry point
147567faccaSacruz  */
148567faccaSacruz /* ARGSUSED */
149567faccaSacruz static int
ctfs_ctl_getattr(vnode_t * vp,vattr_t * vap,int flags,cred_t * cr,caller_context_t * ct)150*da6c28aaSamw ctfs_ctl_getattr(vnode_t *vp, vattr_t *vap, int flags,
151*da6c28aaSamw     cred_t *cr, caller_context_t *ct)
152567faccaSacruz {
153567faccaSacruz 	vap->va_mode = 0222;
154567faccaSacruz 
155964da2a9Sacruz 	return (ctfs_ctl_common_getattr(vp, vap));
156567faccaSacruz }
157567faccaSacruz 
158567faccaSacruz /*
159567faccaSacruz  * ctfs_stat_getattr - VOP_GETATTR entry point
160567faccaSacruz  */
161567faccaSacruz /* ARGSUSED */
162567faccaSacruz static int
ctfs_stat_getattr(vnode_t * vp,vattr_t * vap,int flags,cred_t * cr,caller_context_t * ct)163*da6c28aaSamw ctfs_stat_getattr(vnode_t *vp, vattr_t *vap, int flags, cred_t *cr,
164*da6c28aaSamw     caller_context_t *ct)
165567faccaSacruz {
166567faccaSacruz 	vap->va_mode = 0444;
167567faccaSacruz 
168964da2a9Sacruz 	return (ctfs_ctl_common_getattr(vp, vap));
169567faccaSacruz }
170567faccaSacruz 
1717c478bd9Sstevel@tonic-gate /*
1727c478bd9Sstevel@tonic-gate  * ctfs_ctl_ioctl - VOP_IOCTL entry point
1737c478bd9Sstevel@tonic-gate  *
1747c478bd9Sstevel@tonic-gate  * All the ct_ctl_*(3contract) interfaces point here.
1757c478bd9Sstevel@tonic-gate  */
1767c478bd9Sstevel@tonic-gate /* ARGSUSED */
1777c478bd9Sstevel@tonic-gate static int
ctfs_ctl_ioctl(vnode_t * vp,int cmd,intptr_t arg,int flag,cred_t * cr,int * rvalp,caller_context_t * cct)178*da6c28aaSamw ctfs_ctl_ioctl(
179*da6c28aaSamw 	vnode_t *vp,
180*da6c28aaSamw 	int cmd,
181*da6c28aaSamw 	intptr_t arg,
182*da6c28aaSamw 	int flag,
183*da6c28aaSamw 	cred_t *cr,
184*da6c28aaSamw 	int *rvalp,
185*da6c28aaSamw 	caller_context_t *cct)
1867c478bd9Sstevel@tonic-gate {
1877c478bd9Sstevel@tonic-gate 	ctfs_ctlnode_t	*ctlnode = vp->v_data;
1887c478bd9Sstevel@tonic-gate 	contract_t	*ct = ctlnode->ctfs_ctl_contract;
1897c478bd9Sstevel@tonic-gate 	int		error = 0;
1907c478bd9Sstevel@tonic-gate 	uint64_t	event;
19125e8c5aaSvikram 	int		ack;
1927c478bd9Sstevel@tonic-gate 
1937c478bd9Sstevel@tonic-gate 	switch (cmd) {
1947c478bd9Sstevel@tonic-gate 	case CT_CABANDON:
1957c478bd9Sstevel@tonic-gate 		error = contract_abandon(ct, curproc, 1);
1967c478bd9Sstevel@tonic-gate 		break;
1977c478bd9Sstevel@tonic-gate 
1987c478bd9Sstevel@tonic-gate 	case CT_CACK:
19925e8c5aaSvikram 	case CT_CNACK:
2007c478bd9Sstevel@tonic-gate 		if (copyin((void *)arg, &event, sizeof (uint64_t)))
2017c478bd9Sstevel@tonic-gate 			return (EFAULT);
20225e8c5aaSvikram 		ack = (cmd == CT_CACK) ? CT_ACK : CT_NACK;
20325e8c5aaSvikram 		error = contract_ack(ct, event, ack);
2047c478bd9Sstevel@tonic-gate 		break;
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate 	case CT_CNEWCT:
20725e8c5aaSvikram 		error = contract_newct(ct);
2087c478bd9Sstevel@tonic-gate 		break;
2097c478bd9Sstevel@tonic-gate 
2107c478bd9Sstevel@tonic-gate 	case CT_CQREQ:
21125e8c5aaSvikram 		if (copyin((void *)arg, &event, sizeof (uint64_t)))
21225e8c5aaSvikram 			return (EFAULT);
21325e8c5aaSvikram 		error = contract_qack(ct, event);
2147c478bd9Sstevel@tonic-gate 		break;
2157c478bd9Sstevel@tonic-gate 
2167c478bd9Sstevel@tonic-gate 	case CT_CADOPT:
2177c478bd9Sstevel@tonic-gate 		error = contract_adopt(ct, curproc);
2187c478bd9Sstevel@tonic-gate 		break;
2197c478bd9Sstevel@tonic-gate 
2207c478bd9Sstevel@tonic-gate 	default:
2217c478bd9Sstevel@tonic-gate 		return (EINVAL);
2227c478bd9Sstevel@tonic-gate 	}
2237c478bd9Sstevel@tonic-gate 
2247c478bd9Sstevel@tonic-gate 	return (error);
2257c478bd9Sstevel@tonic-gate }
2267c478bd9Sstevel@tonic-gate 
2277c478bd9Sstevel@tonic-gate const fs_operation_def_t ctfs_tops_ctl[] = {
228aa59c4cbSrsb 	{ VOPNAME_OPEN,		{ .vop_open = ctfs_ctl_open } },
229aa59c4cbSrsb 	{ VOPNAME_CLOSE,	{ .vop_close = ctfs_close } },
230aa59c4cbSrsb 	{ VOPNAME_IOCTL,	{ .vop_ioctl = ctfs_ctl_ioctl } },
231aa59c4cbSrsb 	{ VOPNAME_GETATTR,	{ .vop_getattr = ctfs_ctl_getattr } },
232aa59c4cbSrsb 	{ VOPNAME_ACCESS,	{ .vop_access = ctfs_ctl_access } },
233aa59c4cbSrsb 	{ VOPNAME_READDIR,	{ .error = fs_notdir } },
234aa59c4cbSrsb 	{ VOPNAME_LOOKUP,	{ .error = fs_notdir } },
235aa59c4cbSrsb 	{ VOPNAME_INACTIVE,	{ .vop_inactive = gfs_vop_inactive } },
2367c478bd9Sstevel@tonic-gate 	{ NULL, NULL }
2377c478bd9Sstevel@tonic-gate };
2387c478bd9Sstevel@tonic-gate 
2397c478bd9Sstevel@tonic-gate /*
2407c478bd9Sstevel@tonic-gate  * ctfs_create_statnode
2417c478bd9Sstevel@tonic-gate  *
2427c478bd9Sstevel@tonic-gate  * If necessary, creates a ctlnode for a status file and inserts it
2437c478bd9Sstevel@tonic-gate  * into the specified cdirnode's gfs_dir_t.  Returns either the
2447c478bd9Sstevel@tonic-gate  * existing vnode or the new one.
2457c478bd9Sstevel@tonic-gate  */
2467c478bd9Sstevel@tonic-gate vnode_t *
ctfs_create_statnode(vnode_t * pvp)2477c478bd9Sstevel@tonic-gate ctfs_create_statnode(vnode_t *pvp)
2487c478bd9Sstevel@tonic-gate {
2497c478bd9Sstevel@tonic-gate 	vnode_t *vp;
2507c478bd9Sstevel@tonic-gate 	ctfs_cdirnode_t *cdirnode = pvp->v_data;
2517c478bd9Sstevel@tonic-gate 	ctfs_ctlnode_t *ctlnode;
2527c478bd9Sstevel@tonic-gate 
2537c478bd9Sstevel@tonic-gate 	vp = gfs_file_create(sizeof (ctfs_ctlnode_t), pvp, ctfs_ops_stat);
2547c478bd9Sstevel@tonic-gate 	ctlnode = vp->v_data;
2557c478bd9Sstevel@tonic-gate 	/*
2567c478bd9Sstevel@tonic-gate 	 * We transitively have a hold on the contract through our
2577c478bd9Sstevel@tonic-gate 	 * parent directory.
2587c478bd9Sstevel@tonic-gate 	 */
2597c478bd9Sstevel@tonic-gate 	ctlnode->ctfs_ctl_contract = cdirnode->ctfs_cn_contract;
2607c478bd9Sstevel@tonic-gate 
2617c478bd9Sstevel@tonic-gate 	return (vp);
2627c478bd9Sstevel@tonic-gate }
2637c478bd9Sstevel@tonic-gate 
2647c478bd9Sstevel@tonic-gate /*
2657c478bd9Sstevel@tonic-gate  * ctfs_stat_ioctl - VOP_IOCTL entry point
2667c478bd9Sstevel@tonic-gate  *
2677c478bd9Sstevel@tonic-gate  * The kernel half of ct_status_read(3contract).
2687c478bd9Sstevel@tonic-gate  */
2697c478bd9Sstevel@tonic-gate /* ARGSUSED */
2707c478bd9Sstevel@tonic-gate static int
ctfs_stat_ioctl(vnode_t * vp,int cmd,intptr_t arg,int flag,cred_t * cr,int * rvalp,caller_context_t * cct)271*da6c28aaSamw ctfs_stat_ioctl(
272*da6c28aaSamw 	vnode_t *vp,
273*da6c28aaSamw 	int cmd,
274*da6c28aaSamw 	intptr_t arg,
275*da6c28aaSamw 	int flag,
276*da6c28aaSamw 	cred_t *cr,
277*da6c28aaSamw 	int *rvalp,
278*da6c28aaSamw 	caller_context_t *cct)
2797c478bd9Sstevel@tonic-gate {
2807c478bd9Sstevel@tonic-gate 	ctfs_ctlnode_t	*statnode = vp->v_data;
2817c478bd9Sstevel@tonic-gate 	contract_t	*ct = statnode->ctfs_ctl_contract;
2827c478bd9Sstevel@tonic-gate 	ct_type_t	*type = ct->ct_type;
2837c478bd9Sstevel@tonic-gate 	STRUCT_DECL(ct_status, st);
2847c478bd9Sstevel@tonic-gate 	nvlist_t	*foo;
2857c478bd9Sstevel@tonic-gate 	char		*bufp = NULL;
2867c478bd9Sstevel@tonic-gate 	size_t		len;
2877c478bd9Sstevel@tonic-gate 	model_t		mdl = get_udatamodel();
2887c478bd9Sstevel@tonic-gate 	uint_t		detail;
2897c478bd9Sstevel@tonic-gate 
2907c478bd9Sstevel@tonic-gate 	STRUCT_INIT(st, mdl);
2917c478bd9Sstevel@tonic-gate 
2927c478bd9Sstevel@tonic-gate 	if (cmd != CT_SSTATUS)
2937c478bd9Sstevel@tonic-gate 		return (EINVAL);
2947c478bd9Sstevel@tonic-gate 
2957c478bd9Sstevel@tonic-gate 	if (copyin((void *)arg, STRUCT_BUF(st), STRUCT_SIZE(st)))
2967c478bd9Sstevel@tonic-gate 		return (EFAULT);
2977c478bd9Sstevel@tonic-gate 	detail = STRUCT_FGET(st, ctst_detail);
2987c478bd9Sstevel@tonic-gate 	if (detail == CTD_COMMON) {
2997c478bd9Sstevel@tonic-gate 		mutex_enter(&ct->ct_lock);
300fa9e4066Sahrens 		contract_status_common(ct, VTOZONE(vp), STRUCT_BUF(st), mdl);
3017c478bd9Sstevel@tonic-gate 		mutex_exit(&ct->ct_lock);
3027c478bd9Sstevel@tonic-gate 	} else if (detail <= CTD_ALL) {
3037c478bd9Sstevel@tonic-gate 		VERIFY(nvlist_alloc(&foo, NV_UNIQUE_NAME, KM_SLEEP) == 0);
304fa9e4066Sahrens 		type->ct_type_ops->contop_status(ct, VTOZONE(vp), detail, foo,
3057c478bd9Sstevel@tonic-gate 		    STRUCT_BUF(st), mdl);
3067c478bd9Sstevel@tonic-gate 		VERIFY(nvlist_pack(foo, &bufp, &len, NV_ENCODE_NATIVE,
3077c478bd9Sstevel@tonic-gate 		    KM_SLEEP) == 0);
3087c478bd9Sstevel@tonic-gate 		nvlist_free(foo);
3097c478bd9Sstevel@tonic-gate 
3107c478bd9Sstevel@tonic-gate 		if ((len <= STRUCT_FGET(st, ctst_nbytes)) &&
3117c478bd9Sstevel@tonic-gate 		    (copyout(bufp, STRUCT_FGETP(st, ctst_buffer), len) == -1)) {
3127c478bd9Sstevel@tonic-gate 			kmem_free(bufp, len);
3137c478bd9Sstevel@tonic-gate 			return (EFAULT);
3147c478bd9Sstevel@tonic-gate 		}
3157c478bd9Sstevel@tonic-gate 		kmem_free(bufp, len);
3167c478bd9Sstevel@tonic-gate 		STRUCT_FSET(st, ctst_nbytes, len);
3177c478bd9Sstevel@tonic-gate 	} else {
3187c478bd9Sstevel@tonic-gate 		return (EINVAL);
3197c478bd9Sstevel@tonic-gate 	}
3207c478bd9Sstevel@tonic-gate 	if (copyout(STRUCT_BUF(st), (void *)arg, STRUCT_SIZE(st)))
3217c478bd9Sstevel@tonic-gate 		return (EFAULT);
3227c478bd9Sstevel@tonic-gate 
3237c478bd9Sstevel@tonic-gate 	return (0);
3247c478bd9Sstevel@tonic-gate }
3257c478bd9Sstevel@tonic-gate 
3267c478bd9Sstevel@tonic-gate const fs_operation_def_t ctfs_tops_stat[] = {
327aa59c4cbSrsb 	{ VOPNAME_OPEN,		{ .vop_open = ctfs_open } },
328aa59c4cbSrsb 	{ VOPNAME_CLOSE,	{ .vop_close = ctfs_close } },
329aa59c4cbSrsb 	{ VOPNAME_IOCTL,	{ .vop_ioctl = ctfs_stat_ioctl } },
330567faccaSacruz 	{ VOPNAME_GETATTR,	{ .vop_getattr = ctfs_stat_getattr } },
331aa59c4cbSrsb 	{ VOPNAME_ACCESS,	{ .vop_access = ctfs_access_readonly } },
332aa59c4cbSrsb 	{ VOPNAME_READDIR,	{ .error = fs_notdir } },
333aa59c4cbSrsb 	{ VOPNAME_LOOKUP,	{ .error = fs_notdir } },
334aa59c4cbSrsb 	{ VOPNAME_INACTIVE,	{ .vop_inactive = gfs_vop_inactive } },
3357c478bd9Sstevel@tonic-gate 	{ NULL, NULL }
3367c478bd9Sstevel@tonic-gate };
337