views:

50

answers:

1

I'm trying to get a file lock across a mount point via Java 6 on OSX:

private void tryLockThroughShare() {
    String path = "/Volumes/Groups/mcm/javaTestInShare.txt";

    try {
        RandomAccessFile raf = new RandomAccessFile(path, "rw");
        FileLock flock = raf.getChannel().tryLock();
        System.out.printf("File %s is %s\n", path, (flock != null) ?

("locked") : ("not locked")); raf.write("yoo hoo!".getBytes()); raf.close(); } catch (IOException e) { e.printStackTrace(); } }

When I mount a volume using either AFP or SMB, even though I can write files in the mounted destination, I cannot lock them, receiving instead: IOException (Operation not supported).

After some experimentation I found I could lock when the volume was setup using NFS.

Has anyone found a way to lock a file across a SMB or AFP mount?

A: 

The exception you are getting says it all IOException (Operation not supported). Different file systems have different capabilities and locking is one of them. The Wikipedia Comparison of file systems though it does not mention locking really makes this point clear.

When you are accessing files via SMB or AFP you are effectively using those as the file system, and they are file systems that are not very rich in capabilities. Unfortunately you cannot assume that all the capabilities of the actual file system on which the files are stored will be available via SMB or AFP.

The goal of the SMB protocol is to provide shared access to files, printers and the like on a network, because devices on the network are heterogeneous the protocol limits its functionality to the most universally supported features.

Tendayi Mawushe