From owner-freebsd-hackers@FreeBSD.ORG Thu Aug 25 02:30:46 2005 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id AD89F16A41F for ; Thu, 25 Aug 2005 02:30:46 +0000 (GMT) (envelope-from imp@bsdimp.com) Received: from harmony.village.org (vc4-2-0-87.dsl.netrack.net [199.45.160.85]) by mx1.FreeBSD.org (Postfix) with ESMTP id 50C9143D48 for ; Thu, 25 Aug 2005 02:30:46 +0000 (GMT) (envelope-from imp@bsdimp.com) Received: from localhost (localhost.village.org [127.0.0.1]) by harmony.village.org (8.13.3/8.13.3) with ESMTP id j7P2SEJ4079342; Wed, 24 Aug 2005 20:28:15 -0600 (MDT) (envelope-from imp@bsdimp.com) Date: Wed, 24 Aug 2005 20:28:28 -0600 (MDT) Message-Id: <20050824.202828.133432144.imp@bsdimp.com> To: fierykylin@gmail.com From: "M. Warner Losh" In-Reply-To: <87ab37ab05082405065fb8252@mail.gmail.com> References: <87ab37ab05082405065fb8252@mail.gmail.com> X-Mailer: Mew version 3.3 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=iso-2022-jp Content-Transfer-Encoding: 7bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-2.0 (harmony.village.org [127.0.0.1]); Wed, 24 Aug 2005 20:28:15 -0600 (MDT) Cc: freebsd-hackers@freebsd.org Subject: Re: Enumerating devices and hardware conf from userland X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Aug 2005 02:30:46 -0000 In message: <87ab37ab05082405065fb8252@mail.gmail.com> kylin writes: : >I'm developping a tool running in userland (root) (a command line : >tools) for enumerating all devices present on the machine : : : >This tool must scan all hardware buses : pci, but usb, firewire, ide, : >etc.... and retreive devices states : configure, not configured, handle : >by a driver, not handle by a driver, witch modules is the driver. : >And I want to have all devices present inside a machine. : : : >In some recent Kernel, there is a way from userland, to take a handle : >from the root hardware tree, enumeratiing first buses, and under buses, : >witch device are connect to those buses. This is is what I am looking : >for. : do u just need the read function on the sysctl or do something from : the deep end into kernel ? : does http://www.magnicomp.com/cgi-bin/mcdownload.cgi really help? You can use devinfo to get 99% of the information that you are looking for. This is available in 4.x and newer. In 5.x and newer it also provides information about each device's location and its bus specific plug and play data as well. You can determine which driver is attached to each child in the device tree, or if no device is attached. While you can't directly map the device name to a module name, you can get close with some simple hueristics. There are man pages for the program, and the underlying library. Warner