From 72815b26780df8500a13b607aa603a9a4c3490c9 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Thu, 1 Feb 2018 23:32:29 +0100 Subject: [PATCH] Improve gccgo compatibility Still fails, but with a clearer error message: $ go.gcc build internal/syscallcompat/unix2syscall_linux.go:32:13: error: incompatible types in assignment (cannot use type int64 as type syscall.Timespec_sec_t) s.Atim.Sec = u.Atim.Sec ^ internal/syscallcompat/unix2syscall_linux.go:33:14: error: incompatible types in assignment (cannot use type int64 as type syscall.Timespec_nsec_t) s.Atim.Nsec = u.Atim.Nsec ^ internal/syscallcompat/unix2syscall_linux.go:35:13: error: incompatible types in assignment (cannot use type int64 as type syscall.Timespec_sec_t) s.Mtim.Sec = u.Mtim.Sec ^ internal/syscallcompat/unix2syscall_linux.go:36:14: error: incompatible types in assignment (cannot use type int64 as type syscall.Timespec_nsec_t) s.Mtim.Nsec = u.Mtim.Nsec ^ internal/syscallcompat/unix2syscall_linux.go:38:13: error: incompatible types in assignment (cannot use type int64 as type syscall.Timespec_sec_t) s.Ctim.Sec = u.Ctim.Sec ^ internal/syscallcompat/unix2syscall_linux.go:39:14: error: incompatible types in assignment (cannot use type int64 as type syscall.Timespec_nsec_t) s.Ctim.Nsec = u.Ctim.Nsec ^ --- .../fusefrontend_reverse/ctlsock_interface.go | 5 +++-- .../fusefrontend_reverse/reverse_longnames.go | 4 +++- internal/syscallcompat/unix2syscall_linux.go | 22 +++++++++++++++---- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/internal/fusefrontend_reverse/ctlsock_interface.go b/internal/fusefrontend_reverse/ctlsock_interface.go index 5f61f371..c8ac3792 100644 --- a/internal/fusefrontend_reverse/ctlsock_interface.go +++ b/internal/fusefrontend_reverse/ctlsock_interface.go @@ -3,7 +3,8 @@ package fusefrontend_reverse import ( "path/filepath" "strings" - "syscall" + + "golang.org/x/sys/unix" "github.com/rfjakob/gocryptfs/internal/ctlsock" "github.com/rfjakob/gocryptfs/internal/pathiv" @@ -23,7 +24,7 @@ func (rfs *ReverseFS) EncryptPath(plainPath string) (string, error) { for _, part := range parts { dirIV := pathiv.Derive(cipherPath, pathiv.PurposeDirIV) encryptedPart := rfs.nameTransform.EncryptName(part, dirIV) - if rfs.args.LongNames && len(encryptedPart) > syscall.NAME_MAX { + if rfs.args.LongNames && len(encryptedPart) > unix.NAME_MAX { encryptedPart = rfs.nameTransform.HashLongName(encryptedPart) } cipherPath = filepath.Join(cipherPath, encryptedPart) diff --git a/internal/fusefrontend_reverse/reverse_longnames.go b/internal/fusefrontend_reverse/reverse_longnames.go index 5ea7c0a1..46f7399a 100644 --- a/internal/fusefrontend_reverse/reverse_longnames.go +++ b/internal/fusefrontend_reverse/reverse_longnames.go @@ -7,6 +7,8 @@ import ( "syscall" "time" + "golang.org/x/sys/unix" + "github.com/hanwen/go-fuse/fuse" "github.com/hanwen/go-fuse/fuse/nodefs" @@ -80,7 +82,7 @@ func (rfs *ReverseFS) findLongnameParent(dir string, dirIV []byte, longname stri continue } cName := rfs.nameTransform.EncryptName(plaintextName, dirIV) - if len(cName) <= syscall.NAME_MAX { + if len(cName) <= unix.NAME_MAX { // Entry should have been skipped by the "continue" above log.Panic("logic error or wrong shortNameMax constant?") } diff --git a/internal/syscallcompat/unix2syscall_linux.go b/internal/syscallcompat/unix2syscall_linux.go index 31620258..552d2af2 100644 --- a/internal/syscallcompat/unix2syscall_linux.go +++ b/internal/syscallcompat/unix2syscall_linux.go @@ -10,7 +10,7 @@ import ( // A direct cast does not work because the padding is named differently in // unix.Stat_t for some reason ("X__unused" in syscall, "_" in unix). func Unix2syscall(u unix.Stat_t) syscall.Stat_t { - return syscall.Stat_t{ + s := syscall.Stat_t{ Dev: u.Dev, Ino: u.Ino, Nlink: u.Nlink, @@ -21,8 +21,22 @@ func Unix2syscall(u unix.Stat_t) syscall.Stat_t { Size: u.Size, Blksize: u.Blksize, Blocks: u.Blocks, - Atim: syscall.Timespec(u.Atim), - Mtim: syscall.Timespec(u.Mtim), - Ctim: syscall.Timespec(u.Ctim), + // Casting unix.Timespec to syscall.Timespec does not work on gccgo: + // > cannot use type int64 as type syscall.Timespec_sec_t + // So do it manually, element-wise. + // + //Atim: syscall.Timespec(u.Atim), + //Mtim: syscall.Timespec(u.Mtim), + //Ctim: syscall.Timespec(u.Ctim), } + s.Atim.Sec = u.Atim.Sec + s.Atim.Nsec = u.Atim.Nsec + + s.Mtim.Sec = u.Mtim.Sec + s.Mtim.Nsec = u.Mtim.Nsec + + s.Ctim.Sec = u.Ctim.Sec + s.Ctim.Nsec = u.Ctim.Nsec + + return s }