xref: /onnv-gate/usr/src/uts/common/fs/ctfs/ctfs_tdir.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  * Entries in a /system/contract/<type> directory.
490Sstevel@tonic-gate  */
500Sstevel@tonic-gate static gfs_dirent_t ctfs_tdir_dirents[] = {
510Sstevel@tonic-gate 	{ "bundle", ctfs_create_bundle },
520Sstevel@tonic-gate 	{ "pbundle", ctfs_create_pbundle },
530Sstevel@tonic-gate 	{ "template", ctfs_create_tmplnode },
540Sstevel@tonic-gate 	{ "latest", ctfs_create_latenode, GFS_CACHE_VNODE },
550Sstevel@tonic-gate 	{ NULL }
560Sstevel@tonic-gate };
570Sstevel@tonic-gate #define	CTFS_NSPECIALS	((sizeof ctfs_tdir_dirents / sizeof (gfs_dirent_t)) - 1)
580Sstevel@tonic-gate 
595663Sck153898 static int ctfs_tdir_do_readdir(vnode_t *, void *, int *, offset_t *,
605663Sck153898     offset_t *, void *, int);
615331Samw static int ctfs_tdir_do_lookup(vnode_t *, const char *, vnode_t **, ino64_t *,
62*6492Stimh     cred_t *, int, int *, pathname_t *);
630Sstevel@tonic-gate static ino64_t ctfs_tdir_do_inode(vnode_t *, int);
640Sstevel@tonic-gate 
650Sstevel@tonic-gate /*
660Sstevel@tonic-gate  * ctfs_create_tdirnode
670Sstevel@tonic-gate  */
680Sstevel@tonic-gate vnode_t *
ctfs_create_tdirnode(vnode_t * pvp)690Sstevel@tonic-gate ctfs_create_tdirnode(vnode_t *pvp)
700Sstevel@tonic-gate {
710Sstevel@tonic-gate 	return (gfs_dir_create(sizeof (ctfs_tdirnode_t), pvp, ctfs_ops_tdir,
720Sstevel@tonic-gate 	    ctfs_tdir_dirents, ctfs_tdir_do_inode, CTFS_NAME_MAX,
730Sstevel@tonic-gate 	    ctfs_tdir_do_readdir, ctfs_tdir_do_lookup));
740Sstevel@tonic-gate }
750Sstevel@tonic-gate 
760Sstevel@tonic-gate /*
770Sstevel@tonic-gate  * ctfs_tdir_getattr - VOP_GETATTR entry point
780Sstevel@tonic-gate  */
790Sstevel@tonic-gate /* ARGSUSED */
800Sstevel@tonic-gate static int
ctfs_tdir_getattr(vnode_t * vp,vattr_t * vap,int flags,cred_t * cr,caller_context_t * ct)815331Samw ctfs_tdir_getattr(
825331Samw 	vnode_t *vp,
835331Samw 	vattr_t *vap,
845331Samw 	int flags,
855331Samw 	cred_t *cr,
865331Samw 	caller_context_t *ct)
870Sstevel@tonic-gate {
880Sstevel@tonic-gate 	vap->va_type = VDIR;
890Sstevel@tonic-gate 	vap->va_mode = 0555;
900Sstevel@tonic-gate 	vap->va_nlink = 2 + CTFS_NSPECIALS;
910Sstevel@tonic-gate 	vap->va_size = vap->va_nlink +
920Sstevel@tonic-gate 	    contract_type_count(ct_types[gfs_file_index(vp)]);
930Sstevel@tonic-gate 	vap->va_ctime.tv_sec = vp->v_vfsp->vfs_mtime;
940Sstevel@tonic-gate 	vap->va_ctime.tv_nsec = 0;
950Sstevel@tonic-gate 	contract_type_time(ct_types[gfs_file_index(vp)], &vap->va_atime);
960Sstevel@tonic-gate 	vap->va_mtime = vap->va_atime;
970Sstevel@tonic-gate 	ctfs_common_getattr(vp, vap);
980Sstevel@tonic-gate 
990Sstevel@tonic-gate 	return (0);
1000Sstevel@tonic-gate }
1010Sstevel@tonic-gate 
1020Sstevel@tonic-gate static ino64_t
ctfs_tdir_do_inode(vnode_t * vp,int index)1030Sstevel@tonic-gate ctfs_tdir_do_inode(vnode_t *vp, int index)
1040Sstevel@tonic-gate {
1050Sstevel@tonic-gate 	return (CTFS_INO_TYPE_FILE(gfs_file_index(vp), index));
1060Sstevel@tonic-gate }
1070Sstevel@tonic-gate 
1080Sstevel@tonic-gate /* ARGSUSED */
1090Sstevel@tonic-gate static int
ctfs_tdir_do_readdir(vnode_t * vp,void * dp,int * eofp,offset_t * offp,offset_t * nextp,void * data,int flags)1105663Sck153898 ctfs_tdir_do_readdir(vnode_t *vp, void *dp, int *eofp,
1115663Sck153898     offset_t *offp, offset_t *nextp, void *data, int flags)
1120Sstevel@tonic-gate {
1130Sstevel@tonic-gate 	uint64_t zuniqid;
1140Sstevel@tonic-gate 	ctid_t next;
1150Sstevel@tonic-gate 	ct_type_t *ty = ct_types[gfs_file_index(vp)];
1165663Sck153898 	struct dirent64 *odp = dp;
1175663Sck153898 
118*6492Stimh 	ASSERT(!(flags & V_RDDIR_ENTFLAGS));
1190Sstevel@tonic-gate 
120789Sahrens 	zuniqid = VTOZONE(vp)->zone_uniqid;
1210Sstevel@tonic-gate 	next = contract_type_lookup(ty, zuniqid, *offp);
1220Sstevel@tonic-gate 
1230Sstevel@tonic-gate 	if (next == -1) {
1240Sstevel@tonic-gate 		*eofp = 1;
1250Sstevel@tonic-gate 		return (0);
1260Sstevel@tonic-gate 	}
1270Sstevel@tonic-gate 
1285663Sck153898 	odp->d_ino = CTFS_INO_CT_DIR(next);
1295663Sck153898 	numtos(next, odp->d_name);
1300Sstevel@tonic-gate 	*offp = next;
1310Sstevel@tonic-gate 	*nextp = next + 1;
1320Sstevel@tonic-gate 
1330Sstevel@tonic-gate 	return (0);
1340Sstevel@tonic-gate }
1350Sstevel@tonic-gate 
1365331Samw /* ARGSUSED */
1370Sstevel@tonic-gate static int
ctfs_tdir_do_lookup(vnode_t * vp,const char * nm,vnode_t ** vpp,ino64_t * inop,cred_t * cr,int flags,int * deflags,pathname_t * rpnp)1385331Samw ctfs_tdir_do_lookup(vnode_t *vp, const char *nm, vnode_t **vpp, ino64_t *inop,
139*6492Stimh     cred_t *cr, int flags, int *deflags, pathname_t *rpnp)
1400Sstevel@tonic-gate {
1410Sstevel@tonic-gate 	int i;
1420Sstevel@tonic-gate 	contract_t *ct;
1430Sstevel@tonic-gate 
1440Sstevel@tonic-gate 	i = stoi((char **)&nm);
1450Sstevel@tonic-gate 	if (*nm != '\0')
1460Sstevel@tonic-gate 		return (ENOENT);
1470Sstevel@tonic-gate 
1480Sstevel@tonic-gate 	ct = contract_type_ptr(ct_types[gfs_file_index(vp)], i,
149789Sahrens 	    VTOZONE(vp)->zone_uniqid);
1500Sstevel@tonic-gate 	if (ct == NULL)
1510Sstevel@tonic-gate 		return (ENOENT);
1520Sstevel@tonic-gate 
1530Sstevel@tonic-gate 	*vpp = ctfs_create_cdirnode(vp, ct);
1540Sstevel@tonic-gate 	*inop = gfs_file_inode(*vpp);
1550Sstevel@tonic-gate 	contract_rele(ct);
1560Sstevel@tonic-gate 	return (0);
1570Sstevel@tonic-gate }
1580Sstevel@tonic-gate 
1590Sstevel@tonic-gate const fs_operation_def_t ctfs_tops_tdir[] = {
1603898Srsb 	{ VOPNAME_OPEN,		{ .vop_open = ctfs_open } },
1613898Srsb 	{ VOPNAME_CLOSE,	{ .vop_close = ctfs_close } },
1623898Srsb 	{ VOPNAME_IOCTL,	{ .error = fs_inval } },
1633898Srsb 	{ VOPNAME_GETATTR,	{ .vop_getattr = ctfs_tdir_getattr } },
1643898Srsb 	{ VOPNAME_ACCESS,	{ .vop_access = ctfs_access_dir } },
1653898Srsb 	{ VOPNAME_READDIR,	{ .vop_readdir = gfs_vop_readdir } },
1663898Srsb 	{ VOPNAME_LOOKUP,	{ .vop_lookup = gfs_vop_lookup } },
1673898Srsb 	{ VOPNAME_SEEK,		{ .vop_seek = fs_seek } },
1683898Srsb 	{ VOPNAME_INACTIVE,	{ .vop_inactive = gfs_vop_inactive } },
1690Sstevel@tonic-gate 	{ NULL, NULL }
1700Sstevel@tonic-gate };
171