Skip to content

Commit

Permalink
Improve gccgo compatibility
Browse files Browse the repository at this point in the history
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
              ^
  • Loading branch information
rfjakob committed Feb 1, 2018
1 parent 26ba810 commit 72815b2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
5 changes: 3 additions & 2 deletions internal/fusefrontend_reverse/ctlsock_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion internal/fusefrontend_reverse/reverse_longnames.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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?")
}
Expand Down
22 changes: 18 additions & 4 deletions internal/syscallcompat/unix2syscall_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
}

0 comments on commit 72815b2

Please sign in to comment.