su.static: link with proto area libs (esp. libc)
[unleashed.git] / kernel / fs / ctfs / ctfs_all.c
blob5ae4aed5131ee91cbc52afb056d9e3b86b207cb2
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 2008 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/pathname.h>
47 * CTFS routines for the /system/contract/all vnode.
50 static int ctfs_adir_do_readdir(vnode_t *, void *, int *, offset_t *,
51 offset_t *, void *, int);
52 static int ctfs_adir_do_lookup(vnode_t *, const char *, vnode_t **, ino64_t *,
53 cred_t *, int, int *, pathname_t *);
56 * ctfs_create_adirnode
58 /* ARGSUSED */
59 vnode_t *
60 ctfs_create_adirnode(vnode_t *pvp)
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);
66 return (vp);
70 * ctfs_adir_getattr - fop_getattr entry point
72 /* ARGSUSED */
73 static int
74 ctfs_adir_getattr(
75 vnode_t *vp,
76 vattr_t *vap,
77 int flags,
78 cred_t *cr,
79 caller_context_t *ct)
81 int i, total;
83 vap->va_type = VDIR;
84 vap->va_mode = 0555;
85 for (i = 0, total = 0; i < ct_ntypes; i++)
86 total += contract_type_count(ct_types[i]);
87 vap->va_nlink = 2;
88 vap->va_size = 2 + total;
89 vap->va_ctime.tv_sec = vp->v_vfsp->vfs_mtime;
90 vap->va_ctime.tv_nsec = 0;
91 vap->va_mtime = vap->va_atime = vap->va_ctime;
92 ctfs_common_getattr(vp, vap);
94 return (0);
97 /* ARGSUSED */
98 static int
99 ctfs_adir_do_lookup(vnode_t *vp, const char *nm, vnode_t **vpp, ino64_t *inop,
100 cred_t *cr, int flags, int *deflags, pathname_t *rpnp)
102 int i;
103 contract_t *ct;
105 i = stoi((char **)&nm);
106 if (*nm != '\0')
107 return (ENOENT);
109 ct = contract_ptr(i, VTOZONE(vp)->zone_uniqid);
110 if (ct == NULL)
111 return (ENOENT);
113 *vpp = ctfs_create_symnode(vp, ct);
114 *inop = CTFS_INO_CT_LINK(ct->ct_id);
115 contract_rele(ct);
117 return (0);
120 /* ARGSUSED */
121 static int
122 ctfs_adir_do_readdir(vnode_t *vp, void *dp, int *eofp,
123 offset_t *offp, offset_t *nextp, void *unused, int flags)
125 uint64_t zuniqid;
126 ctid_t next;
127 struct dirent64 *odp = dp;
129 ASSERT(!(flags & V_RDDIR_ENTFLAGS));
131 zuniqid = VTOZONE(vp)->zone_uniqid;
132 next = contract_lookup(zuniqid, *offp);
134 if (next == -1) {
135 *eofp = 1;
136 return (0);
139 odp->d_ino = CTFS_INO_CT_LINK(next);
140 numtos(next, odp->d_name);
141 *offp = next;
142 *nextp = next + 1;
144 return (0);
147 const struct vnodeops ctfs_ops_adir = {
148 .vnop_name = "ctfs all directory",
149 .vop_open = ctfs_open,
150 .vop_close = ctfs_close,
151 .vop_ioctl = fs_inval,
152 .vop_getattr = ctfs_adir_getattr,
153 .vop_access = ctfs_access_dir,
154 .vop_readdir = gfs_vop_readdir,
155 .vop_lookup = gfs_vop_lookup,
156 .vop_seek = fs_seek,
157 .vop_inactive = gfs_vop_inactive,