From 2bd8c55b7f0485eb2c3f019fa3d1f0149af1fdff Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Thu, 21 Dec 2000 07:43:41 +0000 Subject: 2000-12-20 Roland McGrath * copy.c (copy_read): When reading whole aligned pages, use vm_read. Use MAP_FAILED in place of (void *) -1. Use memcpy in place of bcopy. (copy_write): When reading whole aligned pages, use vm_write. Use memcpy in place of bcopy. --- libstore/copy.c | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/libstore/copy.c b/libstore/copy.c index 3f838e5c..b5f00c3b 100644 --- a/libstore/copy.c +++ b/libstore/copy.c @@ -1,8 +1,8 @@ /* Copy store backend - Copyright (C) 1995, 1996, 1997, 1999 Free Software Foundation, Inc. + Copyright (C) 1995,96,97,99,2000 Free Software Foundation, Inc. - Written by Miles Bader + Written by Miles Bader This task is part of the GNU Hurd. @@ -31,15 +31,26 @@ static error_t copy_read (struct store *store, off_t addr, size_t index, size_t amount, void **buf, size_t *len) { + char *data = store->hook + (addr * store->block_size); + + if (page_aligned (data) && page_aligned (amount)) + { + /* When reading whole pages, we can avoid any real copying. */ + error_t err = vm_read (mach_task_self (), + (vm_address_t) data, amount, (pointer_t *) buf); + *len = amount; + return err; + } + if (*len < amount) /* Have to allocate memory for the return value. */ { *buf = mmap (0, amount, PROT_READ|PROT_WRITE, MAP_ANON, 0, 0); - if (*buf == (void *)-1) + if (*buf == MAP_FAILED) return errno; } - bcopy (store->hook + (addr * store->block_size), *buf, amount); + memcpy (*buf, data, amount); *len = amount; return 0; } @@ -48,7 +59,18 @@ static error_t copy_write (struct store *store, off_t addr, size_t index, void *buf, size_t len, size_t *amount) { - bcopy (buf, store->hook + (addr * store->block_size), len); + char *data = store->hook + (addr * store->block_size); + + if (page_aligned (data) && page_aligned (len)) + { + /* When reading whole pages, we can avoid any real copying. */ + error_t err = vm_write (mach_task_self (), + (vm_address_t) data, buf, len); + *amount = len; + return err; + } + + memcpy (data, buf, amount); *amount = len; return 0; } -- cgit v1.2.3