gfs.h revision 3898:c788126f2a20
11541Srgrimes/*
21541Srgrimes * CDDL HEADER START
31541Srgrimes *
41541Srgrimes * The contents of this file are subject to the terms of the
51541Srgrimes * Common Development and Distribution License (the "License").
61541Srgrimes * You may not use this file except in compliance with the License.
71541Srgrimes *
81541Srgrimes * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
91541Srgrimes * or http://www.opensolaris.org/os/licensing.
101541Srgrimes * See the License for the specific language governing permissions
111541Srgrimes * and limitations under the License.
121541Srgrimes *
131541Srgrimes * When distributing Covered Code, include this CDDL HEADER in each
141541Srgrimes * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
151541Srgrimes * If applicable, add the following below this CDDL HEADER, with the
161541Srgrimes * fields enclosed by brackets "[]" replaced with your own identifying
171541Srgrimes * information: Portions Copyright [yyyy] [name of copyright owner]
181541Srgrimes *
191541Srgrimes * CDDL HEADER END
201541Srgrimes */
211541Srgrimes/*
221541Srgrimes * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
231541Srgrimes * Use is subject to license terms.
241541Srgrimes */
251541Srgrimes
261541Srgrimes#ifndef _SYS_GFS_H
271541Srgrimes#define	_SYS_GFS_H
281541Srgrimes
291541Srgrimes#pragma ident	"%Z%%M%	%I%	%E% SMI"
301541Srgrimes
311541Srgrimes#include <sys/types.h>
321541Srgrimes#include <sys/vnode.h>
331541Srgrimes#include <sys/vfs_opreg.h>
344934Ssmace#include <sys/mutex.h>
351541Srgrimes#include <sys/dirent.h>
361541Srgrimes#include <sys/uio.h>
372165Spaul#include <sys/list.h>
382165Spaul#include <sys/pathname.h>
392165Spaul
401938Sdg#ifdef	__cplusplus
414934Ssmaceextern "C" {
421541Srgrimes#endif
434934Ssmace
441541Srgrimestypedef struct gfs_opsvec {
451541Srgrimes	const char		*gfsv_name;	/* vnode description */
461541Srgrimes	const fs_operation_def_t *gfsv_template; /* ops template */
471541Srgrimes	vnodeops_t		**gfsv_ops;	/* ptr to result */
481541Srgrimes} gfs_opsvec_t;
494934Ssmace
501541Srgrimesint gfs_make_opsvec(gfs_opsvec_t *);
514934Ssmace
521541Srgrimes#define	GFS_CACHE_VNODE		0x1
531541Srgrimes
541541Srgrimestypedef struct gfs_dirent {
551541Srgrimes	char			*gfse_name;	/* entry name */
561541Srgrimes	vnode_t *(*gfse_ctor)(vnode_t *);	/* constructor */
571541Srgrimes	int			gfse_flags;	/* flags */
581541Srgrimes	list_node_t		gfse_link;	/* dynamic list */
591541Srgrimes	vnode_t			*gfse_vnode;	/* cached vnode */
601541Srgrimes} gfs_dirent_t;
611541Srgrimes
621541Srgrimestypedef enum gfs_type {
632165Spaul	GFS_DIR,
642165Spaul	GFS_FILE
65} gfs_type_t;
66
67typedef struct gfs_file {
68	vnode_t		*gfs_vnode;	/* current vnode */
69	vnode_t		*gfs_parent;	/* parent vnode */
70	size_t		gfs_size;	/* size of private data structure */
71	gfs_type_t	gfs_type;	/* type of vnode */
72	int		gfs_index;	/* index in parent dir */
73	ino64_t		gfs_ino;	/* inode for this vnode */
74} gfs_file_t;
75
76typedef int (*gfs_readdir_cb)(vnode_t *, struct dirent64 *, int *, offset_t *,
77    offset_t *, void *);
78typedef int (*gfs_lookup_cb)(vnode_t *, const char *, vnode_t **, ino64_t *);
79typedef ino64_t (*gfs_inode_cb)(vnode_t *, int);
80
81typedef struct gfs_dir {
82	gfs_file_t	gfsd_file;	/* generic file attributes */
83	gfs_dirent_t	*gfsd_static;	/* statically defined entries */
84	int		gfsd_nstatic;	/* # static entries */
85	kmutex_t	gfsd_lock;	/* protects entries */
86	int		gfsd_maxlen;	/* maximum name length */
87	gfs_readdir_cb	gfsd_readdir;	/* readdir() callback */
88	gfs_lookup_cb	gfsd_lookup;	/* lookup() callback */
89	gfs_inode_cb	gfsd_inode;	/* get an inode number */
90} gfs_dir_t;
91
92struct vfs;
93
94extern vnode_t *gfs_file_create(size_t, vnode_t *, vnodeops_t *);
95extern vnode_t *gfs_dir_create(size_t, vnode_t *, vnodeops_t *,
96    gfs_dirent_t *, gfs_inode_cb, int, gfs_readdir_cb, gfs_lookup_cb);
97extern vnode_t *gfs_root_create(size_t, struct vfs *, vnodeops_t *, ino64_t,
98    gfs_dirent_t *, gfs_inode_cb, int, gfs_readdir_cb, gfs_lookup_cb);
99
100extern void *gfs_file_inactive(vnode_t *);
101extern void *gfs_dir_inactive(vnode_t *);
102
103extern int gfs_dir_lookup(vnode_t *, const char *, vnode_t **);
104extern int gfs_dir_readdir(vnode_t *, uio_t *, int *, void *);
105
106#define	gfs_dir_lock(gd)	mutex_enter(&(gd)->gfsd_lock)
107#define	gfs_dir_unlock(gd)	mutex_exit(&(gd)->gfsd_lock)
108
109#define	gfs_file_parent(vp)	(((gfs_file_t *)(vp)->v_data)->gfs_parent)
110
111#define	gfs_file_index(vp)	(((gfs_file_t *)(vp)->v_data)->gfs_index)
112#define	gfs_file_set_index(vp, idx)	\
113	(((gfs_file_t *)(vp)->v_data)->gfs_index = (idx))
114
115#define	gfs_file_inode(vp)	(((gfs_file_t *)(vp)->v_data)->gfs_ino)
116#define	gfs_file_set_inode(vp, ino)	\
117	(((gfs_file_t *)(vp)->v_data)->gfs_ino = (ino))
118
119typedef struct gfs_readdir_state {
120	struct dirent64 *grd_dirent;	/* directory entry buffer */
121	size_t		grd_namlen;	/* max file name length */
122	size_t		grd_ureclen;	/* exported record size */
123	ssize_t		grd_oresid;	/* original uio_resid */
124	ino64_t		grd_parent;	/* inode of parent */
125	ino64_t		grd_self;	/* inode of self */
126} gfs_readdir_state_t;
127
128extern int gfs_readdir_init(gfs_readdir_state_t *, int, int, uio_t *, ino64_t,
129    ino64_t);
130extern int gfs_readdir_emit(gfs_readdir_state_t *, uio_t *, offset_t, ino64_t,
131    const char *);
132extern int gfs_readdir_emitn(gfs_readdir_state_t *, uio_t *, offset_t, ino64_t,
133    unsigned long);
134extern int gfs_readdir_pred(gfs_readdir_state_t *, uio_t *, offset_t *);
135extern int gfs_readdir_fini(gfs_readdir_state_t *, int, int *, int);
136
137extern int gfs_lookup_dot(vnode_t **, vnode_t *, vnode_t *, const char *);
138
139extern int gfs_vop_lookup(vnode_t *, char *, vnode_t **, pathname_t *,
140    int, vnode_t *, cred_t *);
141extern int gfs_vop_readdir(vnode_t *, uio_t *, cred_t *, int *);
142extern int gfs_vop_map(vnode_t *, offset_t, struct as *, caddr_t *,
143    size_t, uchar_t, uchar_t, uint_t, cred_t *);
144extern void gfs_vop_inactive(vnode_t *, cred_t *);
145
146
147#ifdef	__cplusplus
148}
149#endif
150
151#endif	/* _SYS_GFS_H */
152