xref: /titanic_50/usr/src/uts/common/sys/gfs.h (revision b3700b074e637f8c6991b70754c88a2cfffb246b)
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 /*
23  * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
24  */
25 
26 /*
27  * These are Consolidation Private interfaces and are subject to change.
28  */
29 
30 #ifndef _SYS_GFS_H
31 #define	_SYS_GFS_H
32 
33 #include <sys/types.h>
34 #include <sys/vnode.h>
35 #include <sys/vfs_opreg.h>
36 #include <sys/mutex.h>
37 #include <sys/dirent.h>
38 #include <sys/extdirent.h>
39 #include <sys/uio.h>
40 #include <sys/list.h>
41 #include <sys/pathname.h>
42 
43 #ifdef	__cplusplus
44 extern "C" {
45 #endif
46 
47 typedef struct gfs_opsvec {
48 	const char		*gfsv_name;	/* vnode description */
49 	const fs_operation_def_t *gfsv_template; /* ops template */
50 	vnodeops_t		**gfsv_ops;	/* ptr to result */
51 } gfs_opsvec_t;
52 
53 int gfs_make_opsvec(gfs_opsvec_t *);
54 
55 #define	GFS_CACHE_VNODE		0x1
56 
57 typedef struct gfs_dirent {
58 	char			*gfse_name;	/* entry name */
59 	vnode_t *(*gfse_ctor)(vnode_t *);	/* constructor */
60 	int			gfse_flags;	/* flags */
61 	list_node_t		gfse_link;	/* dynamic list */
62 	vnode_t			*gfse_vnode;	/* cached vnode */
63 } gfs_dirent_t;
64 
65 typedef enum gfs_type {
66 	GFS_DIR,
67 	GFS_FILE
68 } gfs_type_t;
69 
70 typedef struct gfs_file {
71 	vnode_t		*gfs_vnode;	/* current vnode */
72 	vnode_t		*gfs_parent;	/* parent vnode */
73 	size_t		gfs_size;	/* size of private data structure */
74 	gfs_type_t	gfs_type;	/* type of vnode */
75 	int		gfs_index;	/* index in parent dir */
76 	ino64_t		gfs_ino;	/* inode for this vnode */
77 } gfs_file_t;
78 
79 typedef int (*gfs_readdir_cb)(vnode_t *, void *, int *, offset_t *,
80     offset_t *, void *, int);
81 typedef int (*gfs_lookup_cb)(vnode_t *, const char *, vnode_t **, ino64_t *,
82     cred_t *, int, int *, pathname_t *);
83 typedef ino64_t (*gfs_inode_cb)(vnode_t *, int);
84 
85 typedef struct gfs_dir {
86 	gfs_file_t	gfsd_file;	/* generic file attributes */
87 	gfs_dirent_t	*gfsd_static;	/* statically defined entries */
88 	int		gfsd_nstatic;	/* # static entries */
89 	kmutex_t	gfsd_lock;	/* protects entries */
90 	int		gfsd_maxlen;	/* maximum name length */
91 	gfs_readdir_cb	gfsd_readdir;	/* readdir() callback */
92 	gfs_lookup_cb	gfsd_lookup;	/* lookup() callback */
93 	gfs_inode_cb	gfsd_inode;	/* get an inode number */
94 } gfs_dir_t;
95 
96 struct vfs;
97 
98 extern vnode_t *gfs_file_create(size_t, vnode_t *, vnodeops_t *);
99 extern vnode_t *gfs_dir_create(size_t, vnode_t *, vnodeops_t *,
100     gfs_dirent_t *, gfs_inode_cb, int, gfs_readdir_cb, gfs_lookup_cb);
101 extern vnode_t *gfs_root_create(size_t, struct vfs *, vnodeops_t *, ino64_t,
102     gfs_dirent_t *, gfs_inode_cb, int, gfs_readdir_cb, gfs_lookup_cb);
103 extern vnode_t *gfs_root_create_file(size_t, struct vfs *, vnodeops_t *,
104     ino64_t);
105 
106 extern void *gfs_file_inactive(vnode_t *);
107 extern void *gfs_dir_inactive(vnode_t *);
108 
109 extern int gfs_dir_case_lookup(vnode_t *, const char *, vnode_t **, cred_t *,
110     int, int *, pathname_t *);
111 extern int gfs_dir_lookup(vnode_t *, const char *, vnode_t **, cred_t *,
112     int, int *, pathname_t *);
113 extern int gfs_dir_readdir(vnode_t *, uio_t *, int *, void *, cred_t *,
114     caller_context_t *, int flags);
115 
116 #define	gfs_dir_lock(gd)	mutex_enter(&(gd)->gfsd_lock)
117 #define	gfs_dir_unlock(gd)	mutex_exit(&(gd)->gfsd_lock)
118 #define	GFS_DIR_LOCKED(gd)	MUTEX_HELD(&(gd)->gfsd_lock)
119 
120 #define	gfs_file_parent(vp)	(((gfs_file_t *)(vp)->v_data)->gfs_parent)
121 
122 #define	gfs_file_index(vp)	(((gfs_file_t *)(vp)->v_data)->gfs_index)
123 #define	gfs_file_set_index(vp, idx)	\
124 	(((gfs_file_t *)(vp)->v_data)->gfs_index = (idx))
125 
126 #define	gfs_file_inode(vp)	(((gfs_file_t *)(vp)->v_data)->gfs_ino)
127 #define	gfs_file_set_inode(vp, ino)	\
128 	(((gfs_file_t *)(vp)->v_data)->gfs_ino = (ino))
129 
130 typedef struct gfs_readdir_state {
131 	void		*grd_dirent;	/* directory entry buffer */
132 	size_t		grd_namlen;	/* max file name length */
133 	size_t		grd_ureclen;	/* exported record size */
134 	ssize_t		grd_oresid;	/* original uio_resid */
135 	ino64_t		grd_parent;	/* inode of parent */
136 	ino64_t		grd_self;	/* inode of self */
137 	int		grd_flags;	/* flags from VOP_READDIR */
138 } gfs_readdir_state_t;
139 
140 extern int gfs_readdir_init(gfs_readdir_state_t *, int, int, uio_t *, ino64_t,
141     ino64_t, int);
142 extern int gfs_readdir_emit(gfs_readdir_state_t *, uio_t *, offset_t, ino64_t,
143     const char *, int);
144 extern int gfs_readdir_emitn(gfs_readdir_state_t *, uio_t *, offset_t, ino64_t,
145     unsigned long);
146 extern int gfs_readdir_pred(gfs_readdir_state_t *, uio_t *, offset_t *);
147 extern int gfs_readdir_fini(gfs_readdir_state_t *, int, int *, int);
148 extern int gfs_get_parent_ino(vnode_t *, cred_t *, caller_context_t *,
149     ino64_t *, ino64_t *);
150 
151 /*
152  * Objects with real extended attributes will get their . and ..
153  * readdir entries from the real xattr directory. GFS_STATIC_ENTRY_OFFSET
154  * lets us skip right to the static entries in the GFS directory.
155  */
156 #define	GFS_STATIC_ENTRY_OFFSET	((offset_t)2)
157 
158 extern int gfs_lookup_dot(vnode_t **, vnode_t *, vnode_t *, const char *);
159 
160 extern int gfs_vop_lookup(vnode_t *, char *, vnode_t **, pathname_t *,
161     int, vnode_t *, cred_t *, caller_context_t *, int *, pathname_t *);
162 extern int gfs_vop_readdir(vnode_t *, uio_t *, cred_t *, int *,
163     caller_context_t *, int);
164 extern int gfs_vop_map(vnode_t *, offset_t, struct as *, caddr_t *,
165     size_t, uchar_t, uchar_t, uint_t, cred_t *, caller_context_t *);
166 extern void gfs_vop_inactive(vnode_t *, cred_t *, caller_context_t *);
167 
168 
169 #ifdef	__cplusplus
170 }
171 #endif
172 
173 #endif	/* _SYS_GFS_H */
174