xref: /onnv-gate/usr/src/uts/common/fs/ctfs/ctfs_tdir.c (revision 5331:3047ad28a67b)
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 /*
223898Srsb  * Copyright 2007 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 
590Sstevel@tonic-gate static int ctfs_tdir_do_readdir(vnode_t *, struct dirent64 *, int *, offset_t *,
600Sstevel@tonic-gate     offset_t *, void *);
61*5331Samw static int ctfs_tdir_do_lookup(vnode_t *, const char *, vnode_t **, ino64_t *,
62*5331Samw     cred_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 *
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
81*5331Samw ctfs_tdir_getattr(
82*5331Samw 	vnode_t *vp,
83*5331Samw 	vattr_t *vap,
84*5331Samw 	int flags,
85*5331Samw 	cred_t *cr,
86*5331Samw 	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
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
1100Sstevel@tonic-gate ctfs_tdir_do_readdir(vnode_t *vp, struct dirent64 *dp, int *eofp,
1110Sstevel@tonic-gate     offset_t *offp, offset_t *nextp, void *data)
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)];
1160Sstevel@tonic-gate 
117789Sahrens 	zuniqid = VTOZONE(vp)->zone_uniqid;
1180Sstevel@tonic-gate 	next = contract_type_lookup(ty, zuniqid, *offp);
1190Sstevel@tonic-gate 
1200Sstevel@tonic-gate 	if (next == -1) {
1210Sstevel@tonic-gate 		*eofp = 1;
1220Sstevel@tonic-gate 		return (0);
1230Sstevel@tonic-gate 	}
1240Sstevel@tonic-gate 
1250Sstevel@tonic-gate 	dp->d_ino = CTFS_INO_CT_DIR(next);
1260Sstevel@tonic-gate 	numtos(next, dp->d_name);
1270Sstevel@tonic-gate 	*offp = next;
1280Sstevel@tonic-gate 	*nextp = next + 1;
1290Sstevel@tonic-gate 
1300Sstevel@tonic-gate 	return (0);
1310Sstevel@tonic-gate }
1320Sstevel@tonic-gate 
133*5331Samw /* ARGSUSED */
1340Sstevel@tonic-gate static int
135*5331Samw ctfs_tdir_do_lookup(vnode_t *vp, const char *nm, vnode_t **vpp, ino64_t *inop,
136*5331Samw     cred_t *cr)
1370Sstevel@tonic-gate {
1380Sstevel@tonic-gate 	int i;
1390Sstevel@tonic-gate 	contract_t *ct;
1400Sstevel@tonic-gate 
1410Sstevel@tonic-gate 	i = stoi((char **)&nm);
1420Sstevel@tonic-gate 	if (*nm != '\0')
1430Sstevel@tonic-gate 		return (ENOENT);
1440Sstevel@tonic-gate 
1450Sstevel@tonic-gate 	ct = contract_type_ptr(ct_types[gfs_file_index(vp)], i,
146789Sahrens 	    VTOZONE(vp)->zone_uniqid);
1470Sstevel@tonic-gate 	if (ct == NULL)
1480Sstevel@tonic-gate 		return (ENOENT);
1490Sstevel@tonic-gate 
1500Sstevel@tonic-gate 	*vpp = ctfs_create_cdirnode(vp, ct);
1510Sstevel@tonic-gate 	*inop = gfs_file_inode(*vpp);
1520Sstevel@tonic-gate 	contract_rele(ct);
1530Sstevel@tonic-gate 	return (0);
1540Sstevel@tonic-gate }
1550Sstevel@tonic-gate 
1560Sstevel@tonic-gate const fs_operation_def_t ctfs_tops_tdir[] = {
1573898Srsb 	{ VOPNAME_OPEN,		{ .vop_open = ctfs_open } },
1583898Srsb 	{ VOPNAME_CLOSE,	{ .vop_close = ctfs_close } },
1593898Srsb 	{ VOPNAME_IOCTL,	{ .error = fs_inval } },
1603898Srsb 	{ VOPNAME_GETATTR,	{ .vop_getattr = ctfs_tdir_getattr } },
1613898Srsb 	{ VOPNAME_ACCESS,	{ .vop_access = ctfs_access_dir } },
1623898Srsb 	{ VOPNAME_READDIR,	{ .vop_readdir = gfs_vop_readdir } },
1633898Srsb 	{ VOPNAME_LOOKUP,	{ .vop_lookup = gfs_vop_lookup } },
1643898Srsb 	{ VOPNAME_SEEK,		{ .vop_seek = fs_seek } },
1653898Srsb 	{ VOPNAME_INACTIVE,	{ .vop_inactive = gfs_vop_inactive } },
1660Sstevel@tonic-gate 	{ NULL, NULL }
1670Sstevel@tonic-gate };
168