SCCS-vsn: usr.sbin/dev_mkdb/dev_mkdb.c 5.6
#endif /* not lint */
#ifndef lint
#endif /* not lint */
#ifndef lint
-static char sccsid[] = "@(#)dev_mkdb.c 5.5 (Berkeley) %G%";
+static char sccsid[] = "@(#)dev_mkdb.c 5.6 (Berkeley) %G%";
#endif /* not lint */
#include <sys/param.h>
#endif /* not lint */
#include <sys/param.h>
register DIR *dirp;
register struct dirent *dp;
struct stat sb;
register DIR *dirp;
register struct dirent *dp;
struct stat sb;
+ char bkeybuf[sizeof(sb.st_rdev) + 1];
DB *db;
DBT data, key;
int ch;
DB *db;
DBT data, key;
int ch;
- key.data = (u_char *)&sb.st_rdev;
- key.size = sizeof(sb.st_rdev);
+ /*
+ * Character devices are stored using st_rdev as the key.
+ * Block devices are stores using st_rdev followed by exactly
+ * one NULL byte as the key.
+ */
+ key.data = bkeybuf;
+ bkeybuf[sizeof(sb.st_rdev)] = NULL;
data.data = buf;
while (dp = readdir(dirp)) {
data.data = buf;
while (dp = readdir(dirp)) {
- if (stat(dp->d_name, &sb))
- error(dp->d_name);
- if (!S_ISCHR(sb.st_mode))
+ if (stat(dp->d_name, &sb)) {
+ (void)fprintf(stderr, "dev_mkdb: can't stat %s\n",
+ dp->d_name);
-
- /* Nul terminate the name so ps doesn't have to. */
+ }
+ if (S_ISCHR(sb.st_mode))
+ key.size = sizeof(sb.st_rdev);
+ else if (S_ISBLK(sb.st_mode))
+ key.size = sizeof(sb.st_rdev) + 1;
+ else
+ continue;
+ /*
+ * Nul terminate the name so caller doesn't have to.
+ */
bcopy(dp->d_name, buf, dp->d_namlen);
buf[dp->d_namlen] = '\0';
data.size = dp->d_namlen + 1;
bcopy(dp->d_name, buf, dp->d_namlen);
buf[dp->d_namlen] = '\0';
data.size = dp->d_namlen + 1;