Skip to content

Conversation

ychin
Copy link
Contributor

@ychin ychin commented Feb 20, 2019

Correctly handle fcntl() failure when calling on unsupported storage systems (e.g. SMB network shared file). The current code only checks for ENOTTY but the OS actually returns ENOTSUP (45) when trying to save to a network shared file. Currently this incorrect handling leads to files not being properly fsync'ed and display a scary error to the user.

Reproduce

To reproduce this case, on a Mac, just mount a shared SMB drive (from Windows). Then try to open a shared network file and save to it. You see see an error saying "E667: Fsync failed".

Notes

Annoyingly, both ENOTTY and ENOTSUP error codes are not documented in the Apple fcntl man page.

Descriptions for ENOTSUP can be found here:

 45 ENOTSUP Not supported.  The attempted operation is not supported for
        the type of object referenced.

This makes sense to me because the docs says fcntl is only implemented for some filesystems so returning ENOTSUP just means you should use fsync as a backup.

An alternative is to simply not check error code and always try fsync as a backup.

Related

Correctly handle fcntl() failure when calling on unsupported storage
systems (e.g. SMB network shared file). The current code only checks for
ENOTTY but the OS actually returns ENOTSUP (45) when trying to save to a
network shared file. Currently this incorrect handling leads to files
not being properly fsync'ed and display a scary error to the user.
@brammool brammool closed this in 3585671 Feb 20, 2019
justinmk added a commit to justinmk/neovim that referenced this pull request Feb 20, 2019
macOS: Try direct fsync() if F_FULLFSYNC fails.
closes neovim#6725
ref vim/vim#4016
vim-patch:8.1.0957

> on macOS F_FULLFSYNC fails with ENOTSUP for unsupported storage systems
> (e.g. SMB), though this is not documented in the Apple fcntl man page.

libuv fixed this in v1.25.0:
libuv/libuv@6fc797c
justinmk added a commit to justinmk/neovim that referenced this pull request Feb 21, 2019
macOS: Try direct fsync() if F_FULLFSYNC fails.
closes neovim#6725
ref vim/vim#4016
vim-patch:8.1.0957

> on macOS F_FULLFSYNC fails with ENOTSUP for unsupported storage systems
> (e.g. SMB), though this is not documented in the Apple fcntl man page.

libuv fixed this in v1.25.0:
libuv/libuv@6fc797c
@ychin ychin deleted the mac-fsync-fix branch February 21, 2019 06:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants