示例#1
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);
}
示例#2
0
文件: fwrite.c 项目: 8l/subc
int _fwrite(void *p, int size, FILE *f) {
	int	k, len, total;

	if ((f->iom & _FWRITE) == 0) return 0;
	if (f->iom & _FERROR) return 0;
	f->last = _FWRITE;
	if ((f->mode & _IOACC) == _IONBF) {
		if ((k = _write(f->fd, p, size)) != size) {
			f->iom |= _FERROR;
			errno = EIO;
		}
		return k;
	}
	total = size;
	len = f->size;
	k = len - f->end;
	if (size < k) k = size;
	memcpy(f->buf + f->end, p, k);
	f->end += k;
	size -= k;
	p += k;
	if (!_fsync(f)) return 0;
	while (size > len) {
		if ((k = _write(f->fd, p, len)) != len) {
			f->iom |= _FERROR;
			errno = EIO;
			return total - size;
		}
		p += len;
		size -= len;
	}
	if (size != 0) {
		memcpy(f->buf, p, size);
		f->end = size;
	}
	if ((f->mode & _IOACC) == _IOLBF && !_fsync(f))
		return total-size;
	return total;
}
示例#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);
	if (hashp->fp != -1 && _fsync(hashp->fp) != 0)
		return (ERROR);
	hashp->new_file = 0;
	return (0);
}
示例#4
0
int
__rpc_raise_fd(int fd)
{
	int nfd;

	if (fd >= __rpc_minfd)
		return (fd);

	if ((nfd = _fcntl(fd, F_DUPFD, __rpc_minfd)) == -1)
		return (fd);

	if (_fsync(nfd) == -1) {
		_close(nfd);
		return (fd);
	}

	if (_close(fd) == -1) {
		/* this is okay, we will syslog an error, then use the new fd */
		syslog(LOG_ERR, "could not close() fd %d; mem & fd leak", fd);
	}

	return (nfd);
}
示例#5
0
文件: unistd.c 项目: drmetal/lollyjar
int fsync(int file)
{
    return _fsync(file);
}