]> git.sur5r.net Git - bacula/bacula/commitdiff
Various DVD fixes.
authorNicolas Boichat <nicolas@boichat.ch>
Mon, 25 Jul 2005 15:37:20 +0000 (15:37 +0000)
committerNicolas Boichat <nicolas@boichat.ch>
Mon, 25 Jul 2005 15:37:20 +0000 (15:37 +0000)
git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@2256 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/src/stored/block.c
bacula/src/stored/dev.c
bacula/src/stored/dvd.c

index 4b65c0d975eb60bb0063c1db677e78824be07398..6a2f20f8acf1f01e96f4b0fbd9ec3fb955da1c8a 100644 (file)
@@ -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"),
index 3b549b1e91fbe2b50c19d3b337bf4d169c6435e0..439e353b9ba5827f5af0e65efa3b0fb252cfa11b 100644 (file)
@@ -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 */
index 01b6d0597af0cb7822dc382650bef64c8c73484f..56b7e257611c1c345764a49877cdbbcf1aef11e7 100644 (file)
@@ -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;
 }