]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/butil.c
added WSACleanup(), corrected WSA_Init() (removed #ifdef)
[bacula/bacula] / bacula / src / stored / butil.c
index 5586309d82afb60cbbf568d29e0e3edc22bdfb00..4d439b5048a49c4112c72bc34433d27816355895 100644 (file)
@@ -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;
 
@@ -93,31 +92,29 @@ DEVICE *setup_to_access_device(JCR *jcr, int read_access)
    }
 
    if ((device=find_device_res(jcr->dev_name, read_access)) == NULL) {
-      Jmsg2(jcr, M_FATAL, 0, _("Cannot find device %s in config file %s.\n"), 
+      Jmsg2(jcr, M_FATAL, 0, _("Cannot find device \"%s\" in config file %s.\n"), 
           jcr->dev_name, configfile);
       return NULL;
    }
    jcr->device = device;
+   pm_strcpy(&jcr->dev_name, device->device_name);
    
    dev = init_dev(NULL, device);
    jcr->device->dev = dev;
-   if (!dev || !open_device(dev)) {
+   new_dcr(jcr, 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;
 }
 
@@ -131,23 +128,39 @@ DEVICE *setup_to_access_device(JCR *jcr, int read_access)
  */
 DEVRES *find_device_res(char *device_name, int read_access)
 {
-   int found = 0;
+   bool found = false;
    DEVRES *device;
 
    LockRes();
-   for (device=NULL; (device=(DEVRES *)GetNextRes(R_DEVICE, (RES *)device)); ) {
+   foreach_res(device, R_DEVICE) {
       if (strcmp(device->device_name, device_name) == 0) {
-        found = 1;
+        found = true;
         break;
       }
    } 
+   if (!found) {
+      /* Search for name of Device resource rather than archive name */
+      if (device_name[0] == '"') {
+        strcpy(device_name, device_name+1);
+        int len = strlen(device_name);
+        if (len > 0) {
+           device_name[len-1] = 0;
+        }
+      }
+      foreach_res(device, R_DEVICE) {
+        if (strcmp(device->hdr.name, device_name) == 0) {
+           found = true;
+           break;
+        }
+      } 
+   }
    UnlockRes();
    if (!found) {
-      Pmsg2(0, _("Could not find device %s in config file %s.\n"), device_name,
+      Pmsg2(0, _("Could not find device \"%s\" in config file %s.\n"), device_name,
            configfile);
       return NULL;
    }
-   Pmsg2(0, _("Using device: %s for %s.\n"), device_name,
+   Pmsg2(0, _("Using device: \"%s\" for %s.\n"), device_name,
              read_access?"reading":"writing");
    return device;
 }
@@ -191,6 +204,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;
 }