1/*- 2 * SPDX-License-Identifier: BSD-3-Clause 3 * 4 * Copyright (c) 2003 Poul-Henning Kamp 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. The names of the authors may not be used to endorse or promote 16 * products derived from this software without specific prior written 17 * permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * SUCH DAMAGE. 30 */ 31#ifndef _LIBGEOM_H_ 32#define _LIBGEOM_H_ 33 34#include <sys/cdefs.h> 35 36#include <sys/queue.h> 37#include <sys/time.h> 38 39#include <geom/geom_ctl.h> 40 41__BEGIN_DECLS 42 43#ifndef DEBUG_LIBGEOM 44#define DEBUG_LIBGEOM 0 45#endif 46 47void geom_stats_close(void); 48void geom_stats_resync(void); 49int geom_stats_open(void); 50void *geom_stats_snapshot_get(void); 51void geom_stats_snapshot_free(void *); 52void geom_stats_snapshot_timestamp(void *, struct timespec *); 53void geom_stats_snapshot_reset(void *); 54struct devstat *geom_stats_snapshot_next(void *); 55 56char *geom_getxml(void); 57char *geom_getxml_geom(const char *, const char *, int); 58 59/* geom_xml2tree.c */ 60 61/* 62 * These structs are used to build the tree based on the XML. 63 * they're named as the kernel variant without the first '_'. 64 */ 65 66struct gclass; 67struct ggeom; 68struct gconsumer; 69struct gprovider; 70 71LIST_HEAD(gconf, gconfig); 72 73struct gident { 74 void *lg_id; 75 void *lg_ptr; 76 enum { ISCLASS, 77 ISGEOM, 78 ISPROVIDER, 79 ISCONSUMER } lg_what; 80}; 81 82struct gmesh { 83 LIST_HEAD(, gclass) lg_class; 84 struct gident *lg_ident; 85}; 86 87struct gconfig { 88 LIST_ENTRY(gconfig) lg_config; 89 char *lg_name; 90 char *lg_val; 91}; 92 93struct gclass { 94 void *lg_id; 95 char *lg_name; 96 LIST_ENTRY(gclass) lg_class; 97 LIST_HEAD(, ggeom) lg_geom; 98 struct gconf lg_config; 99}; 100 101struct ggeom { 102 void *lg_id; 103 struct gclass *lg_class; 104 char *lg_name; 105 u_int lg_rank; 106 LIST_ENTRY(ggeom) lg_geom; 107 LIST_HEAD(, gconsumer) lg_consumer; 108 LIST_HEAD(, gprovider) lg_provider; 109 struct gconf lg_config; 110}; 111 112struct gconsumer { 113 void *lg_id; 114 struct ggeom *lg_geom; 115 LIST_ENTRY(gconsumer) lg_consumer; 116 struct gprovider *lg_provider; 117 LIST_ENTRY(gconsumer) lg_consumers; 118 char *lg_mode; 119 struct gconf lg_config; 120}; 121 122struct gprovider { 123 void *lg_id; 124 char *lg_name; 125 struct ggeom *lg_geom; 126 LIST_ENTRY(gprovider) lg_provider; 127 LIST_HEAD(, gconsumer) lg_consumers; 128 char *lg_mode; 129 off_t lg_mediasize; 130 u_int lg_sectorsize; 131 off_t lg_stripeoffset; 132 off_t lg_stripesize; 133 struct gconf lg_config; 134}; 135 136struct gident * geom_lookupid(struct gmesh *, const void *); 137int geom_xml2tree(struct gmesh *, char *); 138int geom_gettree(struct gmesh *); 139int geom_gettree_geom(struct gmesh *, const char *, const char *, int); 140void geom_deletetree(struct gmesh *); 141 142/* geom_ctl.c */ 143 144struct gctl_req; 145 146#ifdef _STDIO_H_ /* limit #include pollution */ 147void gctl_dump(struct gctl_req *, FILE *); 148#endif 149void gctl_free(struct gctl_req *); 150struct gctl_req *gctl_get_handle(void); 151const char *gctl_issue(struct gctl_req *); 152void gctl_add_param(struct gctl_req *req, const char *name, int len, 153 void *value, int flag); 154void gctl_ro_param(struct gctl_req *, const char *, int, const void *); 155void gctl_rw_param(struct gctl_req *, const char *, int, void *); 156 157/* geom_util.c */ 158int g_open(const char *, int); 159int g_close(int); 160off_t g_mediasize(int); 161ssize_t g_sectorsize(int); 162off_t g_stripeoffset(int); 163off_t g_stripesize(int); 164int g_flush(int); 165int g_delete(int, off_t, off_t); 166int g_get_ident(int, char *, size_t); 167int g_get_name(const char *, char *, size_t); 168int g_open_by_ident(const char *, int, char *, size_t); 169char *g_device_path(const char *); 170char *g_providername(int); 171 172__END_DECLS 173 174#endif /* _LIBGEOM_H_ */ 175