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