• Post Reply Bookmark Topic Watch Topic
  • New Topic

File Locing on CIFS  RSS feed

Ahmed Faizabadi
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ( \\\blah.. ). 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 <io.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/locking.h>
#include <share.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

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 )
fh = _sopen(filename , _O_RDWR, _SH_DENYNO, //_SH_DENYRW,
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\n" );
numread = _read( fh, buffer, 30 );
printf( "%d bytes read: %.30s\n", numread, buffer );
lseek( fh, 0L, SEEK_SET );
printf( "Press a key to unlock the file.....\n" );
_locking( fh, LK_UNLCK, 30L );

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

_close( fh );
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!