/*********************************************************************
*
- * Main Bacula Pool Creation Program
+ * Bacula tape testing program
*
*/
int main(int margc, char *margv[])
jcr = NULL;
if (dev) {
- dev->term();
+ term_dev(dev);
}
if (debug_level > 10)
if (!dev->is_open()) {
if (!first_open_device(dcr)) {
- Pmsg1(0, _("Device open failed. ERR=%s\n"), dev->bstrerror());
+ Pmsg1(0, _("Device open failed. ERR=%s\n"), strerror_dev(dev));
}
}
dev->rewind(dcr);
Pmsg0(0, _("Volume label read correctly.\n"));
break;
case VOL_IO_ERROR:
- Pmsg1(0, _("I/O error on device: ERR=%s"), dev->bstrerror());
+ Pmsg1(0, _("I/O error on device: ERR=%s"), strerror_dev(dev));
break;
case VOL_NAME_ERROR:
Pmsg0(0, _("Volume name error\n"));
break;
case VOL_CREATE_ERROR:
- Pmsg1(0, _("Error creating label. ERR=%s"), dev->bstrerror());
+ Pmsg1(0, _("Error creating label. ERR=%s"), strerror_dev(dev));
break;
case VOL_VERSION_ERROR:
Pmsg0(0, _("Volume version error.\n"));
{
if (!load_dev(dev)) {
- Pmsg1(0, _("Bad status from load. ERR=%s\n"), dev->bstrerror());
+ Pmsg1(0, _("Bad status from load. ERR=%s\n"), strerror_dev(dev));
} else
Pmsg1(0, _("Loaded %s\n"), dev->print_name());
}
static void rewindcmd()
{
if (!dev->rewind(dcr)) {
- Pmsg1(0, _("Bad status from rewind. ERR=%s\n"), dev->bstrerror());
+ Pmsg1(0, _("Bad status from rewind. ERR=%s\n"), strerror_dev(dev));
clrerror_dev(dev, -1);
} else {
Pmsg1(0, _("Rewound %s\n"), dev->print_name());
}
if ((stat = weof_dev(dev, num)) < 0) {
- Pmsg2(0, _("Bad status from weof %d. ERR=%s\n"), stat, dev->bstrerror());
+ Pmsg2(0, _("Bad status from weof %d. ERR=%s\n"), stat, strerror_dev(dev));
return;
} else {
if (num==1) {
*/
static void eomcmd()
{
- if (!dev->eod()) {
- Pmsg1(0, "%s", dev->bstrerror());
+ if (!eod_dev(dev)) {
+ Pmsg1(0, "%s", strerror_dev(dev));
return;
} else {
Pmsg0(0, _("Moved to end of medium.\n"));
num = 1;
}
- if (!dev->bsf(num)) {
- Pmsg1(0, _("Bad status from bsf. ERR=%s\n"), dev->bstrerror());
+ if (!bsf_dev(dev, num)) {
+ Pmsg1(0, _("Bad status from bsf. ERR=%s\n"), strerror_dev(dev));
} else {
Pmsg2(0, _("Backspaced %d file%s.\n"), num, num==1?"":"s");
}
if (num <= 0) {
num = 1;
}
- if (!dev->bsr(num)) {
- Pmsg1(0, _("Bad status from bsr. ERR=%s\n"), dev->bstrerror());
+ if (!bsr_dev(dev, num)) {
+ Pmsg1(0, _("Bad status from bsr. ERR=%s\n"), strerror_dev(dev));
} else {
Pmsg2(0, _("Backspaced %d record%s.\n"), num, num==1?"":"s");
}
if (dev_cap(dev, CAP_TWOEOF)) {
weofcmd();
}
- if (!dev->bsf(1)) {
- Pmsg1(0, _("Backspace file failed! ERR=%s\n"), dev->bstrerror());
+ if (!bsf_dev(dev, 1)) {
+ Pmsg1(0, _("Backspace file failed! ERR=%s\n"), strerror_dev(dev));
goto bail_out;
}
if (dev_cap(dev, CAP_TWOEOF)) {
- if (!dev->bsf(1)) {
- Pmsg1(0, _("Backspace file failed! ERR=%s\n"), dev->bstrerror());
+ if (!bsf_dev(dev, 1)) {
+ Pmsg1(0, _("Backspace file failed! ERR=%s\n"), strerror_dev(dev));
goto bail_out;
}
}
Pmsg0(0, _("Backspaced over EOF OK.\n"));
- if (!dev->bsr(1)) {
- Pmsg1(0, _("Backspace record failed! ERR=%s\n"), dev->bstrerror());
+ if (!bsr_dev(dev, 1)) {
+ Pmsg1(0, _("Backspace record failed! ERR=%s\n"), strerror_dev(dev));
goto bail_out;
}
Pmsg0(0, _("Backspace record OK.\n"));
block = dcr->block;
rec = new_record();
if (!dev->rewind(dcr)) {
- Pmsg1(0, _("Bad status from rewind. ERR=%s\n"), dev->bstrerror());
+ Pmsg1(0, _("Bad status from rewind. ERR=%s\n"), strerror_dev(dev));
goto bail_out;
}
rec->data = check_pool_memory_size(rec->data, block->buf_len);
weofcmd();
}
if (!dev->rewind(dcr)) {
- Pmsg1(0, _("Bad status from rewind. ERR=%s\n"), dev->bstrerror());
+ Pmsg1(0, _("Bad status from rewind. ERR=%s\n"), strerror_dev(dev));
goto bail_out;
} else {
Pmsg0(0, _("Rewind OK.\n"));
empty_block(block);
rec = new_record();
if (!dev->rewind(dcr)) {
- Pmsg1(0, _("Bad status from rewind. ERR=%s\n"), dev->bstrerror());
+ Pmsg1(0, _("Bad status from rewind. ERR=%s\n"), strerror_dev(dev));
goto bail_out;
}
rec->data = check_pool_memory_size(rec->data, block->buf_len);
weofcmd();
}
if (!dev->rewind(dcr)) {
- Pmsg1(0, _("Bad status from rewind. ERR=%s\n"), dev->bstrerror());
+ Pmsg1(0, _("Bad status from rewind. ERR=%s\n"), strerror_dev(dev));
goto bail_out;
} else {
Pmsg0(0, _("Rewind OK.\n"));
continue;
}
Pmsg2(-1, _("Reposition to file:block %d:%d\n"), file, blk);
- if (!dev->reposition(file, blk)) {
+ if (!reposition_dev(dev, file, blk)) {
Pmsg0(0, _("Reposition error.\n"));
goto bail_out;
}
if (dev_cap(dev, CAP_TWOEOF)) {
weofcmd();
}
- dev->close(); /* release device */
+ force_close_device(dev); /* release device */
if (!open_the_device()) {
return -1;
}
Dmsg1(100, "Results from loaded query=%s\n", results);
if (loaded) {
dcr->VolCatInfo.Slot = loaded;
+ offline_or_rewind_dev(dev);
/* We are going to load a new tape, so close the device */
- dev->close();
+ force_close_device(dev);
Pmsg2(-1, _("3302 Issuing autochanger \"unload %d %d\" command.\n"),
loaded, dev->drive_index);
changer = edit_device_codes(dcr, changer,
changer = edit_device_codes(dcr, changer,
dcr->device->changer_command, "load");
Dmsg1(100, "Changer=%s\n", changer);
- dev->close();
+ force_close_device(dev);
status = run_program(changer, timeout, results);
if (status == 0) {
Pmsg2(-1, _("3303 Autochanger \"load %d %d\" status is OK.\n"),
*/
bmicrosleep(sleep_time, 0);
if (!dev->rewind(dcr) || weof_dev(dev,1) < 0) {
- Pmsg1(0, _("Bad status from rewind. ERR=%s\n"), dev->bstrerror());
+ Pmsg1(0, _("Bad status from rewind. ERR=%s\n"), strerror_dev(dev));
clrerror_dev(dev, -1);
Pmsg0(-1, _("\nThe test failed, probably because you need to put\n"
"a longer sleep time in the mtx-script in the load) case.\n"
}
if ((status = weof_dev(dev, 1)) < 0) {
- Pmsg2(0, _("Bad status from weof %d. ERR=%s\n"), status, dev->bstrerror());
+ Pmsg2(0, _("Bad status from weof %d. ERR=%s\n"), status, strerror_dev(dev));
goto bail_out;
} else {
Pmsg1(0, _("Wrote EOF to %s\n"), dev->print_name());
rewindcmd();
Pmsg0(0, _("Now forward spacing 1 file.\n"));
if (!dev->fsf(1)) {
- Pmsg1(0, _("Bad status from fsr. ERR=%s\n"), dev->bstrerror());
+ Pmsg1(0, _("Bad status from fsr. ERR=%s\n"), strerror_dev(dev));
goto bail_out;
}
Pmsg2(-1, _("We should be in file 1. I am at file %d. %s\n"),
Pmsg0(0, _("Now forward spacing 2 files.\n"));
if (!dev->fsf(2)) {
- Pmsg1(0, _("Bad status from fsr. ERR=%s\n"), dev->bstrerror());
+ Pmsg1(0, _("Bad status from fsr. ERR=%s\n"), strerror_dev(dev));
goto bail_out;
}
Pmsg2(-1, _("We should be in file 3. I am at file %d. %s\n"),
rewindcmd();
Pmsg0(0, _("Now forward spacing 4 files.\n"));
if (!dev->fsf(4)) {
- Pmsg1(0, _("Bad status from fsr. ERR=%s\n"), dev->bstrerror());
+ Pmsg1(0, _("Bad status from fsr. ERR=%s\n"), strerror_dev(dev));
goto bail_out;
}
Pmsg2(-1, _("We should be in file 4. I am at file %d. %s\n"),
Pmsg0(-1, "\n");
Pmsg0(0, _("Now forward spacing 1 more file.\n"));
if (!dev->fsf(1)) {
- Pmsg1(0, _("Bad status from fsr. ERR=%s\n"), dev->bstrerror());
+ Pmsg1(0, _("Bad status from fsr. ERR=%s\n"), strerror_dev(dev));
}
Pmsg2(-1, _("We should be in file 5. I am at file %d. %s\n"),
dev->file, dev->file == 5 ? _("This is correct!") : _("This is NOT correct!!!!"));
num = 1;
}
if (!dev->fsf(num)) {
- Pmsg1(0, _("Bad status from fsf. ERR=%s\n"), dev->bstrerror());
+ Pmsg1(0, _("Bad status from fsf. ERR=%s\n"), strerror_dev(dev));
return;
}
if (num == 1) {
num = 1;
}
if (!dev->fsr(num)) {
- Pmsg1(0, _("Bad status from fsr. ERR=%s\n"), dev->bstrerror());
+ Pmsg1(0, _("Bad status from fsr. ERR=%s\n"), strerror_dev(dev));
return;
}
if (num == 1) {
clrerror_dev(dev, -1);
Mmsg2(dev->errmsg, _("read error on %s. ERR=%s.\n"),
dev->dev_name, be.strerror());
- Pmsg2(0, _("Bad status from read %d. ERR=%s\n"), stat, dev->bstrerror());
+ Pmsg2(0, _("Bad status from read %d. ERR=%s\n"), stat, strerror_dev(dev));
if (blocks > 0) {
if (blocks==1) {
printf(_("1 block of %d bytes in file %d\n"), block_size, dev->file);
tot_files = dev->file;
for (;;) {
if (!read_block_from_device(dcr, NO_BLOCK_NUMBER_CHECK)) {
- Dmsg1(100, "!read_block(): ERR=%s\n", dev->bstrerror());
+ Dmsg1(100, "!read_block(): ERR=%s\n", strerror_dev(dev));
if (dev->state & ST_EOT) {
if (blocks > 0) {
if (blocks==1) {
printf(_("Short block read.\n"));
continue;
}
- printf(_("Error reading block. ERR=%s\n"), dev->bstrerror());
+ printf(_("Error reading block. ERR=%s\n"), strerror_dev(dev));
goto bail_out;
}
if (block->block_len != block_size) {
{
int debug = debug_level;
debug_level = 30;
- Pmsg2(0, _("Device status: %u. ERR=%s\n"), status_dev(dev), dev->bstrerror());
+ Pmsg2(0, _("Device status: %u. ERR=%s\n"), status_dev(dev), strerror_dev(dev));
#ifdef xxxx
dump_volume_label(dev);
#endif
if (!write_session_label(dcr, SOS_LABEL)) {
set_jcr_job_status(jcr, JS_ErrorTerminated);
Jmsg1(jcr, M_FATAL, 0, _("Write session label failed. ERR=%s\n"),
- dev->bstrerror());
+ strerror_dev(dev));
ok = false;
}
Pmsg0(-1, _("Wrote Start of Session label.\n"));
set_jcr_job_status(jcr, JS_ErrorTerminated);
}
if (!write_session_label(dcr, EOS_LABEL)) {
- Pmsg1(000, _("Error writting end session label. ERR=%s\n"), dev->bstrerror());
+ Pmsg1(000, _("Error writting end session label. ERR=%s\n"), strerror_dev(dev));
ok = false;
}
/* Write out final block of this session */
/* Multiple Volume tape */
/* Close device so user can use autochanger if desired */
if (dev_cap(dev, CAP_OFFLINEUNMOUNT)) {
- dev->offline();
+ offline_dev(dev);
}
autochanger = autoload_device(dcr, 1, NULL);
if (!autochanger) {
- dev->close();
+ force_close_device(dev);
get_cmd(_("Mount first tape. Press enter when ready: "));
}
free_restore_volume_list(jcr);
set_volume_name("TestVolume1", 1);
jcr->bsr = NULL;
create_restore_volume_list(jcr);
- dev->close();
+ close_device(dev);
+ dev->state &= ~(ST_READ|ST_APPEND);
dev->num_writers = 0;
if (!acquire_device_for_read(dcr)) {
Pmsg1(-1, "%s", dev->errmsg);
read_records(dcr, quickie_cb, my_mount_next_read_volume);
Pmsg4(-1, _("Reposition from %u:%u to %u:%u\n"), dev->file, dev->block_num,
last_file, last_block_num);
- if (!dev->reposition(last_file, last_block_num)) {
- Pmsg1(-1, _("Reposition error. ERR=%s\n"), dev->bstrerror());
+ if (!reposition_dev(dev, last_file, last_block_num)) {
+ Pmsg1(-1, _("Reposition error. ERR=%s\n"), strerror_dev(dev));
goto bail_out;
}
Pmsg1(-1, _("Reading block %u.\n"), last_block_num);
if (!read_block_from_device(dcr, NO_BLOCK_NUMBER_CHECK)) {
- Pmsg1(-1, _("Error reading block: ERR=%s\n"), dev->bstrerror());
+ Pmsg1(-1, _("Error reading block: ERR=%s\n"), strerror_dev(dev));
goto bail_out;
}
if (compare_blocks(last_block, block)) {
/* Multiple Volume tape */
/* Close device so user can use autochanger if desired */
if (dev_cap(dev, CAP_OFFLINEUNMOUNT)) {
- dev->offline();
+ offline_dev(dev);
}
free_restore_volume_list(jcr);
create_restore_volume_list(jcr);
autochanger = autoload_device(dcr, 1, NULL);
if (!autochanger) {
- dev->close();
+ force_close_device(dev);
get_cmd(_("Mount second tape. Press enter when ready: "));
}
* on the previous tape.
*/
Pmsg2(-1, _("Reposition from %u:%u to 0:1\n"), dev->file, dev->block_num);
- if (!dev->reposition(0, 1)) {
- Pmsg1(-1, _("Reposition error. ERR=%s\n"), dev->bstrerror());
+ if (!reposition_dev(dev, 0, 1)) {
+ Pmsg1(-1, _("Reposition error. ERR=%s\n"), strerror_dev(dev));
goto bail_out;
}
Pmsg1(-1, _("Reading block %d.\n"), dev->block_num);
if (!read_block_from_device(dcr, NO_BLOCK_NUMBER_CHECK)) {
- Pmsg1(-1, _("Error reading block: ERR=%s\n"), dev->bstrerror());
+ Pmsg1(-1, _("Error reading block: ERR=%s\n"), strerror_dev(dev));
goto bail_out;
}
if (compare_blocks(first_block, block)) {
/* Now find and compare the last block */
Pmsg4(-1, _("Reposition from %u:%u to %u:%u\n"), dev->file, dev->block_num,
last_file, last_block_num);
- if (!dev->reposition(last_file, last_block_num)) {
- Pmsg1(-1, _("Reposition error. ERR=%s\n"), dev->bstrerror());
+ if (!reposition_dev(dev, last_file, last_block_num)) {
+ Pmsg1(-1, _("Reposition error. ERR=%s\n"), strerror_dev(dev));
goto bail_out;
}
Pmsg1(-1, _("Reading block %d.\n"), dev->block_num);
if (!read_block_from_device(dcr, NO_BLOCK_NUMBER_CHECK)) {
- Pmsg1(-1, _("Error reading block: ERR=%s\n"), dev->bstrerror());
+ Pmsg1(-1, _("Error reading block: ERR=%s\n"), strerror_dev(dev));
goto bail_out;
}
if (compare_blocks(last_block, block)) {
} else {
/* Full test in progress */
if (!fixup_device_block_write_error(jcr->dcr)) {
- Pmsg1(000, _("Cannot fixup device error. %s\n"), dev->bstrerror());
+ Pmsg1(000, _("Cannot fixup device error. %s\n"), strerror_dev(dev));
ok = false;
unlock_device(dev);
return 0;
if (dcr->VolumeName[0] == 0) {
return dir_ask_sysop_to_create_appendable_volume(dcr);
}
- dev->close();
+ /* Close device so user can use autochanger if desired */
+ if (dev_cap(dev, CAP_OFFLINEUNMOUNT)) {
+ offline_dev(dev);
+ }
+ force_close_device(dev);
Pmsg1(-1, "%s", dev->errmsg); /* print reason */
if (dcr->VolumeName[0] == 0 || strcmp(dcr->VolumeName, "TestVolume2") == 0) {
fprintf(stderr, _("Mount second Volume on device %s and press return when ready: "),
}
/* Close device so user can use autochanger if desired */
if (dev_cap(dev, CAP_OFFLINEUNMOUNT)) {
- dev->offline();
+ offline_dev(dev);
}
autochanger = autoload_device(dcr, 1, NULL);
if (!autochanger) {
- dev->close();
+ force_close_device(dev);
fprintf(stderr, _("Mount blank Volume on device %s and press return when ready: "),
dev->print_name());
getchar();
set_volume_name("TestVolume2", 2);
jcr->bsr = NULL;
create_restore_volume_list(jcr);
- dev->close();
+ close_device(dev);
+ dev->clear_read();
if (!acquire_device_for_read(dcr)) {
Pmsg2(0, _("Cannot open Dev=%s, Vol=%s\n"), dev->print_name(), dcr->VolumeName);
return false;