Merge illumos-gate
[unleashed/lotheac.git] / kernel / fs / ctfs / ctfs_sym.c
blobb0ce7097c3b9c946a7b2f84ca4570a889634f71f
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
28 #include <sys/types.h>
29 #include <sys/param.h>
30 #include <sys/time.h>
31 #include <sys/cred.h>
32 #include <sys/vfs.h>
33 #include <sys/gfs.h>
34 #include <sys/vnode.h>
35 #include <sys/systm.h>
36 #include <sys/errno.h>
37 #include <sys/sysmacros.h>
38 #include <sys/fs_subr.h>
39 #include <sys/contract.h>
40 #include <sys/contract_impl.h>
41 #include <sys/ctfs.h>
42 #include <sys/ctfs_impl.h>
43 #include <sys/file.h>
44 #include <sys/cmn_err.h>
47 * CTFS routines for the /system/contract/all/<ctid> vnode.
51 * ctfs_create_symnode
53 * Creates and returns a symnode for the specified contract.
55 vnode_t *
56 ctfs_create_symnode(vnode_t *pvp, contract_t *ct)
58 ctfs_symnode_t *symnode;
59 vnode_t *vp;
60 size_t len;
62 vp = gfs_file_create(sizeof (ctfs_symnode_t), pvp, &ctfs_ops_sym);
63 vp->v_type = VLNK;
64 symnode = vp->v_data;
66 symnode->ctfs_sn_contract = ct;
67 symnode->ctfs_sn_size = len = snprintf(NULL, 0, "../%s/%ld",
68 ct->ct_type->ct_type_name, (long)ct->ct_id) + 1;
69 symnode->ctfs_sn_string = kmem_alloc(len, KM_SLEEP);
70 VERIFY(snprintf(symnode->ctfs_sn_string, len, "../%s/%ld",
71 ct->ct_type->ct_type_name, (long)ct->ct_id) < len);
73 contract_hold(ct);
75 return (vp);
79 * ctfs_sym_getattr - fop_getattr entry point
81 /* ARGSUSED */
82 static int
83 ctfs_sym_getattr(
84 vnode_t *vp,
85 vattr_t *vap,
86 int flags,
87 cred_t *cr,
88 caller_context_t *ct)
90 ctfs_symnode_t *symnode = vp->v_data;
92 vap->va_type = VLNK;
93 vap->va_mode = 0444;
94 vap->va_nlink = 1;
95 vap->va_size = symnode->ctfs_sn_size - 1;
96 vap->va_mtime = vap->va_atime = vap->va_ctime =
97 symnode->ctfs_sn_contract->ct_ctime;
98 ctfs_common_getattr(vp, vap);
100 return (0);
104 * ctfs_sym_readlink - fop_readlink entry point
106 * Since we built the symlink string in ctfs_create_symnode, this is
107 * just a uiomove.
109 /* ARGSUSED */
111 ctfs_sym_readlink(vnode_t *vp, uio_t *uiop, cred_t *cr, caller_context_t *ct)
113 ctfs_symnode_t *symnode = vp->v_data;
115 return (uiomove(symnode->ctfs_sn_string, symnode->ctfs_sn_size - 1,
116 UIO_READ, uiop));
120 * ctfs_sym_inactive - fop_inactive entry point
122 /* ARGSUSED */
123 static void
124 ctfs_sym_inactive(vnode_t *vp, cred_t *cr, caller_context_t *ct)
126 ctfs_symnode_t *symnode;
128 if ((symnode = gfs_file_inactive(vp)) != NULL) {
129 contract_rele(symnode->ctfs_sn_contract);
130 kmem_free(symnode->ctfs_sn_string, symnode->ctfs_sn_size);
131 kmem_free(symnode, sizeof (ctfs_symnode_t));
135 const struct vnodeops ctfs_ops_sym = {
136 .vnop_name = "ctfs all symlink",
137 .vop_open = ctfs_open,
138 .vop_close = ctfs_close,
139 .vop_ioctl = fs_inval,
140 .vop_getattr = ctfs_sym_getattr,
141 .vop_readlink = ctfs_sym_readlink,
142 .vop_access = ctfs_access_readonly,
143 .vop_readdir = fs_notdir,
144 .vop_lookup = fs_notdir,
145 .vop_inactive = ctfs_sym_inactive,