1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*0Sstevel@tonic-gate 29*0Sstevel@tonic-gate #include <sys/types.h> 30*0Sstevel@tonic-gate #include <sys/param.h> 31*0Sstevel@tonic-gate #include <sys/time.h> 32*0Sstevel@tonic-gate #include <sys/cred.h> 33*0Sstevel@tonic-gate #include <sys/vfs.h> 34*0Sstevel@tonic-gate #include <sys/gfs.h> 35*0Sstevel@tonic-gate #include <sys/vnode.h> 36*0Sstevel@tonic-gate #include <sys/systm.h> 37*0Sstevel@tonic-gate #include <sys/errno.h> 38*0Sstevel@tonic-gate #include <sys/sysmacros.h> 39*0Sstevel@tonic-gate #include <fs/fs_subr.h> 40*0Sstevel@tonic-gate #include <sys/contract.h> 41*0Sstevel@tonic-gate #include <sys/contract_impl.h> 42*0Sstevel@tonic-gate #include <sys/ctfs.h> 43*0Sstevel@tonic-gate #include <sys/ctfs_impl.h> 44*0Sstevel@tonic-gate #include <sys/file.h> 45*0Sstevel@tonic-gate 46*0Sstevel@tonic-gate /* 47*0Sstevel@tonic-gate * CTFS routines for the /system/contract/<type>/template vnode. 48*0Sstevel@tonic-gate */ 49*0Sstevel@tonic-gate 50*0Sstevel@tonic-gate /* 51*0Sstevel@tonic-gate * ctfs_create_tmplnode 52*0Sstevel@tonic-gate * 53*0Sstevel@tonic-gate * Creates a new template and tdirnode, and returns the tdirnode. 54*0Sstevel@tonic-gate */ 55*0Sstevel@tonic-gate vnode_t * 56*0Sstevel@tonic-gate ctfs_create_tmplnode(vnode_t *pvp) 57*0Sstevel@tonic-gate { 58*0Sstevel@tonic-gate vnode_t *vp; 59*0Sstevel@tonic-gate ctfs_tmplnode_t *tmplnode; 60*0Sstevel@tonic-gate 61*0Sstevel@tonic-gate ASSERT(gfs_file_index(pvp) < ct_ntypes); 62*0Sstevel@tonic-gate 63*0Sstevel@tonic-gate vp = gfs_file_create(sizeof (ctfs_tmplnode_t), pvp, ctfs_ops_tmpl); 64*0Sstevel@tonic-gate tmplnode = vp->v_data; 65*0Sstevel@tonic-gate tmplnode->ctfs_tmn_tmpl = 66*0Sstevel@tonic-gate ct_types[gfs_file_index(pvp)]->ct_type_default(); 67*0Sstevel@tonic-gate 68*0Sstevel@tonic-gate return (vp); 69*0Sstevel@tonic-gate } 70*0Sstevel@tonic-gate 71*0Sstevel@tonic-gate /* 72*0Sstevel@tonic-gate * ctfs_tmpl_open - VOP_OPEN entry point 73*0Sstevel@tonic-gate * 74*0Sstevel@tonic-gate * Just ensures the right mode bits are set. 75*0Sstevel@tonic-gate */ 76*0Sstevel@tonic-gate /* ARGSUSED */ 77*0Sstevel@tonic-gate static int 78*0Sstevel@tonic-gate ctfs_tmpl_open(vnode_t **vpp, int flag, cred_t *cr) 79*0Sstevel@tonic-gate { 80*0Sstevel@tonic-gate if (flag != (FREAD | FWRITE | FOFFMAX)) 81*0Sstevel@tonic-gate return (EINVAL); 82*0Sstevel@tonic-gate 83*0Sstevel@tonic-gate return (0); 84*0Sstevel@tonic-gate } 85*0Sstevel@tonic-gate 86*0Sstevel@tonic-gate /* 87*0Sstevel@tonic-gate * ctfs_tmpl_getattr - VOP_GETATTR entry point 88*0Sstevel@tonic-gate */ 89*0Sstevel@tonic-gate /* ARGSUSED */ 90*0Sstevel@tonic-gate static int 91*0Sstevel@tonic-gate ctfs_tmpl_getattr(vnode_t *vp, vattr_t *vap, int flags, cred_t *cr) 92*0Sstevel@tonic-gate { 93*0Sstevel@tonic-gate vap->va_type = VREG; 94*0Sstevel@tonic-gate vap->va_mode = 0666; 95*0Sstevel@tonic-gate vap->va_nlink = 1; 96*0Sstevel@tonic-gate vap->va_size = 0; 97*0Sstevel@tonic-gate vap->va_ctime.tv_sec = vp->v_vfsp->vfs_mtime; 98*0Sstevel@tonic-gate vap->va_ctime.tv_nsec = 0; 99*0Sstevel@tonic-gate vap->va_atime = vap->va_mtime = vap->va_ctime; 100*0Sstevel@tonic-gate ctfs_common_getattr(vp, vap); 101*0Sstevel@tonic-gate 102*0Sstevel@tonic-gate return (0); 103*0Sstevel@tonic-gate } 104*0Sstevel@tonic-gate 105*0Sstevel@tonic-gate /* 106*0Sstevel@tonic-gate * ctfs_tmpl_ioctl - VOP_IOCTL entry point 107*0Sstevel@tonic-gate * 108*0Sstevel@tonic-gate * All the ct_tmpl_*(3contract) interfaces point here. 109*0Sstevel@tonic-gate */ 110*0Sstevel@tonic-gate /* ARGSUSED */ 111*0Sstevel@tonic-gate static int 112*0Sstevel@tonic-gate ctfs_tmpl_ioctl(vnode_t *vp, int cmd, intptr_t arg, int flag, cred_t *cr, 113*0Sstevel@tonic-gate int *rvalp) 114*0Sstevel@tonic-gate { 115*0Sstevel@tonic-gate ctfs_tmplnode_t *tmplnode = vp->v_data; 116*0Sstevel@tonic-gate ct_param_t param; 117*0Sstevel@tonic-gate int error; 118*0Sstevel@tonic-gate 119*0Sstevel@tonic-gate switch (cmd) { 120*0Sstevel@tonic-gate case CT_TACTIVATE: 121*0Sstevel@tonic-gate ASSERT(tmplnode->ctfs_tmn_tmpl != NULL); 122*0Sstevel@tonic-gate ctmpl_activate(tmplnode->ctfs_tmn_tmpl); 123*0Sstevel@tonic-gate break; 124*0Sstevel@tonic-gate case CT_TCLEAR: 125*0Sstevel@tonic-gate ASSERT(tmplnode->ctfs_tmn_tmpl != NULL); 126*0Sstevel@tonic-gate ctmpl_clear(tmplnode->ctfs_tmn_tmpl); 127*0Sstevel@tonic-gate break; 128*0Sstevel@tonic-gate case CT_TCREATE: 129*0Sstevel@tonic-gate ASSERT(tmplnode->ctfs_tmn_tmpl != NULL); 130*0Sstevel@tonic-gate return (ctmpl_create(tmplnode->ctfs_tmn_tmpl)); 131*0Sstevel@tonic-gate case CT_TSET: 132*0Sstevel@tonic-gate if (copyin((void *)arg, ¶m, sizeof (ct_param_t))) 133*0Sstevel@tonic-gate return (EFAULT); 134*0Sstevel@tonic-gate return (ctmpl_set(tmplnode->ctfs_tmn_tmpl, ¶m, cr)); 135*0Sstevel@tonic-gate case CT_TGET: 136*0Sstevel@tonic-gate if (copyin((void *)arg, ¶m, sizeof (ct_param_t))) 137*0Sstevel@tonic-gate return (EFAULT); 138*0Sstevel@tonic-gate error = ctmpl_get(tmplnode->ctfs_tmn_tmpl, ¶m); 139*0Sstevel@tonic-gate if (error) 140*0Sstevel@tonic-gate return (error); 141*0Sstevel@tonic-gate if (copyout(¶m, (void *)arg, sizeof (ct_param_t))) 142*0Sstevel@tonic-gate return (EFAULT); 143*0Sstevel@tonic-gate break; 144*0Sstevel@tonic-gate default: 145*0Sstevel@tonic-gate return (EINVAL); 146*0Sstevel@tonic-gate } 147*0Sstevel@tonic-gate 148*0Sstevel@tonic-gate return (0); 149*0Sstevel@tonic-gate } 150*0Sstevel@tonic-gate 151*0Sstevel@tonic-gate /* 152*0Sstevel@tonic-gate * ctfs_tmpl_inactive - VOP_INACTIVE entry point 153*0Sstevel@tonic-gate */ 154*0Sstevel@tonic-gate /* ARGSUSED */ 155*0Sstevel@tonic-gate static void 156*0Sstevel@tonic-gate ctfs_tmpl_inactive(vnode_t *vp, cred_t *cr) 157*0Sstevel@tonic-gate { 158*0Sstevel@tonic-gate ctfs_tmplnode_t *tmplnode; 159*0Sstevel@tonic-gate 160*0Sstevel@tonic-gate if ((tmplnode = gfs_file_inactive(vp)) != NULL) { 161*0Sstevel@tonic-gate ctmpl_free(tmplnode->ctfs_tmn_tmpl); 162*0Sstevel@tonic-gate kmem_free(tmplnode, sizeof (ctfs_tmplnode_t)); 163*0Sstevel@tonic-gate } 164*0Sstevel@tonic-gate } 165*0Sstevel@tonic-gate 166*0Sstevel@tonic-gate const fs_operation_def_t ctfs_tops_tmpl[] = { 167*0Sstevel@tonic-gate { VOPNAME_OPEN, ctfs_tmpl_open }, 168*0Sstevel@tonic-gate { VOPNAME_CLOSE, ctfs_close }, 169*0Sstevel@tonic-gate { VOPNAME_IOCTL, ctfs_tmpl_ioctl }, 170*0Sstevel@tonic-gate { VOPNAME_GETATTR, ctfs_tmpl_getattr }, 171*0Sstevel@tonic-gate { VOPNAME_ACCESS, ctfs_access_readwrite }, 172*0Sstevel@tonic-gate { VOPNAME_READDIR, fs_notdir }, 173*0Sstevel@tonic-gate { VOPNAME_LOOKUP, fs_notdir }, 174*0Sstevel@tonic-gate { VOPNAME_INACTIVE, (fs_generic_func_p) ctfs_tmpl_inactive }, 175*0Sstevel@tonic-gate { NULL, NULL } 176*0Sstevel@tonic-gate }; 177