}
return num;
}
+
+/**
+ * Merges two block containers. Blocks present @a src and missing in
+ * @a dest are duplicated in @a dest.
+ *
+ * @param dest Destination of merge operation
+ * @param src Source of merge operation
+ *
+ * @return Zero on success, non-zero error core on error.
+ */
+int fres_container_merge(struct fres_container *dest,
+ const struct fres_container *src)
+{
+ enum fres_block_type type;
+ int ret;
+
+ for (type=0; type<FRES_NUM_BLOCKS; type++) {
+ const struct fres_block *sb = &src->blocks[type];
+ struct fres_block *db = &dest->blocks[type];
+
+ if (sb->state != FRES_BLOCK_EMPTY &&
+ db->state == FRES_BLOCK_EMPTY) {
+ ret = fres_block_duplicate(db, sb, type);
+ if (ret) {
+ return ret;
+ }
+ }
+ }
+ return 0;
+}
int
fres_container_get_num_blocks(const struct fres_container *c);
+int fres_container_merge(struct fres_container *dest,
+ const struct fres_container *src);
+
#ifdef __cplusplus
} /* extern "C"*/
#endif
return fres_container_get_num_blocks(c->container);
}
+static inline int
+fres_contract_merge(struct fres_contract *dest,
+ const struct fres_contract *src)
+{
+ return fres_container_merge(dest->container, src->container);
+}
+
+
/**
* Macro which defines type-safe contract "accessor" functions for
* various blocks.