Skip to content

Mixup of O_EXCL and O_TRUNC constant values CGO vs non CGO #66

@ncw

Description

@ncw

If you compile and run this program

package main

import (
	"fmt"

	"github.com/winfsp/cgofuse/fuse"
)

func main() {
	fmt.Printf("fuse.O_APPEND = 0x%04x\n", fuse.O_APPEND)
	fmt.Printf("fuse.O_CREAT  = 0x%04x\n", fuse.O_CREAT)
	fmt.Printf("fuse.O_EXCL   = 0x%04x\n", fuse.O_EXCL)
	fmt.Printf("fuse.O_TRUNC  = 0x%04x\n", fuse.O_TRUNC)
}

It prints this

Z:\go\src\github.com\rclone\rclone\cgofusetest>go run test.go
fuse.O_APPEND = 0x0008
fuse.O_CREAT  = 0x0100
fuse.O_EXCL   = 0x0400
fuse.O_TRUNC  = 0x0200

However if you disable CGO and compile it you get a different answer with O_EXCL and O_TRUNC swapped over.

Z:\go\src\github.com\rclone\rclone\cgofusetest>set CGO_ENABLED=0

Z:\go\src\github.com\rclone\rclone\cgofusetest>go run test.go
fuse.O_APPEND = 0x0008
fuse.O_CREAT  = 0x0100
fuse.O_EXCL   = 0x0200
fuse.O_TRUNC  = 0x0400

I believe the non CGO version is correct, at least that agrees with what I receive from WinFSP. It is defined here

O_EXCL = 0x0200
O_TRUNC = 0x0400

whereas the CGO version is defined here - this also looks correct

cgofuse/fuse/fsop_cgo.go

Lines 249 to 250 in f0ad031

O_EXCL = int(C.O_EXCL)
O_TRUNC = int(C.O_TRUNC)

So something a little wacky is going on!

This is compiling on Windows 10 with go1.18.1 and gcc 8.1.0 provided by MinGW using latest released cgofuse v1.5.0 and latest stable WinFSP (2022 installed from 1.10.220006.msi).

This was originally reported in the rclone forum here: https://forum.rclone.org/t/cannot-copy-files-to-mounted-azure-storage-windows/30092 if you want some background.

I suspect that the problem might be with the WinFSP include files, but I couldn't figure out where the constants were defined.

You said before in #19 (comment) where we discussed a very similar issue

WinFsp-FUSE supports both the MSVC and Cygwin environments. In MSVC O_CREAT|O_RDWR translates to 0x0102. In Cygwin it translates to 0x0202. Cgofuse uses the MSVC environment, which is the reason you see 0x0102.

So I wonder if I'm including the Cygwin version of the fuse header files or something like that? This is the include I use

CPATH=C:\Program Files\WinFsp\inc\fuse;C:\Program Files (x86)\WinFsp\inc\fuse

Any help gratefully received!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions