* Copyright (c) 1990 The Regents of the University of California.
* %sccs.include.redist.c%
"@(#) Copyright (c) 1990 The Regents of the University of California.\n\
static char sccsid
[] = "@(#)dev_mkdb.c 5.10 (Berkeley) %G%";
register struct dirent
*dp
;
u_char buf
[MAXNAMLEN
+ 1];
char dbtmp
[MAXPATHLEN
+ 1], dbname
[MAXPATHLEN
+ 1];
while ((ch
= getopt(argc
, argv
, "")) != EOF
)
(void)snprintf(dbtmp
, sizeof(dbtmp
), "%s/dev.tmp", _PATH_VARRUN
);
(void)snprintf(dbname
, sizeof(dbtmp
), "%s/dev.db", _PATH_VARRUN
);
db
= dbopen(dbtmp
, O_CREAT
|O_WRONLY
|O_EXCL
, DEFFILEMODE
, DB_HASH
, NULL
);
* 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.
while (dp
= readdir(dirp
)) {
if (stat(dp
->d_name
, &sb
)) {
(void)fprintf(stderr
, "dev_mkdb: can't stat %s\n",
else if (S_ISBLK(sb
.st_mode
))
* Create the data; nul terminate the name so caller doesn't
bcopy(dp
->d_name
, buf
, dp
->d_namlen
);
buf
[dp
->d_namlen
] = '\0';
data
.size
= dp
->d_namlen
+ 1;
if ((db
->put
)(db
, &key
, &data
, 0))
if (rename(dbtmp
, dbname
)) {
(void)fprintf(stderr
, "dev_mkdb: %s to %s: %s.\n",
dbtmp
, dbname
, strerror(errno
));
(void)fprintf(stderr
, "dev_mkdb: %s: %s\n", n
, strerror(errno
));
(void)fprintf(stderr
, "usage: dev_mkdb\n");