Exemple #1
0
void zero_filemark_count(void)
{
	free(filemarks);
	filemark_alloc = 0;
	filemarks = NULL;

	meta.filemark_count = 0;
	rewrite_meta_file();
}
Exemple #2
0
static int
check_for_overwrite(uint8_t *sam_stat)
{
	uint32_t blk_number;
	uint64_t data_offset;
	unsigned int i;

	if (raw_pos.hdr.blk_type == B_EOD) {
		return 0;
	}

	MHVTL_DBG(2, "At block %ld", (unsigned long)raw_pos.hdr.blk_number);

	/* We aren't at EOD so we are performing a rewrite.  Truncate
	   the data and index files back to the current length.
	*/

	blk_number = raw_pos.hdr.blk_number;
	data_offset = raw_pos.data_offset;

	if (ftruncate(indxfile, blk_number * sizeof(raw_pos))) {
		mkSenseBuf(MEDIUM_ERROR, E_WRITE_ERROR, sam_stat);
		MHVTL_ERR("Index file ftruncate failure, pos: "
			"%" PRId64 ": %s",
			(uint64_t)blk_number * sizeof(raw_pos),
			strerror(errno));
		return -1;
	}
	if (ftruncate(datafile, data_offset)) {
		mkSenseBuf(MEDIUM_ERROR, E_WRITE_ERROR, sam_stat);
		MHVTL_ERR("Data file ftruncate failure, pos: "
			"%" PRId64 ": %s", data_offset,
			strerror(errno));
		return -1;
	}

	/* Update the filemark map removing any filemarks which will be
	   overwritten.  Rewrite the filemark map so that the on-disk image
	   of the map is consistent with the new sizes of the other two files.
	*/

	for (i = 0; i < meta.filemark_count; i++) {
		MHVTL_DBG(2, "filemarks[%d] %d", i, filemarks[i]);
		if (filemarks[i] >= blk_number) {
			MHVTL_DBG(2, "Setting filemark_count from %d to %d",
					meta.filemark_count, i);
			meta.filemark_count = i;
			return rewrite_meta_file();
		}
	}

	return 0;
}
Exemple #3
0
static int add_filemark(uint32_t blk_number)
{
	/* See if we have enough space remaining to add the new filemark.  If
	   not, realloc now.
	*/

	if (check_filemarks_alloc(meta.filemark_count + 1))
			return -1;

	filemarks[meta.filemark_count++] = blk_number;

	/* Now rewrite the meta_header structure and the filemark map. */

	return rewrite_meta_file();
}
Exemple #4
0
void
unload_tape(uint8_t *sam_stat)
{
	if (datafile >= 0) {
		close(datafile);
		datafile = -1;
	}
	if (indxfile >= 0) {
		close(indxfile);
		indxfile = -1;
	}
	if (metafile >= 0) {
		rewrite_meta_file();
		close(metafile);
		metafile = -1;
	}
}
Exemple #5
0
void unload_tape(uint8_t *sam_stat)
{
	if (datafile >= 0) {
		close(datafile);
		datafile = -1;
	}
	if (indxfile >= 0) {
		close(indxfile);
		indxfile = -1;
	}
	if (metafile >= 0) {
		rewrite_meta_file();
		close(metafile);
		metafile = -1;
	}
	free(filemarks);
	filemarks = NULL;
	filemark_alloc = 0;
}