Samba file locking

samba

I'd like to set up my samba server in the following way:

  1. Client 1 opens file A
  2. Client 2 attempts to open file A while Client 1 has it open
  3. Client 2 is granted read-only access to the file

Edit: All clients will be Windows XP or Windows 7 machines.

As per this page, what I want would be closest to a deny-mode of DENY_DOS, but I can't seem to make that option take effect.

Any help would be greatly appreciated.

Best Answer

You cannot force all programs to use the file locking mechanism provided by samba. A lot of 'simple' applications just open the file, make a local copy (either in memory or on local disk) and then close the original file, so the lock only lasts as long as the opening and copying action. Notepad is one example of this. Moreover, this is actually a feature of most progams, not a shortcoming.

Think about what happens when an applications crashes with the lock still in place. Programs using filesystem locks should be aware of it and its implications and have a recover and release mechanism. That's why 'simple' applications avoid filesystem locking.

If you really want to use some kind of 'in use' messages for all applications you should use a versioning system. As mentioned elsewhere on serverfault, this isn't necessarily a technical problem, more a social one: you'll have a hard time convincing non-technical people to actually use it.