From d0fd2f76cf6b0884889cbadc44dc9807523a6d51 Mon Sep 17 00:00:00 2001 From: phk Date: Sat, 9 Sep 2000 11:39:59 +0000 Subject: Add code to devname(3) so it can find the names of devices which were not present when dev_mkdb(8) was run. First the dev_mkdb(8) database is searched, this caters for non-DEVFS cases where people have renamed a device. If that fails we ask the kernel using sysctl kern.devname if the device driver has put a name in the dev_t. This covers DEVFS cloned devices. If that also fails we format a string which isn't entirely useless. --- lib/libc/gen/devname.3 | 1 + lib/libc/gen/devname.c | 39 +++++++++++++++++++++++++++------------ 2 files changed, 28 insertions(+), 12 deletions(-) (limited to 'lib/libc') diff --git a/lib/libc/gen/devname.3 b/lib/libc/gen/devname.3 index b63d6c9..2f39c80 100644 --- a/lib/libc/gen/devname.3 +++ b/lib/libc/gen/devname.3 @@ -41,6 +41,7 @@ .Sh LIBRARY .Lb libc .Sh SYNOPSIS +.Fd #include .Fd #include .Ft char * .Fn devname "dev_t dev" "mode_t type" diff --git a/lib/libc/gen/devname.c b/lib/libc/gen/devname.c index 898c8e8..7d84037 100644 --- a/lib/libc/gen/devname.c +++ b/lib/libc/gen/devname.c @@ -29,6 +29,8 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. + * + * $FreeBSD$ */ #if defined(LIBC_SCCS) && !defined(lint) @@ -36,6 +38,7 @@ static char sccsid[] = "@(#)devname.c 8.2 (Berkeley) 4/29/95"; #endif /* LIBC_SCCS and not lint */ #include +#include #include #include @@ -85,21 +88,33 @@ devname(dev, type) dev_t dev; mode_t type; { - static char buf[20]; + static char buf[30]; /* XXX: pick up from */ + int i, j; char *r; + /* First check the DB file. */ r = xdevname(dev, type); - if (!r) { - r = buf; - if (minor(dev) > 255) { - sprintf(buf, "#%c%d:0x%x", - (type & S_IFMT) == S_IFCHR ? 'C' : 'B', - major(dev), minor(dev)); - } else { - sprintf(buf, "#%c%d:%d", - (type & S_IFMT) == S_IFCHR ? 'C' : 'B', - major(dev), minor(dev)); - } + if (r != NULL) + return (r); + + /* Then ask the kernel. */ + if ((type & S_IFMT) == S_IFCHR) { + j = sizeof(buf); + i = sysctlbyname("kern.devname", buf, &j, &dev, sizeof (dev)); + if (i == 0) + return (buf); + } + + /* Finally just format it */ + r = buf; + if (minor(dev) > 255) { + sprintf(buf, "#%c%d:0x%x", + (type & S_IFMT) == S_IFCHR ? 'C' : 'B', + major(dev), minor(dev)); + } else { + sprintf(buf, "#%c%d:%d", + (type & S_IFMT) == S_IFCHR ? 'C' : 'B', + major(dev), minor(dev)); } return (r); } -- cgit v1.1