JDK-6230772 : (fs) FileChannelImpl.c: off64_t should be used for flock64 (F_SETLK64) in 1.4.2_07 (lnx)
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 1.4.2_07
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: solaris_8
  • CPU: sparc
  • Submitted: 2005-02-18
  • Updated: 2015-04-13
  • Resolved: 2005-07-26
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.4.2_10 b01Fixed
Related Reports
Relates :  
Description
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

Comments
EVALUATION I have verified that the code in question was modified in Tiger during updates for this bug: 4854085: API method FileChannel.lock() works wrong on Linux I am investigating whether these changes are suitable for backport. ###@###.### 2005-2-18 21:09:41 GMT The supported configurations for jdk1.4.2 are listed here: http://java.sun.com/j2se/1.4.2/system-configurations.html It appears that the supported linux use kernels in the 2.4 line, so there is support for 64-bit flocks. We can backport all of the changes for bug 4854085. ###@###.### 2005-03-24 20:26:30 GMT
18-02-2005