libgeom.h revision 182843
1179237Sjb/*-
2179237Sjb * Copyright (c) 2003 Poul-Henning Kamp
3179237Sjb * All rights reserved.
4179237Sjb *
5179237Sjb * Redistribution and use in source and binary forms, with or without
6179237Sjb * modification, are permitted provided that the following conditions
7179237Sjb * are met:
8179237Sjb * 1. Redistributions of source code must retain the above copyright
9179237Sjb *    notice, this list of conditions and the following disclaimer.
10179237Sjb * 2. Redistributions in binary form must reproduce the above copyright
11179237Sjb *    notice, this list of conditions and the following disclaimer in the
12179237Sjb *    documentation and/or other materials provided with the distribution.
13179237Sjb * 3. The names of the authors may not be used to endorse or promote
14179237Sjb *    products derived from this software without specific prior written
15179237Sjb *    permission.
16179237Sjb *
17179237Sjb * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18179237Sjb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19179237Sjb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20179237Sjb * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21179237Sjb * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22179237Sjb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23179237Sjb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24179237Sjb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25179237Sjb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26179237Sjb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27179237Sjb * SUCH DAMAGE.
28179237Sjb *
29179237Sjb * $FreeBSD: head/lib/libgeom/libgeom.h 182843 2008-09-07 13:54:57Z lulf $
30179237Sjb */
31179237Sjb#ifndef _LIBGEOM_H_
32179237Sjb#define _LIBGEOM_H_
33179237Sjb
34226452Smarcel#include <sys/cdefs.h>
35179237Sjb
36179237Sjb#include <sys/queue.h>
37179237Sjb#include <sys/time.h>
38179237Sjb
39244631Srstone#include <geom/geom_ctl.h>
40179237Sjb
41179237Sjb__BEGIN_DECLS
42179237Sjb
43179237Sjbvoid geom_stats_close(void);
44179237Sjbvoid geom_stats_resync(void);
45179237Sjbint geom_stats_open(void);
46179237Sjbvoid *geom_stats_snapshot_get(void);
47179237Sjbvoid geom_stats_snapshot_free(void *);
48179237Sjbvoid geom_stats_snapshot_timestamp(void *, struct timespec *);
49179237Sjbvoid geom_stats_snapshot_reset(void *);
50179237Sjbstruct devstat *geom_stats_snapshot_next(void *);
51244631Srstone
52244631Srstonechar *geom_getxml(void);
53244631Srstone
54244631Srstone/* geom_xml2tree.c */
55244631Srstone
56179237Sjb/*
57179237Sjb * These structs are used to build the tree based on the XML.
58179237Sjb * they're named as the kernel variant without the first '_'.
59179237Sjb */
60179237Sjb
61179237Sjbstruct gclass;
62244631Srstonestruct ggeom;
63244631Srstonestruct gconsumer;
64179237Sjbstruct gprovider;
65179237Sjb
66179237SjbLIST_HEAD(gconf, gconfig);
67179237Sjb
68179237Sjbstruct gident {
69179237Sjb	void			*lg_id;
70179237Sjb	void			*lg_ptr;
71179237Sjb	enum {	ISCLASS,
72209059Sjhb		ISGEOM,
73179237Sjb		ISPROVIDER,
74179237Sjb		ISCONSUMER }	lg_what;
75179237Sjb};
76179237Sjb
77179237Sjbstruct gmesh {
78179237Sjb	LIST_HEAD(, gclass)	lg_class;
79179237Sjb	struct gident		*lg_ident;
80179237Sjb};
81179237Sjb
82179237Sjbstruct gconfig {
83179237Sjb	LIST_ENTRY(gconfig)	lg_config;
84179237Sjb	char			*lg_name;
85179237Sjb	char			*lg_val;
86179237Sjb};
87179237Sjb
88179237Sjbstruct gclass {
89179237Sjb	void			*lg_id;
90179237Sjb	char			*lg_name;
91179237Sjb	LIST_ENTRY(gclass)	lg_class;
92179237Sjb	LIST_HEAD(, ggeom)	lg_geom;
93179237Sjb	struct gconf		lg_config;
94179237Sjb};
95209059Sjhb
96179237Sjbstruct ggeom {
97179237Sjb	void			*lg_id;
98179237Sjb	struct gclass		*lg_class;
99179237Sjb	char			*lg_name;
100179237Sjb	u_int			lg_rank;
101179237Sjb	LIST_ENTRY(ggeom)	lg_geom;
102179237Sjb	LIST_HEAD(, gconsumer)	lg_consumer;
103179237Sjb	LIST_HEAD(, gprovider)	lg_provider;
104179237Sjb	struct gconf		lg_config;
105179237Sjb};
106179237Sjb
107179237Sjbstruct gconsumer {
108179237Sjb	void			*lg_id;
109179237Sjb	struct ggeom		*lg_geom;
110179237Sjb	LIST_ENTRY(gconsumer)	lg_consumer;
111179237Sjb	struct gprovider	*lg_provider;
112179237Sjb	LIST_ENTRY(gconsumer)	lg_consumers;
113179237Sjb	char			*lg_mode;
114179237Sjb	struct gconf		lg_config;
115179237Sjb};
116179237Sjb
117179237Sjbstruct gprovider {
118179237Sjb	void			*lg_id;
119179237Sjb	char			*lg_name;
120179237Sjb	struct ggeom		*lg_geom;
121179237Sjb	LIST_ENTRY(gprovider)	lg_provider;
122179237Sjb	LIST_HEAD(, gconsumer)	lg_consumers;
123179237Sjb	char			*lg_mode;
124179237Sjb	off_t			lg_mediasize;
125179237Sjb	u_int			lg_sectorsize;
126179237Sjb	struct gconf		lg_config;
127179237Sjb};
128179237Sjb
129179237Sjbstruct gident * geom_lookupid(struct gmesh *, const void *);
130179237Sjbint geom_xml2tree(struct gmesh *, char *);
131179237Sjbint geom_gettree(struct gmesh *);
132179237Sjbvoid geom_deletetree(struct gmesh *);
133179237Sjb
134179237Sjb/* geom_ctl.c */
135179237Sjb
136179237Sjbstruct gctl_req;
137179237Sjb
138179237Sjb#ifdef _STDIO_H_			/* limit #include pollution */
139179237Sjbvoid gctl_dump(struct gctl_req *, FILE *);
140179237Sjb#endif
141179237Sjbvoid gctl_free(struct gctl_req *);
142179237Sjbstruct gctl_req *gctl_get_handle(void);
143179237Sjbconst char *gctl_issue(struct gctl_req *);
144179237Sjbvoid gctl_ro_param(struct gctl_req *, const char *, int, const void *);
145179237Sjbvoid gctl_rw_param(struct gctl_req *, const char *, int, void *);
146179237Sjb
147179237Sjb/* geom_util.c */
148179237Sjbint g_open(const char *, int);
149179237Sjbint g_close(int);
150179237Sjboff_t g_mediasize(int);
151179237Sjbssize_t g_sectorsize(int);
152179237Sjbint g_flush(int);
153179237Sjbint g_delete(int, off_t, off_t);
154179237Sjbint g_get_ident(int, char *, size_t);
155244631Srstoneint g_get_name(const char *, char *, size_t);
156179237Sjbint g_open_by_ident(const char *, int, char *, size_t);
157244631Srstonechar *g_device_path(const char *);
158179237Sjbchar *g_providername(int);
159244631Srstone
160179237Sjb__END_DECLS
161179237Sjb
162179237Sjb#endif /* _LIBGEOM_H_ */
163179237Sjb