1 /* 2 * Copyright (c) 1989 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #if defined(LIBC_SCCS) && !defined(lint) 9 static char sccsid[] = "@(#)devname.c 5.15 (Berkeley) 11/04/91"; 10 #endif /* LIBC_SCCS and not lint */ 11 12 #include <sys/types.h> 13 #include <fcntl.h> 14 #include <errno.h> 15 #include <db.h> 16 #include <stdio.h> 17 #include <paths.h> 18 19 char * 20 devname(dev, type) 21 dev_t dev; 22 mode_t type; 23 { 24 struct { 25 mode_t type; 26 dev_t dev; 27 } bkey; 28 static DB *db; 29 static int failure; 30 DBT data, key; 31 32 if (!db && !failure && 33 !(db = dbopen(_PATH_DEVDB, O_RDONLY, 0, DB_HASH, NULL))) { 34 (void)fprintf(stderr, 35 "warning: %s: %s\n", _PATH_DEVDB, strerror(errno)); 36 failure = 1; 37 } 38 if (failure) 39 return("??"); 40 41 /* 42 * Keys are a mode_t followed by a dev_t. The former is the type of 43 * the file (mode & S_IFMT), the latter is the st_rdev field. 44 */ 45 bkey.dev = dev; 46 bkey.type = type; 47 key.data = &bkey; 48 key.size = sizeof(bkey); 49 return((db->get)(db, &key, &data, 0L) ? "??" : (char *)data.data); 50 } 51