]> git.proxmox.com Git - pve-qemu.git/blob - debian/patches/pve/0012-PVE-Up-qemu-img-dd-add-isize-parameter.patch
a2b6deb229eeaefb83503332b4fab90839f0d171
[pve-qemu.git] / debian / patches / pve / 0012-PVE-Up-qemu-img-dd-add-isize-parameter.patch
1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: Wolfgang Bumiller <w.bumiller@proxmox.com>
3 Date: Mon, 6 Apr 2020 12:16:41 +0200
4 Subject: [PATCH] PVE: [Up] qemu-img dd: add isize parameter
5
6 for writing small images from stdin to bigger ones
7
8 In order to distinguish between an actually unexpected and
9 an expected end of input.
10
11 Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
12 Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
13 ---
14 qemu-img.c | 29 ++++++++++++++++++++++++++---
15 1 file changed, 26 insertions(+), 3 deletions(-)
16
17 diff --git a/qemu-img.c b/qemu-img.c
18 index 6b7d1fcb51..17393b2f53 100644
19 --- a/qemu-img.c
20 +++ b/qemu-img.c
21 @@ -4445,11 +4445,13 @@ out:
22 #define C_OF 010
23 #define C_SKIP 020
24 #define C_OSIZE 040
25 +#define C_ISIZE 0100
26
27 struct DdInfo {
28 unsigned int flags;
29 int64_t count;
30 int64_t osize;
31 + int64_t isize;
32 };
33
34 struct DdIo {
35 @@ -4542,6 +4544,20 @@ static int img_dd_osize(const char *arg,
36 return 0;
37 }
38
39 +static int img_dd_isize(const char *arg,
40 + struct DdIo *in, struct DdIo *out,
41 + struct DdInfo *dd)
42 +{
43 + dd->isize = cvtnum(arg);
44 +
45 + if (dd->isize < 0) {
46 + error_report("invalid number: '%s'", arg);
47 + return 1;
48 + }
49 +
50 + return 0;
51 +}
52 +
53 static int img_dd(int argc, char **argv)
54 {
55 int ret = 0;
56 @@ -4556,12 +4572,14 @@ static int img_dd(int argc, char **argv)
57 int c, i;
58 const char *out_fmt = "raw";
59 const char *fmt = NULL;
60 - int64_t size = 0;
61 + int64_t size = 0, readsize = 0;
62 int64_t block_count = 0, out_pos, in_pos;
63 bool force_share = false;
64 struct DdInfo dd = {
65 .flags = 0,
66 .count = 0,
67 + .osize = 0,
68 + .isize = -1,
69 };
70 struct DdIo in = {
71 .bsz = 512, /* Block size is by default 512 bytes */
72 @@ -4583,6 +4601,7 @@ static int img_dd(int argc, char **argv)
73 { "of", img_dd_of, C_OF },
74 { "skip", img_dd_skip, C_SKIP },
75 { "osize", img_dd_osize, C_OSIZE },
76 + { "isize", img_dd_isize, C_ISIZE },
77 { NULL, NULL, 0 }
78 };
79 const struct option long_options[] = {
80 @@ -4789,14 +4808,18 @@ static int img_dd(int argc, char **argv)
81
82 in.buf = g_new(uint8_t, in.bsz);
83
84 - for (out_pos = 0; in_pos < size; block_count++) {
85 + readsize = (dd.isize > 0) ? dd.isize : size;
86 + for (out_pos = 0; in_pos < readsize; block_count++) {
87 int in_ret, out_ret;
88 - size_t in_bsz = in_pos + in.bsz > size ? size - in_pos : in.bsz;
89 + size_t in_bsz = in_pos + in.bsz > readsize ? readsize - in_pos : in.bsz;
90 if (blk1) {
91 in_ret = blk_pread(blk1, in_pos, in.buf, in_bsz);
92 } else {
93 in_ret = read(STDIN_FILENO, in.buf, in_bsz);
94 if (in_ret == 0) {
95 + if (dd.isize == 0) {
96 + goto out;
97 + }
98 /* early EOF is considered an error */
99 error_report("Input ended unexpectedly");
100 ret = -1;