xref: /freebsd/sbin/geom/core/geom.h (revision bc7512cc58af2e8bbe5bbf5ca0059b1daa1da897)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2004 Pawel Jakub Dawidek <pjd@FreeBSD.org>
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  *
28  * $FreeBSD$
29  */
30 
31 #ifndef _GEOM_H_
32 #define	_GEOM_H_
33 #define	G_LIB_VERSION	5
34 
35 /*
36  * The G_FLAG_VERBOSE flag on a command specification means that the
37  * command will accept a -v option and the GEOM framework will print
38  * out status information after the command when it is run with -v.
39  * Additionally a GEOM command can explicitly specify a -v option and
40  * handle it as it would any other option. If both a -v option and
41  * G_FLAG_VERBOSE are specified for a command then both types of verbose
42  * information will be output when that command is run with -v.
43  *
44  * When the G_FLAG_LOADKLD is specified for a command, the GEOM kernel
45  * module will be loaded when that command is run if it has not yet been
46  * loaded. This flag is typically specified for the `create' command.
47  */
48 #define	G_FLAG_NONE	0x0000
49 #define	G_FLAG_VERBOSE	0x0001
50 #define	G_FLAG_LOADKLD	0x0002
51 
52 #define	G_TYPE_NONE	0x00
53 #define	G_TYPE_BOOL	0x01
54 #define	G_TYPE_STRING	0x02
55 #define	G_TYPE_NUMBER	0x03
56 #define	G_TYPE_MASK	0x0f
57 #define	G_TYPE_DONE	0x10
58 #define	G_TYPE_MULTI	0x20
59 #define	G_TYPE_NUMMASK	0xff00
60 #define	G_TYPE_NUMSHIFT	8
61 
62 #define	G_OPT_MAX	16
63 #define	G_OPT_DONE(opt)		do { (opt)->go_type |= G_TYPE_DONE; } while (0)
64 #define	G_OPT_ISDONE(opt)	((opt)->go_type & G_TYPE_DONE)
65 #define	G_OPT_ISMULTI(opt)	((opt)->go_type & G_TYPE_MULTI)
66 #define	G_OPT_TYPE(opt)		((opt)->go_type & G_TYPE_MASK)
67 #define	G_OPT_NUM(opt)		(((opt)->go_type & G_TYPE_NUMMASK) >> G_TYPE_NUMSHIFT)
68 #define	G_OPT_NUMINC(opt)	((opt)->go_type += (1 << G_TYPE_NUMSHIFT))
69 
70 #define	G_VAL_OPTIONAL	((void *)-1)
71 
72 #define G_OPT_SENTINEL	{ '\0', NULL, NULL, G_TYPE_NONE }
73 #define G_NULL_OPTS	{ G_OPT_SENTINEL }
74 #define	G_CMD_SENTINEL	{ NULL, 0, NULL, G_NULL_OPTS, NULL }
75 
76 struct g_option {
77 	char		 go_char;
78 	const char	*go_name;
79 	const void	*go_val;
80 	unsigned	 go_type;
81 };
82 
83 struct g_command {
84 	const char	*gc_name;
85 	unsigned	 gc_flags;
86 	void		(*gc_func)(struct gctl_req *, unsigned);
87 	struct g_option	gc_options[G_OPT_MAX];
88 	const char	*gc_usage;
89 };
90 #endif	/* !_GEOM_H_ */
91