#include "bacula.h"
#include "stored.h"
+#ifdef DEBUG_BLOCK_CHECKSUM
+static const bool debug_block_checksum = true;
+#else
+static const bool debug_block_checksum = false;
+#endif
+
+#ifdef NO_TAPE_WRITE_TEST
+static const bool no_tape_write_test = true;
+#else
+static const bool no_tape_write_test = false;
+#endif
+
+
static bool terminate_writing_volume(DCR *dcr);
static bool do_new_file_bookkeeping(DCR *dcr);
static bool do_dvd_size_checks(DCR *dcr);
DCR *dcr = this;
if (dcr->spooling) {
+ Dmsg0(100, "Write to spool\n");
stat = write_block_to_spool_file(dcr);
return stat;
}
if (dcr->NewVol || dcr->NewFile) {
if (job_canceled(jcr)) {
stat = false;
+ Dmsg0(100, "Canceled\n");
goto bail_out;
}
/* Create a jobmedia record for this job */
dcr->getVolCatName(), jcr->Job);
set_new_volume_parameters(dcr);
stat = false;
+ Dmsg0(100, "cannot create media record\n");
goto bail_out;
}
if (dcr->NewVol) {
int hit_max1, hit_max2;
bool ok = true;
DCR *dcr = this;
+ uint32_t checksum;
-#ifdef NO_TAPE_WRITE_TEST
- empty_block(block);
- return true;
-#endif
+ if (no_tape_write_test) {
+ empty_block(block);
+ return true;
+ }
if (job_canceled(jcr)) {
return false;
}
Dmsg0(100, "return write_block_to_dev with ST_WEOT\n");
dev->dev_errno = ENOSPC;
Jmsg1(jcr, M_FATAL, 0, _("Cannot write block. Device at EOM. dev=%s\n"), dev->print_name());
+ Dmsg1(100, "Attempt to write on read-only Volume. dev=%s\n", dev->print_name());
return false;
}
if (!dev->can_append()) {
dev->dev_errno = EIO;
Jmsg1(jcr, M_FATAL, 0, _("Attempt to write on read-only Volume. dev=%s\n"), dev->print_name());
+ Dmsg1(100, "Attempt to write on read-only Volume. dev=%s\n", dev->print_name());
return false;
}
-
+
if (!dev->is_open()) {
Jmsg1(jcr, M_FATAL, 0, _("Attempt to write on closed device=%s\n"), dev->print_name());
+ Dmsg1(100, "Attempt to write on closed device=%s\n", dev->print_name());
return false;
}
+
/*
* Clear to the end of the buffer if it is not full,
* and on tape devices, apply min and fixed blocking.
}
}
-#ifdef DEBUG_BLOCK_CHECKSUM
- uint32_t checksum;
checksum = ser_block_header(block, dev->do_checksum());
-#else
- ser_block_header(block, dev->do_checksum());
-#endif
/* Limit maximum Volume size to value specified by user */
hit_max1 = (dev->max_volume_size > 0) &&
} while (stat == -1 && (errno == EBUSY || errno == EIO) && retry++ < 3);
-#ifdef DEBUG_BLOCK_CHECKSUM
- uint32_t achecksum = ser_block_header(block, dev->do_checksum());
- if (checksum != achecksum) {
- Jmsg2(jcr, M_ERROR, 0, _("Block checksum changed during write: before=%ud after=%ud\n"),
- checksum, achecksum);
- dump_block(block, "with checksum error");
+ if (debug_block_checksum) {
+ uint32_t achecksum = ser_block_header(block, dev->do_checksum());
+ if (checksum != achecksum) {
+ Jmsg2(jcr, M_ERROR, 0, _("Block checksum changed during write: before=%ud after=%ud\n"),
+ checksum, achecksum);
+ dump_block(block, "with checksum error");
+ }
}
-#endif
#ifdef DEBUG_BLOCK_ZEROING
if (bp[0] == 0 && bp[1] == 0 && bp[2] == 0 && block->buf[12] == 0) {
Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg);
dev->set_short_block();
block->read_len = block->binbuf = 0;
+ Dmsg2(200, "set block=%p binbuf=%d\n", block, block->binbuf);
return false; /* return error */
}
/*
Bacula® - The Network Backup Solution
- Copyright (C) 2000-2011 Free Software Foundation Europe e.V.
+ Copyright (C) 2000-2012 Free Software Foundation Europe e.V.
The main author of Bacula is Kern Sibbald, with contributions from
many others, a complete list can be found in the file AUTHORS.
DEV_RECORD *record;
record = new_record();
dcr->read_block_from_device(NO_BLOCK_NUMBER_CHECK);
- read_record_from_block(dcr, block, record);
+ read_record_from_block(dcr, record);
get_session_record(dev, record, &sessrec);
free_record(record);
Jmsg(jcr, M_INFO, 0, _("Mounted Volume \"%s\".\n"), dcr->VolumeName);
block->BlockNumber, block->block_len, block->BlockVer,
block->VolSessionId, block->VolSessionTime);
if (verbose == 1) {
- read_record_from_block(dcr, block, rec);
+ read_record_from_block(dcr, rec);
Pmsg9(-1, _("File:blk=%u:%u blk_num=%u blen=%u First rec FI=%s SessId=%u SessTim=%u Strm=%s rlen=%d\n"),
dev->file, dev->block_num,
block->BlockNumber, block->block_len,
goto bail_out;
}
memset(rec->data, 0, rec->data_len);
- if (!read_record_from_block(dcr, block, rec)) {
+ if (!read_record_from_block(dcr, rec)) {
berrno be;
Pmsg1(0, _("Read block failed! ERR=%s\n"), be.bstrerror(dev->dev_errno));
goto bail_out;
goto bail_out;
}
memset(rec->data, 0, rec->data_len);
- if (!read_record_from_block(dcr, block, rec)) {
+ if (!read_record_from_block(dcr, rec)) {
berrno be;
Pmsg2(0, _("Read record failed. Block %d! ERR=%s\n"), i, be.bstrerror(dev->dev_errno));
goto bail_out;
goto bail_out;
}
memset(rec->data, 0, rec->data_len);
- if (!read_record_from_block(dcr, block, rec)) {
+ if (!read_record_from_block(dcr, rec)) {
berrno be;
Pmsg1(0, _("Read record failed! ERR=%s\n"), be.bstrerror(dev->dev_errno));
goto bail_out;
block->VolSessionId, block->VolSessionTime);
if (verbose == 1) {
DEV_RECORD *rec = new_record();
- read_record_from_block(dcr, block, rec);
+ read_record_from_block(dcr, rec);
Pmsg9(-1, _("Block=%u file,blk=%u,%u blen=%u First rec FI=%s SessId=%u SessTim=%u Strm=%s rlen=%d\n"),
block->BlockNumber, dev->file, dev->block_num, block->block_len,
FI_to_ascii(buf1, rec->FileIndex), rec->VolSessionId, rec->VolSessionTime,
case B_VTL_DEV:
case B_VTAPE_DEV:
case B_TAPE_DEV:
- unlock_door();
+ unlock_door();
+ /* Fall through wanted */
default:
d_close(m_fd);
break;
"labeled Volume, because: ERR=%s"), NPRT(VolName),
dev->print_name(), dev->print_errmsg());
Dmsg1(130, "%s", jcr->errmsg);
- } else if (!read_record_from_block(dcr, block, record)) {
+ } else if (!read_record_from_block(dcr, record)) {
Mmsg(jcr->errmsg, _("Could not read Volume label from block.\n"));
Dmsg1(130, "%s", jcr->errmsg);
} else if (!unser_volume_label(dev, record)) {
const char *stream_to_ascii(char *buf, int stream, int fi);
bool write_record_to_block(DCR *dcr, DEV_RECORD *rec);
bool can_write_record_to_block(DEV_BLOCK *block, DEV_RECORD *rec);
-bool read_record_from_block(DCR *dcr, DEV_BLOCK *block, DEV_RECORD *rec);
+bool read_record_from_block(DCR *dcr, DEV_RECORD *rec);
DEV_RECORD *new_record();
void free_record(DEV_RECORD *rec);
void empty_record(DEV_RECORD *rec);
* most likely reading the previous record.
*/
dcr->read_block_from_device(NO_BLOCK_NUMBER_CHECK);
- read_record_from_block(dcr, block, trec);
+ read_record_from_block(dcr, trec);
handle_session_record(dev, trec, &sessrec);
ok = record_cb(dcr, trec);
free_record(trec);
lastFileIndex = no_FileIndex;
Dmsg1(dbglvl, "Block %s empty\n", is_block_empty(rec)?"is":"NOT");
for (rec->state_bits=0; ok && !is_block_empty(rec); ) {
- if (!read_record_from_block(dcr, block, rec)) {
+ if (!read_record_from_block(dcr, rec)) {
Dmsg3(400, "!read-break. state_bits=%s blk=%d rem=%d\n", rec_state_bits_to_str(rec),
block->BlockNumber, rec->remainder);
break;
* routine may have to be called again with a new
* block if the entire record was not read.
*/
-bool read_record_from_block(DCR *dcr, DEV_BLOCK *block, DEV_RECORD *rec)
+bool read_record_from_block(DCR *dcr, DEV_RECORD *rec)
{
ser_declare;
uint32_t remlen;
uint32_t rhl;
char buf1[100], buf2[100];
- remlen = block->binbuf;
+ remlen = dcr->block->binbuf;
/* Clear state flags */
rec->state_bits = 0;
- if (block->dev->is_tape()) {
+ if (dcr->block->dev->is_tape()) {
rec->state_bits |= REC_ISTAPE;
}
- rec->Block = ((DEVICE *)block->dev)->EndBlock;
- rec->File = ((DEVICE *)block->dev)->EndFile;
+ rec->Block = ((DEVICE *)(dcr->block->dev))->EndBlock;
+ rec->File = ((DEVICE *)(dcr->block->dev))->EndFile;
/*
* Get the header. There is always a full header,
* otherwise we find it in the next block.
*/
- Dmsg3(450, "Block=%d Ver=%d size=%u\n", block->BlockNumber, block->BlockVer,
- block->block_len);
- if (block->BlockVer == 1) {
+ Dmsg3(450, "Block=%d Ver=%d size=%u\n", dcr->block->BlockNumber, dcr->block->BlockVer,
+ dcr->block->block_len);
+ if (dcr->block->BlockVer == 1) {
rhl = RECHDR1_LENGTH;
} else {
rhl = RECHDR2_LENGTH;
}
if (remlen >= rhl) {
Dmsg4(450, "Enter read_record_block: remlen=%d data_len=%d rem=%d blkver=%d\n",
- remlen, rec->data_len, rec->remainder, block->BlockVer);
+ remlen, rec->data_len, rec->remainder, dcr->block->BlockVer);
- unser_begin(block->bufp, WRITE_RECHDR_LENGTH);
- if (block->BlockVer == 1) {
+ unser_begin(dcr->block->bufp, WRITE_RECHDR_LENGTH);
+ if (dcr->block->BlockVer == 1) {
unser_uint32(VolSessionId);
unser_uint32(VolSessionTime);
} else {
- VolSessionId = block->VolSessionId;
- VolSessionTime = block->VolSessionTime;
+ VolSessionId = dcr->block->VolSessionId;
+ VolSessionTime = dcr->block->VolSessionTime;
}
unser_int32(FileIndex);
unser_int32(Stream);
unser_uint32(data_bytes);
- block->bufp += rhl;
- block->binbuf -= rhl;
+ dcr->block->bufp += rhl;
+ dcr->block->binbuf -= rhl;
remlen -= rhl;
/* If we are looking for more (remainder!=0), we reject anything
rec->VolSessionTime = VolSessionTime;
rec->FileIndex = FileIndex;
if (FileIndex > 0) {
- if (block->FirstIndex == 0) {
- block->FirstIndex = FileIndex;
+ if (dcr->block->FirstIndex == 0) {
+ dcr->block->FirstIndex = FileIndex;
}
- block->LastIndex = FileIndex;
+ dcr->block->LastIndex = FileIndex;
}
Dmsg6(450, "rd_rec_blk() got FI=%s SessId=%d Strm=%s len=%u\n"
*/
Dmsg0(450, "read_record_block: nothing\n");
rec->state_bits |= (REC_NO_HEADER | REC_BLOCK_EMPTY);
- empty_block(block); /* mark block empty */
+ empty_block(dcr->block); /* mark block empty */
return false;
}
* continuing with this block.
*/
rec->state_bits |= (REC_NO_HEADER | REC_BLOCK_EMPTY);
- empty_block(block);
+ empty_block(dcr->block);
Jmsg2(dcr->jcr, M_WARNING, 0, _("Sanity check failed. maxlen=%d datalen=%d. Block discarded.\n"),
MAX_BLOCK_LENGTH, data_bytes);
return false;
*/
if (remlen >= data_bytes) {
/* Got whole record */
- memcpy(rec->data+rec->data_len, block->bufp, data_bytes);
- block->bufp += data_bytes;
- block->binbuf -= data_bytes;
+ memcpy(rec->data+rec->data_len, dcr->block->bufp, data_bytes);
+ dcr->block->bufp += data_bytes;
+ dcr->block->binbuf -= data_bytes;
rec->data_len += data_bytes;
} else {
/* Partial record */
- memcpy(rec->data+rec->data_len, block->bufp, remlen);
- block->bufp += remlen;
- block->binbuf -= remlen;
+ memcpy(rec->data+rec->data_len, dcr->block->bufp, remlen);
+ dcr->block->bufp += remlen;
+ dcr->block->binbuf -= remlen;
rec->data_len += remlen;
rec->remainder = 1; /* partial record transferred */
Dmsg1(450, "read_record_block: partial xfered=%d\n", rec->data_len);