* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
* %sccs.include.redist.c%
static char copyright
[] =
"@(#) Copyright (c) 1990, 1993\n\
The Regents of the University of California. All rights reserved.\n";
static char sccsid
[] = "@(#)dev_mkdb.c 8.1 (Berkeley) %G%";
void err
__P((const char *, ...));
register struct dirent
*dp
;
u_char buf
[MAXNAMLEN
+ 1];
char dbtmp
[MAXPATHLEN
+ 1], dbname
[MAXPATHLEN
+ 1];
while ((ch
= getopt(argc
, argv
, "")) != EOF
)
err("%s: %s", _PATH_DEV
, strerror(errno
));
(void)snprintf(dbtmp
, sizeof(dbtmp
), "%sdev.tmp", _PATH_VARRUN
);
(void)snprintf(dbname
, sizeof(dbtmp
), "%sdev.db", _PATH_VARRUN
);
db
= dbopen(dbtmp
, O_CREAT
|O_EXLOCK
|O_RDWR
|O_TRUNC
,
S_IRUSR
|S_IWUSR
|S_IRGRP
|S_IROTH
, DB_HASH
, NULL
);
err("%s: %s", dbtmp
, strerror(errno
));
* 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. Note
* that the structure may contain padding, so we have to clear it
bzero(&bkey
, sizeof(bkey
));
while (dp
= readdir(dirp
)) {
if (lstat(dp
->d_name
, &sb
)) {
"dev_mkdb: %s: %s\n", dp
->d_name
, strerror(errno
));
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))
err("dbput %s: %s\n", dbtmp
, strerror(errno
));
if (rename(dbtmp
, dbname
))
err("rename %s to %s: %s", dbtmp
, dbname
, strerror(errno
));
(void)fprintf(stderr
, "usage: dev_mkdb\n");
err(const char *fmt
, ...)
(void)fprintf(stderr
, "dev_mkdb: ");
(void)vfprintf(stderr
, fmt
, ap
);
(void)fprintf(stderr
, "\n");