Licensing Information
Open Source Used In Cisco FXOS 1.1(4) 975
tdb.map_ptr = NULL;
if ((open_flags & O_ACCMODE) == O_WRONLY) {
goto fail;
}
if (hash_size == 0) hash_size = DEFAULT_HASH_SIZE;
tdb.read_only = ((open_flags & O_ACCMODE) == O_RDONLY);
if (name != NULL) {
tdb.fd = open(name, open_flags, mode);
if (tdb.fd == -1) {
goto fail;
}
}
/* ensure there is only one process initialising at once */
tdb_brlock(&tdb, GLOBAL_LOCK, LOCK_SET, F_WRLCK, F_SETLKW);
if (tdb_flags & TDB_CLEAR_IF_FIRST) {
/* we need to zero the database if we are the only
one with it open */
if (tdb_brlock(&tdb, ACTIVE_LOCK, LOCK_SET, F_WRLCK, F_SETLK) == 0) {
ftruncate(tdb.fd, 0);
tdb_brlock(&tdb, ACTIVE_LOCK, LOCK_CLEAR, F_WRLCK, F_SETLK);
}
}
/* leave this lock in place */
tdb_brlock(&tdb, ACTIVE_LOCK, LOCK_SET, F_RDLCK, F_SETLKW);
if (read(tdb.fd, &tdb.header, sizeof(tdb.header)) != sizeof(tdb.header) ||
strcmp(tdb.header.magic_food, TDB_MAGIC_FOOD) != 0 ||
tdb.header.version != TDB_VERSION) {
/* its not a valid database - possibly initialise it */
if (!(open_flags & O_CREAT)) {
goto fail;
}
if (tdb_new_database(&tdb, hash_size) == -1) goto fail;
lseek(tdb.fd, 0, SEEK_SET);
if (tdb.fd != -1 && read(tdb.fd, &tdb.header,
sizeof(tdb.header)) !=
sizeof(tdb.header))
goto fail;
}