xref: /freebsd/lib/libgeom/libgeom.h (revision b3e7694832e81d7a904a10f525f8797b753bf0d3)
1e13db587SPoul-Henning Kamp /*-
2*eb8f8877SWarner Losh  * SPDX-License-Identifier: BSD-3-Clause
35e53a4f9SPedro F. Giffuni  *
4e13db587SPoul-Henning Kamp  * Copyright (c) 2003 Poul-Henning Kamp
5e13db587SPoul-Henning Kamp  * All rights reserved.
6e13db587SPoul-Henning Kamp  *
7e13db587SPoul-Henning Kamp  * Redistribution and use in source and binary forms, with or without
8e13db587SPoul-Henning Kamp  * modification, are permitted provided that the following conditions
9e13db587SPoul-Henning Kamp  * are met:
10e13db587SPoul-Henning Kamp  * 1. Redistributions of source code must retain the above copyright
11e13db587SPoul-Henning Kamp  *    notice, this list of conditions and the following disclaimer.
12e13db587SPoul-Henning Kamp  * 2. Redistributions in binary form must reproduce the above copyright
13e13db587SPoul-Henning Kamp  *    notice, this list of conditions and the following disclaimer in the
14e13db587SPoul-Henning Kamp  *    documentation and/or other materials provided with the distribution.
15e13db587SPoul-Henning Kamp  * 3. The names of the authors may not be used to endorse or promote
16e13db587SPoul-Henning Kamp  *    products derived from this software without specific prior written
17e13db587SPoul-Henning Kamp  *    permission.
18e13db587SPoul-Henning Kamp  *
19e13db587SPoul-Henning Kamp  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20e13db587SPoul-Henning Kamp  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21e13db587SPoul-Henning Kamp  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22e13db587SPoul-Henning Kamp  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23e13db587SPoul-Henning Kamp  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24e13db587SPoul-Henning Kamp  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25e13db587SPoul-Henning Kamp  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26e13db587SPoul-Henning Kamp  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27e13db587SPoul-Henning Kamp  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28e13db587SPoul-Henning Kamp  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29e13db587SPoul-Henning Kamp  * SUCH DAMAGE.
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 
43748e404fSScott Long #ifndef DEBUG_LIBGEOM
44748e404fSScott Long #define DEBUG_LIBGEOM 0
45748e404fSScott Long #endif
46748e404fSScott 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);
577f16b501SAlexander Motin char *geom_getxml_geom(const char *, const char *, int);
587bd4e7b4SPoul-Henning Kamp 
597bd4e7b4SPoul-Henning Kamp /* geom_xml2tree.c */
607bd4e7b4SPoul-Henning Kamp 
617bd4e7b4SPoul-Henning Kamp /*
627bd4e7b4SPoul-Henning Kamp  * These structs are used to build the tree based on the XML.
637bd4e7b4SPoul-Henning Kamp  * they're named as the kernel variant without the first '_'.
647bd4e7b4SPoul-Henning Kamp  */
657bd4e7b4SPoul-Henning Kamp 
667bd4e7b4SPoul-Henning Kamp struct gclass;
677bd4e7b4SPoul-Henning Kamp struct ggeom;
687bd4e7b4SPoul-Henning Kamp struct gconsumer;
697bd4e7b4SPoul-Henning Kamp struct gprovider;
707bd4e7b4SPoul-Henning Kamp 
717bd4e7b4SPoul-Henning Kamp LIST_HEAD(gconf, gconfig);
727bd4e7b4SPoul-Henning Kamp 
737bd4e7b4SPoul-Henning Kamp struct gident {
74ccac9da4SJohn Baldwin 	void			*lg_id;
75ccac9da4SJohn Baldwin 	void			*lg_ptr;
767bd4e7b4SPoul-Henning Kamp 	enum {	ISCLASS,
777bd4e7b4SPoul-Henning Kamp 		ISGEOM,
787bd4e7b4SPoul-Henning Kamp 		ISPROVIDER,
79019100deSJuli Mallett 		ISCONSUMER }	lg_what;
807bd4e7b4SPoul-Henning Kamp };
817bd4e7b4SPoul-Henning Kamp 
827bd4e7b4SPoul-Henning Kamp struct gmesh {
83ccac9da4SJohn Baldwin 	LIST_HEAD(, gclass)	lg_class;
84ccac9da4SJohn Baldwin 	struct gident		*lg_ident;
857bd4e7b4SPoul-Henning Kamp };
867bd4e7b4SPoul-Henning Kamp 
877bd4e7b4SPoul-Henning Kamp struct gconfig {
88ccac9da4SJohn Baldwin 	LIST_ENTRY(gconfig)	lg_config;
89ccac9da4SJohn Baldwin 	char			*lg_name;
90ccac9da4SJohn Baldwin 	char			*lg_val;
917bd4e7b4SPoul-Henning Kamp };
927bd4e7b4SPoul-Henning Kamp 
937bd4e7b4SPoul-Henning Kamp struct gclass {
94ccac9da4SJohn Baldwin 	void			*lg_id;
95ccac9da4SJohn Baldwin 	char			*lg_name;
96ccac9da4SJohn Baldwin 	LIST_ENTRY(gclass)	lg_class;
97ccac9da4SJohn Baldwin 	LIST_HEAD(, ggeom)	lg_geom;
98ccac9da4SJohn Baldwin 	struct gconf		lg_config;
997bd4e7b4SPoul-Henning Kamp };
1007bd4e7b4SPoul-Henning Kamp 
1017bd4e7b4SPoul-Henning Kamp struct ggeom {
102ccac9da4SJohn Baldwin 	void			*lg_id;
103ccac9da4SJohn Baldwin 	struct gclass		*lg_class;
104ccac9da4SJohn Baldwin 	char			*lg_name;
105ccac9da4SJohn Baldwin 	u_int			lg_rank;
106ccac9da4SJohn Baldwin 	LIST_ENTRY(ggeom)	lg_geom;
107ccac9da4SJohn Baldwin 	LIST_HEAD(, gconsumer)	lg_consumer;
108ccac9da4SJohn Baldwin 	LIST_HEAD(, gprovider)	lg_provider;
109ccac9da4SJohn Baldwin 	struct gconf		lg_config;
1107bd4e7b4SPoul-Henning Kamp };
1117bd4e7b4SPoul-Henning Kamp 
1127bd4e7b4SPoul-Henning Kamp struct gconsumer {
113ccac9da4SJohn Baldwin 	void			*lg_id;
114ccac9da4SJohn Baldwin 	struct ggeom		*lg_geom;
115ccac9da4SJohn Baldwin 	LIST_ENTRY(gconsumer)	lg_consumer;
116ccac9da4SJohn Baldwin 	struct gprovider	*lg_provider;
117ccac9da4SJohn Baldwin 	LIST_ENTRY(gconsumer)	lg_consumers;
118ccac9da4SJohn Baldwin 	char			*lg_mode;
119ccac9da4SJohn Baldwin 	struct gconf		lg_config;
1207bd4e7b4SPoul-Henning Kamp };
1217bd4e7b4SPoul-Henning Kamp 
1227bd4e7b4SPoul-Henning Kamp struct gprovider {
123ccac9da4SJohn Baldwin 	void			*lg_id;
124ccac9da4SJohn Baldwin 	char			*lg_name;
125ccac9da4SJohn Baldwin 	struct ggeom		*lg_geom;
126ccac9da4SJohn Baldwin 	LIST_ENTRY(gprovider)	lg_provider;
127ccac9da4SJohn Baldwin 	LIST_HEAD(, gconsumer)	lg_consumers;
128ccac9da4SJohn Baldwin 	char			*lg_mode;
129ccac9da4SJohn Baldwin 	off_t			lg_mediasize;
130ccac9da4SJohn Baldwin 	u_int			lg_sectorsize;
13135daa28fSXin LI 	off_t			lg_stripeoffset;
13235daa28fSXin LI 	off_t			lg_stripesize;
133ccac9da4SJohn Baldwin 	struct gconf		lg_config;
1347bd4e7b4SPoul-Henning Kamp };
1357bd4e7b4SPoul-Henning Kamp 
1365f145b19SDag-Erling Smørgrav struct gident * geom_lookupid(struct gmesh *, const void *);
1375f145b19SDag-Erling Smørgrav int geom_xml2tree(struct gmesh *, char *);
1385f145b19SDag-Erling Smørgrav int geom_gettree(struct gmesh *);
1397f16b501SAlexander Motin int geom_gettree_geom(struct gmesh *, const char *, const char *, int);
1405f145b19SDag-Erling Smørgrav void geom_deletetree(struct gmesh *);
1417bd4e7b4SPoul-Henning Kamp 
1424b8938c1SPoul-Henning Kamp /* geom_ctl.c */
1434b8938c1SPoul-Henning Kamp 
14463728c47SPoul-Henning Kamp struct gctl_req;
1454b8938c1SPoul-Henning Kamp 
1464b8938c1SPoul-Henning Kamp #ifdef _STDIO_H_			/* limit #include pollution */
1475f145b19SDag-Erling Smørgrav void gctl_dump(struct gctl_req *, FILE *);
1484b8938c1SPoul-Henning Kamp #endif
1495f145b19SDag-Erling Smørgrav void gctl_free(struct gctl_req *);
1507e02e189SPoul-Henning Kamp struct gctl_req *gctl_get_handle(void);
1515f145b19SDag-Erling Smørgrav const char *gctl_issue(struct gctl_req *);
1522117cdd4SAlexander Motin void gctl_add_param(struct gctl_req *req, const char *name, int len,
1532117cdd4SAlexander Motin     void *value, int flag);
1545f145b19SDag-Erling Smørgrav void gctl_ro_param(struct gctl_req *, const char *, int, const void *);
1555f145b19SDag-Erling Smørgrav void gctl_rw_param(struct gctl_req *, const char *, int, void *);
1564b8938c1SPoul-Henning Kamp 
157fbda685dSPawel Jakub Dawidek /* geom_util.c */
1585f145b19SDag-Erling Smørgrav int g_open(const char *, int);
1595f145b19SDag-Erling Smørgrav int g_close(int);
1605f145b19SDag-Erling Smørgrav off_t g_mediasize(int);
1615f145b19SDag-Erling Smørgrav ssize_t g_sectorsize(int);
16235daa28fSXin LI off_t g_stripeoffset(int);
16335daa28fSXin LI off_t g_stripesize(int);
1645f145b19SDag-Erling Smørgrav int g_flush(int);
1655f145b19SDag-Erling Smørgrav int g_delete(int, off_t, off_t);
1665f145b19SDag-Erling Smørgrav int g_get_ident(int, char *, size_t);
1675f145b19SDag-Erling Smørgrav int g_get_name(const char *, char *, size_t);
1685f145b19SDag-Erling Smørgrav int g_open_by_ident(const char *, int, char *, size_t);
169f805f204SUlf Lilleengen char *g_device_path(const char *);
170f805f204SUlf Lilleengen char *g_providername(int);
171fbda685dSPawel Jakub Dawidek 
172ccac9da4SJohn Baldwin __END_DECLS
173ccac9da4SJohn Baldwin 
174e13db587SPoul-Henning Kamp #endif /* _LIBGEOM_H_ */
175