diff options
| author | manu <manu@NetBSD.org> | 2001-07-04 20:42:02 +0000 |
|---|---|---|
| committer | manu <manu@NetBSD.org> | 2001-07-04 20:42:02 +0000 |
| commit | b70b2499b00a3e4bdbf6b7e6b89d2afb486b8938 (patch) | |
| tree | 428c1695582f717ab66940b2770d9e829c28c8f0 /usr.sbin/dev_mkdb | |
| parent | e7313e53ae70826b5487de5c51b9a2cc830b666a (diff) | |
Added flags to choose the location of the input device directory and the
output device database. Goal is to be consistent with other *_mkdb
utilities such as pwd_mkdb or kvm_mkdb.
Diffstat (limited to 'usr.sbin/dev_mkdb')
| -rw-r--r-- | usr.sbin/dev_mkdb/dev_mkdb.8 | 16 | ||||
| -rw-r--r-- | usr.sbin/dev_mkdb/dev_mkdb.c | 52 |
2 files changed, 48 insertions, 20 deletions
diff --git a/usr.sbin/dev_mkdb/dev_mkdb.8 b/usr.sbin/dev_mkdb/dev_mkdb.8 index 87fd7ed5c90..ef8a4b89016 100644 --- a/usr.sbin/dev_mkdb/dev_mkdb.8 +++ b/usr.sbin/dev_mkdb/dev_mkdb.8 @@ -30,7 +30,7 @@ .\" SUCH DAMAGE. .\" .\" from: @(#)dev_mkdb.8 8.1 (Berkeley) 6/6/93 -.\" $NetBSD: dev_mkdb.8,v 1.5 1997/10/17 00:12:43 lukem Exp $ +.\" $NetBSD: dev_mkdb.8,v 1.6 2001/07/04 20:42:02 manu Exp $ .\" .Dd June 6, 1993 .Os @@ -42,6 +42,8 @@ database .Sh SYNOPSIS .Nm +.Op Fl o Ar database +.Op directory .Sh DESCRIPTION The .Nm @@ -50,16 +52,22 @@ command creates a hash access method database in .Dq Pa /var/run/dev.db which contains the names of all of the character and block special -files in the -.Dq Pa /dev -directory, using the file type and the +files in the specified directory, using the file type and the .Fa st_rdev field as the key. +If no directory is specified, the +.Dq Pa /dev +directory is used. .Pp Keys are a structure containing a mode_t followed by a dev_t, with any padding zero'd out. The former is the type of the file (st_mode & S_IFMT), the latter is the st_rdev field. +.Pp +The options are as follows: +.Bl -tag -width indent +.It Fl o Ar database +Put the output databases in the named file. .Sh FILES .Bl -tag -width /var/run/dev.db -compact .It Pa /dev diff --git a/usr.sbin/dev_mkdb/dev_mkdb.c b/usr.sbin/dev_mkdb/dev_mkdb.c index d806bd4919f..fcd355337ac 100644 --- a/usr.sbin/dev_mkdb/dev_mkdb.c +++ b/usr.sbin/dev_mkdb/dev_mkdb.c @@ -1,4 +1,4 @@ -/* $NetBSD: dev_mkdb.c,v 1.10 2001/04/10 06:11:27 enami Exp $ */ +/* $NetBSD: dev_mkdb.c,v 1.11 2001/07/04 20:42:02 manu Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -43,7 +43,7 @@ __COPYRIGHT("@(#) Copyright (c) 1990, 1993\n\ #if 0 static char sccsid[] = "from: @(#)dev_mkdb.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: dev_mkdb.c,v 1.10 2001/04/10 06:11:27 enami Exp $"); +__RCSID("$NetBSD: dev_mkdb.c,v 1.11 2001/07/04 20:42:02 manu Exp $"); #endif #endif /* not lint */ @@ -82,11 +82,19 @@ main(argc, argv) FTSENT *p; int ch; u_char buf[MAXPATHLEN + 1]; - char dbtmp[MAXPATHLEN + 1], dbname[MAXPATHLEN + 1]; + char dbtmp[MAXPATHLEN + 1]; + char dbname[MAXPATHLEN + 1]; + char *dbname_arg = NULL; char *pathv[2]; + char path_dev[MAXPATHLEN + 1] = _PATH_DEV; + char cur_dir[MAXPATHLEN + 1]; - while ((ch = getopt(argc, argv, "")) != -1) + while ((ch = getopt(argc, argv, "o:")) != -1) switch (ch) { + case 'o': + if (strlen(optarg) <= MAXPATHLEN) + dbname_arg = optarg; + break; case '?': default: usage(); @@ -94,20 +102,29 @@ main(argc, argv) argc -= optind; argv += optind; - if (argc > 0) + if ((argc == 1) && (strlen(argv[0]) <= MAXPATHLEN)) + strncpy(path_dev, argv[0], MAXPATHLEN); + + if (argc > 1) usage(); - if (chdir(_PATH_DEV)) - err(1, "%s", _PATH_DEV); + if (!getcwd(cur_dir, MAXPATHLEN)) + err(1, "%s", cur_dir); - pathv[0] = _PATH_DEV; + if (chdir(path_dev)) + err(1, "%s", path_dev); + + pathv[0] = path_dev; pathv[1] = NULL; ftsp = fts_open(pathv, FTS_PHYSICAL, NULL); if (ftsp == NULL) - err(1, "fts_open: %s", _PATH_DEV); + err(1, "fts_open: %s", path_dev); - (void)snprintf(dbtmp, sizeof(dbtmp), "%sdev.tmp", _PATH_VARRUN); - (void)snprintf(dbname, sizeof(dbtmp), "%sdev.db", _PATH_VARRUN); + (void)snprintf(dbtmp, MAXPATHLEN, "%sdev.tmp", _PATH_VARTMP); + if (dbname_arg) + strncpy(dbname, dbname_arg, MAXPATHLEN); + else + (void)snprintf(dbname, MAXPATHLEN, "%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); if (db == NULL) @@ -143,15 +160,18 @@ main(argc, argv) /* * Create the data; nul terminate the name so caller doesn't - * have to. Skip _PATH_DEV and slash. + * have to. Skip path_dev and slash. */ - strlcpy(buf, p->fts_path + sizeof(_PATH_DEV), sizeof(buf)); - data.size = p->fts_pathlen - sizeof(_PATH_DEV) + 1; - if ((*db->put)(db, &key, &data, 0)) + strlcpy(buf, p->fts_path + strlen(path_dev), sizeof(buf)); + data.size = p->fts_pathlen - strlen(path_dev) + 1; + if ((*db->put)(db, &key, &data, 0)) { err(1, "dbput %s", dbtmp); + } } (void)(*db->close)(db); fts_close(ftsp); + if (chdir(cur_dir)) + err(1, "%s", cur_dir); if (rename(dbtmp, dbname)) err(1, "rename %s to %s", dbtmp, dbname); exit(0); @@ -161,6 +181,6 @@ void usage() { - (void)fprintf(stderr, "usage: dev_mkdb\n"); + (void)fprintf(stderr, "usage: dev_mkdb [-o database] [directory]\n"); exit(1); } |
