geom_dump.c (250868) | geom_dump.c (258683) |
---|---|
1/*- 2 * Copyright (c) 2002 Poul-Henning Kamp 3 * Copyright (c) 2002 Networks Associates Technology, Inc. 4 * All rights reserved. 5 * 6 * This software was developed for the FreeBSD Project by Poul-Henning Kamp 7 * and NAI Labs, the Security Research Division of Network Associates, Inc. 8 * under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the --- 20 unchanged lines hidden (view full) --- 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 */ 35 36#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2002 Poul-Henning Kamp 3 * Copyright (c) 2002 Networks Associates Technology, Inc. 4 * All rights reserved. 5 * 6 * This software was developed for the FreeBSD Project by Poul-Henning Kamp 7 * and NAI Labs, the Security Research Division of Network Associates, Inc. 8 * under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the --- 20 unchanged lines hidden (view full) --- 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 */ 35 36#include <sys/cdefs.h> |
37__FBSDID("$FreeBSD: head/sys/geom/geom_dump.c 250868 2013-05-21 18:40:54Z jh $"); | 37__FBSDID("$FreeBSD: head/sys/geom/geom_dump.c 258683 2013-11-27 14:25:06Z mav $"); |
38 39#include <sys/param.h> 40#include <sys/sbuf.h> 41#include <sys/systm.h> 42#include <sys/malloc.h> 43#include <machine/stdarg.h> 44 45#include <geom/geom.h> --- 103 unchanged lines hidden (view full) --- 149 LIST_FOREACH(mp, &g_classes, class) { 150 if (!strcmp(mp->name, G_DISK_CLASS_NAME) || !strcmp(mp->name, "MD")) 151 g_conftxt_class(sb, mp); 152 } 153 sbuf_finish(sb); 154} 155 156 | 38 39#include <sys/param.h> 40#include <sys/sbuf.h> 41#include <sys/systm.h> 42#include <sys/malloc.h> 43#include <machine/stdarg.h> 44 45#include <geom/geom.h> --- 103 unchanged lines hidden (view full) --- 149 LIST_FOREACH(mp, &g_classes, class) { 150 if (!strcmp(mp->name, G_DISK_CLASS_NAME) || !strcmp(mp->name, "MD")) 151 g_conftxt_class(sb, mp); 152 } 153 sbuf_finish(sb); 154} 155 156 |
157static void 158g_conf_print_escaped(struct sbuf *sb, const char *fmt, const char *str) | 157void 158g_conf_printf_escaped(struct sbuf *sb, const char *fmt, ...) |
159{ 160 struct sbuf *s; 161 const u_char *c; | 159{ 160 struct sbuf *s; 161 const u_char *c; |
162 va_list ap; |
|
162 163 s = sbuf_new_auto(); | 163 164 s = sbuf_new_auto(); |
165 va_start(ap, fmt); 166 sbuf_vprintf(s, fmt, ap); 167 va_end(ap); 168 sbuf_finish(s); |
|
164 | 169 |
165 for (c = str; *c != '\0'; c++) { | 170 for (c = sbuf_data(s); *c != '\0'; c++) { |
166 if (*c == '&' || *c == '<' || *c == '>' || 167 *c == '\'' || *c == '"' || *c > 0x7e) | 171 if (*c == '&' || *c == '<' || *c == '>' || 172 *c == '\'' || *c == '"' || *c > 0x7e) |
168 sbuf_printf(s, "%X;", *c); | 173 sbuf_printf(sb, "&#x%X;", *c); |
169 else if (*c == '\t' || *c == '\n' || *c == '\r' || *c > 0x1f) | 174 else if (*c == '\t' || *c == '\n' || *c == '\r' || *c > 0x1f) |
170 sbuf_putc(s, *c); | 175 sbuf_putc(sb, *c); |
171 else | 176 else |
172 sbuf_putc(s, '?'); | 177 sbuf_putc(sb, '?'); |
173 } | 178 } |
174 sbuf_finish(s); 175 sbuf_printf(sb, fmt, sbuf_data(s)); | |
176 sbuf_delete(s); 177} 178 179static void 180g_conf_consumer(struct sbuf *sb, struct g_consumer *cp) 181{ 182 183 sbuf_printf(sb, "\t<consumer id=\"%p\">\n", cp); --- 15 unchanged lines hidden (view full) --- 199static void 200g_conf_provider(struct sbuf *sb, struct g_provider *pp) 201{ 202 203 sbuf_printf(sb, "\t<provider id=\"%p\">\n", pp); 204 sbuf_printf(sb, "\t <geom ref=\"%p\"/>\n", pp->geom); 205 sbuf_printf(sb, "\t <mode>r%dw%de%d</mode>\n", 206 pp->acr, pp->acw, pp->ace); | 179 sbuf_delete(s); 180} 181 182static void 183g_conf_consumer(struct sbuf *sb, struct g_consumer *cp) 184{ 185 186 sbuf_printf(sb, "\t<consumer id=\"%p\">\n", cp); --- 15 unchanged lines hidden (view full) --- 202static void 203g_conf_provider(struct sbuf *sb, struct g_provider *pp) 204{ 205 206 sbuf_printf(sb, "\t<provider id=\"%p\">\n", pp); 207 sbuf_printf(sb, "\t <geom ref=\"%p\"/>\n", pp->geom); 208 sbuf_printf(sb, "\t <mode>r%dw%de%d</mode>\n", 209 pp->acr, pp->acw, pp->ace); |
207 g_conf_print_escaped(sb, "\t <name>%s</name>\n", pp->name); | 210 sbuf_printf(sb, "\t <name>"); 211 g_conf_printf_escaped(sb, "%s", pp->name); 212 sbuf_printf(sb, "</name>\n"); |
208 sbuf_printf(sb, "\t <mediasize>%jd</mediasize>\n", 209 (intmax_t)pp->mediasize); 210 sbuf_printf(sb, "\t <sectorsize>%u</sectorsize>\n", pp->sectorsize); 211 sbuf_printf(sb, "\t <stripesize>%u</stripesize>\n", pp->stripesize); 212 sbuf_printf(sb, "\t <stripeoffset>%u</stripeoffset>\n", pp->stripeoffset); 213 if (pp->geom->flags & G_GEOM_WITHER) 214 ; 215 else if (pp->geom->dumpconf != NULL) { --- 8 unchanged lines hidden (view full) --- 224static void 225g_conf_geom(struct sbuf *sb, struct g_geom *gp, struct g_provider *pp, struct g_consumer *cp) 226{ 227 struct g_consumer *cp2; 228 struct g_provider *pp2; 229 230 sbuf_printf(sb, " <geom id=\"%p\">\n", gp); 231 sbuf_printf(sb, " <class ref=\"%p\"/>\n", gp->class); | 213 sbuf_printf(sb, "\t <mediasize>%jd</mediasize>\n", 214 (intmax_t)pp->mediasize); 215 sbuf_printf(sb, "\t <sectorsize>%u</sectorsize>\n", pp->sectorsize); 216 sbuf_printf(sb, "\t <stripesize>%u</stripesize>\n", pp->stripesize); 217 sbuf_printf(sb, "\t <stripeoffset>%u</stripeoffset>\n", pp->stripeoffset); 218 if (pp->geom->flags & G_GEOM_WITHER) 219 ; 220 else if (pp->geom->dumpconf != NULL) { --- 8 unchanged lines hidden (view full) --- 229static void 230g_conf_geom(struct sbuf *sb, struct g_geom *gp, struct g_provider *pp, struct g_consumer *cp) 231{ 232 struct g_consumer *cp2; 233 struct g_provider *pp2; 234 235 sbuf_printf(sb, " <geom id=\"%p\">\n", gp); 236 sbuf_printf(sb, " <class ref=\"%p\"/>\n", gp->class); |
232 g_conf_print_escaped(sb, " <name>%s</name>\n", gp->name); | 237 sbuf_printf(sb, " <name>"); 238 g_conf_printf_escaped(sb, "%s", gp->name); 239 sbuf_printf(sb, "</name>\n"); |
233 sbuf_printf(sb, " <rank>%d</rank>\n", gp->rank); 234 if (gp->flags & G_GEOM_WITHER) 235 sbuf_printf(sb, " <wither/>\n"); 236 else if (gp->dumpconf != NULL) { 237 sbuf_printf(sb, " <config>\n"); 238 gp->dumpconf(sb, "\t", gp, NULL, NULL); 239 sbuf_printf(sb, " </config>\n"); 240 } --- 12 unchanged lines hidden (view full) --- 253} 254 255static void 256g_conf_class(struct sbuf *sb, struct g_class *mp, struct g_geom *gp, struct g_provider *pp, struct g_consumer *cp) 257{ 258 struct g_geom *gp2; 259 260 sbuf_printf(sb, " <class id=\"%p\">\n", mp); | 240 sbuf_printf(sb, " <rank>%d</rank>\n", gp->rank); 241 if (gp->flags & G_GEOM_WITHER) 242 sbuf_printf(sb, " <wither/>\n"); 243 else if (gp->dumpconf != NULL) { 244 sbuf_printf(sb, " <config>\n"); 245 gp->dumpconf(sb, "\t", gp, NULL, NULL); 246 sbuf_printf(sb, " </config>\n"); 247 } --- 12 unchanged lines hidden (view full) --- 260} 261 262static void 263g_conf_class(struct sbuf *sb, struct g_class *mp, struct g_geom *gp, struct g_provider *pp, struct g_consumer *cp) 264{ 265 struct g_geom *gp2; 266 267 sbuf_printf(sb, " <class id=\"%p\">\n", mp); |
261 g_conf_print_escaped(sb, " <name>%s</name>\n", mp->name); | 268 sbuf_printf(sb, " <name>"); 269 g_conf_printf_escaped(sb, "%s", mp->name); 270 sbuf_printf(sb, "</name>\n"); |
262 LIST_FOREACH(gp2, &mp->geom, geom) { 263 if (gp != NULL && gp != gp2) 264 continue; 265 g_conf_geom(sb, gp2, pp, cp); 266 } 267 sbuf_printf(sb, " </class>\n"); 268} 269 --- 37 unchanged lines hidden --- | 271 LIST_FOREACH(gp2, &mp->geom, geom) { 272 if (gp != NULL && gp != gp2) 273 continue; 274 g_conf_geom(sb, gp2, pp, cp); 275 } 276 sbuf_printf(sb, " </class>\n"); 277} 278 --- 37 unchanged lines hidden --- |