140966Smarc /* 240966Smarc * Copyright (c) 1989 The Regents of the University of California. 340966Smarc * All rights reserved. 440966Smarc * 542537Sbostic * %sccs.include.redist.c% 640966Smarc */ 740966Smarc 840966Smarc #if defined(LIBC_SCCS) && !defined(lint) 9*58587Storek static char sccsid[] = "@(#)devname.c 5.17 (Berkeley) 03/09/93"; 1040966Smarc #endif /* LIBC_SCCS and not lint */ 1140966Smarc 1240258Smarc #include <sys/types.h> 1346325Sbostic #include <fcntl.h> 1451534Sbostic #include <errno.h> 1546945Sbostic #include <db.h> 1645158Smarc #include <stdio.h> 1753939Sbostic #include <string.h> 1846337Sbostic #include <paths.h> 1940258Smarc 2040258Smarc char * 2149245Sbostic devname(dev, type) 2240258Smarc dev_t dev; 2349245Sbostic mode_t type; 2440258Smarc { 2549245Sbostic struct { 2649245Sbostic mode_t type; 2749245Sbostic dev_t dev; 2849245Sbostic } bkey; 2946943Sbostic static DB *db; 3046325Sbostic static int failure; 3146943Sbostic DBT data, key; 3240258Smarc 3346943Sbostic if (!db && !failure && 3451534Sbostic !(db = dbopen(_PATH_DEVDB, O_RDONLY, 0, DB_HASH, NULL))) { 3546325Sbostic (void)fprintf(stderr, 3651534Sbostic "warning: %s: %s\n", _PATH_DEVDB, strerror(errno)); 3746325Sbostic failure = 1; 3840258Smarc } 3946325Sbostic if (failure) 4046325Sbostic return("??"); 4140258Smarc 4249245Sbostic /* 4349245Sbostic * Keys are a mode_t followed by a dev_t. The former is the type of 44*58587Storek * the file (mode & S_IFMT), the latter is the st_rdev field. Be 45*58587Storek * sure to clear any padding that may be found in bkey. 4649245Sbostic */ 47*58587Storek bzero(&bkey, sizeof(bkey)); 4849245Sbostic bkey.dev = dev; 4949245Sbostic bkey.type = type; 5049245Sbostic key.data = &bkey; 5149245Sbostic key.size = sizeof(bkey); 5246943Sbostic return((db->get)(db, &key, &data, 0L) ? "??" : (char *)data.data); 5340258Smarc } 54