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 * CTFS routines for the /system/contract/all vnode. 49 0 stevel */ 50 0 stevel 51 5663 ck153898 static int ctfs_adir_do_readdir(vnode_t *, void *, int *, offset_t *, 52 5663 ck153898 offset_t *, void *, int); 53 5331 amw static int ctfs_adir_do_lookup(vnode_t *, const char *, vnode_t **, ino64_t *, 54 6492 timh cred_t *, int, int *, pathname_t *); 55 0 stevel 56 0 stevel /* 57 0 stevel * ctfs_create_adirnode 58 0 stevel */ 59 0 stevel /* ARGSUSED */ 60 0 stevel vnode_t * 61 0 stevel ctfs_create_adirnode(vnode_t *pvp) 62 0 stevel { 63 0 stevel vnode_t *vp = gfs_dir_create(sizeof (ctfs_adirnode_t), pvp, 64 0 stevel ctfs_ops_adir, NULL, NULL, CTFS_NAME_MAX, ctfs_adir_do_readdir, 65 0 stevel ctfs_adir_do_lookup); 66 0 stevel 67 0 stevel return (vp); 68 0 stevel } 69 0 stevel 70 0 stevel /* 71 0 stevel * ctfs_adir_getattr - VOP_GETATTR entry point 72 0 stevel */ 73 0 stevel /* ARGSUSED */ 74 0 stevel static int 75 5331 amw ctfs_adir_getattr( 76 5331 amw vnode_t *vp, 77 5331 amw vattr_t *vap, 78 5331 amw int flags, 79 5331 amw cred_t *cr, 80 5331 amw caller_context_t *ct) 81 0 stevel { 82 0 stevel int i, total; 83 0 stevel 84 0 stevel vap->va_type = VDIR; 85 0 stevel vap->va_mode = 0555; 86 0 stevel for (i = 0, total = 0; i < ct_ntypes; i++) 87 0 stevel total += contract_type_count(ct_types[i]); 88 0 stevel vap->va_nlink = 2; 89 0 stevel vap->va_size = 2 + total; 90 0 stevel vap->va_ctime.tv_sec = vp->v_vfsp->vfs_mtime; 91 0 stevel vap->va_ctime.tv_nsec = 0; 92 0 stevel vap->va_mtime = vap->va_atime = vap->va_ctime; 93 0 stevel ctfs_common_getattr(vp, vap); 94 0 stevel 95 0 stevel return (0); 96 0 stevel } 97 0 stevel 98 5331 amw /* ARGSUSED */ 99 0 stevel static int 100 5331 amw ctfs_adir_do_lookup(vnode_t *vp, const char *nm, vnode_t **vpp, ino64_t *inop, 101 6492 timh cred_t *cr, int flags, int *deflags, pathname_t *rpnp) 102 0 stevel { 103 0 stevel int i; 104 0 stevel contract_t *ct; 105 0 stevel 106 0 stevel i = stoi((char **)&nm); 107 0 stevel if (*nm != '\0') 108 0 stevel return (ENOENT); 109 0 stevel 110 789 ahrens ct = contract_ptr(i, VTOZONE(vp)->zone_uniqid); 111 0 stevel if (ct == NULL) 112 0 stevel return (ENOENT); 113 0 stevel 114 0 stevel *vpp = ctfs_create_symnode(vp, ct); 115 0 stevel *inop = CTFS_INO_CT_LINK(ct->ct_id); 116 0 stevel contract_rele(ct); 117 0 stevel 118 0 stevel return (0); 119 0 stevel } 120 0 stevel 121 0 stevel /* ARGSUSED */ 122 0 stevel static int 123 5663 ck153898 ctfs_adir_do_readdir(vnode_t *vp, void *dp, int *eofp, 124 5663 ck153898 offset_t *offp, offset_t *nextp, void *unused, int flags) 125 0 stevel { 126 0 stevel uint64_t zuniqid; 127 0 stevel ctid_t next; 128 5663 ck153898 struct dirent64 *odp = dp; 129 5663 ck153898 130 6492 timh ASSERT(!(flags & V_RDDIR_ENTFLAGS)); 131 0 stevel 132 789 ahrens zuniqid = VTOZONE(vp)->zone_uniqid; 133 0 stevel next = contract_lookup(zuniqid, *offp); 134 0 stevel 135 0 stevel if (next == -1) { 136 0 stevel *eofp = 1; 137 0 stevel return (0); 138 0 stevel } 139 0 stevel 140 5663 ck153898 odp->d_ino = CTFS_INO_CT_LINK(next); 141 5663 ck153898 numtos(next, odp->d_name); 142 0 stevel *offp = next; 143 0 stevel *nextp = next + 1; 144 0 stevel 145 0 stevel return (0); 146 0 stevel } 147 0 stevel 148 0 stevel const fs_operation_def_t ctfs_tops_adir[] = { 149 3898 rsb { VOPNAME_OPEN, { .vop_open = ctfs_open } }, 150 3898 rsb { VOPNAME_CLOSE, { .vop_close = ctfs_close } }, 151 3898 rsb { VOPNAME_IOCTL, { .error = fs_inval } }, 152 3898 rsb { VOPNAME_GETATTR, { .vop_getattr = ctfs_adir_getattr } }, 153 3898 rsb { VOPNAME_ACCESS, { .vop_access = ctfs_access_dir } }, 154 3898 rsb { VOPNAME_READDIR, { .vop_readdir = gfs_vop_readdir } }, 155 3898 rsb { VOPNAME_LOOKUP, { .vop_lookup = gfs_vop_lookup } }, 156 3898 rsb { VOPNAME_SEEK, { .vop_seek = fs_seek } }, 157 3898 rsb { VOPNAME_INACTIVE, { .vop_inactive = gfs_vop_inactive } }, 158 0 stevel { NULL, NULL } 159 0 stevel }; 160