Ejemplo n.º 1
0
/*
 * Write modified pages to disk
 *
 * Returns:
 *	 0 == OK
 *	-1 DBM_ERROR
 */
static int
hash_sync(const DB *dbp, uint flags)
{
	HTAB *hashp;

	if (flags != 0) {
		errno = EINVAL;
		return (DBM_ERROR);
	}

	if (!dbp)
		return (DBM_ERROR);

	hashp = (HTAB *)dbp->internal;
	if(!hashp)
		return (DBM_ERROR);

	if (!hashp->save_file)
		return (0);
	if (__buf_free(hashp, 0, 1) || flush_meta(hashp))
		return (DBM_ERROR);
#if defined(_WIN32) || defined(_WINDOWS) 
	if (hashp->updateEOF && hashp->filename && !hashp->is_temp) {
		int status = update_EOF(hashp);
		hashp->updateEOF = 0;
		if (status)
			return status;
	}
#endif
	hashp->new_file = 0;
	return (0);
}
Ejemplo n.º 2
0
/*
 * Flushes any changes to the file if necessary and destroys the hashp
 * structure, freeing all allocated space.
 */
static int
hdestroy(HTAB *hashp)
{
	int i, save_errno;

	save_errno = 0;

#ifdef HASH_STATISTICS
	(void)fprintf(stderr, "hdestroy: accesses %ld collisions %ld\n",
	    hash_accesses, hash_collisions);
	(void)fprintf(stderr, "hdestroy: expansions %ld\n",
	    hash_expansions);
	(void)fprintf(stderr, "hdestroy: overflows %ld\n",
	    hash_overflows);
	(void)fprintf(stderr, "keys %ld maxp %d segmentcount %d\n",
	    hashp->NKEYS, hashp->MAX_BUCKET, hashp->nsegs);

	for (i = 0; i < NCACHED; i++)
		(void)fprintf(stderr,
		    "spares[%d] = %d\n", i, hashp->SPARES[i]);
#endif
	/*
	 * Call on buffer manager to free buffers, and if required,
	 * write them to disk.
	 */
	if (__buf_free(hashp, 1, hashp->save_file))
		save_errno = errno;
	if (hashp->dir) {
		free(*hashp->dir);	/* Free initial segments */
		/* Free extra segments */
		while (hashp->exsegs--)
			free(hashp->dir[--hashp->nsegs]);
		free(hashp->dir);
	}
	if (flush_meta(hashp) && !save_errno)
		save_errno = errno;
	/* Free Bigmaps */
	for (i = 0; i < hashp->nmaps; i++)
		if (hashp->mapp[i])
			free(hashp->mapp[i]);
	if (hashp->tmp_key)
		free(hashp->tmp_key);
	if (hashp->tmp_buf)
		free(hashp->tmp_buf);

	if (hashp->fp != -1) {
		(void)_fsync(hashp->fp);
		(void)_close(hashp->fp);
	}

	free(hashp);

	if (save_errno) {
		errno = save_errno;
		return (ERROR);
	}
	return (SUCCESS);
}
Ejemplo n.º 3
0
/*
 * Write modified pages to disk
 *
 * Returns:
 *	 0 == OK
 *	-1 ERROR
 */
static int
hash_sync(const DB *dbp, u_int32_t flags)
{
	HTAB *hashp;

	if (flags != 0) {
		errno = EINVAL;
		return (ERROR);
	}

	if (!dbp)
		return (ERROR);

	hashp = (HTAB *)dbp->internal;
	if (!hashp->save_file)
		return (0);
	if (__buf_free(hashp, 0, 1) || flush_meta(hashp))
		return (ERROR);
	hashp->new_file = 0;
	return (0);
}