]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/label.c
This commit was manufactured by cvs2svn to create tag
[bacula/bacula] / bacula / src / stored / label.c
index 3867976b5d34f34bba051ac2e431d927094cefa4..a92b259ccbb19012493d46b8b288ad447e275120 100644 (file)
@@ -65,7 +65,7 @@ int read_dev_volume_label(JCR *jcr, DEVICE *dev, DEV_BLOCK *block)
    Dmsg3(100, "Enter read_volume_label device=%s vol=%s dev_Vol=%s\n", 
       dev_name(dev), VolName, dev->VolHdr.VolName);
 
-   if (dev->state & ST_LABEL) {       /* did we already read label? */
+   if (dev_state(dev, ST_LABEL)) {      /* did we already read label? */
       /* Compare Volume Names allow special wild card */
       if (VolName && *VolName && *VolName != '*' && strcmp(dev->VolHdr.VolName, VolName) != 0) {
          Mmsg(&jcr->errmsg, _("Wrong Volume mounted on device %s: Wanted %s have %s\n"),
@@ -90,7 +90,7 @@ int read_dev_volume_label(JCR *jcr, DEVICE *dev, DEV_BLOCK *block)
         strerror_dev(dev));
       return jcr->label_status = VOL_NO_MEDIA;
    }
-   strcpy(dev->VolHdr.Id, "**error**");
+   bstrncpy(dev->VolHdr.Id, "**error**", sizeof(dev->VolHdr.Id));
 
    /* Read the Volume label block */
    record = new_record();
@@ -131,6 +131,17 @@ because:\n   %s"), dev_name(dev), strerror_dev(dev));
       return jcr->label_status = VOL_VERSION_ERROR;
    }
 
+   /* We are looking for either an unused Bacula tape (PRE_LABEL) or
+    * a Bacula volume label (VOL_LABEL)
+    */
+   if (dev->VolHdr.LabelType != PRE_LABEL && dev->VolHdr.LabelType != VOL_LABEL) {
+      Mmsg(&jcr->errmsg, _("Volume on %s has bad Bacula label type: %x\n"), 
+         dev_name(dev), dev->VolHdr.LabelType);
+      return jcr->label_status = VOL_LABEL_ERROR;
+   }
+
+   dev->state |= ST_LABEL;           /* set has Bacula label */
+
    /* Compare Volume Names */
    Dmsg2(30, "Compare Vol names: VolName=%s hdr=%s\n", VolName?VolName:"*", dev->VolHdr.VolName);
    if (VolName && *VolName && *VolName != '*' && strcmp(dev->VolHdr.VolName, VolName) != 0) {
@@ -147,16 +158,6 @@ because:\n   %s"), dev_name(dev), strerror_dev(dev));
    }
    Dmsg1(30, "Copy vol_name=%s\n", dev->VolHdr.VolName);
 
-   /* We are looking for either an unused Bacula tape (PRE_LABEL) or
-    * a Bacula volume label (VOL_LABEL)
-    */
-   if (dev->VolHdr.LabelType != PRE_LABEL && dev->VolHdr.LabelType != VOL_LABEL) {
-      Mmsg(&jcr->errmsg, _("Volume on %s has bad Bacula label type: %x\n"), 
-         dev_name(dev), dev->VolHdr.LabelType);
-      return jcr->label_status = VOL_LABEL_ERROR;
-   }
-
-   dev->state |= ST_LABEL;           /* set has Bacula label */
    if (debug_level >= 10) {
       dump_volume_label(dev);
    }
@@ -243,6 +244,7 @@ int write_volume_label_to_block(JCR *jcr, DEVICE *dev, DEV_BLOCK *block)
    create_volume_label_record(jcr, dev, &rec);
 
    empty_block(block);               /* Volume label always at beginning */
+   block->BlockNumber = 0;
    if (!write_record_to_block(block, &rec)) {
       free_pool_memory(rec.data);
       Jmsg1(jcr, M_FATAL, 0, _("Cannot write Volume label to block for device %s\n"),
@@ -318,7 +320,7 @@ static void create_volume_label_record(JCR *jcr, DEVICE *dev, DEV_RECORD *rec)
  *  Returns: 0 on error
  *          1 on success
  */
-void create_volume_label(DEVICE *dev, char *VolName)
+void create_volume_label(DEVICE *dev, char *VolName, char *PoolName)
 {
    struct date_time dt;
    DEVRES *device = (DEVRES *)dev->device;
@@ -331,15 +333,15 @@ void create_volume_label(DEVICE *dev, char *VolName)
 
    /* ***FIXME*** we really need to get the volume name,    
     * pool name, and pool type from the database.
-    * We also need to pickup the MediaType.
     */
-   strcpy(dev->VolHdr.Id, BaculaId);
+   bstrncpy(dev->VolHdr.Id, BaculaId, sizeof(dev->VolHdr.Id));
    dev->VolHdr.VerNum = BaculaTapeVersion;
    dev->VolHdr.LabelType = PRE_LABEL;  /* Mark tape as unused */
    bstrncpy(dev->VolHdr.VolName, VolName, sizeof(dev->VolHdr.VolName));
-   strcpy(dev->VolHdr.PoolName, "Default");
+   bstrncpy(dev->VolHdr.PoolName, PoolName, sizeof(dev->VolHdr.PoolName));
    bstrncpy(dev->VolHdr.MediaType, device->media_type, sizeof(dev->VolHdr.MediaType));
-   strcpy(dev->VolHdr.PoolType, "Backup");
+
+   bstrncpy(dev->VolHdr.PoolType, "Backup", sizeof(dev->VolHdr.PoolType));
 
    /* Put label time/date in header */
    if (BaculaTapeVersion >= 11) {
@@ -385,10 +387,7 @@ int write_volume_label_to_dev(JCR *jcr, DEVRES *device, char *VolName, char *Poo
 
 
    Dmsg0(99, "write_volume_label()\n");
-   create_volume_label(dev, VolName);
-   bstrncpy(dev->VolHdr.MediaType, device->media_type, sizeof(dev->VolHdr.MediaType));
-   bstrncpy(dev->VolHdr.VolName, VolName, sizeof(dev->VolHdr.VolName));
-   bstrncpy(dev->VolHdr.PoolName, PoolName, sizeof(dev->VolHdr.PoolName));
+   create_volume_label(dev, VolName, PoolName);
 
    if (!rewind_dev(dev)) {
       memset(&dev->VolHdr, 0, sizeof(dev->VolHdr));
@@ -440,9 +439,7 @@ int write_volume_label_to_dev(JCR *jcr, DEVRES *device, char *VolName, char *Poo
 void create_session_label(JCR *jcr, DEV_RECORD *rec, int label)
 {
    ser_declare;
-   struct date_time dt;
 
-   rec->sync          = 1;         /* wait for completion */
    rec->VolSessionId   = jcr->VolSessionId;
    rec->VolSessionTime = jcr->VolSessionTime;
    rec->Stream        = jcr->JobId;
@@ -454,15 +451,9 @@ void create_session_label(JCR *jcr, DEV_RECORD *rec, int label)
 
    ser_uint32(jcr->JobId);
 
-   if (BaculaTapeVersion >= 11) {
-      ser_btime(get_current_btime());
-      ser_float64(0);
-   } else {
-      /* OLD WAY DEPRECATED */
-      get_current_time(&dt);
-      ser_float64(dt.julian_day_number);
-      ser_float64(dt.julian_day_fraction);
-   }
+   /* Changed in VerNum 11 */
+   ser_btime(get_current_btime());
+   ser_float64(0);
 
    ser_string(jcr->pool_name);
    ser_string(jcr->pool_type);
@@ -474,9 +465,8 @@ void create_session_label(JCR *jcr, DEV_RECORD *rec, int label)
    ser_string(jcr->fileset_name);
    ser_uint32(jcr->JobType);
    ser_uint32(jcr->JobLevel);
-   if (BaculaTapeVersion >= 11) {
-      ser_string(jcr->fileset_md5);
-   }
+   /* Added in VerNum 11 */
+   ser_string(jcr->fileset_md5);
 
    if (label == EOS_LABEL) {
       ser_uint32(jcr->JobFiles);
@@ -506,27 +496,27 @@ int write_session_label(JCR *jcr, DEV_BLOCK *block, int label)
    rec = new_record();
    Dmsg1(90, "session_label record=%x\n", rec);
    switch (label) {
-      case SOS_LABEL:
-        if (dev->state & ST_TAPE) {
-           jcr->StartBlock = dev->block_num;
-           jcr->StartFile  = dev->file;
-        } else {
-           jcr->StartBlock = (uint32_t)dev->file_addr;
-           jcr->StartFile = (uint32_t)(dev->file_addr >> 32);
-        }
-        break;
-      case EOS_LABEL:
-        if (dev->state & ST_TAPE) {
-           jcr->EndBlock = dev->EndBlock;
-           jcr->EndFile  = dev->EndFile;
-        } else {
-           jcr->EndBlock = (uint32_t)dev->file_addr;
-           jcr->EndFile = (uint32_t)(dev->file_addr >> 32);
-        }
-        break;
-      default:
-         Jmsg1(jcr, M_ABORT, 0, _("Bad session label = %d\n"), label);
-        break;
+   case SOS_LABEL:
+      if (dev->state & ST_TAPE) {
+        jcr->StartBlock = dev->block_num;
+        jcr->StartFile  = dev->file;
+      } else {
+        jcr->StartBlock = (uint32_t)dev->file_addr;
+        jcr->StartFile = (uint32_t)(dev->file_addr >> 32);
+      }
+      break;
+   case EOS_LABEL:
+      if (dev->state & ST_TAPE) {
+        jcr->EndBlock = dev->EndBlock;
+        jcr->EndFile  = dev->EndFile;
+      } else {
+        jcr->EndBlock = (uint32_t)dev->file_addr;
+        jcr->EndFile = (uint32_t)(dev->file_addr >> 32);
+      }
+      break;
+   default:
+      Jmsg1(jcr, M_ABORT, 0, _("Bad session label = %d\n"), label);
+      break;
    }
    create_session_label(jcr, rec, label);
    rec->FileIndex = label;