Esempio n. 1
0
File: tdb.c Progetto: Arkhont/samba
static enum TDB_ERROR replace_data(struct tdb_context *tdb,
				   struct hash_info *h,
				   struct tdb_data key, struct tdb_data dbuf,
				   tdb_off_t old_off, tdb_len_t old_room,
				   bool growing)
{
	tdb_off_t new_off;
	enum TDB_ERROR ecode;

	/* Allocate a new record. */
	new_off = alloc(tdb, key.dsize, dbuf.dsize, h->h, TDB_USED_MAGIC,
			growing);
	if (TDB_OFF_IS_ERR(new_off)) {
		return new_off;
	}

	/* We didn't like the existing one: remove it. */
	if (old_off) {
		tdb->stats.frees++;
		ecode = add_free_record(tdb, old_off,
					sizeof(struct tdb_used_record)
					+ key.dsize + old_room,
					TDB_LOCK_WAIT, true);
		if (ecode == TDB_SUCCESS)
			ecode = replace_in_hash(tdb, h, new_off);
	} else {
		ecode = add_to_hash(tdb, h, new_off);
	}
	if (ecode != TDB_SUCCESS) {
		return ecode;
	}

	new_off += sizeof(struct tdb_used_record);
	ecode = tdb->methods->twrite(tdb, new_off, key.dptr, key.dsize);
	if (ecode != TDB_SUCCESS) {
		return ecode;
	}

	new_off += key.dsize;
	ecode = tdb->methods->twrite(tdb, new_off, dbuf.dptr, dbuf.dsize);
	if (ecode != TDB_SUCCESS) {
		return ecode;
	}

	if (tdb->flags & TDB_SEQNUM)
		tdb_inc_seqnum(tdb);

	return TDB_SUCCESS;
}
Esempio n. 2
0
File: tdb.c Progetto: Arkhont/samba
static enum TDB_ERROR update_data(struct tdb_context *tdb,
				  tdb_off_t off,
				  struct tdb_data dbuf,
				  tdb_len_t extra)
{
	enum TDB_ERROR ecode;

	ecode = tdb->methods->twrite(tdb, off, dbuf.dptr, dbuf.dsize);
	if (ecode == TDB_SUCCESS && extra) {
		/* Put a zero in; future versions may append other data. */
		ecode = tdb->methods->twrite(tdb, off + dbuf.dsize, "", 1);
	}
	if (tdb->flags & TDB_SEQNUM)
		tdb_inc_seqnum(tdb);

	return ecode;
}
Esempio n. 3
0
enum TDB_ERROR tdb_delete(struct tdb_context *tdb, struct tdb_data key)
{
	tdb_off_t off;
	struct tdb_used_record rec;
	struct hash_info h;
	enum TDB_ERROR ecode;

	if (tdb->flags & TDB_VERSION1) {
		if (tdb1_delete(tdb, key) == -1)
			return tdb->last_error;
		return TDB_SUCCESS;
	}

	off = find_and_lock(tdb, key, F_WRLCK, &h, &rec, NULL);
	if (TDB_OFF_IS_ERR(off)) {
		return tdb->last_error = TDB_OFF_TO_ERR(off);
	}

	if (!off) {
		ecode = TDB_ERR_NOEXIST;
		goto unlock;
	}

	ecode = delete_from_hash(tdb, &h);
	if (ecode != TDB_SUCCESS) {
		goto unlock;
	}

	/* Free the deleted entry. */
	tdb->stats.frees++;
	ecode = add_free_record(tdb, off,
				sizeof(struct tdb_used_record)
				+ rec_key_length(&rec)
				+ rec_data_length(&rec)
				+ rec_extra_padding(&rec),
				TDB_LOCK_WAIT, true);

	if (tdb->flags & TDB_SEQNUM)
		tdb_inc_seqnum(tdb);

unlock:
	tdb_unlock_hashes(tdb, h.hlock_start, h.hlock_range, F_WRLCK);
	return tdb->last_error = ecode;
}