xref: /illumos-gate/usr/src/uts/common/fs/ctfs/ctfs_all.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 /*
22*ab04eb8eStimh  * Copyright 2008 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 #include <sys/pathname.h>
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate /*
467c478bd9Sstevel@tonic-gate  * CTFS routines for the /system/contract/all vnode.
477c478bd9Sstevel@tonic-gate  */
487c478bd9Sstevel@tonic-gate 
49b38f0970Sck153898 static int ctfs_adir_do_readdir(vnode_t *, void *, int *, offset_t *,
50b38f0970Sck153898     offset_t *, void *, int);
51da6c28aaSamw static int ctfs_adir_do_lookup(vnode_t *, const char *, vnode_t **, ino64_t *,
52*ab04eb8eStimh     cred_t *, int, int *, pathname_t *);
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate /*
557c478bd9Sstevel@tonic-gate  * ctfs_create_adirnode
567c478bd9Sstevel@tonic-gate  */
577c478bd9Sstevel@tonic-gate /* ARGSUSED */
587c478bd9Sstevel@tonic-gate vnode_t *
ctfs_create_adirnode(vnode_t * pvp)597c478bd9Sstevel@tonic-gate ctfs_create_adirnode(vnode_t *pvp)
607c478bd9Sstevel@tonic-gate {
617c478bd9Sstevel@tonic-gate 	vnode_t *vp = gfs_dir_create(sizeof (ctfs_adirnode_t), pvp,
627c478bd9Sstevel@tonic-gate 	    ctfs_ops_adir, NULL, NULL, CTFS_NAME_MAX, ctfs_adir_do_readdir,
637c478bd9Sstevel@tonic-gate 	    ctfs_adir_do_lookup);
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate 	return (vp);
667c478bd9Sstevel@tonic-gate }
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate /*
697c478bd9Sstevel@tonic-gate  * ctfs_adir_getattr - VOP_GETATTR entry point
707c478bd9Sstevel@tonic-gate  */
717c478bd9Sstevel@tonic-gate /* ARGSUSED */
727c478bd9Sstevel@tonic-gate static int
ctfs_adir_getattr(vnode_t * vp,vattr_t * vap,int flags,cred_t * cr,caller_context_t * ct)73da6c28aaSamw ctfs_adir_getattr(
74da6c28aaSamw 	vnode_t *vp,
75da6c28aaSamw 	vattr_t *vap,
76da6c28aaSamw 	int flags,
77da6c28aaSamw 	cred_t *cr,
78da6c28aaSamw 	caller_context_t *ct)
797c478bd9Sstevel@tonic-gate {
807c478bd9Sstevel@tonic-gate 	int i, total;
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate 	vap->va_type = VDIR;
837c478bd9Sstevel@tonic-gate 	vap->va_mode = 0555;
847c478bd9Sstevel@tonic-gate 	for (i = 0, total = 0; i < ct_ntypes; i++)
857c478bd9Sstevel@tonic-gate 		total += contract_type_count(ct_types[i]);
867c478bd9Sstevel@tonic-gate 	vap->va_nlink = 2;
877c478bd9Sstevel@tonic-gate 	vap->va_size = 2 + total;
887c478bd9Sstevel@tonic-gate 	vap->va_ctime.tv_sec = vp->v_vfsp->vfs_mtime;
897c478bd9Sstevel@tonic-gate 	vap->va_ctime.tv_nsec = 0;
907c478bd9Sstevel@tonic-gate 	vap->va_mtime = vap->va_atime = vap->va_ctime;
917c478bd9Sstevel@tonic-gate 	ctfs_common_getattr(vp, vap);
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate 	return (0);
947c478bd9Sstevel@tonic-gate }
957c478bd9Sstevel@tonic-gate 
96da6c28aaSamw /* ARGSUSED */
977c478bd9Sstevel@tonic-gate static int
ctfs_adir_do_lookup(vnode_t * vp,const char * nm,vnode_t ** vpp,ino64_t * inop,cred_t * cr,int flags,int * deflags,pathname_t * rpnp)98da6c28aaSamw ctfs_adir_do_lookup(vnode_t *vp, const char *nm, vnode_t **vpp, ino64_t *inop,
99*ab04eb8eStimh     cred_t *cr, int flags, int *deflags, pathname_t *rpnp)
1007c478bd9Sstevel@tonic-gate {
1017c478bd9Sstevel@tonic-gate 	int i;
1027c478bd9Sstevel@tonic-gate 	contract_t *ct;
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate 	i = stoi((char **)&nm);
1057c478bd9Sstevel@tonic-gate 	if (*nm != '\0')
1067c478bd9Sstevel@tonic-gate 		return (ENOENT);
1077c478bd9Sstevel@tonic-gate 
108fa9e4066Sahrens 	ct = contract_ptr(i, VTOZONE(vp)->zone_uniqid);
1097c478bd9Sstevel@tonic-gate 	if (ct == NULL)
1107c478bd9Sstevel@tonic-gate 		return (ENOENT);
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate 	*vpp = ctfs_create_symnode(vp, ct);
1137c478bd9Sstevel@tonic-gate 	*inop = CTFS_INO_CT_LINK(ct->ct_id);
1147c478bd9Sstevel@tonic-gate 	contract_rele(ct);
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate 	return (0);
1177c478bd9Sstevel@tonic-gate }
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate /* ARGSUSED */
1207c478bd9Sstevel@tonic-gate static int
ctfs_adir_do_readdir(vnode_t * vp,void * dp,int * eofp,offset_t * offp,offset_t * nextp,void * unused,int flags)121b38f0970Sck153898 ctfs_adir_do_readdir(vnode_t *vp, void *dp, int *eofp,
122b38f0970Sck153898     offset_t *offp, offset_t *nextp, void *unused, int flags)
1237c478bd9Sstevel@tonic-gate {
1247c478bd9Sstevel@tonic-gate 	uint64_t zuniqid;
1257c478bd9Sstevel@tonic-gate 	ctid_t next;
126b38f0970Sck153898 	struct dirent64 *odp = dp;
127b38f0970Sck153898 
128*ab04eb8eStimh 	ASSERT(!(flags & V_RDDIR_ENTFLAGS));
1297c478bd9Sstevel@tonic-gate 
130fa9e4066Sahrens 	zuniqid = VTOZONE(vp)->zone_uniqid;
1317c478bd9Sstevel@tonic-gate 	next = contract_lookup(zuniqid, *offp);
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate 	if (next == -1) {
1347c478bd9Sstevel@tonic-gate 		*eofp = 1;
1357c478bd9Sstevel@tonic-gate 		return (0);
1367c478bd9Sstevel@tonic-gate 	}
1377c478bd9Sstevel@tonic-gate 
138b38f0970Sck153898 	odp->d_ino = CTFS_INO_CT_LINK(next);
139b38f0970Sck153898 	numtos(next, odp->d_name);
1407c478bd9Sstevel@tonic-gate 	*offp = next;
1417c478bd9Sstevel@tonic-gate 	*nextp = next + 1;
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate 	return (0);
1447c478bd9Sstevel@tonic-gate }
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate const fs_operation_def_t ctfs_tops_adir[] = {
147aa59c4cbSrsb 	{ VOPNAME_OPEN,		{ .vop_open = ctfs_open } },
148aa59c4cbSrsb 	{ VOPNAME_CLOSE,	{ .vop_close = ctfs_close } },
149aa59c4cbSrsb 	{ VOPNAME_IOCTL,	{ .error = fs_inval } },
150aa59c4cbSrsb 	{ VOPNAME_GETATTR,	{ .vop_getattr = ctfs_adir_getattr } },
151aa59c4cbSrsb 	{ VOPNAME_ACCESS,	{ .vop_access = ctfs_access_dir } },
152aa59c4cbSrsb 	{ VOPNAME_READDIR,	{ .vop_readdir = gfs_vop_readdir } },
153aa59c4cbSrsb 	{ VOPNAME_LOOKUP,	{ .vop_lookup = gfs_vop_lookup } },
154aa59c4cbSrsb 	{ VOPNAME_SEEK,		{ .vop_seek = fs_seek } },
155aa59c4cbSrsb 	{ VOPNAME_INACTIVE,	{ .vop_inactive = gfs_vop_inactive } },
1567c478bd9Sstevel@tonic-gate 	{ NULL, NULL }
1577c478bd9Sstevel@tonic-gate };
158