]> git.sur5r.net Git - bacula/bacula/commitdiff
scripts/dvd-handler: "zero" brand-new DVD+/-RW to fix a problem with some
authorNicolas Boichat <nicolas@boichat.ch>
Sun, 16 Oct 2005 21:19:51 +0000 (21:19 +0000)
committerNicolas Boichat <nicolas@boichat.ch>
Sun, 16 Oct 2005 21:19:51 +0000 (21:19 +0000)
   DVD-writers, thanks to Arno Lehmann for reporting this, and providing the
   way to fix it.

git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@2452 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/nb-1.37
bacula/scripts/dvd-handler.in
bacula/src/stored/dvd.c

index f0102f9e868b15ced1c5fe3050e21578ac468615..a936e1b36f853e4bc214c69750aabd0804512212 100644 (file)
@@ -5,6 +5,9 @@ General:
 
 Changes to 1.37.*:
 16Oct05
+ - scripts/dvd-handler: "zero" brand-new DVD+/-RW to fix a problem with some
+   DVD-writers, thanks to Arno Lehmann for reporting this, and providing the
+   way to fix it.
  - new scripts/dvd-handler. Note: it also needs a patched version of dvd+rw-tools.
  - new scripts/dvd-freespace. Note: it needs a patched version of dvd+rw-tools.
  - dvd.c:dvd_write_part: Don't write empty part. (Fix 4GB crossing bug reported by Arno Lehmann)
index 53e42fe8860f95efcee209ae36fdbc639e8d8966..fdae793164e70dc7533d6027a782664f3b35212a 100644 (file)
@@ -113,6 +113,7 @@ class disk:
    def __init__(self, devicename):
       self.device = devicename
       self.disktype = "none"
+      self.diskstatus = "none"
       self.hardwaredevice = "none"
       self.pid = 0
       self.next_session = -1
@@ -132,10 +133,10 @@ class disk:
       if not self.mediumtype_collected:
          self.collect_mediumtype();
       
-      self.me  = "Class disk, initialized with device " + self.device + "\n"
-      self.me += "type = " + self.disktype
+      self.me  = "Class disk, initialized with device '" + self.device + "'\n"
+      self.me += "type = '" + self.disktype + "' status = '" + self.diskstatus + "'\n"
       self.me += " next_session = " + str(self.next_session) + " capacity = " + str(self.capacity) + "\n"
-      self.me += "Hardware device is " + self.hardwaredevice + "\n"
+      self.me += "Hardware device is '" + self.hardwaredevice + "'\n"
       return self.me
 
    def collect_freespace(self): # Collects current free space
@@ -184,13 +185,22 @@ class disk:
       
       hardware = re.search(r"INQUIRY:\s+(.*)\n", result, re.MULTILINE)
       mediatype = re.search(r"\sMounted Media:\s+([0-9A-F]{2})h, (\S*)\s", result, re.MULTILINE)
+      status = re.search(r"\sDisc status:\s+(.*)\n", result, re.MULTILINE)
       
       if hardware:
          self.hardwaredevice = hardware.group(1)
+      
       if mediatype:
          self.disktype = mediatype.group(2)
       else:
          raise DVDError("Media type not found in " + dvdrwmediainfo + " output")
+      
+      if status:
+         self.diskstatus = status.group(1)
+      else:
+         raise DVDError("Disc status not found in " + dvdrwmediainfo + " output")
+
+      
       self.mediumtype_collected = 1
       return
 
@@ -206,11 +216,21 @@ class disk:
       
       return "DVD-RW" == self.disktype or "DVD+RW" == self.disktype or "DVD-RAM" == self.disktype
 
+   def is_blank(self):
+      if not self.mediumtype_collected:
+         self.collect_mediumtype();
+      
+      return self.diskstatus == "blank"
+
    def free(self):
       if not self.freespace_collected:
          self.collect_freespace();
       
-      return self.capacity-self.next_session-margin
+      fr = self.capacity-self.next_session-margin
+      if fr < 0:
+         return 0
+      else:
+         return fr
 
    def term_handler(self, signum, frame):
       print 'dvd-handler: Signal term_handler called with signal', signum
@@ -224,10 +244,8 @@ class disk:
 
    def write(self, newvol, partfile):
       # Blank DVD+/-RW/-RAM when there is no data on it
-      # Ideally, we should only have to do it once, but I don't know how to
-      # identify if a disk is blank of if it is brand-new.
-      if newvol and self.is_RW() and self.is_empty():
-         print "DVD looks brand-new, blank it to fix some DVD-writers bugs."
+      if newvol and self.is_RW() and self.is_blank():
+         print "DVD+/-RW looks brand-new, blank it to fix some DVD-writers bugs."
          self.blank()
          print "Done, now writing the real part file."
       
index f0c824832883dc6428e2e05bbfc9280f997518af..af5ca1318b5b4cc2ee48430ed174db23dc409534 100644 (file)
@@ -317,8 +317,11 @@ bool dvd_write_part(DCR *dcr)
     *     been crossed
     *   - Bacula thinks he must finish to write to the device, so it
     *     tries to write the last part (0-byte), but dvd-writepart fails...
+    *
+    * There is one exception: when recycling a volume, we write a blank part
+    * file, so, then, we need to accept to write it.
     */
-   if (dev->part_size == 0) {
+   if ((dev->part_size == 0) && (dev->part > 0)) {
       Dmsg2(29, "dvd_write_part: device is %s, won't write blank part %d\n", dev->print_name(), dev->part);
       /* Delete spool file */
       make_spooled_dvd_filename(dev, archive_name);
@@ -724,6 +727,11 @@ bool truncate_dvd_dev(DCR *dcr) {
       return false;
    }
    
+   /* Set num_parts to zero (on disk) */
+   dev->num_parts = 0;
+   dcr->VolCatInfo.VolCatParts = 0;
+   dev->VolCatInfo.VolCatParts = 0;
+   
    if (dvd_open_first_part(dcr, OPEN_READ_WRITE) < 0) {
       Dmsg0(100, "truncate_dvd_dev: Error while opening first part (2).\n");
       return false;
@@ -748,7 +756,7 @@ bool check_can_write_on_non_blank_dvd(DCR *dcr) {
    if (name_max < 1024) {
       name_max = 1024;
    }
-         
+   
    if (!(dp = opendir(dev->device->mount_point))) {
       berrno be;
       dev->dev_errno = errno;