+ int stat;
+
+ /*
+ * The bsr->reposition flag is set any time a bsr is done.
+ * In this case, we can probably reposition the
+ * tape to the next available bsr position.
+ */
+ if (bsr) {
+ bsr->reposition = false;
+ stat = match_all(bsr, rec, volrec, sessrec, true);
+ /*
+ * Note, bsr->reposition is set by match_all when
+ * a bsr is done. We turn it off if a match was
+ * found or if we cannot use positioning
+ */
+ if (stat != 0 || !bsr->use_positioning) {
+ bsr->reposition = false;
+ }
+ } else {
+ stat = 1; /* no bsr => match all */
+ }
+ return stat;
+}
+
+/*
+ * 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;
+
+ /* Do tape/disk seeking only if CAP_POSITIONBLOCKS is on */
+ if (!root_bsr || !root_bsr->use_positioning ||
+ !root_bsr->reposition || !dev->has_cap(CAP_POSITIONBLOCKS)) {
+ Dmsg2(dbglevel, "No nxt_bsr use_pos=%d repos=%d\n", root_bsr->use_positioning, root_bsr->reposition);
+ return NULL;
+ }
+ Dmsg2(dbglevel, "use_pos=%d repos=%d\n", root_bsr->use_positioning, root_bsr->reposition);
+ root_bsr->mount_next_volume = false;
+ /* Walk through all bsrs to find the next one to use => smallest file,block */
+ 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;
+}
+
+/*
+ * ***FIXME***
+ * This routine needs to be fixed to only look at items that
+ * are not marked as done. Otherwise, it can find a bsr
+ * that has already been consumed, and this will cause the
+ * bsr to be used, thus we may seek back and re-read the
+ * same records, causing an error. This deficiency must
+ * be fixed. For the moment, it has been kludged in
+ * read_record.c to avoid seeking back if find_next_bsr
+ * returns a bsr pointing to a smaller address (file/block).
+ */
+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;
+
+ /* Find the smallest file in the found_bsr */
+ vf = found_bsr->volfile;
+ found_bsr_sfile = vf->sfile;
+ while ( (vf=vf->next) ) {
+ if (vf->sfile < found_bsr_sfile) {
+ found_bsr_sfile = vf->sfile;
+ }