1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #pragma ident "%Z%%M% %I% %E% SMI" 28 29 #include <sys/types.h> 30 #include <sys/param.h> 31 #include <sys/time.h> 32 #include <sys/cred.h> 33 #include <sys/vfs.h> 34 #include <sys/gfs.h> 35 #include <sys/vnode.h> 36 #include <sys/systm.h> 37 #include <sys/errno.h> 38 #include <sys/sysmacros.h> 39 #include <fs/fs_subr.h> 40 #include <sys/contract.h> 41 #include <sys/contract_impl.h> 42 #include <sys/ctfs.h> 43 #include <sys/ctfs_impl.h> 44 #include <sys/file.h> 45 #include <sys/pathname.h> 46 47 /* 48 * CTFS routines for the /system/contract/all vnode. 49 */ 50 51 static int ctfs_adir_do_readdir(vnode_t *, struct dirent64 *, int *, offset_t *, 52 offset_t *, void *); 53 static int ctfs_adir_do_lookup(vnode_t *, const char *, vnode_t **, ino64_t *); 54 55 /* 56 * ctfs_create_adirnode 57 */ 58 /* ARGSUSED */ 59 vnode_t * 60 ctfs_create_adirnode(vnode_t *pvp) 61 { 62 vnode_t *vp = gfs_dir_create(sizeof (ctfs_adirnode_t), pvp, 63 ctfs_ops_adir, NULL, NULL, CTFS_NAME_MAX, ctfs_adir_do_readdir, 64 ctfs_adir_do_lookup); 65 66 return (vp); 67 } 68 69 /* 70 * ctfs_adir_getattr - VOP_GETATTR entry point 71 */ 72 /* ARGSUSED */ 73 static int 74 ctfs_adir_getattr(vnode_t *vp, vattr_t *vap, int flags, cred_t *cr) 75 { 76 int i, total; 77 78 vap->va_type = VDIR; 79 vap->va_mode = 0555; 80 for (i = 0, total = 0; i < ct_ntypes; i++) 81 total += contract_type_count(ct_types[i]); 82 vap->va_nlink = 2; 83 vap->va_size = 2 + total; 84 vap->va_ctime.tv_sec = vp->v_vfsp->vfs_mtime; 85 vap->va_ctime.tv_nsec = 0; 86 vap->va_mtime = vap->va_atime = vap->va_ctime; 87 ctfs_common_getattr(vp, vap); 88 89 return (0); 90 } 91 92 static int 93 ctfs_adir_do_lookup(vnode_t *vp, const char *nm, vnode_t **vpp, ino64_t *inop) 94 { 95 int i; 96 contract_t *ct; 97 98 i = stoi((char **)&nm); 99 if (*nm != '\0') 100 return (ENOENT); 101 102 ct = contract_ptr(i, VTOZONE(vp)->zone_uniqid); 103 if (ct == NULL) 104 return (ENOENT); 105 106 *vpp = ctfs_create_symnode(vp, ct); 107 *inop = CTFS_INO_CT_LINK(ct->ct_id); 108 contract_rele(ct); 109 110 return (0); 111 } 112 113 /* ARGSUSED */ 114 static int 115 ctfs_adir_do_readdir(vnode_t *vp, struct dirent64 *dp, int *eofp, 116 offset_t *offp, offset_t *nextp, void *unused) 117 { 118 uint64_t zuniqid; 119 ctid_t next; 120 121 zuniqid = VTOZONE(vp)->zone_uniqid; 122 next = contract_lookup(zuniqid, *offp); 123 124 if (next == -1) { 125 *eofp = 1; 126 return (0); 127 } 128 129 dp->d_ino = CTFS_INO_CT_LINK(next); 130 numtos(next, dp->d_name); 131 *offp = next; 132 *nextp = next + 1; 133 134 return (0); 135 } 136 137 const fs_operation_def_t ctfs_tops_adir[] = { 138 { VOPNAME_OPEN, ctfs_open }, 139 { VOPNAME_CLOSE, ctfs_close }, 140 { VOPNAME_IOCTL, fs_inval }, 141 { VOPNAME_GETATTR, ctfs_adir_getattr }, 142 { VOPNAME_ACCESS, ctfs_access_dir }, 143 { VOPNAME_READDIR, gfs_vop_readdir }, 144 { VOPNAME_LOOKUP, gfs_vop_lookup }, 145 { VOPNAME_SEEK, fs_seek }, 146 { VOPNAME_INACTIVE, (fs_generic_func_p) gfs_vop_inactive }, 147 { NULL, NULL } 148 }; 149