asf_kld.c revision 201387
1139749Simp/*-
226159Sse * Copyright (c) 2006 The FreeBSD Project
326159Sse * All rights reserved.
426159Sse *
526159Sse * Redistribution and use in source and binary forms, with or without
626159Sse * modification, are permitted provided that the following conditions
726159Sse * are met:
826159Sse * 1. Redistributions of source code must retain the above copyright
926159Sse *    notice, this list of conditions and the following disclaimer.
1026159Sse * 2. Redistributions in binary form must reproduce the above copyright
1126159Sse *    notice, this list of conditions and the following disclaimer in the
1226159Sse *    documentation and/or other materials provided with the distribution.
1326159Sse *
1426159Sse * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1526159Sse * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1626159Sse * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1726159Sse * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1826159Sse * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1926159Sse * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2026159Sse * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2126159Sse * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2226159Sse * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2326159Sse * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2426159Sse * SUCH DAMAGE.
2526159Sse */
2650477Speter
2726159Sse#include <sys/cdefs.h>
2826159Sse__FBSDID("$FreeBSD: head/usr.sbin/asf/asf_kld.c 201387 2010-01-02 11:05:34Z ed $");
296100Sse
3039231Sgibbs#include <sys/param.h>
31165217Sjhb#include <sys/linker.h>
3239231Sgibbs#include <err.h>
3339231Sgibbs#include <string.h>
3439231Sgibbs
3526159Sse#include "asf.h"
366767Sse
37165217Sjhb/*
38165217Sjhb * Get the linker file list using the kld interface.
39165217Sjhb * Works with a live kernel only.
40165217Sjhb */
416100Ssevoid
42165217Sjhbasf_kld(void)
43165217Sjhb{
44165217Sjhb	struct kld_file_stat kfs;
456100Sse	int fid = 0;	/* indicates the beginning of the linker file list */
46163805Simp
476100Sse	while ((fid = kldnext(fid)) != 0) {
48120063Sscottl		if (fid == -1)
49120063Sscottl			err(2, "kldnext");
50120063Sscottl		kfs.version = sizeof(kfs);	/* must be set for kldstat(2) */
51120063Sscottl		/* Get info on this linker file */
52120063Sscottl		if (kldstat(fid, &kfs) == -1)
53120063Sscottl			err(2, "kldstat");
54120063Sscottl		if (strcmp(kfs.name, KERNFILE) == 0)
55120063Sscottl			continue;
56163163Sjmg		/* Add to our list of linker files */
57163163Sjmg		kfile_add(kfs.name, kfs.address);
58163163Sjmg	}
59163163Sjmg}
60163163Sjmg