libgeom.h revision 169305
1120921Sache/*-
2120921Sache * Copyright (c) 2003 Poul-Henning Kamp
3120921Sache * All rights reserved.
4120921Sache *
5120921Sache * Redistribution and use in source and binary forms, with or without
6120921Sache * modification, are permitted provided that the following conditions
7120921Sache * are met:
8120921Sache * 1. Redistributions of source code must retain the above copyright
9120921Sache *    notice, this list of conditions and the following disclaimer.
10120921Sache * 2. Redistributions in binary form must reproduce the above copyright
11120921Sache *    notice, this list of conditions and the following disclaimer in the
12120921Sache *    documentation and/or other materials provided with the distribution.
13120921Sache * 3. The names of the authors may not be used to endorse or promote
14120921Sache *    products derived from this software without specific prior written
15120921Sache *    permission.
16120921Sache *
17120921Sache * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18120921Sache * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19120921Sache * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20120921Sache * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21120921Sache * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22120921Sache * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23120921Sache * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24120921Sache * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25120921Sache * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26120921Sache * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27120921Sache * SUCH DAMAGE.
28120921Sache *
29120921Sache * $FreeBSD: head/lib/libgeom/libgeom.h 169305 2007-05-06 10:00:27Z des $
30120921Sache */
31120921Sache#ifndef _LIBGEOM_H_
32120921Sache#define _LIBGEOM_H_
33120921Sache
34120921Sache#include <sys/cdefs.h>
35120921Sache
36120921Sache#include <sys/queue.h>
37120921Sache#include <sys/time.h>
38120921Sache
39120921Sache#include <geom/geom_ctl.h>
40
41__BEGIN_DECLS
42
43void geom_stats_close(void);
44void geom_stats_resync(void);
45int geom_stats_open(void);
46void *geom_stats_snapshot_get(void);
47void geom_stats_snapshot_free(void *);
48void geom_stats_snapshot_timestamp(void *, struct timespec *);
49void geom_stats_snapshot_reset(void *);
50struct devstat *geom_stats_snapshot_next(void *);
51
52char *geom_getxml(void);
53
54/* geom_xml2tree.c */
55
56/*
57 * These structs are used to build the tree based on the XML.
58 * they're named as the kernel variant without the first '_'.
59 */
60
61struct gclass;
62struct ggeom;
63struct gconsumer;
64struct gprovider;
65
66LIST_HEAD(gconf, gconfig);
67
68struct gident {
69	void			*lg_id;
70	void			*lg_ptr;
71	enum {	ISCLASS,
72		ISGEOM,
73		ISPROVIDER,
74		ISCONSUMER }	lg_what;
75};
76
77struct gmesh {
78	LIST_HEAD(, gclass)	lg_class;
79	struct gident		*lg_ident;
80};
81
82struct gconfig {
83	LIST_ENTRY(gconfig)	lg_config;
84	char			*lg_name;
85	char			*lg_val;
86};
87
88struct gclass {
89	void			*lg_id;
90	char			*lg_name;
91	LIST_ENTRY(gclass)	lg_class;
92	LIST_HEAD(, ggeom)	lg_geom;
93	struct gconf		lg_config;
94};
95
96struct ggeom {
97	void			*lg_id;
98	struct gclass		*lg_class;
99	char			*lg_name;
100	u_int			lg_rank;
101	LIST_ENTRY(ggeom)	lg_geom;
102	LIST_HEAD(, gconsumer)	lg_consumer;
103	LIST_HEAD(, gprovider)	lg_provider;
104	struct gconf		lg_config;
105};
106
107struct gconsumer {
108	void			*lg_id;
109	struct ggeom		*lg_geom;
110	LIST_ENTRY(gconsumer)	lg_consumer;
111	struct gprovider	*lg_provider;
112	LIST_ENTRY(gconsumer)	lg_consumers;
113	char			*lg_mode;
114	struct gconf		lg_config;
115};
116
117struct gprovider {
118	void			*lg_id;
119	char			*lg_name;
120	struct ggeom		*lg_geom;
121	LIST_ENTRY(gprovider)	lg_provider;
122	LIST_HEAD(, gconsumer)	lg_consumers;
123	char			*lg_mode;
124	off_t			lg_mediasize;
125	u_int			lg_sectorsize;
126	struct gconf		lg_config;
127};
128
129struct gident * geom_lookupid(struct gmesh *, const void *);
130int geom_xml2tree(struct gmesh *, char *);
131int geom_gettree(struct gmesh *);
132void geom_deletetree(struct gmesh *);
133
134/* geom_ctl.c */
135
136struct gctl_req;
137
138#ifdef _STDIO_H_			/* limit #include pollution */
139void gctl_dump(struct gctl_req *, FILE *);
140#endif
141void gctl_free(struct gctl_req *);
142struct gctl_req *gctl_get_handle(void);
143const char *gctl_issue(struct gctl_req *);
144void gctl_ro_param(struct gctl_req *, const char *, int, const void *);
145void gctl_rw_param(struct gctl_req *, const char *, int, void *);
146
147/* geom_util.c */
148int g_open(const char *, int);
149int g_close(int);
150off_t g_mediasize(int);
151ssize_t g_sectorsize(int);
152int g_flush(int);
153int g_delete(int, off_t, off_t);
154int g_get_ident(int, char *, size_t);
155int g_get_name(const char *, char *, size_t);
156int g_open_by_ident(const char *, int, char *, size_t);
157
158__END_DECLS
159
160#endif /* _LIBGEOM_H_ */
161