This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
/* Forward referenced functions */
static void create_volume_label_record(DCR *dcr, DEV_RECORD *rec);
/* Forward referenced functions */
static void create_volume_label_record(DCR *dcr, DEV_RECORD *rec);
- Dmsg3(100, "Enter read_volume_label device=%s vol=%s dev_Vol=%s\n",
- dev->print_name(), VolName, dev->VolHdr.VolumeName[0]?dev->VolHdr.VolumeName:
- "*NULL*");
+ Dmsg4(100, "Enter read_volume_label res=%d device=%s vol=%s dev_Vol=%s\n",
+ dev->reserved_device, dev->print_name(), VolName,
+ dev->VolHdr.VolumeName[0]?dev->VolHdr.VolumeName:"*NULL*");
}
if (dev->is_labeled()) { /* did we already read label? */
/* Compare Volume Names allow special wild card */
}
if (dev->is_labeled()) { /* did we already read label? */
/* Compare Volume Names allow special wild card */
- Jmsg(jcr, M_FATAL, 0, "Too many tries: %s", jcr->errmsg);
+ Jmsg(jcr, M_FATAL, 0, _("Too many tries: %s"), jcr->errmsg);
Mmsg(jcr->errmsg, _("Wrong Volume mounted on device %s: Wanted %s have %s\n"),
dev->print_name(), VolName, dev->VolHdr.VolumeName);
if (!dev->poll && jcr->label_errors++ > 100) {
Mmsg(jcr->errmsg, _("Wrong Volume mounted on device %s: Wanted %s have %s\n"),
dev->print_name(), VolName, dev->VolHdr.VolumeName);
if (!dev->poll && jcr->label_errors++ > 100) {
- Jmsg(jcr, M_FATAL, 0, "Too many tries: %s", jcr->errmsg);
+ Jmsg(jcr, M_FATAL, 0, _("Too many tries: %s"), jcr->errmsg);
if (!read_block_from_dev(dcr, NO_BLOCK_NUMBER_CHECK)) {
Mmsg(jcr->errmsg, _("Requested Volume \"%s\" on %s is not a Bacula "
"labeled Volume, because: ERR=%s"), NPRT(VolName),
if (!read_block_from_dev(dcr, NO_BLOCK_NUMBER_CHECK)) {
Mmsg(jcr->errmsg, _("Requested Volume \"%s\" on %s is not a Bacula "
"labeled Volume, because: ERR=%s"), NPRT(VolName),
Dmsg1(30, "%s", jcr->errmsg);
} else if (!read_record_from_block(block, record)) {
Mmsg(jcr->errmsg, _("Could not read Volume label from block.\n"));
Dmsg1(30, "%s", jcr->errmsg);
} else if (!unser_volume_label(dev, record)) {
Mmsg(jcr->errmsg, _("Could not unserialize Volume label: ERR=%s\n"),
Dmsg1(30, "%s", jcr->errmsg);
} else if (!read_record_from_block(block, record)) {
Mmsg(jcr->errmsg, _("Could not read Volume label from block.\n"));
Dmsg1(30, "%s", jcr->errmsg);
} else if (!unser_volume_label(dev, record)) {
Mmsg(jcr->errmsg, _("Could not unserialize Volume label: ERR=%s\n"),
Dmsg1(30, "%s", jcr->errmsg);
} else if (strcmp(dev->VolHdr.Id, BaculaId) != 0 &&
strcmp(dev->VolHdr.Id, OldBaculaId) != 0) {
Dmsg1(30, "%s", jcr->errmsg);
} else if (strcmp(dev->VolHdr.Id, BaculaId) != 0 &&
strcmp(dev->VolHdr.Id, OldBaculaId) != 0) {
dev->print_name(), dev->VolHdr.LabelType);
Dmsg1(30, "%s", jcr->errmsg);
if (!dev->poll && jcr->label_errors++ > 100) {
dev->print_name(), dev->VolHdr.LabelType);
Dmsg1(30, "%s", jcr->errmsg);
if (!dev->poll && jcr->label_errors++ > 100) {
- Jmsg(jcr, M_FATAL, 0, "Too many tries: %s", jcr->errmsg);
+ Jmsg(jcr, M_FATAL, 0, _("Too many tries: %s"), jcr->errmsg);
if (!dev->poll && jcr->label_errors++ > 100) {
Jmsg(jcr, M_FATAL, 0, "Too many tries: %s", jcr->errmsg);
}
if (!dev->poll && jcr->label_errors++ > 100) {
Jmsg(jcr, M_FATAL, 0, "Too many tries: %s", jcr->errmsg);
}
Dmsg0(30, "Leave read_volume_label() VOL_OK\n");
/* If we are a streaming device, we only get one chance to read */
if (!dev_cap(dev, CAP_STREAM)) {
Dmsg0(30, "Leave read_volume_label() VOL_OK\n");
/* If we are a streaming device, we only get one chance to read */
if (!dev_cap(dev, CAP_STREAM)) {
if (have_ansi_label) {
stat = read_ansi_ibm_label(dcr);
/* If we want a label and didn't find it, return error */
if (have_ansi_label) {
stat = read_ansi_ibm_label(dcr);
/* If we want a label and didn't find it, return error */
* after the label will be destroyed,
* in fact, we write the label 5 times !!!!
*
* after the label will be destroyed,
* in fact, we write the label 5 times !!!!
*
-bool write_new_volume_label_to_dev(DCR *dcr, const char *VolName, const char *PoolName)
+bool write_new_volume_label_to_dev(DCR *dcr, const char *VolName,
+ const char *PoolName, bool dvdnow)
- Dmsg1(100, "Label type=%d\n", dev->label_type);
- if (!rewind_dev(dev)) {
+ if (dev->open(dcr, OPEN_READ_WRITE) < 0) {
+ /* If device is not tape, attempt to create it */
+ if (dev->is_tape() || dev->open(dcr, CREATE_READ_WRITE) < 0) {
+ goto bail_out;
+ }
+ }
+ Dmsg1(150, "Label type=%d\n", dev->label_type);
+ if (!dev->rewind(dcr)) {
+ free_volume(dev);
- Dmsg2(30, "Bad status on %s from rewind: ERR=%s\n", dev->print_name(), strerror_dev(dev));
+ Dmsg2(30, "Bad status on %s from rewind: ERR=%s\n", dev->print_name(), dev->bstrerror());
- /* Create PRE_LABEL */
- create_volume_label(dev, VolName, PoolName);
+ /* Create PRE_LABEL or VOL_LABEL if DVD */
+ create_volume_label(dev, VolName, PoolName, dvdnow);
/* Temporarily mark in append state to enable writing */
dev->set_append();
if (!write_record_to_block(dcr->block, dcr->rec)) {
/* Temporarily mark in append state to enable writing */
dev->set_append();
if (!write_record_to_block(dcr->block, dcr->rec)) {
- Dmsg2(30, "Bad Label write on %s: ERR=%s\n", dev->print_name(), strerror_dev(dev));
+ Dmsg2(30, "Bad Label write on %s: ERR=%s\n", dev->print_name(), dev->bstrerror());
goto bail_out;
} else {
Dmsg2(30, "Wrote label of %d bytes to %s\n", dcr->rec->data_len, dev->print_name());
goto bail_out;
} else {
Dmsg2(30, "Wrote label of %d bytes to %s\n", dcr->rec->data_len, dev->print_name());
Dmsg0(99, "Call write_block_to_dev()\n");
if (!write_block_to_dev(dcr)) {
Dmsg0(99, "Call write_block_to_dev()\n");
if (!write_block_to_dev(dcr)) {
- Dmsg2(30, "Bad Label write on %s: ERR=%s\n", dev->print_name(), strerror_dev(dev));
+ Dmsg2(30, "Bad Label write on %s: ERR=%s\n", dev->print_name(), dev->bstrerror());
+
+ /* Now commit block to DVD if we should write now */
+ if (dev->is_dvd() && dvdnow) {
+ if (!dvd_write_part(dcr)) {
+ Dmsg2(30, "Bad DVD write on %s: ERR=%s\n", dev->print_name(), dev->bstrerror());
+ goto bail_out;
+ }
+ }
+
memset(&dev->VolHdr, 0, sizeof(dev->VolHdr));
dev->clear_append(); /* remove append since this is PRE_LABEL */
return false;
memset(&dev->VolHdr, 0, sizeof(dev->VolHdr));
dev->clear_append(); /* remove append since this is PRE_LABEL */
return false;
Dmsg2(190, "set append found freshly labeled volume. fd=%d dev=%x\n", dev->fd, dev);
dev->VolHdr.LabelType = VOL_LABEL; /* set Volume label */
dev->set_append();
Dmsg2(190, "set append found freshly labeled volume. fd=%d dev=%x\n", dev->fd, dev);
dev->VolHdr.LabelType = VOL_LABEL; /* set Volume label */
dev->set_append();
/*
* If we are not dealing with a streaming device,
* write the block now to ensure we have write permission.
/*
* If we are not dealing with a streaming device,
* write the block now to ensure we have write permission.
* avoids re-writing the ANSI label, which we do not want to do.
*/
if (!dev_cap(dev, CAP_STREAM)) {
* avoids re-writing the ANSI label, which we do not want to do.
*/
if (!dev_cap(dev, CAP_STREAM)) {
- if (!rewind_dev(dev)) {
- Jmsg2(jcr, M_WARNING, 0, _("Rewind error on device %s: ERR=%s\n"),
- dev->print_name(), strerror_dev(dev));
+ if (!dev->rewind(dcr)) {
+ Jmsg2(jcr, M_FATAL, 0, _("Rewind error on device %s: ERR=%s\n"),
+ dev->print_name(), dev->bstrerror());
+ return false;
- if (!truncate_dev(dcr)) {
- Jmsg2(jcr, M_WARNING, 0, _("Truncate error on device %s: ERR=%s\n"),
- dev->print_name(), strerror_dev(dev));
+ if (!dev->truncate(dcr)) {
+ Jmsg2(jcr, M_FATAL, 0, _("Truncate error on device %s: ERR=%s\n"),
+ dev->print_name(), dev->bstrerror());
+ return false;
Dmsg1(200, "Attempt to write to device fd=%d.\n", dev->fd);
if (!write_block_to_dev(dcr)) {
Jmsg2(jcr, M_ERROR, 0, _("Unable to write device %s: ERR=%s\n"),
Dmsg1(200, "Attempt to write to device fd=%d.\n", dev->fd);
if (!write_block_to_dev(dcr)) {
Jmsg2(jcr, M_ERROR, 0, _("Unable to write device %s: ERR=%s\n"),
/* Set or reset Volume statistics */
dev->VolCatInfo.VolCatJobs = 0;
dev->VolCatInfo.VolCatFiles = 0;
/* Set or reset Volume statistics */
dev->VolCatInfo.VolCatJobs = 0;
dev->VolCatInfo.VolCatFiles = 0;
dev->VolCatInfo.VolCatErrors = 0;
dev->VolCatInfo.VolCatBlocks = 0;
dev->VolCatInfo.VolCatRBytes = 0;
dev->VolCatInfo.VolCatErrors = 0;
dev->VolCatInfo.VolCatBlocks = 0;
dev->VolCatInfo.VolCatRBytes = 0;
bstrncpy(dev->VolCatInfo.VolCatStatus, "Append", sizeof(dev->VolCatInfo.VolCatStatus));
if (!dir_update_volume_info(dcr, true)) { /* indicate doing relabel */
return false;
bstrncpy(dev->VolCatInfo.VolCatStatus, "Append", sizeof(dev->VolCatInfo.VolCatStatus));
if (!dir_update_volume_info(dcr, true)) { /* indicate doing relabel */
return false;
rec->VolSessionId = jcr->VolSessionId;
rec->VolSessionTime = jcr->VolSessionTime;
rec->Stream = jcr->NumVolumes;
rec->VolSessionId = jcr->VolSessionId;
rec->VolSessionTime = jcr->VolSessionTime;
rec->Stream = jcr->NumVolumes;
- Dmsg2(100, "Created Vol label rec: FI=%s len=%d\n", FI_to_ascii(rec->FileIndex),
+ Dmsg2(150, "Created Vol label rec: FI=%s len=%d\n", FI_to_ascii(buf, rec->FileIndex),
-void create_volume_label(DEVICE *dev, const char *VolName, const char *PoolName)
+void create_volume_label(DEVICE *dev, const char *VolName,
+ const char *PoolName, bool dvdnow)
memset(&dev->VolHdr, 0, sizeof(dev->VolHdr));
bstrncpy(dev->VolHdr.Id, BaculaId, sizeof(dev->VolHdr.Id));
dev->VolHdr.VerNum = BaculaTapeVersion;
memset(&dev->VolHdr, 0, sizeof(dev->VolHdr));
bstrncpy(dev->VolHdr.Id, BaculaId, sizeof(dev->VolHdr.Id));
dev->VolHdr.VerNum = BaculaTapeVersion;
- dev->VolHdr.LabelType = PRE_LABEL; /* Mark tape as unused */
+ if (dev->is_dvd() && dvdnow) {
+ /* We do not want to re-label a DVD so write VOL_LABEL now */
+ dev->VolHdr.LabelType = VOL_LABEL;
+ } else {
+ dev->VolHdr.LabelType = PRE_LABEL; /* Mark tape as unused */
+ }
bstrncpy(dev->VolHdr.VolumeName, VolName, sizeof(dev->VolHdr.VolumeName));
bstrncpy(dev->VolHdr.PoolName, PoolName, sizeof(dev->VolHdr.PoolName));
bstrncpy(dev->VolHdr.MediaType, device->media_type, sizeof(dev->VolHdr.MediaType));
bstrncpy(dev->VolHdr.VolumeName, VolName, sizeof(dev->VolHdr.VolumeName));
bstrncpy(dev->VolHdr.PoolName, PoolName, sizeof(dev->VolHdr.PoolName));
bstrncpy(dev->VolHdr.MediaType, device->media_type, sizeof(dev->VolHdr.MediaType));
if (!write_block_to_device(dcr)) {
Dmsg0(90, "Got session label write_block_to_dev error.\n");
/* ****FIXME***** errno is not set here */
if (!write_block_to_device(dcr)) {
Dmsg0(90, "Got session label write_block_to_dev error.\n");
/* ****FIXME***** errno is not set here */
- FI_to_ascii(rec->FileIndex), rec->VolSessionId,
- stream_to_ascii(rec->Stream, rec->FileIndex), rec->data_len,
+ FI_to_ascii(buf1, rec->FileIndex), rec->VolSessionId,
+ stream_to_ascii(buf2, rec->Stream, rec->FileIndex), rec->data_len,
- Dmsg2(20, "Leave write_session_label Block=%d File=%d\n",
- dev->block_num, dev->file);
+ Dmsg2(50, "Leave write_session_label Block=%ud File=%ud\n",
+ dev->get_block(), dev->get_file());
if (rec->FileIndex != VOL_LABEL && rec->FileIndex != PRE_LABEL) {
Mmsg3(dev->errmsg, _("Expecting Volume Label, got FI=%s Stream=%s len=%d\n"),
if (rec->FileIndex != VOL_LABEL && rec->FileIndex != PRE_LABEL) {
Mmsg3(dev->errmsg, _("Expecting Volume Label, got FI=%s Stream=%s len=%d\n"),
- FI_to_ascii(rec->FileIndex),
- stream_to_ascii(rec->Stream, rec->FileIndex),
+ FI_to_ascii(buf1, rec->FileIndex),
+ stream_to_ascii(buf2, rec->Stream, rec->FileIndex),
unser_string(dev->VolHdr.ProgDate);
ser_end(rec->data, SER_LENGTH_Volume_Label);
unser_string(dev->VolHdr.ProgDate);
ser_end(rec->data, SER_LENGTH_Volume_Label);
- Dmsg0(90, "unser_vol_label\n");
- if (debug_level >= 90) {
+ Dmsg0(190, "unser_vol_label\n");
+ if (debug_level >= 190) {
dev->VolHdr.Id, dev->VolHdr.VerNum,
dev->VolHdr.VolumeName, dev->VolHdr.PrevVolumeName,
File, LabelType, dev->VolHdr.LabelSize,
dev->VolHdr.Id, dev->VolHdr.VerNum,
dev->VolHdr.VolumeName, dev->VolHdr.PrevVolumeName,
File, LabelType, dev->VolHdr.LabelSize,
if (dev->VolHdr.VerNum >= 11) {
char dt[50];
bstrftime(dt, sizeof(dt), btime_to_unix(dev->VolHdr.label_btime));
if (dev->VolHdr.VerNum >= 11) {
char dt[50];
bstrftime(dt, sizeof(dt), btime_to_unix(dev->VolHdr.label_btime));
tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday, tm.tm_hour, tm.tm_min);
}
tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday, tm.tm_hour, tm.tm_min);
}
-"", type, label.JobId, label.VerNum,
+""), type, label.JobId, label.VerNum,
label.PoolName, label.PoolType,
label.JobName, label.ClientName);
if (label.VerNum >= 10) {
label.PoolName, label.PoolType,
label.JobName, label.ClientName);
if (label.VerNum >= 10) {
-"", label.Job, label.FileSetName, label.JobType, label.JobLevel);
+""), label.Job, label.FileSetName, label.JobType, label.JobLevel);
edit_uint64_with_commas(label.JobFiles, ec1),
edit_uint64_with_commas(label.JobBytes, ec2),
edit_uint64_with_commas(label.StartBlock, ec3),
edit_uint64_with_commas(label.JobFiles, ec1),
edit_uint64_with_commas(label.JobBytes, ec2),
edit_uint64_with_commas(label.StartBlock, ec3),
tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday, tm.tm_hour, tm.tm_min);
}
tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday, tm.tm_hour, tm.tm_min);
}
type, dev->file, dev->block_num, rec->VolSessionId,
rec->VolSessionTime, rec->Stream, rec->data_len);
break;
type, dev->file, dev->block_num, rec->VolSessionId,
rec->VolSessionTime, rec->Stream, rec->data_len);
break;
type, dev->file, dev->block_num, rec->VolSessionId,
rec->VolSessionTime, rec->Stream, rec->data_len);
break;
type, dev->file, dev->block_num, rec->VolSessionId,
rec->VolSessionTime, rec->Stream, rec->data_len);
break;
case SOS_LABEL:
unser_session_label(&label, rec);
bstrftimes(dt, sizeof(dt), btime_to_unix(label.write_btime));
case SOS_LABEL:
unser_session_label(&label, rec);
bstrftimes(dt, sizeof(dt), btime_to_unix(label.write_btime));
type, dev->file, dev->block_num, rec->VolSessionId, rec->VolSessionTime, label.JobId);
type, dev->file, dev->block_num, rec->VolSessionId, rec->VolSessionTime, label.JobId);
label.Job, dt, label.JobLevel, label.JobType);
break;
case EOS_LABEL:
char ed1[30], ed2[30];
unser_session_label(&label, rec);
bstrftimes(dt, sizeof(dt), btime_to_unix(label.write_btime));
label.Job, dt, label.JobLevel, label.JobType);
break;
case EOS_LABEL:
char ed1[30], ed2[30];
unser_session_label(&label, rec);
bstrftimes(dt, sizeof(dt), btime_to_unix(label.write_btime));
type, dev->file, dev->block_num, rec->VolSessionId, rec->VolSessionTime, label.JobId);
type, dev->file, dev->block_num, rec->VolSessionId, rec->VolSessionTime, label.JobId);
dt, label.JobLevel, label.JobType,
edit_uint64_with_commas(label.JobFiles, ed1),
edit_uint64_with_commas(label.JobBytes, ed2),
dt, label.JobLevel, label.JobType,
edit_uint64_with_commas(label.JobFiles, ed1),
edit_uint64_with_commas(label.JobBytes, ed2),
type, dev->file, dev->block_num, rec->VolSessionId, rec->VolSessionTime,
rec->Stream, rec->data_len);
break;
type, dev->file, dev->block_num, rec->VolSessionId, rec->VolSessionTime,
rec->Stream, rec->data_len);
break;