xref: /NextBSD/sys/cddl/contrib/opensolaris/uts/common/sys/gfs.h (revision 4bf303e5af1834cdd3092175eeca7676420229c4)
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/mutex.h>
36 #include <sys/dirent.h>
37 #include <sys/extdirent.h>
38 #include <sys/uio.h>
39 #include <sys/list.h>
40 
41 #ifdef	__cplusplus
42 extern "C" {
43 #endif
44 
45 #define	GFS_CACHE_VNODE		0x1
46 
47 typedef struct gfs_dirent {
48 	char			*gfse_name;	/* entry name */
49 	vnode_t *(*gfse_ctor)(vnode_t *);	/* constructor */
50 	int			gfse_flags;	/* flags */
51 	list_node_t		gfse_link;	/* dynamic list */
52 	vnode_t			*gfse_vnode;	/* cached vnode */
53 } gfs_dirent_t;
54 
55 typedef enum gfs_type {
56 	GFS_DIR,
57 	GFS_FILE
58 } gfs_type_t;
59 
60 typedef struct gfs_file {
61 	vnode_t		*gfs_vnode;	/* current vnode */
62 	vnode_t		*gfs_parent;	/* parent vnode */
63 	size_t		gfs_size;	/* size of private data structure */
64 	gfs_type_t	gfs_type;	/* type of vnode */
65 	int		gfs_index;	/* index in parent dir */
66 	ino64_t		gfs_ino;	/* inode for this vnode */
67 } gfs_file_t;
68 
69 typedef int (*gfs_readdir_cb)(vnode_t *, void *, int *, offset_t *,
70     offset_t *, void *, int);
71 typedef int (*gfs_lookup_cb)(vnode_t *, const char *, vnode_t **, ino64_t *,
72     cred_t *, int, int *, pathname_t *);
73 typedef ino64_t (*gfs_inode_cb)(vnode_t *, int);
74 
75 typedef struct gfs_dir {
76 	gfs_file_t	gfsd_file;	/* generic file attributes */
77 	gfs_dirent_t	*gfsd_static;	/* statically defined entries */
78 	int		gfsd_nstatic;	/* # static entries */
79 	kmutex_t	gfsd_lock;	/* protects entries */
80 	int		gfsd_maxlen;	/* maximum name length */
81 	gfs_readdir_cb	gfsd_readdir;	/* readdir() callback */
82 	gfs_lookup_cb	gfsd_lookup;	/* lookup() callback */
83 	gfs_inode_cb	gfsd_inode;	/* get an inode number */
84 } gfs_dir_t;
85 
86 struct vfs;
87 
88 extern vnode_t *gfs_file_create(size_t, vnode_t *, vfs_t *, vnodeops_t *);
89 extern vnode_t *gfs_dir_create(size_t, vnode_t *, vfs_t *, vnodeops_t *,
90     gfs_dirent_t *, gfs_inode_cb, int, gfs_readdir_cb, gfs_lookup_cb);
91 extern vnode_t *gfs_root_create(size_t, vfs_t *, vnodeops_t *, ino64_t,
92     gfs_dirent_t *, gfs_inode_cb, int, gfs_readdir_cb, gfs_lookup_cb);
93 extern vnode_t *gfs_root_create_file(size_t, struct vfs *, vnodeops_t *,
94     ino64_t);
95 
96 extern void *gfs_file_inactive(vnode_t *);
97 extern void *gfs_dir_inactive(vnode_t *);
98 
99 extern int gfs_dir_case_lookup(vnode_t *, const char *, vnode_t **, cred_t *,
100     int, int *, pathname_t *);
101 extern int gfs_dir_lookup(vnode_t *, const char *, vnode_t **, cred_t *,
102     int, int *, pathname_t *);
103 extern int gfs_vop_lookup(vnode_t *, char *, vnode_t **, pathname_t *,
104     int, vnode_t *, cred_t *, caller_context_t *, int *, pathname_t *);
105 extern int gfs_dir_readdir(vnode_t *, uio_t *, int *, int *, u_long **, void *,
106     cred_t *, int flags);
107 
108 #define	gfs_dir_lock(gd)	mutex_enter(&(gd)->gfsd_lock)
109 #define	gfs_dir_unlock(gd)	mutex_exit(&(gd)->gfsd_lock)
110 #define	GFS_DIR_LOCKED(gd)	MUTEX_HELD(&(gd)->gfsd_lock)
111 
112 #define	gfs_file_parent(vp)	(((gfs_file_t *)(vp)->v_data)->gfs_parent)
113 
114 #define	gfs_file_index(vp)	(((gfs_file_t *)(vp)->v_data)->gfs_index)
115 #define	gfs_file_set_index(vp, idx)	\
116 	(((gfs_file_t *)(vp)->v_data)->gfs_index = (idx))
117 
118 #define	gfs_file_inode(vp)	(((gfs_file_t *)(vp)->v_data)->gfs_ino)
119 #define	gfs_file_set_inode(vp, ino)	\
120 	(((gfs_file_t *)(vp)->v_data)->gfs_ino = (ino))
121 
122 typedef struct gfs_readdir_state {
123 	void		*grd_dirent;	/* directory entry buffer */
124 	size_t		grd_namlen;	/* max file name length */
125 	size_t		grd_ureclen;	/* exported record size */
126 	ssize_t		grd_oresid;	/* original uio_resid */
127 	ino64_t		grd_parent;	/* inode of parent */
128 	ino64_t		grd_self;	/* inode of self */
129 	int		grd_flags;	/* flags from VOP_READDIR */
130 } gfs_readdir_state_t;
131 
132 extern int gfs_readdir_init(gfs_readdir_state_t *, int, int, uio_t *, ino64_t,
133     ino64_t, int);
134 extern int gfs_readdir_emit(gfs_readdir_state_t *, uio_t *, offset_t, ino64_t,
135     const char *, int, int *, u_long **);
136 extern int gfs_readdir_pred(gfs_readdir_state_t *, uio_t *, offset_t *, int *,
137     u_long **);
138 extern int gfs_readdir_fini(gfs_readdir_state_t *, int, int *, int);
139 extern int gfs_get_parent_ino(vnode_t *, cred_t *, caller_context_t *,
140     ino64_t *, ino64_t *);
141 
142 /*
143  * Objects with real extended attributes will get their . and ..
144  * readdir entries from the real xattr directory. GFS_STATIC_ENTRY_OFFSET
145  * lets us skip right to the static entries in the GFS directory.
146  */
147 #define	GFS_STATIC_ENTRY_OFFSET	((offset_t)2)
148 
149 extern int gfs_lookup_dot(vnode_t **, vnode_t *, vnode_t *, const char *);
150 
151 extern int gfs_vop_readdir(struct vop_readdir_args *);
152 extern int gfs_vop_reclaim(struct vop_reclaim_args *);
153 
154 
155 #ifdef	__cplusplus
156 }
157 #endif
158 
159 #endif	/* _SYS_GFS_H */
160