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]
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>
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>
42 #include <sys/ctfs_impl.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
},
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
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
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
);
102 ctfs_tdir_do_inode(vnode_t
*vp
, int index
)
104 return (CTFS_INO_TYPE_FILE(gfs_file_index(vp
), index
));
109 ctfs_tdir_do_readdir(vnode_t
*vp
, void *dp
, int *eofp
,
110 offset_t
*offp
, offset_t
*nextp
, void *data
, int flags
)
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
);
127 odp
->d_ino
= CTFS_INO_CT_DIR(next
);
128 numtos(next
, odp
->d_name
);
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
)
143 i
= stoi((char **)&nm
);
147 ct
= contract_type_ptr(ct_types
[gfs_file_index(vp
)], i
,
148 VTOZONE(vp
)->zone_uniqid
);
152 *vpp
= ctfs_create_cdirnode(vp
, ct
);
153 *inop
= gfs_file_inode(*vpp
);
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
,
168 .vop_inactive
= gfs_vop_inactive
,