+/*
+ * Create a new Device Control Record and attach
+ * it to the device (if this is a real job).
+ */
+DCR *new_dcr(JCR *jcr, DEVICE *dev)
+{
+ DCR *dcr = (DCR *)malloc(sizeof(DCR));
+ memset(dcr, 0, sizeof(DCR));
+ dcr->jcr = jcr;
+ if (dev) {
+ dcr->dev = dev;
+ dcr->device = dev->device;
+ dcr->block = new_block(dev);
+ dcr->rec = new_record();
+ dcr->max_job_spool_size = dev->device->max_job_spool_size;
+ /* Attach this dcr only if dev is initialized */
+ if (dev->fd != 0 && jcr && jcr->JobType != JT_SYSTEM) {
+ dev->attached_dcrs->append(dcr); /* attach dcr to device */
+// jcr->dcrs->append(dcr); /* put dcr in list for Job */
+ }
+ }
+ dcr->spool_fd = -1;
+ return dcr;
+}
+
+/*
+ * Search the dcrs list for the given dcr. If it is found,
+ * as it should be, then remove it. Also zap the jcr pointer
+ * to the dcr if it is the same one.
+ */
+#ifdef needed
+static void remove_dcr_from_dcrs(DCR *dcr)
+{
+ JCR *jcr = dcr->jcr;
+ if (jcr->dcrs) {
+ int i = 0;
+ DCR *ldcr;
+ int num = jcr->dcrs->size();
+ for (i=0; i < num; i++) {
+ ldcr = (DCR *)jcr->dcrs->get(i);
+ if (ldcr == dcr) {
+ jcr->dcrs->remove(i);
+ if (jcr->dcr == dcr) {
+ jcr->dcr = NULL;
+ }
+ }
+ }
+ }
+}
+#endif
+
+/*
+ * Free up all aspects of the given dcr -- i.e. dechain it,
+ * release allocated memory, zap pointers, ...
+ */
+void free_dcr(DCR *dcr)
+{
+ JCR *jcr = dcr->jcr;
+ DEVICE *dev = dcr->dev;