- }
-
- /* cache the page size */
- tdb->page_size = getpagesize();
- if (tdb->page_size <= 0) {
- tdb->page_size = 0x2000;
- }
-
- /* FIXME: Used to be 5 for TDB_VOLATILE. */
- tdb->max_dead_records = 0;
-
- if ((open_flags & O_ACCMODE) == O_WRONLY) {
- tdb_logerr(tdb, TDB_ERR_EINVAL, TDB_LOG_USE_ERROR,
- "tdb1_open_ex: can't open tdb %s write-only",
- name);
- errno = EINVAL;
- goto fail;
- }
-
- if (hash_size == 0)
- hash_size = TDB1_DEFAULT_HASH_SIZE;
- if ((open_flags & O_ACCMODE) == O_RDONLY) {
- tdb->read_only = 1;
- /* read only databases don't do locking */
- tdb->flags |= TDB_NOLOCK;
- }
-
- /* internal databases don't mmap or lock, and start off cleared */
- if (tdb->flags & TDB_INTERNAL) {
- tdb->flags |= (TDB_NOLOCK | TDB_NOMMAP);
- if (tdb1_new_database(tdb, hash_size) != 0) {
- tdb_logerr(tdb, tdb->last_error, TDB_LOG_ERROR,
- "tdb1_open_ex: tdb1_new_database failed!");
- goto fail;
- }
- goto internal;
- }
-
- if ((tdb->file->fd = open(name, open_flags, mode)) == -1) {
- tdb_logerr(tdb, TDB_ERR_IO, TDB_LOG_ERROR,
- "tdb1_open_ex: could not open file %s: %s",
- name, strerror(errno));
- goto fail; /* errno set by open(2) */
- }
-
- /* on exec, don't inherit the fd */
- v = fcntl(tdb->file->fd, F_GETFD, 0);
- fcntl(tdb->file->fd, F_SETFD, v | FD_CLOEXEC);
-
- /* ensure there is only one process initialising at once */
- if (tdb1_nest_lock(tdb, TDB1_OPEN_LOCK, F_WRLCK, TDB_LOCK_WAIT) == -1) {
- tdb_logerr(tdb, tdb->last_error, TDB_LOG_ERROR,
- "tdb1_open_ex: failed to get open lock on %s: %s",
- name, strerror(errno));
- goto fail; /* errno set by tdb1_brlock */
- }
-
- errno = 0;
- if (read(tdb->file->fd, &tdb->header, sizeof(tdb->header)) != sizeof(tdb->header)
- || strcmp(tdb->header.magic_food, TDB_MAGIC_FOOD) != 0) {
- if (!(open_flags & O_CREAT) || tdb1_new_database(tdb, hash_size) == -1) {
- if (errno == 0) {
- errno = EIO; /* ie bad format or something */
- }
- goto fail;
+ } else if (tdb->hash_fn == tdb1_incompatible_hash)
+ hash_alg = "tdb1_incompatible_hash";
+ else
+ hash_alg = "the user defined";
+
+ if (tdb->tdb1.header.version != TDB1_BYTEREV(TDB1_VERSION)) {
+ if (tdb->flags & TDB_CONVERT) {
+ return tdb_logerr(tdb, TDB_ERR_IO, TDB_LOG_ERROR,
+ "tdb1_open:"
+ " %s does not need TDB_CONVERT",
+ tdb->name);