- }
-
- /* cache the page size */
- tdb->tdb1.page_size = getpagesize();
- if (tdb->tdb1.page_size <= 0) {
- tdb->tdb1.page_size = 0x2000;
- }
-
- /* FIXME: Used to be 5 for TDB_VOLATILE. */
- tdb->tdb1.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->flags |= TDB_RDONLY;
- /* 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->tdb1.header, sizeof(tdb->tdb1.header)) != sizeof(tdb->tdb1.header)
- || strcmp(tdb->tdb1.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;