From 7ba656b867c8c723d9f02cabe4ba4c22872ccd4c Mon Sep 17 00:00:00 2001 From: Nicolas Boichat Date: Mon, 25 Jul 2005 15:37:20 +0000 Subject: [PATCH] Various DVD fixes. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@2256 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/stored/block.c | 23 +++++++++++++---------- bacula/src/stored/dev.c | 21 +++++++++++++++------ bacula/src/stored/dvd.c | 8 +++++++- 3 files changed, 35 insertions(+), 17 deletions(-) diff --git a/bacula/src/stored/block.c b/bacula/src/stored/block.c index 4b65c0d975..6a2f20f8ac 100644 --- a/bacula/src/stored/block.c +++ b/bacula/src/stored/block.c @@ -884,19 +884,22 @@ reread: return false; } - /*Dmsg1(200, "dev->file_size=%u\n",(unsigned int)dev->file_size); - Dmsg1(200, "lseek=%u\n",(unsigned int)lseek(dev->fd, 0, SEEK_CUR)); - Dmsg1(200, "dev->part_start=%u\n",(unsigned int)dev->part_start); - Dmsg1(200, "dev->file_size-dev->part_start=%u\n",(unsigned int)dev->file_size-dev->part_start); - Dmsg1(200, "dev->part_size=%u\n", (unsigned int)dev->part_size); - Dmsg1(200, "dev->part=%u\n", (unsigned int)dev->part); - Dmsg1(200, "dev->VolCatInfo.VolCatParts=%u\n", (unsigned int)dev->VolCatInfo.VolCatParts); - Dmsg3(200, "Tests : %d %d %d\n", (dev->VolCatInfo.VolCatParts > 0), - ((dev->file_size-dev->part_start) == dev->part_size), + /*Dmsg1(100, "dev->file_size=%u\n",(unsigned int)dev->file_size); + Dmsg1(100, "dev->file_addr=%u\n",(unsigned int)dev->file_addr); + Dmsg1(100, "lseek=%u\n",(unsigned int)lseek(dev->fd, 0, SEEK_CUR)); + Dmsg1(100, "dev->part_start=%u\n",(unsigned int)dev->part_start); + Dmsg1(100, "dev->file_addr-dev->part_start=%u\n",(unsigned int)dev->file_addr-dev->part_start); + Dmsg1(100, "dev->file_size-dev->part_start=%u\n",(unsigned int)dev->file_size-dev->part_start); + Dmsg1(100, "dev->part_size=%u\n", (unsigned int)dev->part_size); + Dmsg1(100, "dev->part=%u\n", (unsigned int)dev->part); + Dmsg1(100, "dev->num_parts=%u\n", (unsigned int)dev->num_parts); + Dmsg1(100, "dev->VolCatInfo.VolCatParts=%u\n", (unsigned int)dev->VolCatInfo.VolCatParts); + Dmsg3(100, "Tests : %d %d %d\n", (dev->VolCatInfo.VolCatParts > 0), + ((dev->file_addr-dev->part_start) == dev->part_size), (dev->part <= dev->VolCatInfo.VolCatParts));*/ /* Check for part file end */ if ((dev->num_parts > 0) && - ((dev->file_size-dev->part_start) == dev->part_size) && + ((dev->file_addr-dev->part_start) == dev->part_size) && (dev->part < dev->num_parts)) { if (open_next_part(dcr) < 0) { Jmsg2(dcr->jcr, M_FATAL, 0, _("Unable to open device next part %s: ERR=%s\n"), diff --git a/bacula/src/stored/dev.c b/bacula/src/stored/dev.c index 3b549b1e91..439e353b9b 100644 --- a/bacula/src/stored/dev.c +++ b/bacula/src/stored/dev.c @@ -484,7 +484,7 @@ void DEVICE::open_dvd_device(DCR *dcr, int omode) return; } } - + Dmsg5(29, "open dev: %s dev=%s mode=%s part=%d npart=%d\n", is_dvd()?"DVD":"disk", archive_name.c_str(), mode_to_str(omode), part, num_parts); @@ -514,11 +514,21 @@ void DEVICE::open_dvd_device(DCR *dcr, int omode) Mmsg2(errmsg, _("Could not open: %s, ERR=%s\n"), archive_name.c_str(), be.strerror()); Dmsg1(29, "open failed: %s", errmsg); - if (omode == OPEN_READ_ONLY) { - make_spooled_dvd_filename(this, archive_name); - /* Use system open() */ - fd = ::open(archive_name.c_str(), mode, 0640); /* try on spool */ + + if ((omode == OPEN_READ_ONLY) && (part == num_parts)) { + /* If the last part (on spool), doesn't exists when reading, create it and read from it + * (it will report immediately an EOF): + * Sometimes it is better to finish with an EOF than with an error. */ + set_mode(OPEN_READ_WRITE); + fd = ::open(archive_name.c_str(), mode, 0640); + set_mode(OPEN_READ_ONLY); } + + /* We don't need it. Only the last part is on spool */ + /*if (omode == OPEN_READ_ONLY) { + make_spooled_dvd_filename(this, archive_name); + fd = ::open(archive_name.c_str(), mode, 0640); // try on spool + }*/ } Dmsg1(100, "after open fd=%d\n", fd); if (fd >= 0) { @@ -537,7 +547,6 @@ void DEVICE::open_dvd_device(DCR *dcr, int omode) dev_errno = 0; set_opened(); use_count = 1; - Dmsg2(100, "after open(2a) part=%d part_size=%d\n", part, part_size); update_pos_dev(this); /* update position */ /* NB: It seems this code is wrong... part number is incremented in open_next_part, not here */ diff --git a/bacula/src/stored/dvd.c b/bacula/src/stored/dvd.c index 01b6d0597a..56b7e25761 100644 --- a/bacula/src/stored/dvd.c +++ b/bacula/src/stored/dvd.c @@ -357,7 +357,7 @@ int open_next_part(DCR *dcr) Dmsg1(000, "Device %s is not dvd!!!!\n", dev->print_name()); return -1; } - + /* When appending, do not open a new part if the current is empty */ if (dev->can_append() && (dev->part >= dev->num_parts) && (dev->part_size == 0)) { @@ -436,10 +436,16 @@ int open_next_part(DCR *dcr) Dmsg2(50, "Call dev->open(vol=%s, mode=%d\n", dev->VolCatInfo.VolCatName, dev->openmode); /* Open next part */ + + int append = dev->can_append(); if (dev->open(dcr, dev->openmode) < 0) { return -1; } dev->set_labeled(); /* all next parts are "labeled" */ + if (append && (dev->part == dev->num_parts)) { /* If needed, set the append flag back */ + dev->set_append(); + } + return dev->fd; } -- 2.39.5