From c59c5d9d832c96789ea30ebe879f741a51ecd75b Mon Sep 17 00:00:00 2001 From: Nicolas Boichat Date: Sun, 16 Oct 2005 21:19:51 +0000 Subject: [PATCH] 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. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@2452 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/nb-1.37 | 3 +++ bacula/scripts/dvd-handler.in | 34 ++++++++++++++++++++++++++-------- bacula/src/stored/dvd.c | 12 ++++++++++-- 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/bacula/nb-1.37 b/bacula/nb-1.37 index f0102f9e86..a936e1b36f 100644 --- a/bacula/nb-1.37 +++ b/bacula/nb-1.37 @@ -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) diff --git a/bacula/scripts/dvd-handler.in b/bacula/scripts/dvd-handler.in index 53e42fe886..fdae793164 100644 --- a/bacula/scripts/dvd-handler.in +++ b/bacula/scripts/dvd-handler.in @@ -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." diff --git a/bacula/src/stored/dvd.c b/bacula/src/stored/dvd.c index f0c8248328..af5ca1318b 100644 --- a/bacula/src/stored/dvd.c +++ b/bacula/src/stored/dvd.c @@ -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; -- 2.39.5