diff --git a/src/stored/bcopy.c b/src/stored/bcopy.c index 8a3ecfa2f8d..44a630ff623 100644 --- a/src/stored/bcopy.c +++ b/src/stored/bcopy.c @@ -83,6 +83,7 @@ int main (int argc, char *argv[]) char *DirectorName = NULL; DIRRES *director = NULL; bool ignore_label_errors = false; + DCR *in_dcr, *out_dcr; setlocale(LC_ALL, ""); bindtextdomain("bareos", LOCALEDIR); @@ -191,11 +192,15 @@ int main (int argc, char *argv[]) * Setup and acquire input device for reading */ Dmsg0(100, "About to setup input jcr\n"); - in_jcr = setup_jcr("bcopy", argv[0], bsr, director, iVolumeName, true); /* read device */ + + in_dcr = New(DCR); + in_jcr = setup_jcr("bcopy", argv[0], bsr, director, in_dcr, iVolumeName, true); /* read device */ if (!in_jcr) { exit(1); } + in_jcr->ignore_label_errors = ignore_label_errors; + in_dev = in_jcr->dcr->dev; if (!in_dev) { exit(1); @@ -205,14 +210,18 @@ int main (int argc, char *argv[]) * Setup output device for writing */ Dmsg0(100, "About to setup output jcr\n"); - out_jcr = setup_jcr("bcopy", argv[1], bsr, director, oVolumeName, false); /* write device */ + + out_dcr = New(DCR); + out_jcr = setup_jcr("bcopy", argv[1], bsr, director, out_dcr, oVolumeName, false); /* write device */ if (!out_jcr) { exit(1); } + out_dev = out_jcr->dcr->dev; if (!out_dev) { exit(1); } + Dmsg0(100, "About to acquire device for writing\n"); /* diff --git a/src/stored/bextract.c b/src/stored/bextract.c index ec2a4228a7f..6cad5dc718f 100644 --- a/src/stored/bextract.c +++ b/src/stored/bextract.c @@ -384,7 +384,8 @@ static void do_extract(char *devname) enable_backup_privileges(NULL, 1); - jcr = setup_jcr("bextract", devname, bsr, director, VolumeName, true); /* read device */ + dcr = New(DCR); + jcr = setup_jcr("bextract", devname, bsr, director, dcr, VolumeName, true); /* read device */ if (!jcr) { exit(1); } diff --git a/src/stored/bls.c b/src/stored/bls.c index 2fecc7da614..93ac452064b 100644 --- a/src/stored/bls.c +++ b/src/stored/bls.c @@ -239,7 +239,8 @@ int main (int argc, char *argv[]) if (bsrName) { bsr = parse_bsr(NULL, bsrName); } - jcr = setup_jcr("bls", argv[i], bsr, director, VolumeName, true); /* read device */ + dcr = New(DCR); + jcr = setup_jcr("bls", argv[i], bsr, director, dcr, VolumeName, true); /* read device */ if (!jcr) { exit(1); } diff --git a/src/stored/bscan.c b/src/stored/bscan.c index 66bdc17c960..de6d6b554e9 100644 --- a/src/stored/bscan.c +++ b/src/stored/bscan.c @@ -135,6 +135,7 @@ int main (int argc, char *argv[]) char *VolumeName = NULL; char *DirectorName = NULL; DIRRES *director = NULL; + DCR *dcr; #if defined(HAVE_DYNAMIC_CATS_BACKENDS) alist *backend_directories = NULL; #endif @@ -292,18 +293,20 @@ int main (int argc, char *argv[]) /* Check that working directory is good */ if (stat(working_directory, &stat_buf) != 0) { Emsg1(M_ERROR_TERM, 0, _("Working Directory: %s not found. Cannot continue.\n"), - working_directory); + working_directory); } if (!S_ISDIR(stat_buf.st_mode)) { Emsg1(M_ERROR_TERM, 0, _("Working Directory: %s is not a directory. Cannot continue.\n"), - working_directory); + working_directory); } - bjcr = setup_jcr("bscan", argv[0], bsr, director, VolumeName, true); /* read device */ + dcr = New(DCR); + bjcr = setup_jcr("bscan", argv[0], bsr, director, dcr, VolumeName, true); if (!bjcr) { exit(1); } dev = bjcr->read_dcr->dev; + if (showProgress) { char ed1[50]; struct stat sb; diff --git a/src/stored/btape.c b/src/stored/btape.c index 0a748ee78da..1069385d353 100644 --- a/src/stored/btape.c +++ b/src/stored/btape.c @@ -290,20 +290,23 @@ int main(int margc, char *margv[]) exit(1); } - jcr = setup_jcr("btape", margv[0], bsr, director, NULL, false); /* write device */ + dcr = New(BTAPE_DCR); + jcr = setup_jcr("btape", margv[0], bsr, director, dcr, NULL, false); /* write device */ if (!jcr) { exit(1); } + dev = jcr->dcr->dev; if (!dev) { exit(1); } + if (!dev->is_tape()) { Pmsg0(000, _("btape only works with tape storage.\n")); usage(); exit(1); } - dcr = jcr->dcr; + if (!open_the_device()) { exit(1); } diff --git a/src/stored/butil.c b/src/stored/butil.c index 4ea6073aef0..8d4e6b2a891 100644 --- a/src/stored/butil.c +++ b/src/stored/butil.c @@ -35,7 +35,8 @@ #include "stored.h" /* Forward referenced functions */ -static DCR *setup_to_access_device(JCR *jcr, char *dev_name, const char *VolumeName, bool readonly); +static bool setup_to_access_device(DCR *dcr, JCR *jcr, char *dev_name, + const char *VolumeName, bool readonly); static DEVRES *find_device_res(char *device_name, bool readonly); static void my_free_jcr(JCR *jcr); @@ -76,11 +77,11 @@ char *rec_state_bits_to_str(DEV_RECORD *rec) * tools (e.g. bls, bextract, bscan, ...) */ JCR *setup_jcr(const char *name, char *dev_name, - BSR *bsr, DIRRES *director, + BSR *bsr, DIRRES *director, DCR *dcr, const char *VolumeName, bool readonly) { - DCR *dcr; JCR *jcr = new_jcr(sizeof(JCR), my_free_jcr); + jcr->bsr = bsr; jcr->director = director; jcr->VolSessionId = 1; @@ -107,15 +108,17 @@ JCR *setup_jcr(const char *name, char *dev_name, init_autochangers(); create_volume_lists(); - dcr = setup_to_access_device(jcr, dev_name, VolumeName, readonly); - if (!dcr) { + if (!setup_to_access_device(dcr, jcr, dev_name, VolumeName, readonly)) { return NULL; } + if (!bsr && VolumeName) { bstrncpy(dcr->VolumeName, VolumeName, sizeof(dcr->VolumeName)); } + bstrncpy(dcr->pool_name, "Default", sizeof(dcr->pool_name)); bstrncpy(dcr->pool_type, "Backup", sizeof(dcr->pool_type)); + return jcr; } @@ -124,12 +127,12 @@ JCR *setup_jcr(const char *name, char *dev_name, * If the caller wants read access, acquire the device, otherwise, * the caller will do it. */ -static DCR *setup_to_access_device(JCR *jcr, char *dev_name, const char *VolumeName, bool readonly) +static bool setup_to_access_device(DCR *dcr, JCR *jcr, char *dev_name, + const char *VolumeName, bool readonly) { DEVICE *dev; char *p; DEVRES *device; - DCR *dcr; char VolName[MAX_NAME_LENGTH]; init_reservations_lock(); @@ -162,17 +165,16 @@ static DCR *setup_to_access_device(JCR *jcr, char *dev_name, const char *VolumeN if ((device = find_device_res(dev_name, readonly)) == NULL) { Jmsg2(jcr, M_FATAL, 0, _("Cannot find device \"%s\" in config file %s.\n"), - dev_name, configfile); - return NULL; + dev_name, configfile); + return false; } dev = init_dev(jcr, device); if (!dev) { Jmsg1(jcr, M_FATAL, 0, _("Cannot init device %s\n"), dev_name); - return NULL; + return false; } device->dev = dev; - dcr = New(DCR); jcr->dcr = dcr; setup_new_dcr_device(jcr, dcr, dev, NULL); if (!readonly) { @@ -189,20 +191,19 @@ static DCR *setup_to_access_device(JCR *jcr, char *dev_name, const char *VolumeN if (readonly) { /* read only access? */ Dmsg0(100, "Acquire device for read\n"); if (!acquire_device_for_read(dcr)) { - return NULL; + return false; } jcr->read_dcr = dcr; } else { if (!first_open_device(dcr)) { Jmsg1(jcr, M_FATAL, 0, _("Cannot open %s\n"), dev->print_name()); - return NULL; + return false; } } - return dcr; + return true; } - /* * Called here when freeing JCR so that we can get rid * of "daemon" specific memory allocated. diff --git a/src/stored/protos.h b/src/stored/protos.h index 36e63cbcd30..4efc0873ed0 100644 --- a/src/stored/protos.h +++ b/src/stored/protos.h @@ -68,7 +68,7 @@ void ser_block_header(DEV_BLOCK *block); /* butil.c -- utilities for SD tool programs */ void print_ls_output(const char *fname, const char *link, int type, struct stat *statp); JCR *setup_jcr(const char *name, char *dev_name, - BSR *bsr, DIRRES *director, + BSR *bsr, DIRRES *director, DCR* dcr, const char *VolumeName, bool readonly); void display_tape_error_status(JCR *jcr, DEVICE *dev);