+#define WIMLIB_REF_MASK_PUBLIC (WIMLIB_REF_FLAG_GLOB_ENABLE | \
+ WIMLIB_REF_FLAG_GLOB_ERR_ON_NOMATCH)
+
+struct reference_info {
+ WIMStruct *dest_wim;
+ struct list_head new_blobs;
+ struct list_head new_subwims;
+ int ref_flags;
+ struct blob_table *src_table;
+};
+
+static void
+init_reference_info(struct reference_info *info, WIMStruct *dest_wim,
+ int ref_flags)
+{
+ info->dest_wim = dest_wim;
+ INIT_LIST_HEAD(&info->new_blobs);
+ INIT_LIST_HEAD(&info->new_subwims);
+ info->ref_flags = ref_flags;
+}
+
+static void
+commit_reference_info(struct reference_info *info)
+{
+ list_splice(&info->new_subwims, &info->dest_wim->subwims);
+}
+
+static void
+rollback_reference_info(struct reference_info *info)
+{
+ WIMStruct *subwim;
+ struct blob_descriptor *blob;
+
+ while (!list_empty(&info->new_subwims)) {
+ subwim = list_first_entry(&info->new_subwims,
+ WIMStruct, subwim_node);
+ list_del(&subwim->subwim_node);
+ wimlib_free(subwim);
+ }
+
+ while (!list_empty(&info->new_blobs)) {
+ blob = list_first_entry(&info->new_blobs,
+ struct blob_descriptor, blob_table_list);
+ list_del(&blob->blob_table_list);
+ blob_table_unlink(info->dest_wim->blob_table, blob);
+ free_blob_descriptor(blob);
+ }
+}
+