winfsp / cgofuse

Cross-platform FUSE library for Go - Works on Windows, macOS, Linux, FreeBSD, NetBSD, OpenBSD
https://winfsp.dev
MIT License
514 stars 82 forks source link

O_RDONLY and friends are missing #3

Closed ncw closed 7 years ago

ncw commented 7 years ago

Normally I'd read O_RDONLY from syscall, but I don't think that will work on Windows, so thsese constants need to be duplicated in cgofuse.

These are necessary when working out which mode to open a file in (read or write) when the flags just can't be passed on.

ncw commented 7 years ago

If you want I'll send a PR for this - I just wanted to make a note of this before a forgot!

billziss-gh commented 7 years ago

Good catch. We would have to make it cross-platform (constants are not same on UNIX and Windows).

If you have the code ready you can send a PR. Otherwise I will add it and make sure it is correct on all supported platforms.

billziss-gh commented 7 years ago

Ok, I am finishing some testing using CGODEBUG=cgocheck=2 (as per your suggestion in the rclone issue) and I will add those flags.

billziss-gh commented 7 years ago

Commit 67b4cc0079281d71c50adc57badb53685a84f225 just added these flags. Testing it now.

billziss-gh commented 7 years ago

Merged into master.

ncw commented 7 years ago

Super - thank you :-)

O_ACCMODE would be useful too for masking whether the mode is read or write. Here is the libc doc it says GNU only, but it is mentioned in the posix fnctl docs. Note sure whether that is supported on Windows though.

billziss-gh commented 7 years ago

MSVC does not define O_ACCMODE. It turns out that Mingw does as:

#define _O_ACCMODE (_O_RDONLY|_O_WRONLY|_O_RDWR)

So I will add a similar definition to fuse.go.

billziss-gh commented 7 years ago

Added with commit 3650807204ba06ebebf426b2a22b0f4b177ff595.

Please note that on Windows O_RDONLY == 0, O_WRONLY == 1 and O_RDWR == 2. So do not assume that O_RDONLY|O_WRONLY == O_RDWR.

ncw commented 7 years ago

That seems very sensible - thanks :+1: