xref: /onnv-gate/usr/src/uts/common/fs/ctfs/ctfs_all.c (revision 6492:903545192033)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
53898Srsb  * Common Development and Distribution License (the "License").
63898Srsb  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*6492Stimh  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
270Sstevel@tonic-gate 
280Sstevel@tonic-gate #include <sys/types.h>
290Sstevel@tonic-gate #include <sys/param.h>
300Sstevel@tonic-gate #include <sys/time.h>
310Sstevel@tonic-gate #include <sys/cred.h>
320Sstevel@tonic-gate #include <sys/vfs.h>
333898Srsb #include <sys/vfs_opreg.h>
340Sstevel@tonic-gate #include <sys/gfs.h>
350Sstevel@tonic-gate #include <sys/vnode.h>
360Sstevel@tonic-gate #include <sys/systm.h>
370Sstevel@tonic-gate #include <sys/errno.h>
380Sstevel@tonic-gate #include <sys/sysmacros.h>
390Sstevel@tonic-gate #include <fs/fs_subr.h>
400Sstevel@tonic-gate #include <sys/contract.h>
410Sstevel@tonic-gate #include <sys/contract_impl.h>
420Sstevel@tonic-gate #include <sys/ctfs.h>
430Sstevel@tonic-gate #include <sys/ctfs_impl.h>
440Sstevel@tonic-gate #include <sys/file.h>
450Sstevel@tonic-gate #include <sys/pathname.h>
460Sstevel@tonic-gate 
470Sstevel@tonic-gate /*
480Sstevel@tonic-gate  * CTFS routines for the /system/contract/all vnode.
490Sstevel@tonic-gate  */
500Sstevel@tonic-gate 
515663Sck153898 static int ctfs_adir_do_readdir(vnode_t *, void *, int *, offset_t *,
525663Sck153898     offset_t *, void *, int);
535331Samw static int ctfs_adir_do_lookup(vnode_t *, const char *, vnode_t **, ino64_t *,
54*6492Stimh     cred_t *, int, int *, pathname_t *);
550Sstevel@tonic-gate 
560Sstevel@tonic-gate /*
570Sstevel@tonic-gate  * ctfs_create_adirnode
580Sstevel@tonic-gate  */
590Sstevel@tonic-gate /* ARGSUSED */
600Sstevel@tonic-gate vnode_t *
ctfs_create_adirnode(vnode_t * pvp)610Sstevel@tonic-gate ctfs_create_adirnode(vnode_t *pvp)
620Sstevel@tonic-gate {
630Sstevel@tonic-gate 	vnode_t *vp = gfs_dir_create(sizeof (ctfs_adirnode_t), pvp,
640Sstevel@tonic-gate 	    ctfs_ops_adir, NULL, NULL, CTFS_NAME_MAX, ctfs_adir_do_readdir,
650Sstevel@tonic-gate 	    ctfs_adir_do_lookup);
660Sstevel@tonic-gate 
670Sstevel@tonic-gate 	return (vp);
680Sstevel@tonic-gate }
690Sstevel@tonic-gate 
700Sstevel@tonic-gate /*
710Sstevel@tonic-gate  * ctfs_adir_getattr - VOP_GETATTR entry point
720Sstevel@tonic-gate  */
730Sstevel@tonic-gate /* ARGSUSED */
740Sstevel@tonic-gate static int
ctfs_adir_getattr(vnode_t * vp,vattr_t * vap,int flags,cred_t * cr,caller_context_t * ct)755331Samw ctfs_adir_getattr(
765331Samw 	vnode_t *vp,
775331Samw 	vattr_t *vap,
785331Samw 	int flags,
795331Samw 	cred_t *cr,
805331Samw 	caller_context_t *ct)
810Sstevel@tonic-gate {
820Sstevel@tonic-gate 	int i, total;
830Sstevel@tonic-gate 
840Sstevel@tonic-gate 	vap->va_type = VDIR;
850Sstevel@tonic-gate 	vap->va_mode = 0555;
860Sstevel@tonic-gate 	for (i = 0, total = 0; i < ct_ntypes; i++)
870Sstevel@tonic-gate 		total += contract_type_count(ct_types[i]);
880Sstevel@tonic-gate 	vap->va_nlink = 2;
890Sstevel@tonic-gate 	vap->va_size = 2 + total;
900Sstevel@tonic-gate 	vap->va_ctime.tv_sec = vp->v_vfsp->vfs_mtime;
910Sstevel@tonic-gate 	vap->va_ctime.tv_nsec = 0;
920Sstevel@tonic-gate 	vap->va_mtime = vap->va_atime = vap->va_ctime;
930Sstevel@tonic-gate 	ctfs_common_getattr(vp, vap);
940Sstevel@tonic-gate 
950Sstevel@tonic-gate 	return (0);
960Sstevel@tonic-gate }
970Sstevel@tonic-gate 
985331Samw /* ARGSUSED */
990Sstevel@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)1005331Samw ctfs_adir_do_lookup(vnode_t *vp, const char *nm, vnode_t **vpp, ino64_t *inop,
101*6492Stimh     cred_t *cr, int flags, int *deflags, pathname_t *rpnp)
1020Sstevel@tonic-gate {
1030Sstevel@tonic-gate 	int i;
1040Sstevel@tonic-gate 	contract_t *ct;
1050Sstevel@tonic-gate 
1060Sstevel@tonic-gate 	i = stoi((char **)&nm);
1070Sstevel@tonic-gate 	if (*nm != '\0')
1080Sstevel@tonic-gate 		return (ENOENT);
1090Sstevel@tonic-gate 
110789Sahrens 	ct = contract_ptr(i, VTOZONE(vp)->zone_uniqid);
1110Sstevel@tonic-gate 	if (ct == NULL)
1120Sstevel@tonic-gate 		return (ENOENT);
1130Sstevel@tonic-gate 
1140Sstevel@tonic-gate 	*vpp = ctfs_create_symnode(vp, ct);
1150Sstevel@tonic-gate 	*inop = CTFS_INO_CT_LINK(ct->ct_id);
1160Sstevel@tonic-gate 	contract_rele(ct);
1170Sstevel@tonic-gate 
1180Sstevel@tonic-gate 	return (0);
1190Sstevel@tonic-gate }
1200Sstevel@tonic-gate 
1210Sstevel@tonic-gate /* ARGSUSED */
1220Sstevel@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)1235663Sck153898 ctfs_adir_do_readdir(vnode_t *vp, void *dp, int *eofp,
1245663Sck153898     offset_t *offp, offset_t *nextp, void *unused, int flags)
1250Sstevel@tonic-gate {
1260Sstevel@tonic-gate 	uint64_t zuniqid;
1270Sstevel@tonic-gate 	ctid_t next;
1285663Sck153898 	struct dirent64 *odp = dp;
1295663Sck153898 
130*6492Stimh 	ASSERT(!(flags & V_RDDIR_ENTFLAGS));
1310Sstevel@tonic-gate 
132789Sahrens 	zuniqid = VTOZONE(vp)->zone_uniqid;
1330Sstevel@tonic-gate 	next = contract_lookup(zuniqid, *offp);
1340Sstevel@tonic-gate 
1350Sstevel@tonic-gate 	if (next == -1) {
1360Sstevel@tonic-gate 		*eofp = 1;
1370Sstevel@tonic-gate 		return (0);
1380Sstevel@tonic-gate 	}
1390Sstevel@tonic-gate 
1405663Sck153898 	odp->d_ino = CTFS_INO_CT_LINK(next);
1415663Sck153898 	numtos(next, odp->d_name);
1420Sstevel@tonic-gate 	*offp = next;
1430Sstevel@tonic-gate 	*nextp = next + 1;
1440Sstevel@tonic-gate 
1450Sstevel@tonic-gate 	return (0);
1460Sstevel@tonic-gate }
1470Sstevel@tonic-gate 
1480Sstevel@tonic-gate const fs_operation_def_t ctfs_tops_adir[] = {
1493898Srsb 	{ VOPNAME_OPEN,		{ .vop_open = ctfs_open } },
1503898Srsb 	{ VOPNAME_CLOSE,	{ .vop_close = ctfs_close } },
1513898Srsb 	{ VOPNAME_IOCTL,	{ .error = fs_inval } },
1523898Srsb 	{ VOPNAME_GETATTR,	{ .vop_getattr = ctfs_adir_getattr } },
1533898Srsb 	{ VOPNAME_ACCESS,	{ .vop_access = ctfs_access_dir } },
1543898Srsb 	{ VOPNAME_READDIR,	{ .vop_readdir = gfs_vop_readdir } },
1553898Srsb 	{ VOPNAME_LOOKUP,	{ .vop_lookup = gfs_vop_lookup } },
1563898Srsb 	{ VOPNAME_SEEK,		{ .vop_seek = fs_seek } },
1573898Srsb 	{ VOPNAME_INACTIVE,	{ .vop_inactive = gfs_vop_inactive } },
1580Sstevel@tonic-gate 	{ NULL, NULL }
1590Sstevel@tonic-gate };
160