+static int const dbglvl = 50; /* debug level */
+
+/*
+ * We setup the StorageId or StorageId group if it is
+ * an autochanger from the Storage and put it in
+ * the media record.
+ * store == NULL => use existing StorageId
+ */
+void set_storageid_in_mr(STORE *store, MEDIA_DBR *mr)
+{
+ if (store == NULL) {
+ /* Just use the plain (single) StorageId */
+ mr->sid_group = edit_int64(mr->StorageId, mr->sid);
+ return;
+ }
+
+ /* At this point we know store != NULL */
+ mr->StorageId = store->StorageId;
+ /* Get to the parent of the autochanger (if any) */
+ if (store->changer) {
+ store = store->changer;
+ mr->StorageId = store->StorageId;
+ }
+ /* Go to the master shared storage head (if any) */
+ if (store->shared_storage && store->shared_storage->ac_group) {
+ store = store->shared_storage;
+ }
+ /* If it is an autochanger we should have an ac_group */
+ if (store->autochanger && store->ac_group) {
+ /* Note we keep the StorageId of the local autochanger */
+ mr->sid_group = store->ac_group;
+ } else {
+ /* Otherwise, we just use the plain (single) StorageId */
+ mr->sid_group = edit_int64(mr->StorageId, mr->sid);
+ }
+}
+
+static void add_volume_to_exclude_list(JCR *jcr, int index, MEDIA_DBR *mr)
+{
+ char ed1[50];
+ if (index == 1) {
+ *jcr->next_vol_list = 0;
+
+ } else if (*jcr->next_vol_list) {
+ pm_strcat(jcr->next_vol_list, ",");
+ }
+ pm_strcat(jcr->next_vol_list, edit_int64(mr->MediaId, ed1));
+
+ /* The list is valid only in find_next_volume_for_append() */
+ mr->exclude_list = NULL;
+}
+
+static void set_volume_to_exclude_list(JCR *jcr, int index, MEDIA_DBR *mr)
+{
+ if (index == 1) {
+ *jcr->next_vol_list = 0;
+ }
+ mr->exclude_list = jcr->next_vol_list;
+}
+