A customer has found out an exception at java.nio.channels.FileChannel#tryLock.
REPRODUCE :
Compile the attached test case("test.java") and launch "java test" in 1.4.2_07.
Then the following message appears.
goedel[42]% java test
ok
ng
java.io.IOException: Invalid argument
at sun.nio.ch.FileChannelImpl.lock0(Native Method)
at sun.nio.ch.FileChannelImpl.tryLock(FileChannelImpl.java:788)
at test.main(test.java:22)
INVESTIGATION :
The following source code is extracted from FileChannelImpl.c.
ALthough F_SETLK64 is used, "off_t" is used for some variable.
This seems to cause EINVAL in fcntl.
The customer wonders if "off64_t" is reasonable.....
(comment for explanation are added in the below source code.)
--- ./j2se/src/solaris/native/sun/nio/ch/FileChannelImpl.c ----
......
( about line# 240)
..
#ifdef __solaris__
typedef struct flock64 FLOCK;
#endif
#ifdef __linux__
/* Linux kernels, at least in the 2.2 series, don't really support 64-bit
* flocks, though they do define F_SETLK{,W}64 == F_SETLK{,W}.
*/
typedef struct flock FLOCK;
#endif
JNIEXPORT jint JNICALL
Java_sun_nio_ch_FileChannelImpl_lock0(JNIEnv *env, jobject this, jobject fdo,
jboolean block, jlong pos, jlong size,
jboolean shared)
{
jint fd = fdval(env, fdo);
jint lockResult = 0;
int cmd = 0;
FLOCK fl;
#ifdef __linux__
if (size > 0x7fffffff) {
size = 0x7fffffff;
}
#endif
fl.l_whence = SEEK_SET;
fl.l_len = (off_t)size; // off64_t should be used !?
fl.l_start = (off_t)pos; // off64_t should be used !?
if (shared == JNI_TRUE) {
fl.l_type = F_RDLCK;
} else {
fl.l_type = F_WRLCK;
}
if (block == JNI_TRUE) {
cmd = F_SETLKW64;
} else {
cmd = F_SETLK64;
}
lockResult = fcntl(fd, cmd, &fl);
.......
======
Actually, truss command shows as follows.
goedel[50] truss java test
......
close(7) = 0
fcntl(5, F_SETLK64, 0xFFBEECD8) = 0
fcntl(5, F_SETLK64, 0xFFBEEC70) = 0
okwrite(1, " o k", 2) = 2
write(1, "\n", 1) = 1
fcntl(5, F_SETLK64, 0xFFBEECD8) Err#22 EINVAL
open("/usr/dt/lib/nls/msg/C/SUNW_OST_OSLIB.cat", O_RDONLY) Err#2 ENOENT
open("/usr/lib/locale/C/LC_MESSAGES/SUNW_OST_OSLIB.mo", O_RDONLY) Err#2 ENOENT
ngwrite(1, " n g", 2) = 2
write(1, "\n", 1) = 1
java.io.IOException: Invalid argumentwrite(2, " j a v a . i o . I O E x".., 37) = 37
write(2, "\n", 1) = 1
at sun.nio.ch.FileChannelImpl.lock0(Native Method)write(2, "\t a t s u n . n i o .".., 51) = 51
write(2, "\n", 1) = 1
at sun.nio.ch.FileChannelImpl.tryLock(FileChannelImpl.java:788)write(2, "\t a t s u n . n i o .".., 64) = 64
poll(0xFB981B40, 0, 50) = 0
.....
###@###.### 2005-2-18 07:09:59 GMT
REPRODUCE :
Compile the attached test case("test.java") and launch "java test" in 1.4.2_07.
Then the following message appears.
goedel[42]% java test
ok
ng
java.io.IOException: Invalid argument
at sun.nio.ch.FileChannelImpl.lock0(Native Method)
at sun.nio.ch.FileChannelImpl.tryLock(FileChannelImpl.java:788)
at test.main(test.java:22)
INVESTIGATION :
The following source code is extracted from FileChannelImpl.c.
ALthough F_SETLK64 is used, "off_t" is used for some variable.
This seems to cause EINVAL in fcntl.
The customer wonders if "off64_t" is reasonable.....
(comment for explanation are added in the below source code.)
--- ./j2se/src/solaris/native/sun/nio/ch/FileChannelImpl.c ----
......
( about line# 240)
..
#ifdef __solaris__
typedef struct flock64 FLOCK;
#endif
#ifdef __linux__
/* Linux kernels, at least in the 2.2 series, don't really support 64-bit
* flocks, though they do define F_SETLK{,W}64 == F_SETLK{,W}.
*/
typedef struct flock FLOCK;
#endif
JNIEXPORT jint JNICALL
Java_sun_nio_ch_FileChannelImpl_lock0(JNIEnv *env, jobject this, jobject fdo,
jboolean block, jlong pos, jlong size,
jboolean shared)
{
jint fd = fdval(env, fdo);
jint lockResult = 0;
int cmd = 0;
FLOCK fl;
#ifdef __linux__
if (size > 0x7fffffff) {
size = 0x7fffffff;
}
#endif
fl.l_whence = SEEK_SET;
fl.l_len = (off_t)size; // off64_t should be used !?
fl.l_start = (off_t)pos; // off64_t should be used !?
if (shared == JNI_TRUE) {
fl.l_type = F_RDLCK;
} else {
fl.l_type = F_WRLCK;
}
if (block == JNI_TRUE) {
cmd = F_SETLKW64;
} else {
cmd = F_SETLK64;
}
lockResult = fcntl(fd, cmd, &fl);
.......
======
Actually, truss command shows as follows.
goedel[50] truss java test
......
close(7) = 0
fcntl(5, F_SETLK64, 0xFFBEECD8) = 0
fcntl(5, F_SETLK64, 0xFFBEEC70) = 0
okwrite(1, " o k", 2) = 2
write(1, "\n", 1) = 1
fcntl(5, F_SETLK64, 0xFFBEECD8) Err#22 EINVAL
open("/usr/dt/lib/nls/msg/C/SUNW_OST_OSLIB.cat", O_RDONLY) Err#2 ENOENT
open("/usr/lib/locale/C/LC_MESSAGES/SUNW_OST_OSLIB.mo", O_RDONLY) Err#2 ENOENT
ngwrite(1, " n g", 2) = 2
write(1, "\n", 1) = 1
java.io.IOException: Invalid argumentwrite(2, " j a v a . i o . I O E x".., 37) = 37
write(2, "\n", 1) = 1
at sun.nio.ch.FileChannelImpl.lock0(Native Method)write(2, "\t a t s u n . n i o .".., 51) = 51
write(2, "\n", 1) = 1
at sun.nio.ch.FileChannelImpl.tryLock(FileChannelImpl.java:788)write(2, "\t a t s u n . n i o .".., 64) = 64
poll(0xFB981B40, 0, 50) = 0
.....
###@###.### 2005-2-18 07:09:59 GMT
- relates to
-
JDK-6371627 (fc) IOException when trying to use FileChannel.lock on a file in ClearCase MVFS
- Closed