summaryrefslogtreecommitdiffstats
path: root/sys/boot/ofw/libofw/ofw_copy.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/boot/ofw/libofw/ofw_copy.c')
-rw-r--r--sys/boot/ofw/libofw/ofw_copy.c33
1 files changed, 30 insertions, 3 deletions
diff --git a/sys/boot/ofw/libofw/ofw_copy.c b/sys/boot/ofw/libofw/ofw_copy.c
index ecfb8e6..1ae37c7 100644
--- a/sys/boot/ofw/libofw/ofw_copy.c
+++ b/sys/boot/ofw/libofw/ofw_copy.c
@@ -34,6 +34,8 @@
#include "libofw.h"
+#define READIN_BUF (4 * 1024)
+
ssize_t
ofw_copyin(const void *src, vm_offset_t dest, const size_t len)
{
@@ -51,7 +53,32 @@ ofw_copyout(const vm_offset_t src, void *dest, const size_t len)
ssize_t
ofw_readin(const int fd, vm_offset_t dest, const size_t len)
{
- return(read(fd, (void *) dest, len));
-}
+ void *buf;
+ size_t resid, chunk, get;
+ ssize_t got;
+ vm_offset_t p;
+
+ p = dest;
+
+ chunk = min(READIN_BUF, len);
+ buf = malloc(chunk);
+ if (buf == NULL) {
+ printf("ofw_readin: buf malloc failed\n");
+ return(0);
+ }
-
+ for (resid = len; resid > 0; resid -= got, p += got) {
+ get = min(chunk, resid);
+ got = read(fd, buf, get);
+
+ if (got <= 0) {
+ printf("ofw_readin: read failed\n");
+ break;
+ }
+
+ bcopy(buf, (void *)p, got);
+ }
+
+ free(buf);
+ return(len - resid);
+}
OpenPOWER on IntegriCloud