+/*
+ * Find the next bsr that applies to the current tape.
+ * It is the one with the smallest VolFile position.
+ */
+BSR *find_next_bsr(BSR *root_bsr, DEVICE *dev)
+{
+ BSR *bsr;
+ BSR *found_bsr = NULL;
+
+ if (!root_bsr || !root_bsr->use_positioning ||
+ !root_bsr->reposition || !dev_is_tape(dev)) {
+ Dmsg2(100, "No nxt_bsr use_pos=%d repos=%d\n", root_bsr->use_positioning, root_bsr->reposition);
+ return NULL;
+ }
+ Dmsg2(100, "use_pos=%d repos=%d\n", root_bsr->use_positioning, root_bsr->reposition);
+ root_bsr->mount_next_volume = false;
+ for (bsr=root_bsr; bsr; bsr=bsr->next) {
+ if (bsr->done || !match_volume(bsr, bsr->volume, &dev->VolHdr, 1)) {
+ continue;
+ }
+ if (found_bsr == NULL) {
+ found_bsr = bsr;
+ } else {
+ found_bsr = find_smallest_volfile(found_bsr, bsr);
+ }
+ }
+ /*
+ * If we get to this point and found no bsr, it means
+ * that any additional bsr's must apply to the next
+ * tape, so set a flag.
+ */
+ if (found_bsr == NULL) {
+ root_bsr->mount_next_volume = true;
+ }
+ return found_bsr;
+}
+
+static BSR *find_smallest_volfile(BSR *found_bsr, BSR *bsr)
+{
+ BSR *return_bsr = found_bsr;
+ BSR_VOLFILE *vf;
+ BSR_VOLBLOCK *vb;
+ uint32_t found_bsr_sfile, bsr_sfile;
+ uint32_t found_bsr_sblock, bsr_sblock;
+
+ vf = found_bsr->volfile;
+ found_bsr_sfile = vf->sfile;
+ while ( (vf=vf->next) ) {
+ if (vf->sfile < found_bsr_sfile) {
+ found_bsr_sfile = vf->sfile;
+ }
+ }
+ vf = bsr->volfile;
+ bsr_sfile = vf->sfile;
+ while ( (vf=vf->next) ) {
+ if (vf->sfile < bsr_sfile) {
+ bsr_sfile = vf->sfile;
+ }
+ }
+ if (found_bsr_sfile > bsr_sfile) {
+ return_bsr = bsr;
+ } else if (found_bsr_sfile == bsr_sfile) {
+ /* Must check block */
+ vb = found_bsr->volblock;
+ found_bsr_sblock = vb->sblock;
+ while ( (vb=vb->next) ) {
+ if (vb->sblock < found_bsr_sblock) {
+ found_bsr_sblock = vb->sblock;
+ }
+ }
+ vb = bsr->volblock;
+ bsr_sblock = vb->sblock;
+ while ( (vb=vb->next) ) {
+ if (vb->sblock < bsr_sblock) {
+ bsr_sblock = vb->sblock;
+ }
+ }
+ if (found_bsr_sblock > bsr_sblock) {
+ return_bsr = bsr;
+ }
+ }
+
+ return return_bsr;
+}
+
+/*
+ * Called to tell the matcher that the end of
+ * the current file has been reached.
+ * The bsr argument is not used, but is included
+ * for consistency with the other match calls.
+ *
+ * Returns: true if we should reposition
+ * : false otherwise.
+ */
+bool match_set_eof(BSR *bsr, DEV_RECORD *rec)
+{
+ BSR *rbsr = rec->bsr;
+ Dmsg1(100, "match_set %d\n", rbsr != NULL);
+ if (!rbsr) {
+ return false;
+ }
+ rec->bsr = NULL;
+ rbsr->found++;
+ if (rbsr->count && rbsr->found >= rbsr->count) {
+ rbsr->done = true;
+ rbsr->root->reposition = true;
+ Dmsg2(100, "match_set_eof reposition count=%d found=%d\n",
+ rbsr->count, rbsr->found);
+ return true;
+ }
+ return false;
+}
+