Home | History | Annotate | Download | only in ctfs
      1     0    stevel /*
      2     0    stevel  * CDDL HEADER START
      3     0    stevel  *
      4     0    stevel  * The contents of this file are subject to the terms of the
      5  3898       rsb  * Common Development and Distribution License (the "License").
      6  3898       rsb  * You may not use this file except in compliance with the License.
      7     0    stevel  *
      8     0    stevel  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
      9     0    stevel  * or http://www.opensolaris.org/os/licensing.
     10     0    stevel  * See the License for the specific language governing permissions
     11     0    stevel  * and limitations under the License.
     12     0    stevel  *
     13     0    stevel  * When distributing Covered Code, include this CDDL HEADER in each
     14     0    stevel  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     15     0    stevel  * If applicable, add the following below this CDDL HEADER, with the
     16     0    stevel  * fields enclosed by brackets "[]" replaced with your own identifying
     17     0    stevel  * information: Portions Copyright [yyyy] [name of copyright owner]
     18     0    stevel  *
     19     0    stevel  * CDDL HEADER END
     20     0    stevel  */
     21     0    stevel /*
     22  6492      timh  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
     23     0    stevel  * Use is subject to license terms.
     24     0    stevel  */
     25     0    stevel 
     26     0    stevel #pragma ident	"%Z%%M%	%I%	%E% SMI"
     27     0    stevel 
     28     0    stevel #include <sys/types.h>
     29     0    stevel #include <sys/param.h>
     30     0    stevel #include <sys/time.h>
     31     0    stevel #include <sys/cred.h>
     32     0    stevel #include <sys/vfs.h>
     33  3898       rsb #include <sys/vfs_opreg.h>
     34     0    stevel #include <sys/gfs.h>
     35     0    stevel #include <sys/vnode.h>
     36     0    stevel #include <sys/systm.h>
     37     0    stevel #include <sys/errno.h>
     38     0    stevel #include <sys/sysmacros.h>
     39     0    stevel #include <fs/fs_subr.h>
     40     0    stevel #include <sys/contract.h>
     41     0    stevel #include <sys/contract_impl.h>
     42     0    stevel #include <sys/ctfs.h>
     43     0    stevel #include <sys/ctfs_impl.h>
     44     0    stevel #include <sys/file.h>
     45     0    stevel #include <sys/pathname.h>
     46     0    stevel 
     47     0    stevel /*
     48     0    stevel  * Entries in a /system/contract/<type> directory.
     49     0    stevel  */
     50     0    stevel static gfs_dirent_t ctfs_tdir_dirents[] = {
     51     0    stevel 	{ "bundle", ctfs_create_bundle },
     52     0    stevel 	{ "pbundle", ctfs_create_pbundle },
     53     0    stevel 	{ "template", ctfs_create_tmplnode },
     54     0    stevel 	{ "latest", ctfs_create_latenode, GFS_CACHE_VNODE },
     55     0    stevel 	{ NULL }
     56     0    stevel };
     57     0    stevel #define	CTFS_NSPECIALS	((sizeof ctfs_tdir_dirents / sizeof (gfs_dirent_t)) - 1)
     58     0    stevel 
     59  5663  ck153898 static int ctfs_tdir_do_readdir(vnode_t *, void *, int *, offset_t *,
     60  5663  ck153898     offset_t *, void *, int);
     61  5331       amw static int ctfs_tdir_do_lookup(vnode_t *, const char *, vnode_t **, ino64_t *,
     62  6492      timh     cred_t *, int, int *, pathname_t *);
     63     0    stevel static ino64_t ctfs_tdir_do_inode(vnode_t *, int);
     64     0    stevel 
     65     0    stevel /*
     66     0    stevel  * ctfs_create_tdirnode
     67     0    stevel  */
     68     0    stevel vnode_t *
     69     0    stevel ctfs_create_tdirnode(vnode_t *pvp)
     70     0    stevel {
     71     0    stevel 	return (gfs_dir_create(sizeof (ctfs_tdirnode_t), pvp, ctfs_ops_tdir,
     72     0    stevel 	    ctfs_tdir_dirents, ctfs_tdir_do_inode, CTFS_NAME_MAX,
     73     0    stevel 	    ctfs_tdir_do_readdir, ctfs_tdir_do_lookup));
     74     0    stevel }
     75     0    stevel 
     76     0    stevel /*
     77     0    stevel  * ctfs_tdir_getattr - VOP_GETATTR entry point
     78     0    stevel  */
     79     0    stevel /* ARGSUSED */
     80     0    stevel static int
     81  5331       amw ctfs_tdir_getattr(
     82  5331       amw 	vnode_t *vp,
     83  5331       amw 	vattr_t *vap,
     84  5331       amw 	int flags,
     85  5331       amw 	cred_t *cr,
     86  5331       amw 	caller_context_t *ct)
     87     0    stevel {
     88     0    stevel 	vap->va_type = VDIR;
     89     0    stevel 	vap->va_mode = 0555;
     90     0    stevel 	vap->va_nlink = 2 + CTFS_NSPECIALS;
     91     0    stevel 	vap->va_size = vap->va_nlink +
     92     0    stevel 	    contract_type_count(ct_types[gfs_file_index(vp)]);
     93     0    stevel 	vap->va_ctime.tv_sec = vp->v_vfsp->vfs_mtime;
     94     0    stevel 	vap->va_ctime.tv_nsec = 0;
     95     0    stevel 	contract_type_time(ct_types[gfs_file_index(vp)], &vap->va_atime);
     96     0    stevel 	vap->va_mtime = vap->va_atime;
     97     0    stevel 	ctfs_common_getattr(vp, vap);
     98     0    stevel 
     99     0    stevel 	return (0);
    100     0    stevel }
    101     0    stevel 
    102     0    stevel static ino64_t
    103     0    stevel ctfs_tdir_do_inode(vnode_t *vp, int index)
    104     0    stevel {
    105     0    stevel 	return (CTFS_INO_TYPE_FILE(gfs_file_index(vp), index));
    106     0    stevel }
    107     0    stevel 
    108     0    stevel /* ARGSUSED */
    109     0    stevel static int
    110  5663  ck153898 ctfs_tdir_do_readdir(vnode_t *vp, void *dp, int *eofp,
    111  5663  ck153898     offset_t *offp, offset_t *nextp, void *data, int flags)
    112     0    stevel {
    113     0    stevel 	uint64_t zuniqid;
    114     0    stevel 	ctid_t next;
    115     0    stevel 	ct_type_t *ty = ct_types[gfs_file_index(vp)];
    116  5663  ck153898 	struct dirent64 *odp = dp;
    117  5663  ck153898 
    118  6492      timh 	ASSERT(!(flags & V_RDDIR_ENTFLAGS));
    119     0    stevel 
    120   789    ahrens 	zuniqid = VTOZONE(vp)->zone_uniqid;
    121     0    stevel 	next = contract_type_lookup(ty, zuniqid, *offp);
    122     0    stevel 
    123     0    stevel 	if (next == -1) {
    124     0    stevel 		*eofp = 1;
    125     0    stevel 		return (0);
    126     0    stevel 	}
    127     0    stevel 
    128  5663  ck153898 	odp->d_ino = CTFS_INO_CT_DIR(next);
    129  5663  ck153898 	numtos(next, odp->d_name);
    130     0    stevel 	*offp = next;
    131     0    stevel 	*nextp = next + 1;
    132     0    stevel 
    133     0    stevel 	return (0);
    134     0    stevel }
    135     0    stevel 
    136  5331       amw /* ARGSUSED */
    137     0    stevel static int
    138  5331       amw ctfs_tdir_do_lookup(vnode_t *vp, const char *nm, vnode_t **vpp, ino64_t *inop,
    139  6492      timh     cred_t *cr, int flags, int *deflags, pathname_t *rpnp)
    140     0    stevel {
    141     0    stevel 	int i;
    142     0    stevel 	contract_t *ct;
    143     0    stevel 
    144     0    stevel 	i = stoi((char **)&nm);
    145     0    stevel 	if (*nm != '\0')
    146     0    stevel 		return (ENOENT);
    147     0    stevel 
    148     0    stevel 	ct = contract_type_ptr(ct_types[gfs_file_index(vp)], i,
    149   789    ahrens 	    VTOZONE(vp)->zone_uniqid);
    150     0    stevel 	if (ct == NULL)
    151     0    stevel 		return (ENOENT);
    152     0    stevel 
    153     0    stevel 	*vpp = ctfs_create_cdirnode(vp, ct);
    154     0    stevel 	*inop = gfs_file_inode(*vpp);
    155     0    stevel 	contract_rele(ct);
    156     0    stevel 	return (0);
    157     0    stevel }
    158     0    stevel 
    159     0    stevel const fs_operation_def_t ctfs_tops_tdir[] = {
    160  3898       rsb 	{ VOPNAME_OPEN,		{ .vop_open = ctfs_open } },
    161  3898       rsb 	{ VOPNAME_CLOSE,	{ .vop_close = ctfs_close } },
    162  3898       rsb 	{ VOPNAME_IOCTL,	{ .error = fs_inval } },
    163  3898       rsb 	{ VOPNAME_GETATTR,	{ .vop_getattr = ctfs_tdir_getattr } },
    164  3898       rsb 	{ VOPNAME_ACCESS,	{ .vop_access = ctfs_access_dir } },
    165  3898       rsb 	{ VOPNAME_READDIR,	{ .vop_readdir = gfs_vop_readdir } },
    166  3898       rsb 	{ VOPNAME_LOOKUP,	{ .vop_lookup = gfs_vop_lookup } },
    167  3898       rsb 	{ VOPNAME_SEEK,		{ .vop_seek = fs_seek } },
    168  3898       rsb 	{ VOPNAME_INACTIVE,	{ .vop_inactive = gfs_vop_inactive } },
    169     0    stevel 	{ NULL, NULL }
    170     0    stevel };
    171