Editing with vim clears Windows 10 file system archive bit.

Corinna Vinschen corinna-cygwin@cygwin.com
Tue Nov 16 14:06:27 GMT 2021

On Nov 15 14:18, Gary Johnson wrote:
> On 2021-11-15, Corinna Vinschen via Cygwin wrote:
> > Changing that is actually pretty simple, just set FILE_ATTRIBUTE_ARCHIVE
> > as soon as the underlying NtCreateFile is called for an open(O_CREAT).
> > 
> > Fixed in current git.
> I had thought that this might be a bug in Vim, so did a git bisect
> to find the offending commit.  For the record, it was this one:
> [...]
> The only change I see to an open() call was removing O_TRUNC on
> systems with ftruncate() and adding a later call to ftruncate() on
> systems that have it.  There were also some changes to the setting
> of permissions (fchown(), fchmod() and chmod()).  These changes were
> all in the buf_write() function in fileio.c.
> That open() call had the O_CREAT flag before and after the change.

You are sooo right.

My bugfix appears to work, but it's fixing a non-existent bug.
NtCreateFile actually sets the ARCHIVE bit all the time when creating a
new file, even if it's not explicitely given as parameter.  That makes a
lot of sense, of course, given how the archiving mechanism works on

The *real* problem is in fact that Cygwin caches the wrong file
attribute bits when creating a new file, and that's where fchmod fails:
It writes back the wrongly cached bits.  This doesn't happen with
chmod, because it re-opens the existing file and fetches the correct
attributes bit at the time.

I guess I'll revert my patch and create a new one which is more to the


More information about the Cygwin mailing list