コード例 #1
0
/**
 * statstape_printall(d):
 * Print statistics relating to each of the archives in a set.
 */
int
statstape_printall(TAPE_S * d)
{
	struct tapemetadata tmd;
	uint8_t * flist;
	size_t nfiles;
	size_t file;

	/* Get a list of the metadata files. */
	if (storage_directory_read(d->machinenum, 'm', 0, &flist, &nfiles))
		goto err0;

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

	/* Iterate through the files. */
	for (file = 0; file < nfiles; file++) {
		/* Zero archive statistics. */
		chunks_stats_zeroarchive(d->C);

		/* Read the tape metadata. */
		if (multitape_metadata_get_byhash(d->SR, d->C, &tmd,
		    &flist[file * 32], 0))
			goto err1;

		/* Compute statistics. */
		if (multitape_chunkiter_tmd(d->SR, d->C, &tmd,
		    callback_print, d->C, 0))
			goto err2;

		/* Print the statistics. */
		if (chunks_stats_printarchive(stdout, d->C, tmd.name))
			goto err2;

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

	/* Free the list of files. */
	free(flist);

	/* Success! */
	return (0);

err2:
	multitape_metadata_free(&tmd);
err1:
	free(flist);
err0:
	/* Failure! */
	return (-1);
}
コード例 #2
0
/**
 * statstape_printlist(d, verbose):
 * Print the names of each of the archives in a set.  If verbose > 0, print
 * the creation times; if verbose > 1, print the argument vector of the
 * program invocation which created the archive.
 */
int
statstape_printlist(TAPE_S * d, int verbose)
{
	struct tapemetadata tmd;
	uint8_t * flist;
	size_t nfiles;
	size_t file;
	struct tm * ltime;
	char datebuf[DATEBUFLEN];
	int arg;

	/* Get a list of the metadata files. */
	if (storage_directory_read(d->machinenum, 'm', 0, &flist, &nfiles))
		goto err0;

	/* Iterate through the files. */
	for (file = 0; file < nfiles; file++) {
		/* Read the tape metadata. */
		if (multitape_metadata_get_byhash(d->SR, NULL, &tmd,
		    &flist[file * 32], 0))
			goto err1;

		/* Print name. */
		if (fprintf(stdout, "%s", tmd.name) < 0) {
			warnp("fprintf");
			goto err2;
		}

		/* Print creation time. */
		if (verbose > 0 && tmd.ctime != -1) {
			if ((ltime = localtime(&tmd.ctime)) == NULL) {
				warnp("localtime");
				goto err2;
			}
			if (strftime(datebuf, DATEBUFLEN, "%F %T",
			    ltime) == 0) {
				warnp("Cannot format date");
				goto err2;
			}
			if (fprintf(stdout, "\t%s", datebuf) < 0) {
				warnp("fprintf");
				goto err2;
			}
		}

		/* Print command line. */
		if (verbose > 1) {
			for (arg = 0; arg < tmd.argc; arg++) {
				if (fprintf(stdout, arg ? " %s" : "\t%s",
				    tmd.argv[arg]) < 0) {
					warnp("fprintf");
					goto err2;
				}
			}
		}

		/* End line. */
		if (fprintf(stdout, "\n") < 0) {
			warnp("fprintf");
			goto err2;
		}

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

	/* Free the list of files. */
	free(flist);

	/* Success! */
	return (0);

err2:
	multitape_metadata_free(&tmd);
err1:
	free(flist);
err0:
	/* Failure! */
	return (-1);
}
コード例 #3
0
/**
 * statstape_printall(d):
 * Print statistics relating to each of the archives in a set.  If
 * ${csv_filename} is not NULL, output will be written in CSV format to that
 * filename.
 */
int
statstape_printall(TAPE_S * d, const char * csv_filename)
{
	struct tapemetadata tmd;
	uint8_t * flist;
	size_t nfiles;
	size_t file;
	FILE * output = stdout;
	int csv = 0;

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

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

	/* Get a list of the metadata files. */
	if (storage_directory_read(d->machinenum, 'm', 0, &flist, &nfiles))
		goto err1;

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

	/* Iterate through the files. */
	for (file = 0; file < nfiles; file++) {
		/* Zero archive statistics. */
		chunks_stats_zeroarchive(d->C);

		/* Read the tape metadata. */
		if (multitape_metadata_get_byhash(d->SR, d->C, &tmd,
		    &flist[file * 32], 0))
			goto err2;

		/* Compute statistics. */
		if (multitape_chunkiter_tmd(d->SR, d->C, &tmd,
		    callback_print, d->C, 0))
			goto err3;

		/* Print the statistics. */
		if (chunks_stats_printarchive(output, d->C, tmd.name, csv))
			goto err3;

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

	/* Free the list of files. */
	free(flist);

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

	/* Success! */
	return (0);

err3:
	multitape_metadata_free(&tmd);
err2:
	free(flist);
err1:
	if (output != stdout)
		fclose(output);
err0:
	/* Failure! */
	return (-1);
}