1110603Sphk/*- 2110603Sphk * Copyright (c) 2003 Poul-Henning Kamp 3110603Sphk * All rights reserved. 4110603Sphk * 5110603Sphk * Redistribution and use in source and binary forms, with or without 6110603Sphk * modification, are permitted provided that the following conditions 7110603Sphk * are met: 8110603Sphk * 1. Redistributions of source code must retain the above copyright 9110603Sphk * notice, this list of conditions and the following disclaimer. 10110603Sphk * 2. Redistributions in binary form must reproduce the above copyright 11110603Sphk * notice, this list of conditions and the following disclaimer in the 12110603Sphk * documentation and/or other materials provided with the distribution. 13110603Sphk * 3. The names of the authors may not be used to endorse or promote 14110603Sphk * products derived from this software without specific prior written 15110603Sphk * permission. 16110603Sphk * 17110603Sphk * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18110603Sphk * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19110603Sphk * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20110603Sphk * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21110603Sphk * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22110603Sphk * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23110603Sphk * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24110603Sphk * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25110603Sphk * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26110603Sphk * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27110603Sphk * SUCH DAMAGE. 28110603Sphk * 29110603Sphk * $FreeBSD: releng/10.3/lib/libgeom/geom_getxml.c 201320 2009-12-31 01:37:26Z ed $ 30110603Sphk */ 31110603Sphk 32110603Sphk#include <sys/types.h> 33110603Sphk#include <sys/sysctl.h> 34110603Sphk#include <stdlib.h> 35110603Sphk#include <string.h> 36110603Sphk#include "libgeom.h" 37110603Sphk 38110603Sphkchar * 39201320Sedgeom_getxml(void) 40110603Sphk{ 41110603Sphk char *p; 42180369Slulf size_t l = 0; 43180369Slulf int mib[3]; 44180369Slulf size_t sizep; 45110603Sphk 46180369Slulf sizep = sizeof(mib) / sizeof(*mib); 47180369Slulf if (sysctlnametomib("kern.geom.confxml", mib, &sizep) != 0) 48180369Slulf return (NULL); 49180369Slulf if (sysctl(mib, sizep, NULL, &l, NULL, 0) != 0) 50180369Slulf return (NULL); 51180369Slulf l += 4096; 52110603Sphk p = malloc(l); 53180369Slulf if (p == NULL) 54180369Slulf return (NULL); 55180369Slulf if (sysctl(mib, sizep, p, &l, NULL, 0) != 0) { 56110603Sphk free(p); 57110603Sphk return (NULL); 58110603Sphk } 59180369Slulf return (reallocf(p, strlen(p) + 1)); 60110603Sphk} 61