]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/butil.c
Implement first cut DCR in SD
[bacula/bacula] / bacula / src / stored / butil.c
index a9cad0198e052f3b83d6c642db2a34fc89a121e4..1e1387cf4bd3b2a0594c3cc8fcf7408571bd108c 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *
  *  Utility routines for "tool" programs such as bscan, bls,
- *    bextract, ...  
+ *    bextract, ...  Some routines also used by Bacula.
  * 
  *  Normally nothing in this file is called by the Storage   
  *    daemon because we interact more directly with the user
@@ -71,7 +71,6 @@ char *rec_state_to_str(DEV_RECORD *rec)
 DEVICE *setup_to_access_device(JCR *jcr, int read_access)
 {
    DEVICE *dev;
-   DEV_BLOCK *block;
    char *p;
    DEVRES *device;
 
@@ -86,7 +85,7 @@ DEVICE *setup_to_access_device(JCR *jcr, int read_access)
          while (p >= jcr->dev_name && *p != '/')
            p--;
          if (*p == '/') {
-           strcpy(jcr->VolumeName, p+1);
+           pm_strcpy(&jcr->VolumeName, p+1);
            *p = 0;
         }
       }
@@ -97,25 +96,23 @@ DEVICE *setup_to_access_device(JCR *jcr, int read_access)
           jcr->dev_name, configfile);
       return NULL;
    }
+   jcr->device = device;
    
    dev = init_dev(NULL, device);
-   if (!dev || !open_device(dev)) {
+   jcr->device->dev = dev;
+   if (!dev || !first_open_device(dev)) {
       Jmsg1(jcr, M_FATAL, 0, _("Cannot open %s\n"), jcr->dev_name);
       return NULL;
    }
    Dmsg0(90, "Device opened for read.\n");
 
-   block = new_block(dev);
-
    create_vol_list(jcr);
 
    if (read_access) {
-      if (!acquire_device_for_read(jcr, dev, block)) {
-        free_block(block);
+      if (!acquire_device_for_read(jcr)) {
         return NULL;
       }
    }
-   free_block(block);
    return dev;
 }
 
@@ -189,6 +186,10 @@ static void my_free_jcr(JCR *jcr)
    if (jcr->VolList) {
       free_vol_list(jcr);
    }  
+   if (jcr->dcr) {
+      free_dcr(jcr->dcr);
+      jcr->dcr = NULL;
+   }
      
    return;
 }
@@ -209,16 +210,16 @@ JCR *setup_jcr(char *name, char *device, BSR *bsr, char *VolumeName)
    jcr->pool_type = get_pool_memory(PM_FNAME);
    strcpy(jcr->pool_type, "Backup");
    jcr->job_name = get_pool_memory(PM_FNAME);
-   strcpy(jcr->job_name, "Dummy.Job.Name");
+   pm_strcpy(&jcr->job_name, "Dummy.Job.Name");
    jcr->client_name = get_pool_memory(PM_FNAME);
-   strcpy(jcr->client_name, "Dummy.Client.Name");
-   strcpy(jcr->Job, name);
+   pm_strcpy(&jcr->client_name, "Dummy.Client.Name");
+   bstrncpy(jcr->Job, name, sizeof(jcr->Job));
    jcr->fileset_name = get_pool_memory(PM_FNAME);
-   strcpy(jcr->fileset_name, "Dummy.fileset.name");
+   pm_strcpy(&jcr->fileset_name, "Dummy.fileset.name");
    jcr->fileset_md5 = get_pool_memory(PM_FNAME);
-   strcpy(jcr->fileset_md5, "Dummy.fileset.md5");
-   jcr->JobId = 1;
-   jcr->JobType = JT_BACKUP;
+   pm_strcpy(&jcr->fileset_md5, "Dummy.fileset.md5");
+   jcr->JobId = 0;
+   jcr->JobType = JT_CONSOLE;
    jcr->JobLevel = L_FULL;
    jcr->JobStatus = JS_Terminated;
    jcr->dev_name = get_pool_memory(PM_FNAME);
@@ -226,6 +227,7 @@ JCR *setup_jcr(char *name, char *device, BSR *bsr, char *VolumeName)
    if (!bsr && VolumeName) {
       pm_strcpy(&jcr->VolumeName, VolumeName);
    }
+   jcr->where = bstrdup("");
    return jcr;
 }
 
@@ -237,12 +239,11 @@ void display_tape_error_status(JCR *jcr, DEVICE *dev)
 {
    uint32_t status;
 
-   Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg);
-   status_dev(dev, &status);
+   status = status_dev(dev);
    Dmsg1(20, "Device status: %x\n", status);
    if (status & BMT_EOD)
       Jmsg(jcr, M_ERROR, 0, _("Unexpected End of Data\n"));
-   else if (status & BMT_EOT)
+  else if (status & BMT_EOT)
       Jmsg(jcr, M_ERROR, 0, _("Unexpected End of Tape\n"));
    else if (status & BMT_EOF)
       Jmsg(jcr, M_ERROR, 0, _("Unexpected End of File\n"));
@@ -250,44 +251,4 @@ void display_tape_error_status(JCR *jcr, DEVICE *dev)
       Jmsg(jcr, M_ERROR, 0, _("Tape Door is Open\n"));
    else if (!(status & BMT_ONLINE))
       Jmsg(jcr, M_ERROR, 0, _("Unexpected Tape is Off-line\n"));
-   else
-      Jmsg(jcr, M_ERROR, 0, _("Read error on Record Header %s: %s\n"), dev_name(dev), strerror(errno));
-}
-
-
-extern char *getuser(uid_t uid);
-extern char *getgroup(gid_t gid);
-
-void print_ls_output(char *fname, char *link, int type, struct stat *statp)
-{
-   char buf[1000]; 
-   char ec1[30];
-   char *p, *f;
-   int n;
-
-   p = encode_mode(statp->st_mode, buf);
-   n = sprintf(p, "  %2d ", (uint32_t)statp->st_nlink);
-   p += n;
-   n = sprintf(p, "%-8.8s %-8.8s", getuser(statp->st_uid), getgroup(statp->st_gid));
-   p += n;
-   n = sprintf(p, "%8.8s ", edit_uint64(statp->st_size, ec1));
-   p += n;
-   p = encode_time(statp->st_ctime, p);
-   *p++ = ' ';
-   *p++ = ' ';
-   /* Copy file name */
-   for (f=fname; *f && (p-buf) < (int)sizeof(buf); )
-      *p++ = *f++;
-   if (type == FT_LNK) {
-      *p++ = ' ';
-      *p++ = '-';
-      *p++ = '>';
-      *p++ = ' ';
-      /* Copy link name */
-      for (f=link; *f && (p-buf) < (int)sizeof(buf); )
-        *p++ = *f++;
-   }
-   *p++ = '\n';
-   *p = 0;
-   fputs(buf, stdout);
 }