nbdkit/0012-null-pattern-random-Make-these-plugins-work-on-32-bi.patch
2018-07-15 17:36:34 +01:00

143 lines
3.7 KiB
Diff

From 0c710f36c5e686ae0f02c67dc6b19e1622e23d8a Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Sun, 15 Jul 2018 17:32:22 +0100
Subject: [PATCH 12/12] null, pattern, random: Make these plugins work on 32
bit machines.
These plugins had copied code from the nbdkit-memory-plugin. The
memory plugin needs to store actual data in an array so uses size_t.
However these other plugins don't have to store anything and so shoule
use int64_t, enabling them to work on 32 bit platforms.
---
plugins/null/null.c | 10 +++-------
plugins/pattern/pattern.c | 12 ++++--------
plugins/random/random.c | 12 ++++--------
3 files changed, 11 insertions(+), 23 deletions(-)
diff --git a/plugins/null/null.c b/plugins/null/null.c
index 905cc64..1daafac 100644
--- a/plugins/null/null.c
+++ b/plugins/null/null.c
@@ -44,7 +44,7 @@
#include <nbdkit-plugin.h>
/* The size of disk in bytes (initialized by size=<SIZE> parameter). */
-static size_t size = 0;
+static int64_t size = 0;
static int
null_config (const char *key, const char *value)
@@ -55,11 +55,7 @@ null_config (const char *key, const char *value)
r = nbdkit_parse_size (value);
if (r == -1)
return -1;
- if (r > SIZE_MAX) {
- nbdkit_error ("size > SIZE_MAX");
- return -1;
- }
- size = (ssize_t) r;
+ size = r;
}
else {
nbdkit_error ("unknown parameter '%s'", key);
@@ -108,7 +104,7 @@ null_close (void *handle)
static int64_t
null_get_size (void *handle)
{
- return (int64_t) size;
+ return size;
}
/* Read data. */
diff --git a/plugins/pattern/pattern.c b/plugins/pattern/pattern.c
index e1dc798..11b258d 100644
--- a/plugins/pattern/pattern.c
+++ b/plugins/pattern/pattern.c
@@ -45,7 +45,7 @@
#include <nbdkit-plugin.h>
/* The size of disk in bytes (initialized by size=<SIZE> parameter). */
-static size_t size = 0;
+static int64_t size = 0;
static int
pattern_config (const char *key, const char *value)
@@ -56,11 +56,7 @@ pattern_config (const char *key, const char *value)
r = nbdkit_parse_size (value);
if (r == -1)
return -1;
- if (r > SIZE_MAX) {
- nbdkit_error ("size > SIZE_MAX");
- return -1;
- }
- size = (ssize_t) r;
+ size = r;
}
else {
nbdkit_error ("unknown parameter '%s'", key);
@@ -89,7 +85,7 @@ pattern_open (int readonly)
static int64_t
pattern_get_size (void *handle)
{
- return (int64_t) size;
+ return size;
}
#define MIN(a, b) ((a) < (b) ? (a) : (b))
@@ -102,7 +98,7 @@ pattern_pread (void *handle, void *buf, uint32_t count, uint64_t offset,
char *b = buf;
uint64_t d;
uint64_t o;
- size_t n;
+ uint32_t n;
while (count > 0) {
d = htobe64 (offset & ~7);
diff --git a/plugins/random/random.c b/plugins/random/random.c
index 185609d..8adc26e 100644
--- a/plugins/random/random.c
+++ b/plugins/random/random.c
@@ -45,7 +45,7 @@
#include <nbdkit-plugin.h>
/* The size of disk in bytes (initialized by size=<SIZE> parameter). */
-static size_t size = 0;
+static int64_t size = 0;
/* Seed. */
static uint32_t seed;
@@ -95,11 +95,7 @@ random_config (const char *key, const char *value)
r = nbdkit_parse_size (value);
if (r == -1)
return -1;
- if (r > SIZE_MAX) {
- nbdkit_error ("size > SIZE_MAX");
- return -1;
- }
- size = (ssize_t) r;
+ size = r;
}
else {
nbdkit_error ("unknown parameter '%s'", key);
@@ -129,7 +125,7 @@ random_open (int readonly)
static int64_t
random_get_size (void *handle)
{
- return (int64_t) size;
+ return size;
}
/* Read data. */
@@ -137,7 +133,7 @@ static int
random_pread (void *handle, void *buf, uint32_t count, uint64_t offset,
uint32_t flags)
{
- size_t i;
+ uint32_t i;
unsigned char *b = buf;
uint32_t s;
--
2.17.1