Tags: patch The new code for creating regular-file lock files has a problem if the system crashes while the lock file is being created: due to races inside the file system, if the crash occurs at the wrong time the file system may end up with an empty regular-file lock file, which after the reboot will cause Emacs to bypass locking for that file indefinitely (unless the empty lock file is removed manually by the user). On a POSIX-conforming system the problem can occur only if the system crashes just as a lock file is being created. Fixing this requires using a synchronization primitive such as fsync on the newly created file, before renaming it. While looking into this I noticed some other file synchronization problems. fsync is used sometimes when fdatasync will do. Emacs does not consistently retry fsync after being interrupted. It sometimes incorrectly reports an error merely because fsync isn't supported. And it sometimes incorrectly skips fsync merely because we are on a non-BSD system. Attached a patch which I'd like to install. If MS-Windows has fdatasync already this should build on MS-Windows; if not, the MS-Windows port needs to compile lib/fdatasync.c or support an fdatasync substitute in some other way.