xref: /freebsd/lib/libgeom/libgeom.h (revision 748e404f265fbf5c868b090f03da1bae6bb12d4e)
1e13db587SPoul-Henning Kamp /*-
2e13db587SPoul-Henning Kamp  * Copyright (c) 2003 Poul-Henning Kamp
3e13db587SPoul-Henning Kamp  * All rights reserved.
4e13db587SPoul-Henning Kamp  *
5e13db587SPoul-Henning Kamp  * Redistribution and use in source and binary forms, with or without
6e13db587SPoul-Henning Kamp  * modification, are permitted provided that the following conditions
7e13db587SPoul-Henning Kamp  * are met:
8e13db587SPoul-Henning Kamp  * 1. Redistributions of source code must retain the above copyright
9e13db587SPoul-Henning Kamp  *    notice, this list of conditions and the following disclaimer.
10e13db587SPoul-Henning Kamp  * 2. Redistributions in binary form must reproduce the above copyright
11e13db587SPoul-Henning Kamp  *    notice, this list of conditions and the following disclaimer in the
12e13db587SPoul-Henning Kamp  *    documentation and/or other materials provided with the distribution.
13e13db587SPoul-Henning Kamp  * 3. The names of the authors may not be used to endorse or promote
14e13db587SPoul-Henning Kamp  *    products derived from this software without specific prior written
15e13db587SPoul-Henning Kamp  *    permission.
16e13db587SPoul-Henning Kamp  *
17e13db587SPoul-Henning Kamp  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18e13db587SPoul-Henning Kamp  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19e13db587SPoul-Henning Kamp  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20e13db587SPoul-Henning Kamp  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21e13db587SPoul-Henning Kamp  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22e13db587SPoul-Henning Kamp  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23e13db587SPoul-Henning Kamp  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24e13db587SPoul-Henning Kamp  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25e13db587SPoul-Henning Kamp  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26e13db587SPoul-Henning Kamp  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27e13db587SPoul-Henning Kamp  * SUCH DAMAGE.
28e13db587SPoul-Henning Kamp  *
29e13db587SPoul-Henning Kamp  * $FreeBSD$
30e13db587SPoul-Henning Kamp  */
31e13db587SPoul-Henning Kamp #ifndef _LIBGEOM_H_
32e13db587SPoul-Henning Kamp #define _LIBGEOM_H_
33e13db587SPoul-Henning Kamp 
34ccac9da4SJohn Baldwin #include <sys/cdefs.h>
35ccac9da4SJohn Baldwin 
367bd4e7b4SPoul-Henning Kamp #include <sys/queue.h>
37ba798fb2SPoul-Henning Kamp #include <sys/time.h>
38e13db587SPoul-Henning Kamp 
394b8938c1SPoul-Henning Kamp #include <geom/geom_ctl.h>
404b8938c1SPoul-Henning Kamp 
41ccac9da4SJohn Baldwin __BEGIN_DECLS
42ccac9da4SJohn Baldwin 
43*748e404fSScott Long #ifndef DEBUG_LIBGEOM
44*748e404fSScott Long #define DEBUG_LIBGEOM 0
45*748e404fSScott Long #endif
46*748e404fSScott Long 
47e13db587SPoul-Henning Kamp void geom_stats_close(void);
48e13db587SPoul-Henning Kamp void geom_stats_resync(void);
49e13db587SPoul-Henning Kamp int geom_stats_open(void);
50e13db587SPoul-Henning Kamp void *geom_stats_snapshot_get(void);
515f145b19SDag-Erling Smørgrav void geom_stats_snapshot_free(void *);
525f145b19SDag-Erling Smørgrav void geom_stats_snapshot_timestamp(void *, struct timespec *);
535f145b19SDag-Erling Smørgrav void geom_stats_snapshot_reset(void *);
545f145b19SDag-Erling Smørgrav struct devstat *geom_stats_snapshot_next(void *);
55e13db587SPoul-Henning Kamp 
567bd4e7b4SPoul-Henning Kamp char *geom_getxml(void);
577bd4e7b4SPoul-Henning Kamp 
587bd4e7b4SPoul-Henning Kamp /* geom_xml2tree.c */
597bd4e7b4SPoul-Henning Kamp 
607bd4e7b4SPoul-Henning Kamp /*
617bd4e7b4SPoul-Henning Kamp  * These structs are used to build the tree based on the XML.
627bd4e7b4SPoul-Henning Kamp  * they're named as the kernel variant without the first '_'.
637bd4e7b4SPoul-Henning Kamp  */
647bd4e7b4SPoul-Henning Kamp 
657bd4e7b4SPoul-Henning Kamp struct gclass;
667bd4e7b4SPoul-Henning Kamp struct ggeom;
677bd4e7b4SPoul-Henning Kamp struct gconsumer;
687bd4e7b4SPoul-Henning Kamp struct gprovider;
697bd4e7b4SPoul-Henning Kamp 
707bd4e7b4SPoul-Henning Kamp LIST_HEAD(gconf, gconfig);
717bd4e7b4SPoul-Henning Kamp 
727bd4e7b4SPoul-Henning Kamp struct gident {
73ccac9da4SJohn Baldwin 	void			*lg_id;
74ccac9da4SJohn Baldwin 	void			*lg_ptr;
757bd4e7b4SPoul-Henning Kamp 	enum {	ISCLASS,
767bd4e7b4SPoul-Henning Kamp 		ISGEOM,
777bd4e7b4SPoul-Henning Kamp 		ISPROVIDER,
78019100deSJuli Mallett 		ISCONSUMER }	lg_what;
797bd4e7b4SPoul-Henning Kamp };
807bd4e7b4SPoul-Henning Kamp 
817bd4e7b4SPoul-Henning Kamp struct gmesh {
82ccac9da4SJohn Baldwin 	LIST_HEAD(, gclass)	lg_class;
83ccac9da4SJohn Baldwin 	struct gident		*lg_ident;
847bd4e7b4SPoul-Henning Kamp };
857bd4e7b4SPoul-Henning Kamp 
867bd4e7b4SPoul-Henning Kamp struct gconfig {
87ccac9da4SJohn Baldwin 	LIST_ENTRY(gconfig)	lg_config;
88ccac9da4SJohn Baldwin 	char			*lg_name;
89ccac9da4SJohn Baldwin 	char			*lg_val;
907bd4e7b4SPoul-Henning Kamp };
917bd4e7b4SPoul-Henning Kamp 
927bd4e7b4SPoul-Henning Kamp struct gclass {
93ccac9da4SJohn Baldwin 	void			*lg_id;
94ccac9da4SJohn Baldwin 	char			*lg_name;
95ccac9da4SJohn Baldwin 	LIST_ENTRY(gclass)	lg_class;
96ccac9da4SJohn Baldwin 	LIST_HEAD(, ggeom)	lg_geom;
97ccac9da4SJohn Baldwin 	struct gconf		lg_config;
987bd4e7b4SPoul-Henning Kamp };
997bd4e7b4SPoul-Henning Kamp 
1007bd4e7b4SPoul-Henning Kamp struct ggeom {
101ccac9da4SJohn Baldwin 	void			*lg_id;
102ccac9da4SJohn Baldwin 	struct gclass		*lg_class;
103ccac9da4SJohn Baldwin 	char			*lg_name;
104ccac9da4SJohn Baldwin 	u_int			lg_rank;
105ccac9da4SJohn Baldwin 	LIST_ENTRY(ggeom)	lg_geom;
106ccac9da4SJohn Baldwin 	LIST_HEAD(, gconsumer)	lg_consumer;
107ccac9da4SJohn Baldwin 	LIST_HEAD(, gprovider)	lg_provider;
108ccac9da4SJohn Baldwin 	struct gconf		lg_config;
1097bd4e7b4SPoul-Henning Kamp };
1107bd4e7b4SPoul-Henning Kamp 
1117bd4e7b4SPoul-Henning Kamp struct gconsumer {
112ccac9da4SJohn Baldwin 	void			*lg_id;
113ccac9da4SJohn Baldwin 	struct ggeom		*lg_geom;
114ccac9da4SJohn Baldwin 	LIST_ENTRY(gconsumer)	lg_consumer;
115ccac9da4SJohn Baldwin 	struct gprovider	*lg_provider;
116ccac9da4SJohn Baldwin 	LIST_ENTRY(gconsumer)	lg_consumers;
117ccac9da4SJohn Baldwin 	char			*lg_mode;
118ccac9da4SJohn Baldwin 	struct gconf		lg_config;
1197bd4e7b4SPoul-Henning Kamp };
1207bd4e7b4SPoul-Henning Kamp 
1217bd4e7b4SPoul-Henning Kamp struct gprovider {
122ccac9da4SJohn Baldwin 	void			*lg_id;
123ccac9da4SJohn Baldwin 	char			*lg_name;
124ccac9da4SJohn Baldwin 	struct ggeom		*lg_geom;
125ccac9da4SJohn Baldwin 	LIST_ENTRY(gprovider)	lg_provider;
126ccac9da4SJohn Baldwin 	LIST_HEAD(, gconsumer)	lg_consumers;
127ccac9da4SJohn Baldwin 	char			*lg_mode;
128ccac9da4SJohn Baldwin 	off_t			lg_mediasize;
129ccac9da4SJohn Baldwin 	u_int			lg_sectorsize;
13035daa28fSXin LI 	off_t			lg_stripeoffset;
13135daa28fSXin LI 	off_t			lg_stripesize;
132ccac9da4SJohn Baldwin 	struct gconf		lg_config;
1337bd4e7b4SPoul-Henning Kamp };
1347bd4e7b4SPoul-Henning Kamp 
1355f145b19SDag-Erling Smørgrav struct gident * geom_lookupid(struct gmesh *, const void *);
1365f145b19SDag-Erling Smørgrav int geom_xml2tree(struct gmesh *, char *);
1375f145b19SDag-Erling Smørgrav int geom_gettree(struct gmesh *);
1385f145b19SDag-Erling Smørgrav void geom_deletetree(struct gmesh *);
1397bd4e7b4SPoul-Henning Kamp 
1404b8938c1SPoul-Henning Kamp /* geom_ctl.c */
1414b8938c1SPoul-Henning Kamp 
14263728c47SPoul-Henning Kamp struct gctl_req;
1434b8938c1SPoul-Henning Kamp 
1444b8938c1SPoul-Henning Kamp #ifdef _STDIO_H_			/* limit #include pollution */
1455f145b19SDag-Erling Smørgrav void gctl_dump(struct gctl_req *, FILE *);
1464b8938c1SPoul-Henning Kamp #endif
1475f145b19SDag-Erling Smørgrav void gctl_free(struct gctl_req *);
1487e02e189SPoul-Henning Kamp struct gctl_req *gctl_get_handle(void);
1495f145b19SDag-Erling Smørgrav const char *gctl_issue(struct gctl_req *);
1505f145b19SDag-Erling Smørgrav void gctl_ro_param(struct gctl_req *, const char *, int, const void *);
1515f145b19SDag-Erling Smørgrav void gctl_rw_param(struct gctl_req *, const char *, int, void *);
1524b8938c1SPoul-Henning Kamp 
153fbda685dSPawel Jakub Dawidek /* geom_util.c */
1545f145b19SDag-Erling Smørgrav int g_open(const char *, int);
1555f145b19SDag-Erling Smørgrav int g_close(int);
1565f145b19SDag-Erling Smørgrav off_t g_mediasize(int);
1575f145b19SDag-Erling Smørgrav ssize_t g_sectorsize(int);
15835daa28fSXin LI off_t g_stripeoffset(int);
15935daa28fSXin LI off_t g_stripesize(int);
1605f145b19SDag-Erling Smørgrav int g_flush(int);
1615f145b19SDag-Erling Smørgrav int g_delete(int, off_t, off_t);
1625f145b19SDag-Erling Smørgrav int g_get_ident(int, char *, size_t);
1635f145b19SDag-Erling Smørgrav int g_get_name(const char *, char *, size_t);
1645f145b19SDag-Erling Smørgrav int g_open_by_ident(const char *, int, char *, size_t);
165f805f204SUlf Lilleengen char *g_device_path(const char *);
166f805f204SUlf Lilleengen char *g_providername(int);
167fbda685dSPawel Jakub Dawidek 
168ccac9da4SJohn Baldwin __END_DECLS
169ccac9da4SJohn Baldwin 
170e13db587SPoul-Henning Kamp #endif /* _LIBGEOM_H_ */
171