]> git.sur5r.net Git - bacula/bacula/commitdiff
kes Add a new close_part() class in the SD to save the device
authorKern Sibbald <kern@sibbald.com>
Thu, 7 Sep 2006 08:47:10 +0000 (08:47 +0000)
committerKern Sibbald <kern@sibbald.com>
Thu, 7 Sep 2006 08:47:10 +0000 (08:47 +0000)
     state around open/close_part/open for DVD writing.  This
     should fix the num_dvd_parts getting zeroed as reported by
     Richard Mortimer.
kes  Apply patch from Richard Mortimer that correct edit code
     for debug output of st_size.

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

bacula/src/stored/dev.c
bacula/src/stored/dev.h
bacula/src/stored/dvd.c
bacula/technotes-1.39

index e3bcda034e90392629ae7f0a6722f6a39ea1c9f1..b52f92353b737bf546032657e18082c4e7ece6e8 100644 (file)
@@ -1817,6 +1817,30 @@ void DEVICE::close()
    openmode = 0;
 }
 
+/*
+ * This call closes the device, but it is used in DVD handling
+ *  where we close one part and then open the next part. The
+ *  difference between close_part() and close() is that close_part()
+ *  saves the state information of the device (e.g. the Volume lable,
+ *  the Volume Catalog record, ...  This permits opening and closing
+ *  the Volume parts multiple times without losing track of what the    
+ *  main Volume parameters are.
+ */
+void DEVICE::close_part(DCR *dcr)
+{
+   VOLUME_LABEL saveVolHdr;
+   VOLUME_CAT_INFO saveVolCatInfo;     /* Volume Catalog Information */
+
+
+   memcpy(&saveVolHdr, &VolHdr, sizeof(saveVolHdr));
+   memcpy(&saveVolCatInfo, &VolCatInfo, sizeof(saveVolCatInfo));
+   close();                           /* close current part */
+   memcpy(&VolHdr, &saveVolHdr, sizeof(VolHdr));
+   memcpy(&VolCatInfo, &saveVolCatInfo, sizeof(VolCatInfo));
+   memcpy(&dcr->VolCatInfo, &saveVolCatInfo, sizeof(dcr->VolCatInfo));
+}
+
+
 
 
 bool DEVICE::truncate(DCR *dcr) /* We need the DCR for DVD-writing */
index af494d5ecdbe7b9fe1ce01b37c6123c4a6487db9..3781e7c63b20343040fd8284ea45cb0111f8d8f7 100644 (file)
@@ -343,6 +343,7 @@ public:
    void block(int why);          /* in dev.c */
    void unblock();               /* in dev.c */
    void close();                 /* in dev.c */
+   void close_part(DCR *dcr);    /* in dev.c */
    bool truncate(DCR *dcr);      /* in dev.c */
    int open(DCR *dcr, int mode); /* in dev.c */
    void term(void);              /* in dev.c */
index bfa47a4a0bf3a1fd42d8a0358aaaab52dcfed646..bcd360c6c95d1339d081b58b1a6e07a1273ce1f7 100644 (file)
@@ -470,7 +470,6 @@ bool dvd_write_part(DCR *dcr)
 int dvd_open_next_part(DCR *dcr)
 {
    DEVICE *dev = dcr->dev;
-   VOLUME_LABEL VolHdr;
 
    Dmsg6(29, "Enter: == open_next_part part=%d npart=%d dev=%s vol=%s mode=%d file_addr=%d\n", 
       dev->part, dev->num_dvd_parts, dev->print_name(),
@@ -487,14 +486,7 @@ int dvd_open_next_part(DCR *dcr)
       return dev->fd;
    }
 
-   /*              
-    * Note, when we close, the Volume header is zeroed. Since
-    *  we reopen, but are in fact opening the same volume without
-    *  re-reading the Volume header, we simply save and restore it.
-    */
-   memcpy(&VolHdr, &dev->VolHdr, sizeof(VolHdr));
-   dev->close();                      /* close current part */
-   memcpy(&dev->VolCatInfo, &dcr->VolCatInfo, sizeof(dev->VolCatInfo));
+   dev->close_part(dcr);               /* close current part */
    
    /*
     * If we have a spooled part open, write it to the
@@ -561,8 +553,6 @@ int dvd_open_next_part(DCR *dcr)
    if (dev->open(dcr, OPEN_READ_ONLY) < 0) {
       return -1;
    } 
-   /* Restore Volume header record */
-   memcpy(&dev->VolHdr, &VolHdr, sizeof(dev->VolHdr));
    dev->set_labeled();                   /* all next parts are "labeled" */
    
    return dev->fd;
@@ -576,20 +566,12 @@ int dvd_open_next_part(DCR *dcr)
 int dvd_open_first_part(DCR *dcr, int mode)
 {
    DEVICE *dev = dcr->dev;
-   VOLUME_LABEL VolHdr;
 
    Dmsg5(29, "Enter: ==== open_first_part dev=%s Vol=%s mode=%d num_dvd_parts=%d append=%d\n", dev->print_name(), 
          dev->VolCatInfo.VolCatName, dev->openmode, dev->num_dvd_parts, dev->can_append());
 
 
-   /*              
-    * Note, when we close, the Volume header is zeroed. Since
-    *  we reopen, but are in fact opening the same volume without
-    *  re-reading the Volume header, we simply save and restore it.
-    */
-   memcpy(&VolHdr, &dev->VolHdr, sizeof(VolHdr));
-   dev->close();
-   memcpy(&dev->VolCatInfo, &dcr->VolCatInfo, sizeof(dev->VolCatInfo));
+   dev->close_part(dcr);
 
    Dmsg2(400, "Call dev->open(vol=%s, mode=%d)\n", dcr->VolCatInfo.VolCatName, 
          mode);
@@ -597,9 +579,6 @@ int dvd_open_first_part(DCR *dcr, int mode)
    dev->part = 1;
    dev->part_start = 0;
 
-
-   /* Restore Volume header record */
-   memcpy(&dev->VolHdr, &VolHdr, sizeof(dev->VolHdr));
    if (dev->open(dcr, mode) < 0) {
       Dmsg0(400, "open dev() failed\n");
       return -1;
@@ -778,8 +757,7 @@ bool truncate_dvd(DCR *dcr)
 {
    DEVICE* dev = dcr->dev;
 
-   dev->close();
-   memcpy(&dev->VolCatInfo, &dcr->VolCatInfo, sizeof(dev->VolCatInfo));
+   dev->close_part(dcr);
 
    if (!unmount_dvd(dev, 1)) {
       Dmsg0(400, "truncate_dvd: Failed to unmount DVD\n");
@@ -811,8 +789,7 @@ bool truncate_dvd(DCR *dcr)
       return false;
    }
    
-   dev->close();
-   memcpy(&dev->VolCatInfo, &dcr->VolCatInfo, sizeof(dev->VolCatInfo));
+   dev->close_part(dcr);
    
    Dmsg0(400, "truncate_dvd: Opening first part (2)...\n");
    
@@ -904,7 +881,7 @@ bool check_can_write_on_non_blank_dvd(DCR *dcr)
                   filename.c_str(), be.strerror());
                return false;
             }
-            Dmsg2(99, "check_can_write_on_non_blank_dvd: size of %s is %d\n", 
+            Dmsg2(99, "check_can_write_on_non_blank_dvd: size of %s is %lld\n", 
                filename.c_str(), filestat.st_size);
             matched = filestat.st_size == 0;
          }
index 8b6269985df8965a88f05febe8d4fc1dc8fdcff4..3abf44e4412909baf3a126c05985a0cc6f919c1b 100644 (file)
@@ -2,6 +2,12 @@
 
 General:
 07Sep06
+kes  Add a new close_part() class in the SD to save the device
+     state around open/close_part/open for DVD writing.  This
+     should fix the num_dvd_parts getting zeroed as reported by
+     Richard Mortimer.
+kes  Apply patch from Richard Mortimer that correct edit code
+     for debug output of st_size.
 ebl  Add support of encrypted data stream to bscan.
      display data_len instead of data content (may be binary)
 06Sep06