Merge commit '2cedd8f0ecbd2b29bf0aac72bb8b7413b0326938' into merges
[unleashed.git] / kernel / fs / ctfs / ctfs_tdir.c
blob52a0b1245fa13b784687db7fd3f67098d67a489b
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 * Entries in a /system/contract/<type> directory.
49 static gfs_dirent_t ctfs_tdir_dirents[] = {
50 { "bundle", ctfs_create_bundle },
51 { "pbundle", ctfs_create_pbundle },
52 { "template", ctfs_create_tmplnode },
53 { "latest", ctfs_create_latenode, GFS_CACHE_VNODE },
54 { NULL }
56 #define CTFS_NSPECIALS ((sizeof ctfs_tdir_dirents / sizeof (gfs_dirent_t)) - 1)
58 static int ctfs_tdir_do_readdir(vnode_t *, void *, int *, offset_t *,
59 offset_t *, void *, int);
60 static int ctfs_tdir_do_lookup(vnode_t *, const char *, vnode_t **, ino64_t *,
61 cred_t *, int, int *, pathname_t *);
62 static ino64_t ctfs_tdir_do_inode(vnode_t *, int);
65 * ctfs_create_tdirnode
67 vnode_t *
68 ctfs_create_tdirnode(vnode_t *pvp)
70 return (gfs_dir_create(sizeof (ctfs_tdirnode_t), pvp, &ctfs_ops_tdir,
71 ctfs_tdir_dirents, ctfs_tdir_do_inode, CTFS_NAME_MAX,
72 ctfs_tdir_do_readdir, ctfs_tdir_do_lookup));
76 * ctfs_tdir_getattr - fop_getattr entry point
78 /* ARGSUSED */
79 static int
80 ctfs_tdir_getattr(
81 vnode_t *vp,
82 vattr_t *vap,
83 int flags,
84 cred_t *cr,
85 caller_context_t *ct)
87 vap->va_type = VDIR;
88 vap->va_mode = 0555;
89 vap->va_nlink = 2 + CTFS_NSPECIALS;
90 vap->va_size = vap->va_nlink +
91 contract_type_count(ct_types[gfs_file_index(vp)]);
92 vap->va_ctime.tv_sec = vp->v_vfsp->vfs_mtime;
93 vap->va_ctime.tv_nsec = 0;
94 contract_type_time(ct_types[gfs_file_index(vp)], &vap->va_atime);
95 vap->va_mtime = vap->va_atime;
96 ctfs_common_getattr(vp, vap);
98 return (0);
101 static ino64_t
102 ctfs_tdir_do_inode(vnode_t *vp, int index)
104 return (CTFS_INO_TYPE_FILE(gfs_file_index(vp), index));
107 /* ARGSUSED */
108 static int
109 ctfs_tdir_do_readdir(vnode_t *vp, void *dp, int *eofp,
110 offset_t *offp, offset_t *nextp, void *data, int flags)
112 uint64_t zuniqid;
113 ctid_t next;
114 ct_type_t *ty = ct_types[gfs_file_index(vp)];
115 struct dirent64 *odp = dp;
117 ASSERT(!(flags & V_RDDIR_ENTFLAGS));
119 zuniqid = VTOZONE(vp)->zone_uniqid;
120 next = contract_type_lookup(ty, zuniqid, *offp);
122 if (next == -1) {
123 *eofp = 1;
124 return (0);
127 odp->d_ino = CTFS_INO_CT_DIR(next);
128 numtos(next, odp->d_name);
129 *offp = next;
130 *nextp = next + 1;
132 return (0);
135 /* ARGSUSED */
136 static int
137 ctfs_tdir_do_lookup(vnode_t *vp, const char *nm, vnode_t **vpp, ino64_t *inop,
138 cred_t *cr, int flags, int *deflags, pathname_t *rpnp)
140 int i;
141 contract_t *ct;
143 i = stoi((char **)&nm);
144 if (*nm != '\0')
145 return (ENOENT);
147 ct = contract_type_ptr(ct_types[gfs_file_index(vp)], i,
148 VTOZONE(vp)->zone_uniqid);
149 if (ct == NULL)
150 return (ENOENT);
152 *vpp = ctfs_create_cdirnode(vp, ct);
153 *inop = gfs_file_inode(*vpp);
154 contract_rele(ct);
155 return (0);
158 const struct vnodeops ctfs_ops_tdir = {
159 .vnop_name = "ctfs template directory",
160 .vop_open = ctfs_open,
161 .vop_close = ctfs_close,
162 .vop_ioctl = fs_inval,
163 .vop_getattr = ctfs_tdir_getattr,
164 .vop_access = ctfs_access_dir,
165 .vop_readdir = gfs_vop_readdir,
166 .vop_lookup = gfs_vop_lookup,
167 .vop_seek = fs_seek,
168 .vop_inactive = gfs_vop_inactive,