1110545Sphk/*-
2110545Sphk * Copyright (c) 2003 Poul-Henning Kamp
3110545Sphk * All rights reserved.
4110545Sphk *
5110545Sphk * Redistribution and use in source and binary forms, with or without
6110545Sphk * modification, are permitted provided that the following conditions
7110545Sphk * are met:
8110545Sphk * 1. Redistributions of source code must retain the above copyright
9110545Sphk *    notice, this list of conditions and the following disclaimer.
10110545Sphk * 2. Redistributions in binary form must reproduce the above copyright
11110545Sphk *    notice, this list of conditions and the following disclaimer in the
12110545Sphk *    documentation and/or other materials provided with the distribution.
13110545Sphk * 3. The names of the authors may not be used to endorse or promote
14110545Sphk *    products derived from this software without specific prior written
15110545Sphk *    permission.
16110545Sphk *
17110545Sphk * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18110545Sphk * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19110545Sphk * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20110545Sphk * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21110545Sphk * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22110545Sphk * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23110545Sphk * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24110545Sphk * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25110545Sphk * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26110545Sphk * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27110545Sphk * SUCH DAMAGE.
28110545Sphk *
29110545Sphk * $FreeBSD$
30110545Sphk */
31110545Sphk#ifndef _LIBGEOM_H_
32110545Sphk#define _LIBGEOM_H_
33110545Sphk
34126786Sjhb#include <sys/cdefs.h>
35126786Sjhb
36110603Sphk#include <sys/queue.h>
37110547Sphk#include <sys/time.h>
38110545Sphk
39112510Sphk#include <geom/geom_ctl.h>
40112510Sphk
41126786Sjhb__BEGIN_DECLS
42126786Sjhb
43253469Sscottl#ifndef DEBUG_LIBGEOM
44253469Sscottl#define DEBUG_LIBGEOM 0
45253469Sscottl#endif
46253469Sscottl
47110545Sphkvoid geom_stats_close(void);
48110545Sphkvoid geom_stats_resync(void);
49110545Sphkint geom_stats_open(void);
50110545Sphkvoid *geom_stats_snapshot_get(void);
51169305Sdesvoid geom_stats_snapshot_free(void *);
52169305Sdesvoid geom_stats_snapshot_timestamp(void *, struct timespec *);
53169305Sdesvoid geom_stats_snapshot_reset(void *);
54169305Sdesstruct devstat *geom_stats_snapshot_next(void *);
55110545Sphk
56110603Sphkchar *geom_getxml(void);
57110603Sphk
58110603Sphk/* geom_xml2tree.c */
59110603Sphk
60110603Sphk/*
61110603Sphk * These structs are used to build the tree based on the XML.
62110603Sphk * they're named as the kernel variant without the first '_'.
63110603Sphk */
64110603Sphk
65110603Sphkstruct gclass;
66110603Sphkstruct ggeom;
67110603Sphkstruct gconsumer;
68110603Sphkstruct gprovider;
69110603Sphk
70110603SphkLIST_HEAD(gconf, gconfig);
71110603Sphk
72110603Sphkstruct gident {
73126786Sjhb	void			*lg_id;
74126786Sjhb	void			*lg_ptr;
75110603Sphk	enum {	ISCLASS,
76110603Sphk		ISGEOM,
77110603Sphk		ISPROVIDER,
78234107Sjmallett		ISCONSUMER }	lg_what;
79110603Sphk};
80110603Sphk
81110603Sphkstruct gmesh {
82126786Sjhb	LIST_HEAD(, gclass)	lg_class;
83126786Sjhb	struct gident		*lg_ident;
84110603Sphk};
85110603Sphk
86110603Sphkstruct gconfig {
87126786Sjhb	LIST_ENTRY(gconfig)	lg_config;
88126786Sjhb	char			*lg_name;
89126786Sjhb	char			*lg_val;
90110603Sphk};
91110603Sphk
92110603Sphkstruct gclass {
93126786Sjhb	void			*lg_id;
94126786Sjhb	char			*lg_name;
95126786Sjhb	LIST_ENTRY(gclass)	lg_class;
96126786Sjhb	LIST_HEAD(, ggeom)	lg_geom;
97126786Sjhb	struct gconf		lg_config;
98110603Sphk};
99110603Sphk
100110603Sphkstruct ggeom {
101126786Sjhb	void			*lg_id;
102126786Sjhb	struct gclass		*lg_class;
103126786Sjhb	char			*lg_name;
104126786Sjhb	u_int			lg_rank;
105126786Sjhb	LIST_ENTRY(ggeom)	lg_geom;
106126786Sjhb	LIST_HEAD(, gconsumer)	lg_consumer;
107126786Sjhb	LIST_HEAD(, gprovider)	lg_provider;
108126786Sjhb	struct gconf		lg_config;
109110603Sphk};
110110603Sphk
111110603Sphkstruct gconsumer {
112126786Sjhb	void			*lg_id;
113126786Sjhb	struct ggeom		*lg_geom;
114126786Sjhb	LIST_ENTRY(gconsumer)	lg_consumer;
115126786Sjhb	struct gprovider	*lg_provider;
116126786Sjhb	LIST_ENTRY(gconsumer)	lg_consumers;
117126786Sjhb	char			*lg_mode;
118126786Sjhb	struct gconf		lg_config;
119110603Sphk};
120110603Sphk
121110603Sphkstruct gprovider {
122126786Sjhb	void			*lg_id;
123126786Sjhb	char			*lg_name;
124126786Sjhb	struct ggeom		*lg_geom;
125126786Sjhb	LIST_ENTRY(gprovider)	lg_provider;
126126786Sjhb	LIST_HEAD(, gconsumer)	lg_consumers;
127126786Sjhb	char			*lg_mode;
128126786Sjhb	off_t			lg_mediasize;
129126786Sjhb	u_int			lg_sectorsize;
130202454Sdelphij	off_t			lg_stripeoffset;
131202454Sdelphij	off_t			lg_stripesize;
132126786Sjhb	struct gconf		lg_config;
133110603Sphk};
134110603Sphk
135169305Sdesstruct gident * geom_lookupid(struct gmesh *, const void *);
136169305Sdesint geom_xml2tree(struct gmesh *, char *);
137169305Sdesint geom_gettree(struct gmesh *);
138169305Sdesvoid geom_deletetree(struct gmesh *);
139110603Sphk
140112510Sphk/* geom_ctl.c */
141112510Sphk
142112709Sphkstruct gctl_req;
143112510Sphk
144112510Sphk#ifdef _STDIO_H_			/* limit #include pollution */
145169305Sdesvoid gctl_dump(struct gctl_req *, FILE *);
146112510Sphk#endif
147169305Sdesvoid gctl_free(struct gctl_req *);
148115625Sphkstruct gctl_req *gctl_get_handle(void);
149169305Sdesconst char *gctl_issue(struct gctl_req *);
150169305Sdesvoid gctl_ro_param(struct gctl_req *, const char *, int, const void *);
151169305Sdesvoid gctl_rw_param(struct gctl_req *, const char *, int, void *);
152112510Sphk
153169299Spjd/* geom_util.c */
154169305Sdesint g_open(const char *, int);
155169305Sdesint g_close(int);
156169305Sdesoff_t g_mediasize(int);
157169305Sdesssize_t g_sectorsize(int);
158202454Sdelphijoff_t g_stripeoffset(int);
159202454Sdelphijoff_t g_stripesize(int);
160169305Sdesint g_flush(int);
161169305Sdesint g_delete(int, off_t, off_t);
162169305Sdesint g_get_ident(int, char *, size_t);
163169305Sdesint g_get_name(const char *, char *, size_t);
164169305Sdesint g_open_by_ident(const char *, int, char *, size_t);
165182843Slulfchar *g_device_path(const char *);
166182843Slulfchar *g_providername(int);
167169299Spjd
168126786Sjhb__END_DECLS
169126786Sjhb
170110545Sphk#endif /* _LIBGEOM_H_ */
171