121 lines
3.6 KiB
Diff
121 lines
3.6 KiB
Diff
From e8af3f231361966e12eedf5656d7ef70432cf9ff Mon Sep 17 00:00:00 2001
|
|
From: "Richard W.M. Jones" <rjones@redhat.com>
|
|
Date: Sat, 27 Nov 2021 09:51:33 +0000
|
|
Subject: [PATCH] common/regions: Implement append_region_end
|
|
|
|
This function was documented but not implemented, add the
|
|
implementation.
|
|
|
|
(cherry picked from commit 6f7485f8bcda1a316a57048207ce2c3092af544a)
|
|
---
|
|
common/regions/regions.c | 60 ++++++++++++++++++++++++++--------------
|
|
common/regions/regions.h | 2 --
|
|
2 files changed, 40 insertions(+), 22 deletions(-)
|
|
|
|
diff --git a/common/regions/regions.c b/common/regions/regions.c
|
|
index bb7a278c..841c5c40 100644
|
|
--- a/common/regions/regions.c
|
|
+++ b/common/regions/regions.c
|
|
@@ -119,10 +119,10 @@ append_padding (regions *rs, uint64_t alignment)
|
|
}
|
|
|
|
int
|
|
-append_region_len (regions *rs,
|
|
+append_region_va (regions *rs,
|
|
const char *description, uint64_t len,
|
|
uint64_t pre_aligment, uint64_t post_alignment,
|
|
- enum region_type type, ...)
|
|
+ enum region_type type, va_list ap)
|
|
{
|
|
struct region region;
|
|
|
|
@@ -139,24 +139,10 @@ append_region_len (regions *rs,
|
|
region.len = len;
|
|
region.end = region.start + region.len - 1;
|
|
region.type = type;
|
|
- if (type == region_file) {
|
|
- va_list ap;
|
|
- size_t i;
|
|
-
|
|
- va_start (ap, type);
|
|
- i = va_arg (ap, size_t);
|
|
- va_end (ap);
|
|
- region.u.i = i;
|
|
- }
|
|
- else if (type == region_data) {
|
|
- va_list ap;
|
|
- const unsigned char *data;
|
|
-
|
|
- va_start (ap, type);
|
|
- data = va_arg (ap, const unsigned char *);
|
|
- va_end (ap);
|
|
- region.u.data = data;
|
|
- }
|
|
+ if (type == region_file)
|
|
+ region.u.i = va_arg (ap, size_t);
|
|
+ else if (type == region_data)
|
|
+ region.u.data = va_arg (ap, const unsigned char *);
|
|
if (append_one_region (rs, region) == -1)
|
|
return -1;
|
|
|
|
@@ -169,3 +155,37 @@ append_region_len (regions *rs,
|
|
|
|
return 0;
|
|
}
|
|
+
|
|
+int
|
|
+append_region_len (regions *rs,
|
|
+ const char *description, uint64_t len,
|
|
+ uint64_t pre_aligment, uint64_t post_alignment,
|
|
+ enum region_type type, ...)
|
|
+{
|
|
+ va_list ap;
|
|
+ int r;
|
|
+
|
|
+ va_start (ap, type);
|
|
+ r = append_region_va (rs, description, len,
|
|
+ pre_aligment, post_alignment, type, ap);
|
|
+ va_end (ap);
|
|
+ return r;
|
|
+}
|
|
+
|
|
+int
|
|
+append_region_end (regions *rs,
|
|
+ const char *description, uint64_t end,
|
|
+ uint64_t pre_aligment, uint64_t post_alignment,
|
|
+ enum region_type type, ...)
|
|
+{
|
|
+ va_list ap;
|
|
+ int r;
|
|
+ uint64_t len;
|
|
+
|
|
+ va_start (ap, type);
|
|
+ len = end - virtual_size (rs) + 1;
|
|
+ r = append_region_va (rs, description, len,
|
|
+ pre_aligment, post_alignment, type, ap);
|
|
+ va_end (ap);
|
|
+ return r;
|
|
+}
|
|
diff --git a/common/regions/regions.h b/common/regions/regions.h
|
|
index 13fc41e2..6dfd5d88 100644
|
|
--- a/common/regions/regions.h
|
|
+++ b/common/regions/regions.h
|
|
@@ -123,7 +123,6 @@ extern int append_region_len (regions *regions,
|
|
uint64_t pre_aligment, uint64_t post_alignment,
|
|
enum region_type type, ...);
|
|
|
|
-#if 0
|
|
/* Same as append_region_len (above) but instead of specifying the
|
|
* size of the main region, specify the end byte as an offset. Note
|
|
* the end byte is included in the region, it's is NOT the end+1 byte.
|
|
@@ -132,6 +131,5 @@ extern int append_region_end (regions *regions,
|
|
const char *description, uint64_t end,
|
|
uint64_t pre_aligment, uint64_t post_alignment,
|
|
enum region_type type, ...);
|
|
-#endif
|
|
|
|
#endif /* NBDKIT_REGIONS_H */
|
|
--
|
|
2.31.1
|
|
|