+/*
+ * Start walk of vol chain
+ * The proper way to walk the vol chain is:
+ * VOLRES *vol;
+ * foreach_vol(vol) {
+ * ...
+ * }
+ * endeach_vol(vol);
+ *
+ * It is possible to leave out the endeach_vol(vol), but
+ * in that case, the last vol referenced must be explicitly
+ * released with:
+ *
+ * free_vol_item(vol);
+ *
+ */
+VOLRES *vol_walk_start()
+{
+ VOLRES *vol;
+ lock_volumes();
+ vol = (VOLRES *)vol_list->first();
+ if (vol) {
+ vol->inc_use_count();
+ Dmsg2(dbglvl, "Inc walk_start use_count=%d volname=%s\n",
+ vol->use_count(), vol->vol_name);
+ }
+ unlock_volumes();
+ return vol;
+}
+
+/*
+ * Get next vol from chain, and release current one
+ */
+VOLRES *vol_walk_next(VOLRES *prev_vol)
+{
+ VOLRES *vol;
+
+ lock_volumes();
+ vol = (VOLRES *)vol_list->next(prev_vol);
+ if (vol) {
+ vol->inc_use_count();
+ Dmsg2(dbglvl, "Inc walk_next use_count=%d volname=%s\n",
+ vol->use_count(), vol->vol_name);
+ }
+ unlock_volumes();
+ if (prev_vol) {
+ free_vol_item(prev_vol);
+ }
+ return vol;
+}
+
+/*
+ * Release last vol referenced
+ */
+void vol_walk_end(VOLRES *vol)
+{
+ if (vol) {
+ Dmsg2(dbglvl, "Free walk_end use_count=%d volname=%s\n",
+ vol->use_count(), vol->vol_name);
+ free_vol_item(vol);
+ }
+}
+