off_t smaller than Long; "Invalid argument" in FileLock.release

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

On every call to FileLock.release, I get an IOException with
message = "Invalid argument" or something like that.
FileLock.release eventually calls Java_gnu_java_nio_VMChannel_unlock
in native/jni/java-nio/gnu_java_nio_VMChannel.c, which in turn
calls cpnio_fcntl in native/jni/java-nio/javanio.c which punts to
the C system call fcntl. It appears fcntl returns -1 and sets errno
to indicate the "Invalid argument" message.

strace shows the following: the lock is created successfully:

fcntl(11, F_SETLKW, {type=F_WRLCK, whence=SEEK_SET, start=0, len=0}) = 0

but later on the attempt to release it fails:

fcntl(11, F_SETLK, {type=F_UNLCK, whence=SEEK_SET, start=0, len=-1}) =
-1 EINVAL (Invalid argument)

I believe the key here is that for the unlock call, len=-1.
I believe it should be 0 for the unlock call.

There is some logic in Java_gnu_java_nio_VMChannel_lock to
recognize Long.MAX_VALUE and substitute 0 for that, however,
there is no corresponding logic in Java_gnu_java_nio_VMChannel_unlock.
In that function, len is cast to off_t which is 4 bytes on the platform
of interest (ARM), so (I guess) that is the origin of the -1 in the
call to fcntl;
it's 0xFFFFFFFF (low 32 bits of Long.MAX_VALUE).

When I replace Long.MAX_VALUE with Integer.MAX_VALUE in my code,
strace shows that the call to fcntl to unlock returns 0 (success).

At this point I will suggest that Java_gnu_java_nio_VMChannel_unlock
be equipped to detect len = Long.MAX_VALUE and substitute 0,
as in Java_gnu_java_nio_VMChannel_lock.

(I was using Long.MAX_VALUE in my code since from reading the
documentation for java.nio.channels.FileChannel,
http://java.sun.com/j2se/1.4.2/docs/api/java/nio/channels/FileChannel.html
it appears that Long.MAX_VALUE is a special value.
Yes, it's not really necessary for me to do so, but Classpath should
handle it correctly. I don't know what, in general, Classpath should do if
off_t is smaller than Long.)

HTH & all the best.

Robert Dodier


[Index of Archives]     [Linux Kernel]     [Linux Cryptography]     [Fedora]     [Fedora Directory]     [Red Hat Development]

  Powered by Linux