emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Locking files for CLASH_DETECTION now supported on MS-Windows


From: Eli Zaretskii
Subject: Re: Locking files for CLASH_DETECTION now supported on MS-Windows
Date: Tue, 26 Feb 2013 20:41:34 +0200

> Date: Mon, 25 Feb 2013 22:05:15 -0800
> From: Paul Eggert <address@hidden>
> CC: address@hidden
> 
> On 02/25/2013 08:02 PM, Eli Zaretskii wrote:> 
> 
> > On Windows, as long as a file is open, no
> > other application can write to it or remove the file.
> 
> Is this true even if the file is network-mounted via NFS or CIFS?

It is true if the other process runs on the same machine, I think.

> > Is that the "atomic" nature you wanted?
> 
> Partly, but it's not sufficient.  I assume that one process can
> read a file while another is writing to it

That depends on how each process opens the file, exactly.  It can be
arranged that no other process can open the same file, although I
think the default open flags don't do that.

> which means that the readlink and symlink replacements may not be
> atomic.

Don't know about this part, I will have to run some tests.  Since
changes in file metadata _are_ atomic on NTFS (see below) the answer
to that appears to depend on whether NTFS symlinks are implemented as
metadata or as data.  I don't know which is the case, for now.

> I mean that there's an abstract machine where a symbolic link is
> either present or absent, and where readlink ("a", ...),
> symlink ("b", "a"), and unlink ("a") either succeed or fail and affect
> the abstract machine in an all-or-nothing way.  For example, if
> the symbolic link doesn't exist and one process runs
> symlink ("very long link contents", "a")
> at the same time another process runs readlink ("a", buf, sizeof buf)
> where buf is large enough, then the readlink should either fail
> (no symlink present yet) or should succeed with
> the buffer containing all the link contents; it shouldn't succeed with
> partial contents such as "very long link co".

It's hard to give a definitive answer to that, as documentation is
scarce and most of it unofficial.  My conclusion from reading a lot of
technical stuff is that changes to file metadata are atomic on NTFS,
and single-sector read/write operations are also atomic.  That means
'unlink' (file deletion) is atomic, as it affects metadata only, and
so is 'rename' and 'chmod'.  Reads and writes are probably atomic as
long as they are short.  I found nothing about the APIs used by
'symlink' and 'readlink', so all I can say that I hope they are
atomic, because the amount of data they read/write is small.  I will
try to test this when I have time.

In any case, all this atomicity stuff is important for locking files
on Windows volumes, it won't help us with the more important problems
related to Posix and Windows hosts editing the same file on a
networked filesystem.  We could (and should) probably make the Windows
implementation of locking more robust in the face of potential races
between several instances of Emacs running on Windows, but that is
secondary to avoiding problems for Emacs running on Posix hosts.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]