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