1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #ifndef _SYS_GFS_H 28*7c478bd9Sstevel@tonic-gate #define _SYS_GFS_H 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 31*7c478bd9Sstevel@tonic-gate 32*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 33*7c478bd9Sstevel@tonic-gate #include <sys/vnode.h> 34*7c478bd9Sstevel@tonic-gate #include <sys/mutex.h> 35*7c478bd9Sstevel@tonic-gate #include <sys/dirent.h> 36*7c478bd9Sstevel@tonic-gate #include <sys/uio.h> 37*7c478bd9Sstevel@tonic-gate #include <sys/list.h> 38*7c478bd9Sstevel@tonic-gate #include <sys/pathname.h> 39*7c478bd9Sstevel@tonic-gate 40*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 41*7c478bd9Sstevel@tonic-gate extern "C" { 42*7c478bd9Sstevel@tonic-gate #endif 43*7c478bd9Sstevel@tonic-gate 44*7c478bd9Sstevel@tonic-gate typedef struct gfs_opsvec { 45*7c478bd9Sstevel@tonic-gate const char *gfsv_name; /* vnode description */ 46*7c478bd9Sstevel@tonic-gate const fs_operation_def_t *gfsv_template; /* ops template */ 47*7c478bd9Sstevel@tonic-gate vnodeops_t **gfsv_ops; /* ptr to result */ 48*7c478bd9Sstevel@tonic-gate } gfs_opsvec_t; 49*7c478bd9Sstevel@tonic-gate 50*7c478bd9Sstevel@tonic-gate int gfs_make_opsvec(gfs_opsvec_t *); 51*7c478bd9Sstevel@tonic-gate 52*7c478bd9Sstevel@tonic-gate #define GFS_CACHE_VNODE 0x1 53*7c478bd9Sstevel@tonic-gate 54*7c478bd9Sstevel@tonic-gate typedef struct gfs_dirent { 55*7c478bd9Sstevel@tonic-gate char *gfse_name; /* entry name */ 56*7c478bd9Sstevel@tonic-gate vnode_t *(*gfse_ctor)(vnode_t *); /* constructor */ 57*7c478bd9Sstevel@tonic-gate int gfse_flags; /* flags */ 58*7c478bd9Sstevel@tonic-gate list_node_t gfse_link; /* dynamic list */ 59*7c478bd9Sstevel@tonic-gate vnode_t *gfse_vnode; /* cached vnode */ 60*7c478bd9Sstevel@tonic-gate } gfs_dirent_t; 61*7c478bd9Sstevel@tonic-gate 62*7c478bd9Sstevel@tonic-gate typedef enum gfs_type { 63*7c478bd9Sstevel@tonic-gate GFS_DIR, 64*7c478bd9Sstevel@tonic-gate GFS_FILE 65*7c478bd9Sstevel@tonic-gate } gfs_type_t; 66*7c478bd9Sstevel@tonic-gate 67*7c478bd9Sstevel@tonic-gate typedef struct gfs_file { 68*7c478bd9Sstevel@tonic-gate vnode_t *gfs_vnode; /* current vnode */ 69*7c478bd9Sstevel@tonic-gate vnode_t *gfs_parent; /* parent vnode */ 70*7c478bd9Sstevel@tonic-gate size_t gfs_size; /* size of private data structure */ 71*7c478bd9Sstevel@tonic-gate gfs_type_t gfs_type; /* type of vnode */ 72*7c478bd9Sstevel@tonic-gate int gfs_index; /* index in parent dir */ 73*7c478bd9Sstevel@tonic-gate ino64_t gfs_ino; /* inode for this vnode */ 74*7c478bd9Sstevel@tonic-gate } gfs_file_t; 75*7c478bd9Sstevel@tonic-gate 76*7c478bd9Sstevel@tonic-gate typedef int (*gfs_readdir_cb)(vnode_t *, struct dirent64 *, int *, offset_t *, 77*7c478bd9Sstevel@tonic-gate offset_t *, void *); 78*7c478bd9Sstevel@tonic-gate typedef int (*gfs_lookup_cb)(vnode_t *, const char *, vnode_t **, ino64_t *); 79*7c478bd9Sstevel@tonic-gate typedef ino64_t (*gfs_inode_cb)(vnode_t *, int); 80*7c478bd9Sstevel@tonic-gate 81*7c478bd9Sstevel@tonic-gate typedef struct gfs_dir { 82*7c478bd9Sstevel@tonic-gate gfs_file_t gfsd_file; /* generic file attributes */ 83*7c478bd9Sstevel@tonic-gate gfs_dirent_t *gfsd_static; /* statically defined entries */ 84*7c478bd9Sstevel@tonic-gate int gfsd_nstatic; /* # static entries */ 85*7c478bd9Sstevel@tonic-gate kmutex_t gfsd_lock; /* protects entries */ 86*7c478bd9Sstevel@tonic-gate int gfsd_maxlen; /* maximum name length */ 87*7c478bd9Sstevel@tonic-gate gfs_readdir_cb gfsd_readdir; /* readdir() callback */ 88*7c478bd9Sstevel@tonic-gate gfs_lookup_cb gfsd_lookup; /* lookup() callback */ 89*7c478bd9Sstevel@tonic-gate gfs_inode_cb gfsd_inode; /* get an inode number */ 90*7c478bd9Sstevel@tonic-gate } gfs_dir_t; 91*7c478bd9Sstevel@tonic-gate 92*7c478bd9Sstevel@tonic-gate struct vfs; 93*7c478bd9Sstevel@tonic-gate 94*7c478bd9Sstevel@tonic-gate extern vnode_t *gfs_file_create(size_t, vnode_t *, vnodeops_t *); 95*7c478bd9Sstevel@tonic-gate extern vnode_t *gfs_dir_create(size_t, vnode_t *, vnodeops_t *, 96*7c478bd9Sstevel@tonic-gate gfs_dirent_t *, gfs_inode_cb, int, gfs_readdir_cb, gfs_lookup_cb); 97*7c478bd9Sstevel@tonic-gate extern vnode_t *gfs_root_create(size_t, struct vfs *, vnodeops_t *, ino64_t, 98*7c478bd9Sstevel@tonic-gate gfs_dirent_t *, gfs_inode_cb, int, gfs_readdir_cb, gfs_lookup_cb); 99*7c478bd9Sstevel@tonic-gate 100*7c478bd9Sstevel@tonic-gate extern void *gfs_file_inactive(vnode_t *); 101*7c478bd9Sstevel@tonic-gate extern void *gfs_dir_inactive(vnode_t *); 102*7c478bd9Sstevel@tonic-gate 103*7c478bd9Sstevel@tonic-gate extern int gfs_dir_lookup(vnode_t *, const char *, vnode_t **); 104*7c478bd9Sstevel@tonic-gate extern int gfs_dir_readdir(vnode_t *, uio_t *, int *, void *); 105*7c478bd9Sstevel@tonic-gate 106*7c478bd9Sstevel@tonic-gate #define gfs_dir_lock(gd) mutex_enter(&(gd)->gfsd_lock) 107*7c478bd9Sstevel@tonic-gate #define gfs_dir_unlock(gd) mutex_exit(&(gd)->gfsd_lock) 108*7c478bd9Sstevel@tonic-gate 109*7c478bd9Sstevel@tonic-gate #define gfs_file_parent(vp) (((gfs_file_t *)(vp)->v_data)->gfs_parent) 110*7c478bd9Sstevel@tonic-gate 111*7c478bd9Sstevel@tonic-gate #define gfs_file_index(vp) (((gfs_file_t *)(vp)->v_data)->gfs_index) 112*7c478bd9Sstevel@tonic-gate #define gfs_file_set_index(vp, idx) \ 113*7c478bd9Sstevel@tonic-gate (((gfs_file_t *)(vp)->v_data)->gfs_index = (idx)) 114*7c478bd9Sstevel@tonic-gate 115*7c478bd9Sstevel@tonic-gate #define gfs_file_inode(vp) (((gfs_file_t *)(vp)->v_data)->gfs_ino) 116*7c478bd9Sstevel@tonic-gate #define gfs_file_set_inode(vp, ino) \ 117*7c478bd9Sstevel@tonic-gate (((gfs_file_t *)(vp)->v_data)->gfs_ino = (ino)) 118*7c478bd9Sstevel@tonic-gate 119*7c478bd9Sstevel@tonic-gate typedef struct gfs_readdir_state { 120*7c478bd9Sstevel@tonic-gate struct dirent64 *grd_dirent; /* directory entry buffer */ 121*7c478bd9Sstevel@tonic-gate size_t grd_namlen; /* max file name length */ 122*7c478bd9Sstevel@tonic-gate size_t grd_ureclen; /* exported record size */ 123*7c478bd9Sstevel@tonic-gate ssize_t grd_oresid; /* original uio_resid */ 124*7c478bd9Sstevel@tonic-gate ino64_t grd_parent; /* inode of parent */ 125*7c478bd9Sstevel@tonic-gate ino64_t grd_self; /* inode of self */ 126*7c478bd9Sstevel@tonic-gate } gfs_readdir_state_t; 127*7c478bd9Sstevel@tonic-gate 128*7c478bd9Sstevel@tonic-gate extern int gfs_readdir_init(gfs_readdir_state_t *, int, int, uio_t *, ino64_t, 129*7c478bd9Sstevel@tonic-gate ino64_t); 130*7c478bd9Sstevel@tonic-gate extern int gfs_readdir_emit(gfs_readdir_state_t *, uio_t *, offset_t, ino64_t, 131*7c478bd9Sstevel@tonic-gate const char *); 132*7c478bd9Sstevel@tonic-gate extern int gfs_readdir_emitn(gfs_readdir_state_t *, uio_t *, offset_t, ino64_t, 133*7c478bd9Sstevel@tonic-gate unsigned long); 134*7c478bd9Sstevel@tonic-gate extern int gfs_readdir_pred(gfs_readdir_state_t *, uio_t *, offset_t *); 135*7c478bd9Sstevel@tonic-gate extern int gfs_readdir_fini(gfs_readdir_state_t *, int, int *, int); 136*7c478bd9Sstevel@tonic-gate 137*7c478bd9Sstevel@tonic-gate extern int gfs_lookup_dot(vnode_t **, vnode_t *, vnode_t *, const char *); 138*7c478bd9Sstevel@tonic-gate 139*7c478bd9Sstevel@tonic-gate extern int gfs_vop_lookup(vnode_t *, char *, vnode_t **, pathname_t *, 140*7c478bd9Sstevel@tonic-gate int, vnode_t *, cred_t *); 141*7c478bd9Sstevel@tonic-gate extern int gfs_vop_readdir(vnode_t *, uio_t *, cred_t *, int *); 142*7c478bd9Sstevel@tonic-gate extern int gfs_vop_map(vnode_t *, offset_t, struct as *, caddr_t *, 143*7c478bd9Sstevel@tonic-gate size_t, uchar_t, uchar_t, uint_t, cred_t *); 144*7c478bd9Sstevel@tonic-gate extern void gfs_vop_inactive(vnode_t *, cred_t *); 145*7c478bd9Sstevel@tonic-gate 146*7c478bd9Sstevel@tonic-gate 147*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 148*7c478bd9Sstevel@tonic-gate } 149*7c478bd9Sstevel@tonic-gate #endif 150*7c478bd9Sstevel@tonic-gate 151*7c478bd9Sstevel@tonic-gate #endif /* _SYS_GFS_H */ 152