diff options
author | Zheng Da <zhengda1936@gmail.com> | 2010-08-18 14:27:15 +0200 |
---|---|---|
committer | Zheng Da <zhengda1936@gmail.com> | 2010-08-18 14:27:15 +0200 |
commit | bbc9b208562c0497b0034e77369a07e2985ae763 (patch) | |
tree | 6def946fb4fadc52adcde4fd6ed44802b622f72e /libmachdev/block.c | |
parent | 529d8041be254a2ba56543953b1daf8f1c83a204 (diff) |
fix a bug in device_read for block devices.
Diffstat (limited to 'libmachdev/block.c')
-rw-r--r-- | libmachdev/block.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/libmachdev/block.c b/libmachdev/block.c index 2a4b9ae2..756a07bf 100644 --- a/libmachdev/block.c +++ b/libmachdev/block.c @@ -232,6 +232,7 @@ device_read (void *d, mach_port_t reply_port, int reads = 0; char *buf; int npages = (count + PAGE_SIZE - 1) / PAGE_SIZE; + int rest = count; void read_done (int err) { @@ -259,7 +260,7 @@ device_read (void *d, mach_port_t reply_port, ddekit_printf ("read %d pages.\n", npages); for (i = 0; i < npages; i++) { - int size = count > PAGE_SIZE ? PAGE_SIZE : count; + int size = rest > PAGE_SIZE ? PAGE_SIZE : rest; ddekit_printf ("read %d bytes starting from %d\n", size, bn); err = block_dev_rw (bd->dev, bn, buf + i * PAGE_SIZE, @@ -267,7 +268,7 @@ device_read (void *d, mach_port_t reply_port, if (err) break; bn += size >> 9; - count -= size; + rest -= size; reads++; } // TODO when should I deallocate the buffer? |