xref: /titanic_51/usr/src/uts/common/sys/gfs.h (revision 9a8685acb1980e757acb4b2fdbb106654ef61317)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5aa59c4cbSrsb  * Common Development and Distribution License (the "License").
6aa59c4cbSrsb  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
21a237e38eSth199096 
227c478bd9Sstevel@tonic-gate /*
23*9a8685acSstephanie scheffler  * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
24*9a8685acSstephanie scheffler  */
25*9a8685acSstephanie scheffler 
26*9a8685acSstephanie scheffler /*
27*9a8685acSstephanie scheffler  * These are Consolidation Private interfaces and are subject to change.
287c478bd9Sstevel@tonic-gate  */
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #ifndef _SYS_GFS_H
317c478bd9Sstevel@tonic-gate #define	_SYS_GFS_H
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #include <sys/types.h>
347c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
35aa59c4cbSrsb #include <sys/vfs_opreg.h>
367c478bd9Sstevel@tonic-gate #include <sys/mutex.h>
377c478bd9Sstevel@tonic-gate #include <sys/dirent.h>
38b38f0970Sck153898 #include <sys/extdirent.h>
397c478bd9Sstevel@tonic-gate #include <sys/uio.h>
407c478bd9Sstevel@tonic-gate #include <sys/list.h>
417c478bd9Sstevel@tonic-gate #include <sys/pathname.h>
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
447c478bd9Sstevel@tonic-gate extern "C" {
457c478bd9Sstevel@tonic-gate #endif
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate typedef struct gfs_opsvec {
487c478bd9Sstevel@tonic-gate 	const char		*gfsv_name;	/* vnode description */
497c478bd9Sstevel@tonic-gate 	const fs_operation_def_t *gfsv_template; /* ops template */
507c478bd9Sstevel@tonic-gate 	vnodeops_t		**gfsv_ops;	/* ptr to result */
517c478bd9Sstevel@tonic-gate } gfs_opsvec_t;
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate int gfs_make_opsvec(gfs_opsvec_t *);
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate #define	GFS_CACHE_VNODE		0x1
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate typedef struct gfs_dirent {
587c478bd9Sstevel@tonic-gate 	char			*gfse_name;	/* entry name */
597c478bd9Sstevel@tonic-gate 	vnode_t *(*gfse_ctor)(vnode_t *);	/* constructor */
607c478bd9Sstevel@tonic-gate 	int			gfse_flags;	/* flags */
617c478bd9Sstevel@tonic-gate 	list_node_t		gfse_link;	/* dynamic list */
627c478bd9Sstevel@tonic-gate 	vnode_t			*gfse_vnode;	/* cached vnode */
637c478bd9Sstevel@tonic-gate } gfs_dirent_t;
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate typedef enum gfs_type {
667c478bd9Sstevel@tonic-gate 	GFS_DIR,
677c478bd9Sstevel@tonic-gate 	GFS_FILE
687c478bd9Sstevel@tonic-gate } gfs_type_t;
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate typedef struct gfs_file {
717c478bd9Sstevel@tonic-gate 	vnode_t		*gfs_vnode;	/* current vnode */
727c478bd9Sstevel@tonic-gate 	vnode_t		*gfs_parent;	/* parent vnode */
737c478bd9Sstevel@tonic-gate 	size_t		gfs_size;	/* size of private data structure */
747c478bd9Sstevel@tonic-gate 	gfs_type_t	gfs_type;	/* type of vnode */
757c478bd9Sstevel@tonic-gate 	int		gfs_index;	/* index in parent dir */
767c478bd9Sstevel@tonic-gate 	ino64_t		gfs_ino;	/* inode for this vnode */
777c478bd9Sstevel@tonic-gate } gfs_file_t;
787c478bd9Sstevel@tonic-gate 
79b38f0970Sck153898 typedef int (*gfs_readdir_cb)(vnode_t *, void *, int *, offset_t *,
80b38f0970Sck153898     offset_t *, void *, int);
81da6c28aaSamw typedef int (*gfs_lookup_cb)(vnode_t *, const char *, vnode_t **, ino64_t *,
82ab04eb8eStimh     cred_t *, int, int *, pathname_t *);
837c478bd9Sstevel@tonic-gate typedef ino64_t (*gfs_inode_cb)(vnode_t *, int);
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate typedef struct gfs_dir {
867c478bd9Sstevel@tonic-gate 	gfs_file_t	gfsd_file;	/* generic file attributes */
877c478bd9Sstevel@tonic-gate 	gfs_dirent_t	*gfsd_static;	/* statically defined entries */
887c478bd9Sstevel@tonic-gate 	int		gfsd_nstatic;	/* # static entries */
897c478bd9Sstevel@tonic-gate 	kmutex_t	gfsd_lock;	/* protects entries */
907c478bd9Sstevel@tonic-gate 	int		gfsd_maxlen;	/* maximum name length */
917c478bd9Sstevel@tonic-gate 	gfs_readdir_cb	gfsd_readdir;	/* readdir() callback */
927c478bd9Sstevel@tonic-gate 	gfs_lookup_cb	gfsd_lookup;	/* lookup() callback */
937c478bd9Sstevel@tonic-gate 	gfs_inode_cb	gfsd_inode;	/* get an inode number */
947c478bd9Sstevel@tonic-gate } gfs_dir_t;
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate struct vfs;
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate extern vnode_t *gfs_file_create(size_t, vnode_t *, vnodeops_t *);
997c478bd9Sstevel@tonic-gate extern vnode_t *gfs_dir_create(size_t, vnode_t *, vnodeops_t *,
1007c478bd9Sstevel@tonic-gate     gfs_dirent_t *, gfs_inode_cb, int, gfs_readdir_cb, gfs_lookup_cb);
1017c478bd9Sstevel@tonic-gate extern vnode_t *gfs_root_create(size_t, struct vfs *, vnodeops_t *, ino64_t,
1027c478bd9Sstevel@tonic-gate     gfs_dirent_t *, gfs_inode_cb, int, gfs_readdir_cb, gfs_lookup_cb);
103a237e38eSth199096 extern vnode_t *gfs_root_create_file(size_t, struct vfs *, vnodeops_t *,
104a237e38eSth199096     ino64_t);
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate extern void *gfs_file_inactive(vnode_t *);
1077c478bd9Sstevel@tonic-gate extern void *gfs_dir_inactive(vnode_t *);
1087c478bd9Sstevel@tonic-gate 
109ab04eb8eStimh extern int gfs_dir_case_lookup(vnode_t *, const char *, vnode_t **, cred_t *,
110ab04eb8eStimh     int, int *, pathname_t *);
111ab04eb8eStimh extern int gfs_dir_lookup(vnode_t *, const char *, vnode_t **, cred_t *,
112ab04eb8eStimh     int, int *, pathname_t *);
113da6c28aaSamw extern int gfs_dir_readdir(vnode_t *, uio_t *, int *, void *, cred_t *,
114b38f0970Sck153898     caller_context_t *, int flags);
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate #define	gfs_dir_lock(gd)	mutex_enter(&(gd)->gfsd_lock)
1177c478bd9Sstevel@tonic-gate #define	gfs_dir_unlock(gd)	mutex_exit(&(gd)->gfsd_lock)
118ab04eb8eStimh #define	GFS_DIR_LOCKED(gd)	MUTEX_HELD(&(gd)->gfsd_lock)
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate #define	gfs_file_parent(vp)	(((gfs_file_t *)(vp)->v_data)->gfs_parent)
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate #define	gfs_file_index(vp)	(((gfs_file_t *)(vp)->v_data)->gfs_index)
1237c478bd9Sstevel@tonic-gate #define	gfs_file_set_index(vp, idx)	\
1247c478bd9Sstevel@tonic-gate 	(((gfs_file_t *)(vp)->v_data)->gfs_index = (idx))
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate #define	gfs_file_inode(vp)	(((gfs_file_t *)(vp)->v_data)->gfs_ino)
1277c478bd9Sstevel@tonic-gate #define	gfs_file_set_inode(vp, ino)	\
1287c478bd9Sstevel@tonic-gate 	(((gfs_file_t *)(vp)->v_data)->gfs_ino = (ino))
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate typedef struct gfs_readdir_state {
131b38f0970Sck153898 	void		*grd_dirent;	/* directory entry buffer */
1327c478bd9Sstevel@tonic-gate 	size_t		grd_namlen;	/* max file name length */
1337c478bd9Sstevel@tonic-gate 	size_t		grd_ureclen;	/* exported record size */
1347c478bd9Sstevel@tonic-gate 	ssize_t		grd_oresid;	/* original uio_resid */
1357c478bd9Sstevel@tonic-gate 	ino64_t		grd_parent;	/* inode of parent */
1367c478bd9Sstevel@tonic-gate 	ino64_t		grd_self;	/* inode of self */
137b38f0970Sck153898 	int		grd_flags;	/* flags from VOP_READDIR */
1387c478bd9Sstevel@tonic-gate } gfs_readdir_state_t;
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate extern int gfs_readdir_init(gfs_readdir_state_t *, int, int, uio_t *, ino64_t,
141b38f0970Sck153898     ino64_t, int);
1427c478bd9Sstevel@tonic-gate extern int gfs_readdir_emit(gfs_readdir_state_t *, uio_t *, offset_t, ino64_t,
143b38f0970Sck153898     const char *, int);
1447c478bd9Sstevel@tonic-gate extern int gfs_readdir_emitn(gfs_readdir_state_t *, uio_t *, offset_t, ino64_t,
1457c478bd9Sstevel@tonic-gate     unsigned long);
1467c478bd9Sstevel@tonic-gate extern int gfs_readdir_pred(gfs_readdir_state_t *, uio_t *, offset_t *);
1477c478bd9Sstevel@tonic-gate extern int gfs_readdir_fini(gfs_readdir_state_t *, int, int *, int);
148b38f0970Sck153898 extern int gfs_get_parent_ino(vnode_t *, cred_t *, caller_context_t *,
149b38f0970Sck153898     ino64_t *, ino64_t *);
1507c478bd9Sstevel@tonic-gate 
151da6c28aaSamw /*
152da6c28aaSamw  * Objects with real extended attributes will get their . and ..
153da6c28aaSamw  * readdir entries from the real xattr directory. GFS_STATIC_ENTRY_OFFSET
154da6c28aaSamw  * lets us skip right to the static entries in the GFS directory.
155da6c28aaSamw  */
156da6c28aaSamw #define	GFS_STATIC_ENTRY_OFFSET	((offset_t)2)
157da6c28aaSamw 
1587c478bd9Sstevel@tonic-gate extern int gfs_lookup_dot(vnode_t **, vnode_t *, vnode_t *, const char *);
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate extern int gfs_vop_lookup(vnode_t *, char *, vnode_t **, pathname_t *,
161da6c28aaSamw     int, vnode_t *, cred_t *, caller_context_t *, int *, pathname_t *);
162da6c28aaSamw extern int gfs_vop_readdir(vnode_t *, uio_t *, cred_t *, int *,
163da6c28aaSamw     caller_context_t *, int);
1647c478bd9Sstevel@tonic-gate extern int gfs_vop_map(vnode_t *, offset_t, struct as *, caddr_t *,
165da6c28aaSamw     size_t, uchar_t, uchar_t, uint_t, cred_t *, caller_context_t *);
166da6c28aaSamw extern void gfs_vop_inactive(vnode_t *, cred_t *, caller_context_t *);
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate 
1697c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1707c478bd9Sstevel@tonic-gate }
1717c478bd9Sstevel@tonic-gate #endif
1727c478bd9Sstevel@tonic-gate 
1737c478bd9Sstevel@tonic-gate #endif	/* _SYS_GFS_H */
174