10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 53898Srsb * Common Development and Distribution License (the "License"). 63898Srsb * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 21*3957Sth199096 220Sstevel@tonic-gate /* 233898Srsb * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #ifndef _SYS_GFS_H 280Sstevel@tonic-gate #define _SYS_GFS_H 290Sstevel@tonic-gate 300Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 310Sstevel@tonic-gate 320Sstevel@tonic-gate #include <sys/types.h> 330Sstevel@tonic-gate #include <sys/vnode.h> 343898Srsb #include <sys/vfs_opreg.h> 350Sstevel@tonic-gate #include <sys/mutex.h> 360Sstevel@tonic-gate #include <sys/dirent.h> 370Sstevel@tonic-gate #include <sys/uio.h> 380Sstevel@tonic-gate #include <sys/list.h> 390Sstevel@tonic-gate #include <sys/pathname.h> 400Sstevel@tonic-gate 410Sstevel@tonic-gate #ifdef __cplusplus 420Sstevel@tonic-gate extern "C" { 430Sstevel@tonic-gate #endif 440Sstevel@tonic-gate 450Sstevel@tonic-gate typedef struct gfs_opsvec { 460Sstevel@tonic-gate const char *gfsv_name; /* vnode description */ 470Sstevel@tonic-gate const fs_operation_def_t *gfsv_template; /* ops template */ 480Sstevel@tonic-gate vnodeops_t **gfsv_ops; /* ptr to result */ 490Sstevel@tonic-gate } gfs_opsvec_t; 500Sstevel@tonic-gate 510Sstevel@tonic-gate int gfs_make_opsvec(gfs_opsvec_t *); 520Sstevel@tonic-gate 530Sstevel@tonic-gate #define GFS_CACHE_VNODE 0x1 540Sstevel@tonic-gate 550Sstevel@tonic-gate typedef struct gfs_dirent { 560Sstevel@tonic-gate char *gfse_name; /* entry name */ 570Sstevel@tonic-gate vnode_t *(*gfse_ctor)(vnode_t *); /* constructor */ 580Sstevel@tonic-gate int gfse_flags; /* flags */ 590Sstevel@tonic-gate list_node_t gfse_link; /* dynamic list */ 600Sstevel@tonic-gate vnode_t *gfse_vnode; /* cached vnode */ 610Sstevel@tonic-gate } gfs_dirent_t; 620Sstevel@tonic-gate 630Sstevel@tonic-gate typedef enum gfs_type { 640Sstevel@tonic-gate GFS_DIR, 650Sstevel@tonic-gate GFS_FILE 660Sstevel@tonic-gate } gfs_type_t; 670Sstevel@tonic-gate 680Sstevel@tonic-gate typedef struct gfs_file { 690Sstevel@tonic-gate vnode_t *gfs_vnode; /* current vnode */ 700Sstevel@tonic-gate vnode_t *gfs_parent; /* parent vnode */ 710Sstevel@tonic-gate size_t gfs_size; /* size of private data structure */ 720Sstevel@tonic-gate gfs_type_t gfs_type; /* type of vnode */ 730Sstevel@tonic-gate int gfs_index; /* index in parent dir */ 740Sstevel@tonic-gate ino64_t gfs_ino; /* inode for this vnode */ 750Sstevel@tonic-gate } gfs_file_t; 760Sstevel@tonic-gate 770Sstevel@tonic-gate typedef int (*gfs_readdir_cb)(vnode_t *, struct dirent64 *, int *, offset_t *, 780Sstevel@tonic-gate offset_t *, void *); 790Sstevel@tonic-gate typedef int (*gfs_lookup_cb)(vnode_t *, const char *, vnode_t **, ino64_t *); 800Sstevel@tonic-gate typedef ino64_t (*gfs_inode_cb)(vnode_t *, int); 810Sstevel@tonic-gate 820Sstevel@tonic-gate typedef struct gfs_dir { 830Sstevel@tonic-gate gfs_file_t gfsd_file; /* generic file attributes */ 840Sstevel@tonic-gate gfs_dirent_t *gfsd_static; /* statically defined entries */ 850Sstevel@tonic-gate int gfsd_nstatic; /* # static entries */ 860Sstevel@tonic-gate kmutex_t gfsd_lock; /* protects entries */ 870Sstevel@tonic-gate int gfsd_maxlen; /* maximum name length */ 880Sstevel@tonic-gate gfs_readdir_cb gfsd_readdir; /* readdir() callback */ 890Sstevel@tonic-gate gfs_lookup_cb gfsd_lookup; /* lookup() callback */ 900Sstevel@tonic-gate gfs_inode_cb gfsd_inode; /* get an inode number */ 910Sstevel@tonic-gate } gfs_dir_t; 920Sstevel@tonic-gate 930Sstevel@tonic-gate struct vfs; 940Sstevel@tonic-gate 950Sstevel@tonic-gate extern vnode_t *gfs_file_create(size_t, vnode_t *, vnodeops_t *); 960Sstevel@tonic-gate extern vnode_t *gfs_dir_create(size_t, vnode_t *, vnodeops_t *, 970Sstevel@tonic-gate gfs_dirent_t *, gfs_inode_cb, int, gfs_readdir_cb, gfs_lookup_cb); 980Sstevel@tonic-gate extern vnode_t *gfs_root_create(size_t, struct vfs *, vnodeops_t *, ino64_t, 990Sstevel@tonic-gate gfs_dirent_t *, gfs_inode_cb, int, gfs_readdir_cb, gfs_lookup_cb); 100*3957Sth199096 extern vnode_t *gfs_root_create_file(size_t, struct vfs *, vnodeops_t *, 101*3957Sth199096 ino64_t); 1020Sstevel@tonic-gate 1030Sstevel@tonic-gate extern void *gfs_file_inactive(vnode_t *); 1040Sstevel@tonic-gate extern void *gfs_dir_inactive(vnode_t *); 1050Sstevel@tonic-gate 1060Sstevel@tonic-gate extern int gfs_dir_lookup(vnode_t *, const char *, vnode_t **); 1070Sstevel@tonic-gate extern int gfs_dir_readdir(vnode_t *, uio_t *, int *, void *); 1080Sstevel@tonic-gate 1090Sstevel@tonic-gate #define gfs_dir_lock(gd) mutex_enter(&(gd)->gfsd_lock) 1100Sstevel@tonic-gate #define gfs_dir_unlock(gd) mutex_exit(&(gd)->gfsd_lock) 1110Sstevel@tonic-gate 1120Sstevel@tonic-gate #define gfs_file_parent(vp) (((gfs_file_t *)(vp)->v_data)->gfs_parent) 1130Sstevel@tonic-gate 1140Sstevel@tonic-gate #define gfs_file_index(vp) (((gfs_file_t *)(vp)->v_data)->gfs_index) 1150Sstevel@tonic-gate #define gfs_file_set_index(vp, idx) \ 1160Sstevel@tonic-gate (((gfs_file_t *)(vp)->v_data)->gfs_index = (idx)) 1170Sstevel@tonic-gate 1180Sstevel@tonic-gate #define gfs_file_inode(vp) (((gfs_file_t *)(vp)->v_data)->gfs_ino) 1190Sstevel@tonic-gate #define gfs_file_set_inode(vp, ino) \ 1200Sstevel@tonic-gate (((gfs_file_t *)(vp)->v_data)->gfs_ino = (ino)) 1210Sstevel@tonic-gate 1220Sstevel@tonic-gate typedef struct gfs_readdir_state { 1230Sstevel@tonic-gate struct dirent64 *grd_dirent; /* directory entry buffer */ 1240Sstevel@tonic-gate size_t grd_namlen; /* max file name length */ 1250Sstevel@tonic-gate size_t grd_ureclen; /* exported record size */ 1260Sstevel@tonic-gate ssize_t grd_oresid; /* original uio_resid */ 1270Sstevel@tonic-gate ino64_t grd_parent; /* inode of parent */ 1280Sstevel@tonic-gate ino64_t grd_self; /* inode of self */ 1290Sstevel@tonic-gate } gfs_readdir_state_t; 1300Sstevel@tonic-gate 1310Sstevel@tonic-gate extern int gfs_readdir_init(gfs_readdir_state_t *, int, int, uio_t *, ino64_t, 1320Sstevel@tonic-gate ino64_t); 1330Sstevel@tonic-gate extern int gfs_readdir_emit(gfs_readdir_state_t *, uio_t *, offset_t, ino64_t, 1340Sstevel@tonic-gate const char *); 1350Sstevel@tonic-gate extern int gfs_readdir_emitn(gfs_readdir_state_t *, uio_t *, offset_t, ino64_t, 1360Sstevel@tonic-gate unsigned long); 1370Sstevel@tonic-gate extern int gfs_readdir_pred(gfs_readdir_state_t *, uio_t *, offset_t *); 1380Sstevel@tonic-gate extern int gfs_readdir_fini(gfs_readdir_state_t *, int, int *, int); 1390Sstevel@tonic-gate 1400Sstevel@tonic-gate extern int gfs_lookup_dot(vnode_t **, vnode_t *, vnode_t *, const char *); 1410Sstevel@tonic-gate 1420Sstevel@tonic-gate extern int gfs_vop_lookup(vnode_t *, char *, vnode_t **, pathname_t *, 1430Sstevel@tonic-gate int, vnode_t *, cred_t *); 1440Sstevel@tonic-gate extern int gfs_vop_readdir(vnode_t *, uio_t *, cred_t *, int *); 1450Sstevel@tonic-gate extern int gfs_vop_map(vnode_t *, offset_t, struct as *, caddr_t *, 1460Sstevel@tonic-gate size_t, uchar_t, uchar_t, uint_t, cred_t *); 1470Sstevel@tonic-gate extern void gfs_vop_inactive(vnode_t *, cred_t *); 1480Sstevel@tonic-gate 1490Sstevel@tonic-gate 1500Sstevel@tonic-gate #ifdef __cplusplus 1510Sstevel@tonic-gate } 1520Sstevel@tonic-gate #endif 1530Sstevel@tonic-gate 1540Sstevel@tonic-gate #endif /* _SYS_GFS_H */ 155