

jread() and jpread() can return partial reads under some circumnstances; this
is quite wrong, dangerous and seriously broken, and I shouldn't have let it
happen.

I guess I was quite distracted when I wrote those wrappers.

This patch make jread() and jpread() use spread() which never returns partial
reads, unless there was an error.

jreadv() is not fixed and can potentially have the same issue too; but I'll
leave the fix for another patch because it's much more complex and I don't
even know if it's worth it (people doing scatter/gather I/O should already be
taking care of this).



---

 cur-root/libjio.c |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)

diff -puN libjio.c~spread_in_wrappers libjio.c
--- cur/libjio.c~spread_in_wrappers	2004-05-05 19:56:52.000000000 -0300
+++ cur-root/libjio.c	2004-05-05 20:07:33.000000000 -0300
@@ -507,10 +507,18 @@ ssize_t jread(struct jfs *fs, void *buf,
 	off_t pos;
 
 	pthread_mutex_lock(&(fs->lock));
+
 	pos = lseek(fs->fd, 0, SEEK_CUR);
+
 	plockf(fs->fd, F_LOCK, pos, count);
-	rv = read(fs->fd, buf, count);
+	rv = spread(fs->fd, buf, count, pos);
 	plockf(fs->fd, F_ULOCK, pos, count);
+
+	if (rv == count) {
+		/* if success, advance the file pointer */
+		lseek(fs->fd, count, SEEK_CUR);
+	}
+
 	pthread_mutex_unlock(&(fs->lock));
 
 	return rv;
@@ -522,7 +530,7 @@ ssize_t jpread(struct jfs *fs, void *buf
 	int rv;
 
 	plockf(fs->fd, F_LOCK, offset, count);
-	rv = pread(fs->fd, buf, count, offset);
+	rv = spread(fs->fd, buf, count, offset);
 	plockf(fs->fd, F_ULOCK, offset, count);
 	
 	return rv;

_
