dcsimg
File Locking on CIFS fails using Java but succeeds using C
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Ahmed_Faizabadi
Posted On:   Wednesday, January 5, 2005 06:00 AM

I am trying to lock a file using FileChannel's lock method on a CIFS file system. My application is on windows and the CIFS is accessed using UNC format ( \1.2.3.4 lah.. ). I get the following error java.io.IOException: The network request is not supported at sun.nio.ch.FileChannelImpl.lock0(Native Method) at sun.nio.ch.FileChannelImpl.lock(FileChannelImpl.java:750) at java.nio.channels.FileChannel.lock(FileChannel.java:865) From the same machine using the same UNC formatm, when I lock the file using windows C API, I can successfull lock. Anyone has any idea why JVM can not lock even using nio package. Shouldnt it use the same ( or similar ) API under the hood as its clear by the pa   More>>

I am trying to lock a file using FileChannel's lock method on a CIFS file system. My application is on windows and the CIFS is accessed using UNC format ( \1.2.3.4 lah.. ). I get the following error

			
java.io.IOException: The network request is not supported
at sun.nio.ch.FileChannelImpl.lock0(Native Method)
at sun.nio.ch.FileChannelImpl.lock(FileChannelImpl.java:750)
at java.nio.channels.FileChannel.lock(FileChannel.java:865)


From the same machine using the same UNC formatm, when I lock the file using windows C API, I can successfull lock.

Anyone has any idea why JVM can not lock even using nio package. Shouldnt it use the same ( or similar ) API under the hood as its clear by the package name java.nio



The C program I am using is

			
#include
#include
#include
#include
#include
#include
#include
#include
#include

void main( int argc, char **argv )
{
int fh,numread;
char buffer[40];
char filename[500];
/* Quit if can't open file or system doesn't
* support sharing.
*/
if ( argc > 1 )
strcpy(filename,argv[1]);
else
strcpy(filename,"locking.c");
fh = _sopen(filename , _O_RDWR, _SH_DENYNO, //_SH_DENYRW,
_S_IREAD | _S_IWRITE );
if( fh == -1 )
exit( 1 );

/* Lock some bytes and read them. Then unlock. */
if( _locking( fh, LK_NBLCK, 30L ) != -1 )
{
printf( "No one can change these bytes while I'm reading them
" );
numread = _read( fh, buffer, 30 );
printf( "%d bytes read: %.30s
", numread, buffer );
lseek( fh, 0L, SEEK_SET );
printf( "Press a key to unlock the file.....
" );
getchar();
_locking( fh, LK_UNLCK, 30L );

printf( "Now I'm done. Do what you will with them
" );
}
else
perror( "Locking failed
" );

_close( fh );
}

   <<Less
About | Sitemap | Contact