* VOL_CREATE_ERROR
* VOL_VERSION_ERROR
* VOL_LABEL_ERROR
+ * VOL_NO_MEDIA
*/
int read_dev_volume_label(JCR *jcr, DEVICE *dev, DEV_BLOCK *block)
{
DEV_RECORD *record;
int ok = 0;
- Dmsg2(30, "Enter read_volume_label device=%s vol=%s\n",
- dev_name(dev), VolName);
+ Dmsg3(100, "Enter read_volume_label device=%s vol=%s dev_Vol=%s\n",
+ dev_name(dev), VolName, dev->VolHdr.VolName);
if (dev->state & ST_LABEL) { /* did we already read label? */
- /* Compare Volume Names */
- if (VolName && *VolName && strcmp(dev->VolHdr.VolName, VolName) != 0) {
- Mmsg(&jcr->errmsg, _("Volume name mismatch on device %s: Wanted %s got %s\n"),
+ /* Compare Volume Names allow special wild card */
+ if (VolName && *VolName && *VolName != '*' && strcmp(dev->VolHdr.VolName, VolName) != 0) {
+ Mmsg(&jcr->errmsg, _("Wrong Volume mounted on device %s: Wanted %s have %s\n"),
dev_name(dev), VolName, dev->VolHdr.VolName);
/*
* Cancel Job if too many label errors
* => we are in a loop
*/
- if (jcr->label_errors > 100) {
- set_jcr_job_status(jcr, JS_ErrorTerminated);
+ if (jcr->label_errors++ > 100) {
Jmsg(jcr, M_FATAL, 0, "%s", jcr->errmsg);
}
return jcr->label_status = VOL_NAME_ERROR;
if (!rewind_dev(dev)) {
Mmsg(&jcr->errmsg, _("Couldn't rewind device %s ERR=%s\n"), dev_name(dev),
strerror_dev(dev));
- return jcr->label_status = VOL_IO_ERROR;
+ return jcr->label_status = VOL_NO_MEDIA;
}
strcpy(dev->VolHdr.Id, "**error**");
- /* Read the device label block */
+ /* Read the Volume label block */
record = new_record();
Dmsg0(90, "Big if statement in read_volume_label\n");
- if (!read_block_from_dev(dev, block)) {
+ if (!read_block_from_dev(jcr, dev, block, NO_BLOCK_NUMBER_CHECK)) {
Mmsg(&jcr->errmsg, _("Volume on %s is not a Bacula labeled Volume, \
because:\n %s"), dev_name(dev), strerror_dev(dev));
} else if (!read_record_from_block(block, record)) {
/* Compare Volume Names */
Dmsg2(30, "Compare Vol names: VolName=%s hdr=%s\n", VolName?VolName:"*", dev->VolHdr.VolName);
- if (VolName && *VolName && strcmp(dev->VolHdr.VolName, VolName) != 0) {
- Mmsg(&jcr->errmsg, _("Volume name mismatch. Wanted %s got %s\n"),
- VolName, dev->VolHdr.VolName);
+ if (VolName && *VolName && *VolName != '*' && strcmp(dev->VolHdr.VolName, VolName) != 0) {
+ Mmsg(&jcr->errmsg, _("Wrong Volume mounted on device %s: Wanted %s have %s\n"),
+ dev_name(dev), VolName, dev->VolHdr.VolName);
/*
* Cancel Job if too many label errors
* => we are in a loop
*/
- if (jcr->label_errors > 100) {
- set_jcr_job_status(jcr, JS_ErrorTerminated);
+ if (jcr->label_errors++ > 100) {
Jmsg(jcr, M_FATAL, 0, "%s", jcr->errmsg);
}
return jcr->label_status = VOL_NAME_ERROR;
create_volume_label_record(jcr, dev, &rec);
empty_block(block); /* Volume label always at beginning */
+ block->BlockNumber = 0;
if (!write_record_to_block(block, &rec)) {
free_pool_memory(rec.data);
Jmsg1(jcr, M_FATAL, 0, _("Cannot write Volume label to block for device %s\n"),
strcpy(dev->VolHdr.Id, BaculaId);
dev->VolHdr.VerNum = BaculaTapeVersion;
dev->VolHdr.LabelType = PRE_LABEL; /* Mark tape as unused */
- strcpy(dev->VolHdr.VolName, VolName);
+ bstrncpy(dev->VolHdr.VolName, VolName, sizeof(dev->VolHdr.VolName));
strcpy(dev->VolHdr.PoolName, "Default");
- strcpy(dev->VolHdr.MediaType, device->media_type);
+ bstrncpy(dev->VolHdr.MediaType, device->media_type, sizeof(dev->VolHdr.MediaType));
strcpy(dev->VolHdr.PoolType, "Backup");
/* Put label time/date in header */
Dmsg0(99, "write_volume_label()\n");
create_volume_label(dev, VolName);
- strcpy(dev->VolHdr.MediaType, device->media_type);
+ bstrncpy(dev->VolHdr.MediaType, device->media_type, sizeof(dev->VolHdr.MediaType));
bstrncpy(dev->VolHdr.VolName, VolName, sizeof(dev->VolHdr.VolName));
bstrncpy(dev->VolHdr.PoolName, PoolName, sizeof(dev->VolHdr.PoolName));
if (!rewind_dev(dev)) {
+ memset(&dev->VolHdr, 0, sizeof(dev->VolHdr));
Dmsg2(30, "Bad status on %s from rewind. ERR=%s\n", dev_name(dev), strerror_dev(dev));
return 0;
}
if (!write_record_to_block(block, &rec)) {
Dmsg2(30, "Bad Label write on %s. ERR=%s\n", dev_name(dev), strerror_dev(dev));
+ memset(&dev->VolHdr, 0, sizeof(dev->VolHdr));
free_block(block);
free_pool_memory(rec.data);
return 0;
Dmsg0(99, "Call write_block_to_device()\n");
if (!write_block_to_dev(jcr, dev, block)) {
+ memset(&dev->VolHdr, 0, sizeof(dev->VolHdr));
Dmsg2(30, "Bad Label write on %s. ERR=%s\n", dev_name(dev), strerror_dev(dev));
stat = 9;
}
void create_session_label(JCR *jcr, DEV_RECORD *rec, int label)
{
ser_declare;
- struct date_time dt;
rec->sync = 1; /* wait for completion */
rec->VolSessionId = jcr->VolSessionId;
ser_uint32(jcr->JobId);
- if (BaculaTapeVersion >= 11) {
- ser_btime(get_current_btime());
- ser_float64(0);
- } else {
- /* OLD WAY DEPRECATED */
- get_current_time(&dt);
- ser_float64(dt.julian_day_number);
- ser_float64(dt.julian_day_fraction);
- }
+ /* Changed in VerNum 11 */
+ ser_btime(get_current_btime());
+ ser_float64(0);
ser_string(jcr->pool_name);
ser_string(jcr->pool_type);
ser_string(jcr->fileset_name);
ser_uint32(jcr->JobType);
ser_uint32(jcr->JobLevel);
- if (BaculaTapeVersion >= 11) {
- ser_string(jcr->fileset_md5);
- }
+ /* Added in VerNum 11 */
+ ser_string(jcr->fileset_md5);
if (label == EOS_LABEL) {
ser_uint32(jcr->JobFiles);
rec = new_record();
Dmsg1(90, "session_label record=%x\n", rec);
switch (label) {
- case SOS_LABEL:
- if (dev->state & ST_TAPE) {
- jcr->StartBlock = dev->block_num;
- jcr->StartFile = dev->file;
- } else {
- jcr->StartBlock = (uint32_t)dev->file_addr;
- jcr->StartFile = (uint32_t)(dev->file_addr >> 32);
- }
- break;
- case EOS_LABEL:
- if (dev->state & ST_TAPE) {
- jcr->EndBlock = dev->EndBlock;
- jcr->EndFile = dev->EndFile;
- } else {
- jcr->EndBlock = (uint32_t)dev->file_addr;
- jcr->EndFile = (uint32_t)(dev->file_addr >> 32);
- }
- break;
- default:
- Jmsg1(jcr, M_ABORT, 0, _("Bad session label = %d\n"), label);
- break;
+ case SOS_LABEL:
+ if (dev->state & ST_TAPE) {
+ jcr->StartBlock = dev->block_num;
+ jcr->StartFile = dev->file;
+ } else {
+ jcr->StartBlock = (uint32_t)dev->file_addr;
+ jcr->StartFile = (uint32_t)(dev->file_addr >> 32);
+ }
+ break;
+ case EOS_LABEL:
+ if (dev->state & ST_TAPE) {
+ jcr->EndBlock = dev->EndBlock;
+ jcr->EndFile = dev->EndFile;
+ } else {
+ jcr->EndBlock = (uint32_t)dev->file_addr;
+ jcr->EndFile = (uint32_t)(dev->file_addr >> 32);
+ }
+ break;
+ default:
+ Jmsg1(jcr, M_ABORT, 0, _("Bad session label = %d\n"), label);
+ break;
}
create_session_label(jcr, rec, label);
rec->FileIndex = label;