* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
* %sccs.include.redist.c%
static char sccsid
[] = "@(#)testdb.c 8.1 (Berkeley) %G%";
/* Return true if the db file is valid, else false */
register int cc
, kd
, ret
, dbversionlen
;
char dbname
[MAXPATHLEN
], dbversion
[_POSIX2_LINE_MAX
];
char kversion
[_POSIX2_LINE_MAX
];
if ((kd
= open(_PATH_KMEM
, O_RDONLY
, 0)) < 0)
if ((cp
= rindex(uf
, '/')) != 0)
(void) snprintf(dbname
, sizeof(dbname
), "%skvm_%s.db", _PATH_VARDB
, uf
);
if ((db
= dbopen(dbname
, O_RDONLY
, 0, DB_HASH
, NULL
)) == NULL
)
/* Read the version out of the database */
rec
.size
= sizeof(VRS_KEY
) - 1;
if ((db
->get
)(db
, &rec
, &rec
, 0))
if (rec
.data
== 0 || rec
.size
> sizeof(dbversion
))
bcopy(rec
.data
, dbversion
, rec
.size
);
/* Read version string from kernel memory */
rec
.size
= sizeof(VRS_SYM
) - 1;
if ((db
->get
)(db
, &rec
, &rec
, 0))
if (rec
.data
== 0 || rec
.size
!= sizeof(struct nlist
))
bcopy(rec
.data
, &nitem
, sizeof(nitem
));
* Theoretically possible for lseek to be seeking to -1. Not
* that it's something to lie awake nights about, however.
if (lseek(kd
, (off_t
)nitem
.n_value
, SEEK_SET
) == -1 && errno
!= 0)
cc
= read(kd
, kversion
, sizeof(kversion
));
if (cc
< 0 || cc
!= sizeof(kversion
))
/* If they match, we win */
ret
= bcmp(dbversion
, kversion
, dbversionlen
) == 0;