/*
*
* 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
DEVICE *setup_to_access_device(JCR *jcr, int read_access)
{
DEVICE *dev;
- DEV_BLOCK *block;
char *p;
DEVRES *device;
while (p >= jcr->dev_name && *p != '/')
p--;
if (*p == '/') {
- strcpy(jcr->VolumeName, p+1);
+ pm_strcpy(&jcr->VolumeName, p+1);
*p = 0;
}
}
}
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;
}
*/
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;
}
if (jcr->VolList) {
free_vol_list(jcr);
}
+ if (jcr->dcr) {
+ free_dcr(jcr->dcr);
+ jcr->dcr = NULL;
+ }
return;
}
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);
{
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"));
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));
}