* University of Maryland at College Park
*/
/*
- * $Id: tapetype.c,v 1.3.2.3.4.3.2.9 2003/11/28 12:34:52 martinea Exp $
+ * $Id: tapetype.c,v 1.24 2006/03/10 11:56:06 martinea Exp $
*
* tests a tape in a given tape unit and prints a tapetype entry for
* it. */
static int blocksize;
static char *randombytes = (char *) NULL;
+static char *prandombytes = (char *) NULL;
#if USE_RAND
/* If the C library does not define random(), try to use rand() by
} else {
randombytes = p; /* alloc already on boundary */
}
+ prandombytes = p;
}
}
{
fputs("usage: ", stderr);
fputs(sProgName, stderr);
- fputs(" -h", stderr);
+ fputs(" [-h]", stderr);
fputs(" [-c]", stderr);
+ fputs(" [-o]", stderr);
fputs(" [-b blocksize]", stderr);
fputs(" [-e estsize]", stderr);
fputs(" [-f tapedev]", stderr);
fputs("\
-h display this message\n\
-c run hardware compression detection test only\n\
+ -o overwrite amanda tape\n\
-b blocksize record block size (default: 32k)\n\
-e estsize estimated tape size (default: 1g == 1024m)\n\
-f tapedev tape device name (default: $TAPE)\n\
time_t now;
int hwcompr = 0;
int comprtstonly = 0;
+ int overwrite_label = 0;
+ int is_labeled = 0;
+ char *result;
+ char *datestamp = NULL;
+ char *label = NULL;
+
if ((sProgName = strrchr(*argv, '/')) == NULL) {
sProgName = *argv;
sProgName++;
}
+ /* Don't die when child closes pipe */
+ signal(SIGPIPE, SIG_IGN);
+
estsize = 1024 * 1024; /* assume 1 GByte for now */
tapedev = getenv("TAPE");
typename = "unknown-tapetype";
- while ((ch = getopt(argc, argv, "b:e:f:t:hc")) != EOF) {
+ while ((ch = getopt(argc, argv, "b:e:f:t:hco")) != EOF) {
switch (ch) {
case 'b':
blockkb = strtol(optarg, &suffix, 0);
help();
return 1;
break;
+ case 'o':
+ overwrite_label=1;
+ break;
default:
fprintf(stderr, "%s: unknown option \'%c\'\n", sProgName, ch);
/* fall through to ... */
return 1;
}
+/* verifier tape */
+
+
+ fd = tape_open(tapedev, O_RDONLY);
+ if (fd == -1) {
+ fprintf(stderr, "%s: could not open %s: %s\n",
+ sProgName, tapedev, strerror(errno));
+ return 1;
+ }
+
+ if((result = tapefd_rdlabel(fd, &datestamp, &label)) == NULL) {
+ is_labeled = 1;
+ }
+ else if (strcmp(result,"not an amanda tape") == 0) {
+ is_labeled = 2;
+ }
+
+ if(tapefd_rewind(fd) == -1) {
+ fprintf(stderr, "%s: could not rewind %s: %s\n",
+ sProgName, tapedev, strerror(errno));
+ tapefd_close(fd);
+ return 1;
+ }
+
+ tapefd_close(fd);
+
+ if(is_labeled == 1 && overwrite_label == 0) {
+ fprintf(stderr, "%s: The tape is an amanda tape, use -o to overwrite the tape\n",
+ sProgName);
+ return 1;
+ }
+ else if(is_labeled == 2 && overwrite_label == 0) {
+ fprintf(stderr, "%s: The tape is already used, use -o to overwrite the tape\n",
+ sProgName);
+ return 1;
+ }
+
fd = tape_open(tapedev, O_RDWR);
if (fd == -1) {
fprintf(stderr, "%s: could not open %s: %s\n",
/*
* Inform about estimated time needed to run the remaining of this program
*/
- fprintf(stderr, "Estimated time to write 2 * %d Mbyte: ", estsize / 1024);
+ fprintf(stderr, "Estimated time to write 2 * %lu Mbyte: ", (unsigned long) (estsize / 1024));
pass1time = (time_t)(2.0 * pass2time * estsize / (1.0 * pass0size * blockkb));
/* avoid overflow and underflow by doing math in floating point */
fprintf(stderr, "%ld sec = ", pass1time);
if (tapefd_rewind(fd) == -1) {
fprintf(stderr, "%s: could not rewind %s: %s\n",
sProgName, tapedev, strerror(errno));
+ free(randombytes);
return 1;
}
if (tapefd_close(fd) == -1) {
fprintf(stderr, "%s: could not close %s: %s\n",
sProgName, tapedev, strerror(errno));
+ free(randombytes);
return 1;
}
+ free(randombytes);
return 0;
}