1*b819cea2SGordon Ross /*
2*b819cea2SGordon Ross  * CDDL HEADER START
3*b819cea2SGordon Ross  *
4*b819cea2SGordon Ross  * The contents of this file are subject to the terms of the
5*b819cea2SGordon Ross  * Common Development and Distribution License (the "License").
6*b819cea2SGordon Ross  * You may not use this file except in compliance with the License.
7*b819cea2SGordon Ross  *
8*b819cea2SGordon Ross  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*b819cea2SGordon Ross  * or http://www.opensolaris.org/os/licensing.
10*b819cea2SGordon Ross  * See the License for the specific language governing permissions
11*b819cea2SGordon Ross  * and limitations under the License.
12*b819cea2SGordon Ross  *
13*b819cea2SGordon Ross  * When distributing Covered Code, include this CDDL HEADER in each
14*b819cea2SGordon Ross  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*b819cea2SGordon Ross  * If applicable, add the following below this CDDL HEADER, with the
16*b819cea2SGordon Ross  * fields enclosed by brackets "[]" replaced with your own identifying
17*b819cea2SGordon Ross  * information: Portions Copyright [yyyy] [name of copyright owner]
18*b819cea2SGordon Ross  *
19*b819cea2SGordon Ross  * CDDL HEADER END
20*b819cea2SGordon Ross  */
21*b819cea2SGordon Ross /*
22*b819cea2SGordon Ross  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23*b819cea2SGordon Ross  * Use is subject to license terms.
24*b819cea2SGordon Ross  *
25*b819cea2SGordon Ross  * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
26*b819cea2SGordon Ross  */
27*b819cea2SGordon Ross 
28*b819cea2SGordon Ross #ifndef _SYS_VFS_OPREG_H
29*b819cea2SGordon Ross #define	_SYS_VFS_OPREG_H
30*b819cea2SGordon Ross 
31*b819cea2SGordon Ross #include <sys/vfs.h>
32*b819cea2SGordon Ross #include <sys/fem.h>
33*b819cea2SGordon Ross 
34*b819cea2SGordon Ross #ifdef	__cplusplus
35*b819cea2SGordon Ross extern "C" {
36*b819cea2SGordon Ross #endif
37*b819cea2SGordon Ross 
38*b819cea2SGordon Ross #if defined(_KERNEL) || defined(_FAKE_KERNEL)
39*b819cea2SGordon Ross 
40*b819cea2SGordon Ross /*
41*b819cea2SGordon Ross  * The following union allows us to use C99's "designated initializer"
42*b819cea2SGordon Ross  * feature so that we can have strong typechecking for the operations
43*b819cea2SGordon Ross  * used in the the fs_operation_def structures.
44*b819cea2SGordon Ross  */
45*b819cea2SGordon Ross 
46*b819cea2SGordon Ross typedef union fs_func {
47*b819cea2SGordon Ross 	fs_generic_func_p fs_generic;	/* Generic function signature */
48*b819cea2SGordon Ross 	int (*error)();			/* Signature of error function */
49*b819cea2SGordon Ross 	VFS_OPS;		/* Signatures of all vfs operations (vfsops) */
50*b819cea2SGordon Ross 	VNODE_OPS;		/* Signatures of all vnode operations (vops) */
51*b819cea2SGordon Ross 	FEM_OPS;		/* Signatures of all FEM operations (femops) */
52*b819cea2SGordon Ross 	FSEM_OPS;		/* Signatures of all FSEM ops (fsemops) */
53*b819cea2SGordon Ross } fs_func_p;
54*b819cea2SGordon Ross 
55*b819cea2SGordon Ross /*
56*b819cea2SGordon Ross  * File systems use arrays of fs_operation_def structures to form
57*b819cea2SGordon Ross  * name/value pairs of operations.  These arrays get passed to:
58*b819cea2SGordon Ross  *
59*b819cea2SGordon Ross  * 	- vn_make_ops() to create vnodeops
60*b819cea2SGordon Ross  * 	- vfs_makefsops()/vfs_setfsops() to create vfsops.
61*b819cea2SGordon Ross  */
62*b819cea2SGordon Ross typedef struct fs_operation_def {
63*b819cea2SGordon Ross 	char *name;			/* name of operation (NULL at end) */
64*b819cea2SGordon Ross 	fs_func_p func;			/* function implementing operation */
65*b819cea2SGordon Ross } fs_operation_def_t;
66*b819cea2SGordon Ross 
67*b819cea2SGordon Ross /*
68*b819cea2SGordon Ross  * The operation registration mechanism uses two master tables of operations:
69*b819cea2SGordon Ross  * one for vnode operations (vn_ops_table[]) and one for vfs operations
70*b819cea2SGordon Ross  * (vfs_ops_table[]).  These tables are arrays of fs_operation_trans_def
71*b819cea2SGordon Ross  * structures.  They contain all of the information necessary for the system
72*b819cea2SGordon Ross  * to populate an operations structure (e.g., vnodeops, vfsops).
73*b819cea2SGordon Ross  *
74*b819cea2SGordon Ross  * File systems call registration routines (vfs_setfsops(), vfs_makefsops(),
75*b819cea2SGordon Ross  * and vn_make_ops()) and pass in their operations specification tables
76*b819cea2SGordon Ross  * (arrays of fs_operation_def structures).  These routines use the master
77*b819cea2SGordon Ross  * table(s) of operations to build a vnodeops or vfsops structure.
78*b819cea2SGordon Ross  */
79*b819cea2SGordon Ross typedef struct fs_operation_trans_def {
80*b819cea2SGordon Ross 	char *name;			/* name of operation (NULL at end) */
81*b819cea2SGordon Ross 	int offset;			/* byte offset within ops vector */
82*b819cea2SGordon Ross 	fs_generic_func_p defaultFunc;	/* default function */
83*b819cea2SGordon Ross 	fs_generic_func_p errorFunc; 	/* error function */
84*b819cea2SGordon Ross } fs_operation_trans_def_t;
85*b819cea2SGordon Ross 
86*b819cea2SGordon Ross /*
87*b819cea2SGordon Ross  * Generic operations vector types (used for vfs/vnode ops registration).
88*b819cea2SGordon Ross  */
89*b819cea2SGordon Ross 
90*b819cea2SGordon Ross extern int fs_default();		/* "default" function placeholder */
91*b819cea2SGordon Ross extern int fs_error();			/* "error" function placeholder */
92*b819cea2SGordon Ross 
93*b819cea2SGordon Ross int fs_build_vector(void *vector, int *unused_ops,
94*b819cea2SGordon Ross     const fs_operation_trans_def_t *translation,
95*b819cea2SGordon Ross     const fs_operation_def_t *operations);
96*b819cea2SGordon Ross 
97*b819cea2SGordon Ross /*
98*b819cea2SGordon Ross  * Public operations.
99*b819cea2SGordon Ross  */
100*b819cea2SGordon Ross 
101*b819cea2SGordon Ross int	vn_make_ops(const char *, const struct fs_operation_def *,
102*b819cea2SGordon Ross 		vnodeops_t **);
103*b819cea2SGordon Ross void	vn_freevnodeops(vnodeops_t *);
104*b819cea2SGordon Ross 
105*b819cea2SGordon Ross int	vfs_setfsops(int, const fs_operation_def_t *, vfsops_t **);
106*b819cea2SGordon Ross int	vfs_makefsops(const fs_operation_def_t *, vfsops_t **);
107*b819cea2SGordon Ross void	vfs_freevfsops(vfsops_t *);
108*b819cea2SGordon Ross int	vfs_freevfsops_by_type(int);
109*b819cea2SGordon Ross 
110*b819cea2SGordon Ross #endif /* _KERNEL */
111*b819cea2SGordon Ross 
112*b819cea2SGordon Ross #ifdef	__cplusplus
113*b819cea2SGordon Ross }
114*b819cea2SGordon Ross #endif
115*b819cea2SGordon Ross 
116*b819cea2SGordon Ross #endif	/* _SYS_VFS_OPREG_H */
117