[M3devel] random-acces I/O

hendrik at topoi.pooq.com hendrik at topoi.pooq.com
Sun Mar 2 14:12:47 CET 2008


On Sun, Mar 02, 2008 at 11:53:57AM +0100, Olaf Wagner wrote:
> Quoting Dragiša Durić <dragisha at m3w.org>:
> 
> >On Fri, 2008-02-29 at 17:41 -0500, hendrik at topoi.pooq.com wrote:
> >>  ? Are there methods for locking the file -- or portions of it --
> >>    against simutaneous access by other programs, including ones written
> >>    in other languages?
> >
> >  There are. But you have to make some rules, and follow them from all
> >users of your file.
> 
> File.T provides lock() and unlock() methods. You must be aware though
> that file locking is inherently depending on operating system and
> file system, and as far as I know there is not the slightest chance
> of a general applicable specification of locks. In CM3, the POSIX
> target use the POSIX advisory file locking, as far as I know, which
> means that only those interested in heeding the lock will see it.
> Nobody will prevent others from reading or writing the file.

Advisory is fine.

> 
> On Windows, the default behaviour for NTFS is completely different;
> on FAT file systems there are probably no locks at all.
> 
> If your files are located on an NFS share, locking depends on
> the implementation of the rpc.lockd on the server and on the quality
> of the NFS client; for SMBFS/SAMBA, it depends both on the onderlying  
> file system and on the configuration of SAMBA.

In Linux, locking via fcntl is NFS-safe.  locking via flock is 
apparently not.  lockf is implemented via fcntl, so it is presumably 
NFS-safe, too, although the spoecifications don't actually require it to 
be implemented via fcntl.

When I had NFS misconfigured (and I could find no information indicating 
how reconfigure it) one program (monotone) could not lock any NFS files, 
knwew it, and refused to operate as a result.   That's the safe way 
to deal with NFS misconfiguration.  I was annoyed, but overall I was 
quite impressed.  I suspect it used fcntl, though maybe I should ask.
The NFS configuration problem went away on its own during upgrades of 
etch (which at the time was Debian testing).  I have no idea what the 
problem was.

What primitive does Modula 3 use on Linux systems to perform locking?  
Let me hope for fcntl. Or lockf.  But not flock.

-- hendrik



More information about the M3devel mailing list