kill FOFFMAX / O_LARGEFILE
[unleashed/lotheac.git] / kernel / fs / ctfs / ctfs_latest.c
blob6ba535c3ec8b6ef60226ccb38ceeb87e1a5b8688
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>
46 * CTFS routines for the /system/contract/<type>/latest vnode.
50 * ctfs_create_latenode
52 vnode_t *
53 ctfs_create_latenode(vnode_t *pvp)
55 return (gfs_file_create(sizeof (ctfs_latenode_t), pvp,
56 &ctfs_ops_latest));
60 * ctfs_latest_nested_open
62 * The latest node is just a doorway to the status file; this function
63 * is used by ctfs_latest_access, ctfs_latest_open, and
64 * ctfs_latest_getattr to obtain that file.
66 static vnode_t *
67 ctfs_latest_nested_open(vnode_t *vp, cred_t *cr)
69 contract_t *ct = ttolwp(curthread)->lwp_ct_latest[
70 gfs_file_index(gfs_file_parent(vp))];
72 if (ct) {
73 vnode_t *cvp, *svp;
75 cvp = ctfs_create_cdirnode(gfs_file_parent(vp), ct);
77 gfs_file_set_index(cvp, -1);
79 VERIFY(gfs_dir_lookup(cvp, "status", &svp,
80 cr, 0, NULL, NULL) == 0);
82 VN_RELE(cvp);
84 return (svp);
87 return (NULL);
91 * ctfs_latest_access - fop_access entry point
93 * Fails if there isn't a latest contract.
95 /* ARGSUSED */
96 static int
97 ctfs_latest_access(
98 vnode_t *vp,
99 int mode,
100 int flags,
101 cred_t *cr,
102 caller_context_t *ct)
104 vnode_t *nvp;
106 if (mode & (VEXEC | VWRITE))
107 return (EACCES);
109 if (nvp = ctfs_latest_nested_open(vp, cr)) {
110 VN_RELE(nvp);
111 return (0);
114 return (ESRCH);
118 * ctfs_latest_open - fop_open entry point
120 * After checking the mode bits, opens and returns the status file for
121 * the LWP's latest contract.
123 static int
124 ctfs_latest_open(vnode_t **vpp, int flag, cred_t *cr, caller_context_t *ct)
126 vnode_t *nvp;
128 if (flag != (FREAD))
129 return (EINVAL);
131 if (nvp = ctfs_latest_nested_open(*vpp, cr)) {
132 VN_RELE(*vpp);
133 *vpp = nvp;
134 return (fop_open(vpp, flag, cr, ct));
137 return (ESRCH);
141 * ctfs_latest_getattr - the fop_getattr entry point
143 * Fetches and calls fop_getattr on the status file for the LWP's
144 * latest contract. Otherwise it fakes up something bland.
146 static int
147 ctfs_latest_getattr(
148 vnode_t *vp,
149 vattr_t *vap,
150 int flags,
151 cred_t *cr,
152 caller_context_t *ct)
154 vnode_t *nvp;
156 if (nvp = ctfs_latest_nested_open(vp, cr)) {
157 int res = fop_getattr(nvp, vap, flags, cr, ct);
158 VN_RELE(nvp);
159 return (res);
162 vap->va_type = VREG;
163 vap->va_mode = 0444;
164 vap->va_nlink = 1;
165 vap->va_size = 0;
166 vap->va_ctime.tv_sec = vp->v_vfsp->vfs_mtime;
167 vap->va_ctime.tv_nsec = 0;
168 vap->va_atime = vap->va_mtime = vap->va_ctime;
169 ctfs_common_getattr(vp, vap);
171 return (0);
174 const struct vnodeops ctfs_ops_latest = {
175 .vnop_name = "ctfs latest file",
176 .vop_open = ctfs_latest_open,
177 .vop_close = fs_inval,
178 .vop_ioctl = fs_inval,
179 .vop_getattr = ctfs_latest_getattr,
180 .vop_access = ctfs_latest_access,
181 .vop_readdir = fs_notdir,
182 .vop_lookup = fs_notdir,
183 .vop_inactive = gfs_vop_inactive,