xref: /onnv-gate/usr/src/uts/common/fs/ctfs/ctfs_all.c (revision 789:b348f31ed315)
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
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
220Sstevel@tonic-gate /*
230Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #include <sys/types.h>
300Sstevel@tonic-gate #include <sys/param.h>
310Sstevel@tonic-gate #include <sys/time.h>
320Sstevel@tonic-gate #include <sys/cred.h>
330Sstevel@tonic-gate #include <sys/vfs.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 
510Sstevel@tonic-gate static int ctfs_adir_do_readdir(vnode_t *, struct dirent64 *, int *, offset_t *,
520Sstevel@tonic-gate     offset_t *, void *);
530Sstevel@tonic-gate static int ctfs_adir_do_lookup(vnode_t *, const char *, vnode_t **, ino64_t *);
540Sstevel@tonic-gate 
550Sstevel@tonic-gate /*
560Sstevel@tonic-gate  * ctfs_create_adirnode
570Sstevel@tonic-gate  */
580Sstevel@tonic-gate /* ARGSUSED */
590Sstevel@tonic-gate vnode_t *
600Sstevel@tonic-gate ctfs_create_adirnode(vnode_t *pvp)
610Sstevel@tonic-gate {
620Sstevel@tonic-gate 	vnode_t *vp = gfs_dir_create(sizeof (ctfs_adirnode_t), pvp,
630Sstevel@tonic-gate 	    ctfs_ops_adir, NULL, NULL, CTFS_NAME_MAX, ctfs_adir_do_readdir,
640Sstevel@tonic-gate 	    ctfs_adir_do_lookup);
650Sstevel@tonic-gate 
660Sstevel@tonic-gate 	return (vp);
670Sstevel@tonic-gate }
680Sstevel@tonic-gate 
690Sstevel@tonic-gate /*
700Sstevel@tonic-gate  * ctfs_adir_getattr - VOP_GETATTR entry point
710Sstevel@tonic-gate  */
720Sstevel@tonic-gate /* ARGSUSED */
730Sstevel@tonic-gate static int
740Sstevel@tonic-gate ctfs_adir_getattr(vnode_t *vp, vattr_t *vap, int flags, cred_t *cr)
750Sstevel@tonic-gate {
760Sstevel@tonic-gate 	int i, total;
770Sstevel@tonic-gate 
780Sstevel@tonic-gate 	vap->va_type = VDIR;
790Sstevel@tonic-gate 	vap->va_mode = 0555;
800Sstevel@tonic-gate 	for (i = 0, total = 0; i < ct_ntypes; i++)
810Sstevel@tonic-gate 		total += contract_type_count(ct_types[i]);
820Sstevel@tonic-gate 	vap->va_nlink = 2;
830Sstevel@tonic-gate 	vap->va_size = 2 + total;
840Sstevel@tonic-gate 	vap->va_ctime.tv_sec = vp->v_vfsp->vfs_mtime;
850Sstevel@tonic-gate 	vap->va_ctime.tv_nsec = 0;
860Sstevel@tonic-gate 	vap->va_mtime = vap->va_atime = vap->va_ctime;
870Sstevel@tonic-gate 	ctfs_common_getattr(vp, vap);
880Sstevel@tonic-gate 
890Sstevel@tonic-gate 	return (0);
900Sstevel@tonic-gate }
910Sstevel@tonic-gate 
920Sstevel@tonic-gate static int
930Sstevel@tonic-gate ctfs_adir_do_lookup(vnode_t *vp, const char *nm, vnode_t **vpp, ino64_t *inop)
940Sstevel@tonic-gate {
950Sstevel@tonic-gate 	int i;
960Sstevel@tonic-gate 	contract_t *ct;
970Sstevel@tonic-gate 
980Sstevel@tonic-gate 	i = stoi((char **)&nm);
990Sstevel@tonic-gate 	if (*nm != '\0')
1000Sstevel@tonic-gate 		return (ENOENT);
1010Sstevel@tonic-gate 
102*789Sahrens 	ct = contract_ptr(i, VTOZONE(vp)->zone_uniqid);
1030Sstevel@tonic-gate 	if (ct == NULL)
1040Sstevel@tonic-gate 		return (ENOENT);
1050Sstevel@tonic-gate 
1060Sstevel@tonic-gate 	*vpp = ctfs_create_symnode(vp, ct);
1070Sstevel@tonic-gate 	*inop = CTFS_INO_CT_LINK(ct->ct_id);
1080Sstevel@tonic-gate 	contract_rele(ct);
1090Sstevel@tonic-gate 
1100Sstevel@tonic-gate 	return (0);
1110Sstevel@tonic-gate }
1120Sstevel@tonic-gate 
1130Sstevel@tonic-gate /* ARGSUSED */
1140Sstevel@tonic-gate static int
1150Sstevel@tonic-gate ctfs_adir_do_readdir(vnode_t *vp, struct dirent64 *dp, int *eofp,
1160Sstevel@tonic-gate     offset_t *offp, offset_t *nextp, void *unused)
1170Sstevel@tonic-gate {
1180Sstevel@tonic-gate 	uint64_t zuniqid;
1190Sstevel@tonic-gate 	ctid_t next;
1200Sstevel@tonic-gate 
121*789Sahrens 	zuniqid = VTOZONE(vp)->zone_uniqid;
1220Sstevel@tonic-gate 	next = contract_lookup(zuniqid, *offp);
1230Sstevel@tonic-gate 
1240Sstevel@tonic-gate 	if (next == -1) {
1250Sstevel@tonic-gate 		*eofp = 1;
1260Sstevel@tonic-gate 		return (0);
1270Sstevel@tonic-gate 	}
1280Sstevel@tonic-gate 
1290Sstevel@tonic-gate 	dp->d_ino = CTFS_INO_CT_LINK(next);
1300Sstevel@tonic-gate 	numtos(next, dp->d_name);
1310Sstevel@tonic-gate 	*offp = next;
1320Sstevel@tonic-gate 	*nextp = next + 1;
1330Sstevel@tonic-gate 
1340Sstevel@tonic-gate 	return (0);
1350Sstevel@tonic-gate }
1360Sstevel@tonic-gate 
1370Sstevel@tonic-gate const fs_operation_def_t ctfs_tops_adir[] = {
1380Sstevel@tonic-gate 	{ VOPNAME_OPEN,		ctfs_open },
1390Sstevel@tonic-gate 	{ VOPNAME_CLOSE,	ctfs_close },
1400Sstevel@tonic-gate 	{ VOPNAME_IOCTL,	fs_inval },
1410Sstevel@tonic-gate 	{ VOPNAME_GETATTR,	ctfs_adir_getattr },
1420Sstevel@tonic-gate 	{ VOPNAME_ACCESS,	ctfs_access_dir },
1430Sstevel@tonic-gate 	{ VOPNAME_READDIR,	gfs_vop_readdir },
1440Sstevel@tonic-gate 	{ VOPNAME_LOOKUP,	gfs_vop_lookup },
1450Sstevel@tonic-gate 	{ VOPNAME_SEEK,		fs_seek },
1460Sstevel@tonic-gate 	{ VOPNAME_INACTIVE,	(fs_generic_func_p) gfs_vop_inactive },
1470Sstevel@tonic-gate 	{ NULL, NULL }
1480Sstevel@tonic-gate };
149