A simple C program to read out info from geom

Poul-Henning Kamp phk at phk.freebsd.dk
Wed Mar 17 02:01:49 PST 2004


In message <20040317100531.R68939-100000 at x12.dk>, Soeren Straarup writes:
>
>Hi
>I'm trying to get into the geom some more by writting and testing,
>but i'm stuck here, i'm trying to look at the first item in the snap
>shot, using libgeom.h from userland.
><program>
>#include <libgeom.h>
>#include <stdio.h>
>#include <sys/resource.h>
>#include <devstat.h>
>#include <sys/devicestat.h>
>
>
>int main ( void )
>{
>        char *p;
>        struct gmesh gmp;
>        struct devstat *gsp;
>        struct gprovider *pp;
>        struct gconsumer *cp;
>        struct gident *gid;
>        void *sp;
>
>        geom_gettree(&gmp);

You lack a geom_stats_open() here.

>        sp = geom_stats_snapshot_get();
>        gsp = geom_stats_snapshot_next(sp);

gsp is returned as NULL here to tell you about the problem.

>        gid = geom_lookupid(&gmp, gsp->id);

Here you dereference a NULL pointer, and get a core dump.


-- 
Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20
phk at FreeBSD.ORG         | TCP/IP since RFC 956
FreeBSD committer       | BSD since 4.3-tahoe    
Never attribute to malice what can adequately be explained by incompetence.


More information about the freebsd-geom mailing list