-static bool terminate_writing_volume(DCR *dcr);
-static bool do_new_file_bookkeeping(DCR *dcr);
-static bool do_dvd_size_checks(DCR *dcr);
-static void reread_last_block(DCR *dcr);
-
-/*
- * Dump the block header, then walk through
- * the block printing out the record headers.
- */
-void dump_block(DEV_BLOCK *b, const char *msg)
-{
- ser_declare;
- char *p;
- char Id[BLKHDR_ID_LENGTH+1];
- uint32_t CheckSum, BlockCheckSum;
- uint32_t block_len;
- uint32_t BlockNumber;
- uint32_t VolSessionId, VolSessionTime, data_len;
- int32_t FileIndex;
- int32_t Stream;
- int bhl, rhl;
- char buf1[100], buf2[100];
-
- unser_begin(b->buf, BLKHDR1_LENGTH);
- unser_uint32(CheckSum);
- unser_uint32(block_len);
- unser_uint32(BlockNumber);
- unser_bytes(Id, BLKHDR_ID_LENGTH);
- ASSERT(unser_length(b->buf) == BLKHDR1_LENGTH);
- Id[BLKHDR_ID_LENGTH] = 0;
- if (Id[3] == '2') {
- unser_uint32(VolSessionId);
- unser_uint32(VolSessionTime);
- bhl = BLKHDR2_LENGTH;
- rhl = RECHDR2_LENGTH;
- } else {
- VolSessionId = VolSessionTime = 0;
- bhl = BLKHDR1_LENGTH;
- rhl = RECHDR1_LENGTH;
- }
-
- if (block_len > 100000) {
- Dmsg3(20, "Dump block %s 0x%x blocksize too big %u\n", msg, b, block_len);
- return;
- }
-
- BlockCheckSum = bcrc32((uint8_t *)b->buf+BLKHDR_CS_LENGTH,
- block_len-BLKHDR_CS_LENGTH);
- Pmsg6(000, _("Dump block %s %x: size=%d BlkNum=%d\n"
-" Hdrcksum=%x cksum=%x\n"),
- msg, b, block_len, BlockNumber, CheckSum, BlockCheckSum);
- p = b->buf + bhl;
- while (p < (b->buf + block_len+WRITE_RECHDR_LENGTH)) {
- unser_begin(p, WRITE_RECHDR_LENGTH);
- if (rhl == RECHDR1_LENGTH) {
- unser_uint32(VolSessionId);
- unser_uint32(VolSessionTime);
- }
- unser_int32(FileIndex);
- unser_int32(Stream);
- unser_uint32(data_len);
- Pmsg6(000, _(" Rec: VId=%u VT=%u FI=%s Strm=%s len=%d p=%x\n"),
- VolSessionId, VolSessionTime, FI_to_ascii(buf1, FileIndex),
- stream_to_ascii(buf2, Stream, FileIndex), data_len, p);
- p += data_len + rhl;
- }
-}
-
-/*
- * Create a new block structure.
- * We pass device so that the block can inherit the
- * min and max block sizes.
- */
-DEV_BLOCK *new_block(DEVICE *dev)
-{
- DEV_BLOCK *block = (DEV_BLOCK *)get_memory(sizeof(DEV_BLOCK));
-
- memset(block, 0, sizeof(DEV_BLOCK));
-
- /* If the user has specified a max_block_size, use it as the default */
- if (dev->max_block_size == 0) {
- block->buf_len = DEFAULT_BLOCK_SIZE;
- } else {
- block->buf_len = dev->max_block_size;
- }
- block->dev = dev;
- block->block_len = block->buf_len; /* default block size */
- block->buf = get_memory(block->buf_len);
- empty_block(block);
- block->BlockVer = BLOCK_VER; /* default write version */
- Dmsg1(650, "Returning new block=%x\n", block);
- return block;
-}
-
-
-/*
- * Duplicate an existing block (eblock)
- */
-DEV_BLOCK *dup_block(DEV_BLOCK *eblock)
-{
- DEV_BLOCK *block = (DEV_BLOCK *)get_memory(sizeof(DEV_BLOCK));
- int buf_len = sizeof_pool_memory(eblock->buf);
-
- memcpy(block, eblock, sizeof(DEV_BLOCK));
- block->buf = get_memory(buf_len);
- memcpy(block->buf, eblock->buf, buf_len);
- return block;
-}
-
-
-/*
- * Only the first block checksum error was reported.
- * If there are more, report it now.
- */
-void print_block_read_errors(JCR *jcr, DEV_BLOCK *block)
-{
- if (block->read_errors > 1) {
- Jmsg(jcr, M_ERROR, 0, _("%d block read errors not printed.\n"),
- block->read_errors);
- }
-}
-
-/*
- * Free block
- */
-void free_block(DEV_BLOCK *block)
-{
- Dmsg1(999, "free_block buffer %x\n", block->buf);
- free_memory(block->buf);
- Dmsg1(999, "free_block block %x\n", block);
- free_memory((POOLMEM *)block);
-}
-
-/* Empty the block -- for writing */
-void empty_block(DEV_BLOCK *block)
-{
- block->binbuf = WRITE_BLKHDR_LENGTH;
- block->bufp = block->buf + block->binbuf;
- block->read_len = 0;
- block->write_failed = false;
- block->block_read = false;
- block->FirstIndex = block->LastIndex = 0;
-}
-
-/*
- * Create block header just before write. The space
- * in the buffer should have already been reserved by
- * init_block.
- */
-void ser_block_header(DEV_BLOCK *block)
-{
- ser_declare;
- uint32_t CheckSum = 0;
- uint32_t block_len = block->binbuf;
-
- Dmsg1(1390, "ser_block_header: block_len=%d\n", block_len);
- ser_begin(block->buf, BLKHDR2_LENGTH);
- ser_uint32(CheckSum);
- ser_uint32(block_len);
- ser_uint32(block->BlockNumber);
- ser_bytes(WRITE_BLKHDR_ID, BLKHDR_ID_LENGTH);
- if (BLOCK_VER >= 2) {
- ser_uint32(block->VolSessionId);
- ser_uint32(block->VolSessionTime);
- }