xref: /illumos-gate/usr/src/uts/common/fs/objfs/objfs_odir.c (revision e3ae4b35c024af1196582063ecee3ab79367227d)
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #include <fs/fs_subr.h>
27 
28 #include <sys/kmem.h>
29 #include <sys/modctl.h>
30 #include <sys/objfs.h>
31 #include <sys/objfs_impl.h>
32 #include <sys/vfs_opreg.h>
33 #include <sys/stat.h>
34 
35 static gfs_dirent_t objfs_odir_entries[] = {
36 	{ "object", objfs_create_data, 0 },
37 	{ NULL }
38 };
39 
40 /* ARGSUSED */
41 static ino64_t
42 objfs_odir_do_inode(vnode_t *vp, int index)
43 {
44 	objfs_odirnode_t *odir = vp->v_data;
45 
46 	return (OBJFS_INO_DATA(odir->objfs_odir_modctl->mod_id));
47 }
48 
49 vnode_t *
50 objfs_create_odirnode(vnode_t *pvp, struct modctl *mp)
51 {
52 	vnode_t *vp = gfs_dir_create(sizeof (objfs_odirnode_t), pvp,
53 	    objfs_ops_odir, objfs_odir_entries, objfs_odir_do_inode,
54 	    OBJFS_NAME_MAX, NULL, NULL);
55 	objfs_odirnode_t *onode = vp->v_data;
56 
57 	onode->objfs_odir_modctl = mp;
58 
59 	return (vp);
60 }
61 
62 /* ARGSUSED */
63 static int
64 objfs_odir_getattr(vnode_t *vp, vattr_t *vap, int flags, cred_t *cr,
65 	caller_context_t *ct)
66 {
67 	timestruc_t now;
68 
69 	vap->va_type = VDIR;
70 	vap->va_mode = S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP |
71 	    S_IROTH | S_IXOTH;
72 	vap->va_nodeid = gfs_file_inode(vp);
73 	vap->va_nlink = vap->va_size = 2;
74 	gethrestime(&now);
75 	vap->va_atime = vap->va_ctime = vap->va_mtime = now;
76 	return (objfs_common_getattr(vp, vap));
77 }
78 
79 const fs_operation_def_t objfs_tops_odir[] = {
80 	{ VOPNAME_OPEN,		{ .vop_open = objfs_dir_open } },
81 	{ VOPNAME_CLOSE,	{ .vop_close = objfs_common_close } },
82 	{ VOPNAME_IOCTL,	{ .error = fs_inval } },
83 	{ VOPNAME_GETATTR,	{ .vop_getattr = objfs_odir_getattr } },
84 	{ VOPNAME_ACCESS,	{ .vop_access = objfs_dir_access } },
85 	{ VOPNAME_READDIR,	{ .vop_readdir = gfs_vop_readdir } },
86 	{ VOPNAME_LOOKUP,	{ .vop_lookup = gfs_vop_lookup } },
87 	{ VOPNAME_SEEK,		{ .vop_seek = fs_seek } },
88 	{ VOPNAME_INACTIVE,	{ .vop_inactive = gfs_vop_inactive } },
89 	{ NULL }
90 };
91