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