]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/bextract.c
Massive SD calling sequence reorganization
[bacula/bacula] / bacula / src / stored / bextract.c
index daf491715cf51fece8beaeadaf4f35e5a64fbfd8..fb67da69ae724324b30a3474c2b9b3ef6c1e6100 100644 (file)
@@ -2,7 +2,7 @@
  *
  *  Dumb program to extract files from a Bacula backup.
  *
- *   Kern E. Sibbald, 2000
+ *   Kern E. Sibbald, MM
  *
  *   Version $Id$
  *
@@ -38,7 +38,7 @@ int win32_client = 0;
 #endif
 
 static void do_extract(char *fname);
-static bool record_cb(JCR *jcr, DEVICE *dev, DEV_BLOCK *block, DEV_RECORD *rec);
+static bool record_cb(DCR *dcr, DEV_RECORD *rec);
 
 static DEVICE *dev = NULL;
 static DCR *dcr;
@@ -79,6 +79,7 @@ static void usage()
 "       -e <file>       exclude list\n"
 "       -i <file>       include list\n"
 "       -p              proceed inspite of I/O errors\n"
+"       -v              verbose\n"
 "       -V <volumes>    specify Volume names (separated by |)\n"
 "       -?              print this message\n\n");
    exit(1);
@@ -100,7 +101,7 @@ int main (int argc, char *argv[])
    init_include_exclude_files(ff);
    binit(&bfd);
 
-   while ((ch = getopt(argc, argv, "b:c:d:e:i:pV:?")) != -1) {
+   while ((ch = getopt(argc, argv, "b:c:d:e:i:pvV:?")) != -1) {
       switch (ch) {
       case 'b':                    /* bootstrap file */
         bsr = parse_bsr(NULL, optarg);
@@ -122,8 +123,9 @@ int main (int argc, char *argv[])
 
       case 'e':                    /* exclude list */
          if ((fd = fopen(optarg, "r")) == NULL) {
+           berrno be;
             Pmsg2(0, "Could not open exclude file: %s, ERR=%s\n",
-              optarg, strerror(errno));
+              optarg, be.strerror());
            exit(1);
         }
         while (fgets(line, sizeof(line), fd) != NULL) {
@@ -136,8 +138,9 @@ int main (int argc, char *argv[])
 
       case 'i':                    /* include list */
          if ((fd = fopen(optarg, "r")) == NULL) {
+           berrno be;
             Pmsg2(0, "Could not open include file: %s, ERR=%s\n",
-              optarg, strerror(errno));
+              optarg, be.strerror());
            exit(1);
         }
         while (fgets(line, sizeof(line), fd) != NULL) {
@@ -153,6 +156,10 @@ int main (int argc, char *argv[])
         forge_on = true;
         break;
 
+      case 'v':
+        verbose++;
+        break;
+
       case 'V':                    /* Volume name */
         VolumeName = optarg;
         break;
@@ -201,8 +208,11 @@ int main (int argc, char *argv[])
 static void do_extract(char *devname)
 {
    struct stat statp;
-   jcr = setup_jcr("bextract", devname, bsr, VolumeName);
-   dev = setup_to_access_device(jcr, 1);    /* acquire for read */
+   jcr = setup_jcr("bextract", devname, bsr, VolumeName, 1); /* acquire for read */
+   if (!jcr) {
+      exit(1);
+   }
+   dev = jcr->dcr->dev;
    if (!dev) {
       exit(1);
    }
@@ -210,8 +220,9 @@ static void do_extract(char *devname)
 
    /* Make sure where directory exists and that it is a directory */
    if (stat(where, &statp) < 0) {
+      berrno be;
       Emsg2(M_ERROR_TERM, 0, "Cannot stat %s. It must exist. ERR=%s\n",
-        where, strerror(errno));
+        where, be.strerror());
    }
    if (!S_ISDIR(statp.st_mode)) {
       Emsg1(M_ERROR_TERM, 0, "%s must be a directory.\n", where);
@@ -242,9 +253,10 @@ static void do_extract(char *devname)
 /*
  * Called here for each record from read_records()
  */
-static bool record_cb(JCR *jcr, DEVICE *dev, DEV_BLOCK *block, DEV_RECORD *rec)
+static bool record_cb(DCR *dcr, DEV_RECORD *rec)
 {
    int stat;
+   JCR *jcr = dcr->jcr;
 
    if (rec->FileIndex < 0) {
       return true;                    /* we don't want labels */
@@ -329,8 +341,9 @@ static bool record_cb(JCR *jcr, DEVICE *dev, DEV_BLOCK *block, DEV_RECORD *rec)
            if (fileAddr != faddr) {
               fileAddr = faddr;
               if (blseek(&bfd, (off_t)fileAddr, SEEK_SET) < 0) {
+                 berrno be;
                   Emsg2(M_ERROR_TERM, 0, _("Seek error on %s: %s\n"), 
-                    attr->ofname, strerror(errno));
+                    attr->ofname, be.strerror());
               }
            }
         } else {
@@ -340,8 +353,9 @@ static bool record_cb(JCR *jcr, DEVICE *dev, DEV_BLOCK *block, DEV_RECORD *rec)
         total += wsize;
          Dmsg2(8, "Write %u bytes, total=%u\n", wsize, total);
         if ((uint32_t)bwrite(&bfd, wbuf, wsize) != wsize) {
+           berrno be;
             Emsg2(M_ERROR_TERM, 0, _("Write error on %s: %s\n"), 
-              attr->ofname, strerror(errno));
+              attr->ofname, be.strerror());
         }
         fileAddr += wsize;
       }
@@ -367,8 +381,9 @@ static bool record_cb(JCR *jcr, DEVICE *dev, DEV_BLOCK *block, DEV_RECORD *rec)
            if (fileAddr != faddr) {
               fileAddr = faddr;
               if (blseek(&bfd, (off_t)fileAddr, SEEK_SET) < 0) {
+                 berrno be;
                   Emsg3(M_ERROR, 0, _("Seek to %s error on %s: ERR=%s\n"), 
-                    edit_uint64(fileAddr, ec1), attr->ofname, berror(&bfd));
+                    edit_uint64(fileAddr, ec1), attr->ofname, be.strerror());
                  extract = false;
                  return true;
               }
@@ -387,9 +402,10 @@ static bool record_cb(JCR *jcr, DEVICE *dev, DEV_BLOCK *block, DEV_RECORD *rec)
 
          Dmsg2(100, "Write uncompressed %d bytes, total before write=%d\n", compress_len, total);
         if ((uLongf)bwrite(&bfd, compress_buf, (size_t)compress_len) != compress_len) {
+           berrno be;
             Pmsg0(0, "===Write error===\n");
             Emsg2(M_ERROR, 0, _("Write error on %s: %s\n"), 
-              attr->ofname, strerror(errno));
+              attr->ofname, be.strerror());
            extract = false;
            return true;
         }
@@ -448,10 +464,9 @@ bool       dir_send_job_status(JCR *jcr) {return 1;}
 
 bool dir_ask_sysop_to_mount_volume(DCR *dcr)
 {
-   JCR *jcr = dcr->jcr;
    DEVICE *dev = dcr->dev;
    fprintf(stderr, "Mount Volume \"%s\" on device %s and press return when ready: ",
-      jcr->VolumeName, dev_name(dev));
+      dcr->VolumeName, dev_name(dev));
    getchar();  
    return true;
 }