From ed1eac71f485d8f1456ed7d5c8f1260d4462d38b Mon Sep 17 00:00:00 2001 From: Poul-Henning Kamp Date: Tue, 7 Oct 2003 07:12:22 +0000 Subject: [PATCH] Add XXX'ed temporary bounce-buffering. --- lib/libufs/block.c | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/lib/libufs/block.c b/lib/libufs/block.c index 592e15a2339d..c4ff30482707 100644 --- a/lib/libufs/block.c +++ b/lib/libufs/block.c @@ -40,6 +40,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -48,17 +49,24 @@ __FBSDID("$FreeBSD$"); ssize_t bread(struct uufsd *disk, ufs2_daddr_t blockno, void *data, size_t size) { - char *buf; + void *p2; ssize_t cnt; ERROR(disk, NULL); + p2 = data; /* - * For when we need to work with the data as a buffer. + * XXX: various disk controllers require alignment of our buffer + * XXX: which is stricter than struct alignment. + * XXX: Bounce the buffer if not 64 byte aligned. + * XXX: this can be removed if/when the kernel is fixed */ - buf = data; - - cnt = pread(disk->d_fd, data, size, (off_t)(blockno * disk->d_bsize)); + if (((intptr_t)data) & 0x3f) { + p2 = malloc(size); + if (p2 == NULL) + ERROR(disk, "allocate bounce buffer"); + } + cnt = pread(disk->d_fd, p2, size, (off_t)(blockno * disk->d_bsize)); if (cnt == -1) { ERROR(disk, "read error from block device"); goto fail; @@ -71,8 +79,15 @@ bread(struct uufsd *disk, ufs2_daddr_t blockno, void *data, size_t size) ERROR(disk, "short read or read error from block device"); goto fail; } + if (p2 != data) { + memcpy(data, p2, size); + free(p2); + } return (cnt); -fail: memset(buf, 0, size); +fail: memset(data, 0, size); + if (p2 != data) { + free(p2); + } return (-1); } @@ -81,6 +96,7 @@ bwrite(struct uufsd *disk, ufs2_daddr_t blockno, const void *data, size_t size) { ssize_t cnt; int rv; + void *p2 = NULL; ERROR(disk, NULL); @@ -90,7 +106,22 @@ bwrite(struct uufsd *disk, ufs2_daddr_t blockno, const void *data, size_t size) return (-1); } + /* + * XXX: various disk controllers require alignment of our buffer + * XXX: which is stricter than struct alignment. + * XXX: Bounce the buffer if not 64 byte aligned. + * XXX: this can be removed if/when the kernel is fixed + */ + if (((intptr_t)data) & 0x3f) { + p2 = malloc(size); + if (p2 == NULL) + ERROR(disk, "allocate bounce buffer"); + memcpy(p2, data, size); + data = p2; + } cnt = pwrite(disk->d_fd, data, size, (off_t)(blockno * disk->d_bsize)); + if (p2 != NULL) + free(p2); if (cnt == -1) { ERROR(disk, "write error to block device"); return (-1);