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