

According to my fcntl's manpage, POSIX 1003.1-2001 allows l_len parameter to
be negative, and inside jread() and jreadv() we took advantage of that.
However, it also says that it's supported in Linux only since kernel 2.5.49
and 2.4.21, which is quite new.

With this patch we remove the need to use negative lenghts in lockf(), and use
our plockf() wrapper instead.

This has the bonus that on some systems the relation between lockf and fcntl
is unspecified, so we now use fcntl for all our locks.

Thanks to Pieter Grimmerink.



---

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

diff -puN libjio.c~lockf_negative_lenght libjio.c
--- cur/libjio.c~lockf_negative_lenght	2004-05-04 18:36:28.000000000 -0300
+++ cur-root/libjio.c	2004-05-04 20:55:19.000000000 -0300
@@ -503,11 +503,13 @@ int jopen(struct jfs *fs, const char *na
 ssize_t jread(struct jfs *fs, void *buf, size_t count)
 {
 	int rv;
+	off_t pos;
 
 	pthread_mutex_lock(&(fs->lock));
-	lockf(fs->fd, F_LOCK, count);
+	pos = lseek(fs->fd, 0, SEEK_CUR);
+	plockf(fs->fd, F_LOCK, pos, count);
 	rv = read(fs->fd, buf, count);
-	lockf(fs->fd, F_ULOCK, -count);
+	plockf(fs->fd, F_ULOCK, pos, count);
 	pthread_mutex_unlock(&(fs->lock));
 
 	return rv;
@@ -530,15 +532,17 @@ ssize_t jreadv(struct jfs *fs, struct io
 {
 	int rv, i;
 	size_t sum;
+	off_t pos;
 	
 	sum = 0;
 	for (i = 0; i < count; i++)
 		sum += vector[i].iov_len;
 	
 	pthread_mutex_lock(&(fs->lock));
-	lockf(fs->fd, F_LOCK, sum);
+	pos = lseek(fs->fd, 0, SEEK_CUR);
+	plockf(fs->fd, F_LOCK, pos, count);
 	rv = readv(fs->fd, vector, count);
-	lockf(fs->fd, F_ULOCK, -sum);
+	plockf(fs->fd, F_ULOCK, pos, count);
 	pthread_mutex_unlock(&(fs->lock));
 
 	return rv;

_
