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 3898 rsb * Copyright 2007 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/cmn_err.h> 46 0 stevel 47 0 stevel /* 48 0 stevel * CTFS routines for the /system/contract/all/<ctid> vnode. 49 0 stevel */ 50 0 stevel 51 0 stevel /* 52 0 stevel * ctfs_create_symnode 53 0 stevel * 54 0 stevel * Creates and returns a symnode for the specified contract. 55 0 stevel */ 56 0 stevel vnode_t * 57 0 stevel ctfs_create_symnode(vnode_t *pvp, contract_t *ct) 58 0 stevel { 59 0 stevel ctfs_symnode_t *symnode; 60 0 stevel vnode_t *vp; 61 0 stevel size_t len; 62 0 stevel 63 0 stevel vp = gfs_file_create(sizeof (ctfs_symnode_t), pvp, ctfs_ops_sym); 64 0 stevel vp->v_type = VLNK; 65 0 stevel symnode = vp->v_data; 66 0 stevel 67 0 stevel symnode->ctfs_sn_contract = ct; 68 0 stevel symnode->ctfs_sn_size = len = snprintf(NULL, 0, "../%s/%ld", 69 0 stevel ct->ct_type->ct_type_name, (long)ct->ct_id) + 1; 70 0 stevel symnode->ctfs_sn_string = kmem_alloc(len, KM_SLEEP); 71 0 stevel VERIFY(snprintf(symnode->ctfs_sn_string, len, "../%s/%ld", 72 0 stevel ct->ct_type->ct_type_name, (long)ct->ct_id) < len); 73 0 stevel 74 0 stevel contract_hold(ct); 75 0 stevel 76 0 stevel return (vp); 77 0 stevel } 78 0 stevel 79 0 stevel /* 80 0 stevel * ctfs_sym_getattr - VOP_GETATTR entry point 81 0 stevel */ 82 0 stevel /* ARGSUSED */ 83 0 stevel static int 84 5331 amw ctfs_sym_getattr( 85 5331 amw vnode_t *vp, 86 5331 amw vattr_t *vap, 87 5331 amw int flags, 88 5331 amw cred_t *cr, 89 5331 amw caller_context_t *ct) 90 0 stevel { 91 0 stevel ctfs_symnode_t *symnode = vp->v_data; 92 0 stevel 93 0 stevel vap->va_type = VLNK; 94 0 stevel vap->va_mode = 0444; 95 0 stevel vap->va_nlink = 1; 96 0 stevel vap->va_size = symnode->ctfs_sn_size - 1; 97 0 stevel vap->va_mtime = vap->va_atime = vap->va_ctime = 98 0 stevel symnode->ctfs_sn_contract->ct_ctime; 99 0 stevel ctfs_common_getattr(vp, vap); 100 0 stevel 101 0 stevel return (0); 102 0 stevel } 103 0 stevel 104 0 stevel /* 105 0 stevel * ctfs_sym_readlink - VOP_READLINK entry point 106 0 stevel * 107 0 stevel * Since we built the symlink string in ctfs_create_symnode, this is 108 0 stevel * just a uiomove. 109 0 stevel */ 110 0 stevel /* ARGSUSED */ 111 0 stevel int 112 5331 amw ctfs_sym_readlink(vnode_t *vp, uio_t *uiop, cred_t *cr, caller_context_t *ct) 113 0 stevel { 114 0 stevel ctfs_symnode_t *symnode = vp->v_data; 115 0 stevel 116 0 stevel return (uiomove(symnode->ctfs_sn_string, symnode->ctfs_sn_size - 1, 117 0 stevel UIO_READ, uiop)); 118 0 stevel } 119 0 stevel 120 0 stevel /* 121 0 stevel * ctfs_sym_inactive - VOP_INACTIVE entry point 122 0 stevel */ 123 0 stevel /* ARGSUSED */ 124 0 stevel static void 125 5331 amw ctfs_sym_inactive(vnode_t *vp, cred_t *cr, caller_context_t *ct) 126 0 stevel { 127 0 stevel ctfs_symnode_t *symnode; 128 0 stevel 129 0 stevel if ((symnode = gfs_file_inactive(vp)) != NULL) { 130 0 stevel contract_rele(symnode->ctfs_sn_contract); 131 0 stevel kmem_free(symnode->ctfs_sn_string, symnode->ctfs_sn_size); 132 0 stevel kmem_free(symnode, sizeof (ctfs_symnode_t)); 133 0 stevel } 134 0 stevel } 135 0 stevel 136 0 stevel const fs_operation_def_t ctfs_tops_sym[] = { 137 3898 rsb { VOPNAME_OPEN, { .vop_open = ctfs_open } }, 138 3898 rsb { VOPNAME_CLOSE, { .vop_close = ctfs_close } }, 139 3898 rsb { VOPNAME_IOCTL, { .error = fs_inval } }, 140 3898 rsb { VOPNAME_GETATTR, { .vop_getattr = ctfs_sym_getattr } }, 141 3898 rsb { VOPNAME_READLINK, { .vop_readlink = ctfs_sym_readlink } }, 142 3898 rsb { VOPNAME_ACCESS, { .vop_access = ctfs_access_readonly } }, 143 3898 rsb { VOPNAME_READDIR, { .error = fs_notdir } }, 144 3898 rsb { VOPNAME_LOOKUP, { .error = fs_notdir } }, 145 3898 rsb { VOPNAME_INACTIVE, { .vop_inactive = ctfs_sym_inactive } }, 146 0 stevel { NULL, NULL } 147 0 stevel }; 148