/* * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. * * %sccs.include.redist.c% */ #if defined(LIBC_SCCS) && !defined(lint) static char sccsid[] = "@(#)devname.c 8.1 (Berkeley) 06/04/93"; #endif /* LIBC_SCCS and not lint */ #include #include #include #include #include #include #include #include char * devname(dev, type) dev_t dev; mode_t type; { struct { mode_t type; dev_t dev; } bkey; static DB *db; static int failure; DBT data, key; if (!db && !failure && !(db = dbopen(_PATH_DEVDB, O_RDONLY, 0, DB_HASH, NULL))) { warn("warning: %s", _PATH_DEVDB); failure = 1; } if (failure) return ("??"); /* * Keys are a mode_t followed by a dev_t. The former is the type of * the file (mode & S_IFMT), the latter is the st_rdev field. Be * sure to clear any padding that may be found in bkey. */ memset(&bkey, 0, sizeof(bkey)); bkey.dev = dev; bkey.type = type; key.data = &bkey; key.size = sizeof(bkey); return ((db->get)(db, &key, &data, 0) ? "??" : (char *)data.data); }