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*49245Sbostic static char sccsid[] = "@(#)devname.c 5.14 (Berkeley) 05/06/91"; 1040966Smarc #endif /* LIBC_SCCS and not lint */ 1140966Smarc 1240258Smarc #include <sys/types.h> 1346325Sbostic #include <fcntl.h> 1446945Sbostic #include <db.h> 1545158Smarc #include <stdio.h> 1646337Sbostic #include <paths.h> 1740258Smarc 1840258Smarc char * 19*49245Sbostic devname(dev, type) 2040258Smarc dev_t dev; 21*49245Sbostic mode_t type; 2240258Smarc { 23*49245Sbostic struct { 24*49245Sbostic mode_t type; 25*49245Sbostic dev_t dev; 26*49245Sbostic } bkey; 2746943Sbostic static DB *db; 2846325Sbostic static int failure; 2946943Sbostic DBT data, key; 3040258Smarc 3146943Sbostic if (!db && !failure && 3246943Sbostic !(db = hash_open(_PATH_DEVDB, O_RDONLY, 0, NULL))) { 3346325Sbostic (void)fprintf(stderr, 34*49245Sbostic "warning: no device database %s\n", _PATH_DEVDB); 3546325Sbostic failure = 1; 3640258Smarc } 3746325Sbostic if (failure) 3846325Sbostic return("??"); 3940258Smarc 40*49245Sbostic /* 41*49245Sbostic * Keys are a mode_t followed by a dev_t. The former is the type of 42*49245Sbostic * the file (mode & S_IFMT), the latter is the st_rdev field. 43*49245Sbostic */ 44*49245Sbostic bkey.dev = dev; 45*49245Sbostic bkey.type = type; 46*49245Sbostic key.data = &bkey; 47*49245Sbostic key.size = sizeof(bkey); 4846943Sbostic return((db->get)(db, &key, &data, 0L) ? "??" : (char *)data.data); 4940258Smarc } 50