aboutsummaryrefslogtreecommitdiffstats
path: root/tools/xenpaging
diff options
context:
space:
mode:
authorOlaf Hering <olaf@aepfle.de>2011-11-20 17:01:39 +0100
committerOlaf Hering <olaf@aepfle.de>2011-11-20 17:01:39 +0100
commitf67baf4ff50865c06859c2f7164abbb5c6effeec (patch)
treee8d102d3d15c725b39c355276b248ef47e00f8dc /tools/xenpaging
parenta6254d1dba22962b08d056a54c5377b9b0e43689 (diff)
downloadxen-f67baf4ff50865c06859c2f7164abbb5c6effeec.tar.gz
xen-f67baf4ff50865c06859c2f7164abbb5c6effeec.tar.bz2
xen-f67baf4ff50865c06859c2f7164abbb5c6effeec.zip
xenpaging: simplify file_op
Catch lseek() errors. Use -1 as return value and let caller read errno. Remove const casts from buffer pointers, the page is writeable. Use wrapper for write() which matches the read() prototype. Remove unused stdarg.h inclusion. Remove unused macro. Signed-off-by: Olaf Hering <olaf@aepfle.de> Committed-by: Ian Jackson <ian.jackson.citrix.com>
Diffstat (limited to 'tools/xenpaging')
-rw-r--r--tools/xenpaging/file_ops.c29
1 files changed, 9 insertions, 20 deletions
diff --git a/tools/xenpaging/file_ops.c b/tools/xenpaging/file_ops.c
index 1032242c6a..079d2551a8 100644
--- a/tools/xenpaging/file_ops.c
+++ b/tools/xenpaging/file_ops.c
@@ -21,55 +21,44 @@
#include <unistd.h>
-#include <stdarg.h>
#include <xc_private.h>
-
-#define page_offset(_pfn) (((off_t)(_pfn)) << PAGE_SHIFT)
-
-
static int file_op(int fd, void *page, int i,
- ssize_t (*fn)(int, const void *, size_t))
+ ssize_t (*fn)(int, void *, size_t))
{
off_t seek_ret;
- int total;
+ int total = 0;
int bytes;
- int ret;
seek_ret = lseek(fd, i << PAGE_SHIFT, SEEK_SET);
+ if ( seek_ret == (off_t)-1 )
+ return -1;
- total = 0;
while ( total < PAGE_SIZE )
{
bytes = fn(fd, page + total, PAGE_SIZE - total);
if ( bytes <= 0 )
- {
- ret = -errno;
- goto err;
- }
+ return -1;
total += bytes;
}
return 0;
-
- err:
- return ret;
}
-static ssize_t my_read(int fd, const void *buf, size_t count)
+static ssize_t my_write(int fd, void *buf, size_t count)
{
- return read(fd, (void *)buf, count);
+ return write(fd, buf, count);
}
int read_page(int fd, void *page, int i)
{
- return file_op(fd, page, i, &my_read);
+ return file_op(fd, page, i, &read);
}
int write_page(int fd, void *page, int i)
{
- return file_op(fd, page, i, &write);
+ return file_op(fd, page, i, &my_write);
}