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.
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.
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]
23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
30 #pragma ident "%Z%%M% %I% %E% SMI"
32 #include <sys/types.h>
33 #include <sys/vnode.h>
34 #include <sys/mutex.h>
35 #include <sys/dirent.h>
43 #define GFS_CACHE_VNODE 0x1
45 typedef struct gfs_dirent {
46 char *gfse_name; /* entry name */
47 vnode_t *(*gfse_ctor)(vnode_t *); /* constructor */
48 int gfse_flags; /* flags */
49 list_node_t gfse_link; /* dynamic list */
50 vnode_t *gfse_vnode; /* cached vnode */
53 typedef enum gfs_type {
58 typedef struct gfs_file {
59 vnode_t *gfs_vnode; /* current vnode */
60 vnode_t *gfs_parent; /* parent vnode */
61 size_t gfs_size; /* size of private data structure */
62 gfs_type_t gfs_type; /* type of vnode */
63 int gfs_index; /* index in parent dir */
64 ino64_t gfs_ino; /* inode for this vnode */
67 typedef int (*gfs_readdir_cb)(vnode_t *, struct dirent64 *, int *, offset_t *,
69 typedef int (*gfs_lookup_cb)(vnode_t *, const char *, vnode_t **, ino64_t *);
70 typedef ino64_t (*gfs_inode_cb)(vnode_t *, int);
72 typedef struct gfs_dir {
73 gfs_file_t gfsd_file; /* generic file attributes */
74 gfs_dirent_t *gfsd_static; /* statically defined entries */
75 int gfsd_nstatic; /* # static entries */
76 kmutex_t gfsd_lock; /* protects entries */
77 int gfsd_maxlen; /* maximum name length */
78 gfs_readdir_cb gfsd_readdir; /* readdir() callback */
79 gfs_lookup_cb gfsd_lookup; /* lookup() callback */
80 gfs_inode_cb gfsd_inode; /* get an inode number */
85 extern vnode_t *gfs_file_create(size_t, vnode_t *, vfs_t *, vnodeops_t *);
86 extern vnode_t *gfs_dir_create(size_t, vnode_t *, vfs_t *, vnodeops_t *,
87 gfs_dirent_t *, gfs_inode_cb, int, gfs_readdir_cb, gfs_lookup_cb);
88 extern vnode_t *gfs_root_create(size_t, vfs_t *, vnodeops_t *, ino64_t,
89 gfs_dirent_t *, gfs_inode_cb, int, gfs_readdir_cb, gfs_lookup_cb);
90 extern vnode_t *gfs_root_create_file(size_t, struct vfs *, vnodeops_t *,
93 extern void *gfs_file_inactive(vnode_t *);
94 extern void *gfs_dir_inactive(vnode_t *);
96 extern int gfs_dir_lookup(vnode_t *, const char *, vnode_t **);
97 extern int gfs_dir_readdir(vnode_t *, uio_t *, int *, int *, u_long **, void *);
99 #define gfs_dir_lock(gd) mutex_enter(&(gd)->gfsd_lock)
100 #define gfs_dir_unlock(gd) mutex_exit(&(gd)->gfsd_lock)
102 #define gfs_file_parent(vp) (((gfs_file_t *)(vp)->v_data)->gfs_parent)
104 #define gfs_file_index(vp) (((gfs_file_t *)(vp)->v_data)->gfs_index)
105 #define gfs_file_set_index(vp, idx) \
106 (((gfs_file_t *)(vp)->v_data)->gfs_index = (idx))
108 #define gfs_file_inode(vp) (((gfs_file_t *)(vp)->v_data)->gfs_ino)
109 #define gfs_file_set_inode(vp, ino) \
110 (((gfs_file_t *)(vp)->v_data)->gfs_ino = (ino))
112 typedef struct gfs_readdir_state {
113 struct dirent64 *grd_dirent; /* directory entry buffer */
114 size_t grd_namlen; /* max file name length */
115 size_t grd_ureclen; /* exported record size */
116 ssize_t grd_oresid; /* original uio_resid */
117 ino64_t grd_parent; /* inode of parent */
118 ino64_t grd_self; /* inode of self */
119 } gfs_readdir_state_t;
121 extern int gfs_readdir_init(gfs_readdir_state_t *, int, int, uio_t *, ino64_t,
123 extern int gfs_readdir_emit(gfs_readdir_state_t *, uio_t *, offset_t, ino64_t,
124 const char *, int *, u_long **);
125 extern int gfs_readdir_pred(gfs_readdir_state_t *, uio_t *, offset_t *, int *,
127 extern int gfs_readdir_fini(gfs_readdir_state_t *, int, int *, int);
129 extern int gfs_lookup_dot(vnode_t **, vnode_t *, vnode_t *, const char *);
131 extern int gfs_vop_readdir(struct vop_readdir_args *);
132 extern int gfs_vop_inactive(struct vop_inactive_args *);
139 #endif /* _SYS_GFS_H */