Exemplo n.º 1
0
/**
 * statstape_print(d, tapename, csv_filename):
 * Print statistics relating to a specific archive in a set.  Return 0 on
 * success, 1 if the tape does not exist, or -1 on other errors.  If
 * ${csv_filename} is not NULL, output will be written in CSV format to that
 * filename.
 */
int
statstape_print(TAPE_S * d, const char * tapename, const char * csv_filename)
{
	struct tapemetadata tmd;
	int rc = -1;	/* Presume error was not !found. */
	FILE * output = stdout;
	int csv = 0;

	/* Should we output to a CSV file? */
	if (csv_filename != NULL)
		csv = 1;

	/* Cache up to 100 bytes of blocks per chunk in the directory. */
	storage_read_cache_limit(d->SR, 100 * chunks_stats_getdirsz(d->C));

	/* Zero archive statistics. */
	chunks_stats_zeroarchive(d->C);

	/* Read the tape metadata. */
	switch (multitape_metadata_get_byname(d->SR, d->C, &tmd, tapename, 0)) {
	case 0:
		break;
	case 1:
		rc = 1;
		/* FALLTHROUGH */
	default:
		goto err0;
	}

	if (multitape_chunkiter_tmd(d->SR, d->C, &tmd,
	    callback_print, d->C, 0))
		goto err2;

	/* Free parsed metadata. */
	multitape_metadata_free(&tmd);

	/* Open CSV output file, if requested. */
	if (csv && (output = fopen(csv_filename, "a")) == NULL)
		goto err0;

	/* Print the statistics. */
	if (chunks_stats_printarchive(output, d->C, tapename, csv))
		goto err1;

	/* Close CSV output file. */
	if (csv && fclose(output))
		goto err0;

	/* Success! */
	return (0);

err2:
	multitape_metadata_free(&tmd);
err1:
	if (output != stdout)
		fclose(output);
err0:
	/* Failure! */
	return (rc);
}
Exemplo n.º 2
0
/**
 * statstape_print(d, tapename):
 * Print statistics relating to a specific archive in a set.
 */
int
statstape_print(TAPE_S * d, const char * tapename)
{
	struct tapemetadata tmd;

	/* Cache up to 100 bytes of blocks per chunk in the directory. */
	storage_read_cache_limit(d->SR, 100 * chunks_stats_getdirsz(d->C));

	/* Zero archive statistics. */
	chunks_stats_zeroarchive(d->C);

	/* Read the tape metadata. */
	if (multitape_metadata_get_byname(d->SR, d->C, &tmd, tapename, 0))
		goto err0;

	if (multitape_chunkiter_tmd(d->SR, d->C, &tmd,
	    callback_print, d->C, 0))
		goto err1;

	/* Free parsed metadata. */
	multitape_metadata_free(&tmd);

	/* Print the statistics. */
	if (chunks_stats_printarchive(stdout, d->C, tapename))
		goto err0;

	/* Success! */
	return (0);

err1:
	multitape_metadata_free(&tmd);
err0:
	/* Failure! */
	return (-1);
}