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 #include <sys/pathname.h> 46*0Sstevel@tonic-gate 47*0Sstevel@tonic-gate /* 48*0Sstevel@tonic-gate * Entries in a /system/contract/<type> directory. 49*0Sstevel@tonic-gate */ 50*0Sstevel@tonic-gate static gfs_dirent_t ctfs_tdir_dirents[] = { 51*0Sstevel@tonic-gate { "bundle", ctfs_create_bundle }, 52*0Sstevel@tonic-gate { "pbundle", ctfs_create_pbundle }, 53*0Sstevel@tonic-gate { "template", ctfs_create_tmplnode }, 54*0Sstevel@tonic-gate { "latest", ctfs_create_latenode, GFS_CACHE_VNODE }, 55*0Sstevel@tonic-gate { NULL } 56*0Sstevel@tonic-gate }; 57*0Sstevel@tonic-gate #define CTFS_NSPECIALS ((sizeof ctfs_tdir_dirents / sizeof (gfs_dirent_t)) - 1) 58*0Sstevel@tonic-gate 59*0Sstevel@tonic-gate static int ctfs_tdir_do_readdir(vnode_t *, struct dirent64 *, int *, offset_t *, 60*0Sstevel@tonic-gate offset_t *, void *); 61*0Sstevel@tonic-gate static int ctfs_tdir_do_lookup(vnode_t *, const char *, vnode_t **, ino64_t *); 62*0Sstevel@tonic-gate static ino64_t ctfs_tdir_do_inode(vnode_t *, int); 63*0Sstevel@tonic-gate 64*0Sstevel@tonic-gate /* 65*0Sstevel@tonic-gate * ctfs_create_tdirnode 66*0Sstevel@tonic-gate */ 67*0Sstevel@tonic-gate vnode_t * 68*0Sstevel@tonic-gate ctfs_create_tdirnode(vnode_t *pvp) 69*0Sstevel@tonic-gate { 70*0Sstevel@tonic-gate return (gfs_dir_create(sizeof (ctfs_tdirnode_t), pvp, ctfs_ops_tdir, 71*0Sstevel@tonic-gate ctfs_tdir_dirents, ctfs_tdir_do_inode, CTFS_NAME_MAX, 72*0Sstevel@tonic-gate ctfs_tdir_do_readdir, ctfs_tdir_do_lookup)); 73*0Sstevel@tonic-gate } 74*0Sstevel@tonic-gate 75*0Sstevel@tonic-gate /* 76*0Sstevel@tonic-gate * ctfs_tdir_getattr - VOP_GETATTR entry point 77*0Sstevel@tonic-gate */ 78*0Sstevel@tonic-gate /* ARGSUSED */ 79*0Sstevel@tonic-gate static int 80*0Sstevel@tonic-gate ctfs_tdir_getattr(vnode_t *vp, vattr_t *vap, int flags, cred_t *cr) 81*0Sstevel@tonic-gate { 82*0Sstevel@tonic-gate vap->va_type = VDIR; 83*0Sstevel@tonic-gate vap->va_mode = 0555; 84*0Sstevel@tonic-gate vap->va_nlink = 2 + CTFS_NSPECIALS; 85*0Sstevel@tonic-gate vap->va_size = vap->va_nlink + 86*0Sstevel@tonic-gate contract_type_count(ct_types[gfs_file_index(vp)]); 87*0Sstevel@tonic-gate vap->va_ctime.tv_sec = vp->v_vfsp->vfs_mtime; 88*0Sstevel@tonic-gate vap->va_ctime.tv_nsec = 0; 89*0Sstevel@tonic-gate contract_type_time(ct_types[gfs_file_index(vp)], &vap->va_atime); 90*0Sstevel@tonic-gate vap->va_mtime = vap->va_atime; 91*0Sstevel@tonic-gate ctfs_common_getattr(vp, vap); 92*0Sstevel@tonic-gate 93*0Sstevel@tonic-gate return (0); 94*0Sstevel@tonic-gate } 95*0Sstevel@tonic-gate 96*0Sstevel@tonic-gate static ino64_t 97*0Sstevel@tonic-gate ctfs_tdir_do_inode(vnode_t *vp, int index) 98*0Sstevel@tonic-gate { 99*0Sstevel@tonic-gate return (CTFS_INO_TYPE_FILE(gfs_file_index(vp), index)); 100*0Sstevel@tonic-gate } 101*0Sstevel@tonic-gate 102*0Sstevel@tonic-gate /* ARGSUSED */ 103*0Sstevel@tonic-gate static int 104*0Sstevel@tonic-gate ctfs_tdir_do_readdir(vnode_t *vp, struct dirent64 *dp, int *eofp, 105*0Sstevel@tonic-gate offset_t *offp, offset_t *nextp, void *data) 106*0Sstevel@tonic-gate { 107*0Sstevel@tonic-gate uint64_t zuniqid; 108*0Sstevel@tonic-gate ctid_t next; 109*0Sstevel@tonic-gate ct_type_t *ty = ct_types[gfs_file_index(vp)]; 110*0Sstevel@tonic-gate 111*0Sstevel@tonic-gate zuniqid = VTOZ(vp)->zone_uniqid; 112*0Sstevel@tonic-gate next = contract_type_lookup(ty, zuniqid, *offp); 113*0Sstevel@tonic-gate 114*0Sstevel@tonic-gate if (next == -1) { 115*0Sstevel@tonic-gate *eofp = 1; 116*0Sstevel@tonic-gate return (0); 117*0Sstevel@tonic-gate } 118*0Sstevel@tonic-gate 119*0Sstevel@tonic-gate dp->d_ino = CTFS_INO_CT_DIR(next); 120*0Sstevel@tonic-gate numtos(next, dp->d_name); 121*0Sstevel@tonic-gate *offp = next; 122*0Sstevel@tonic-gate *nextp = next + 1; 123*0Sstevel@tonic-gate 124*0Sstevel@tonic-gate return (0); 125*0Sstevel@tonic-gate } 126*0Sstevel@tonic-gate 127*0Sstevel@tonic-gate static int 128*0Sstevel@tonic-gate ctfs_tdir_do_lookup(vnode_t *vp, const char *nm, vnode_t **vpp, ino64_t *inop) 129*0Sstevel@tonic-gate { 130*0Sstevel@tonic-gate int i; 131*0Sstevel@tonic-gate contract_t *ct; 132*0Sstevel@tonic-gate 133*0Sstevel@tonic-gate i = stoi((char **)&nm); 134*0Sstevel@tonic-gate if (*nm != '\0') 135*0Sstevel@tonic-gate return (ENOENT); 136*0Sstevel@tonic-gate 137*0Sstevel@tonic-gate ct = contract_type_ptr(ct_types[gfs_file_index(vp)], i, 138*0Sstevel@tonic-gate VTOZ(vp)->zone_uniqid); 139*0Sstevel@tonic-gate if (ct == NULL) 140*0Sstevel@tonic-gate return (ENOENT); 141*0Sstevel@tonic-gate 142*0Sstevel@tonic-gate *vpp = ctfs_create_cdirnode(vp, ct); 143*0Sstevel@tonic-gate *inop = gfs_file_inode(*vpp); 144*0Sstevel@tonic-gate contract_rele(ct); 145*0Sstevel@tonic-gate return (0); 146*0Sstevel@tonic-gate } 147*0Sstevel@tonic-gate 148*0Sstevel@tonic-gate const fs_operation_def_t ctfs_tops_tdir[] = { 149*0Sstevel@tonic-gate { VOPNAME_OPEN, ctfs_open }, 150*0Sstevel@tonic-gate { VOPNAME_CLOSE, ctfs_close }, 151*0Sstevel@tonic-gate { VOPNAME_IOCTL, fs_inval }, 152*0Sstevel@tonic-gate { VOPNAME_GETATTR, ctfs_tdir_getattr }, 153*0Sstevel@tonic-gate { VOPNAME_ACCESS, ctfs_access_dir }, 154*0Sstevel@tonic-gate { VOPNAME_READDIR, gfs_vop_readdir }, 155*0Sstevel@tonic-gate { VOPNAME_LOOKUP, gfs_vop_lookup }, 156*0Sstevel@tonic-gate { VOPNAME_SEEK, fs_seek }, 157*0Sstevel@tonic-gate { VOPNAME_INACTIVE, (fs_generic_func_p) gfs_vop_inactive }, 158*0Sstevel@tonic-gate { NULL, NULL } 159*0Sstevel@tonic-gate }; 160