Skip to content

Commit 9f8d0d8

Browse files
committed
gccgo: replace syscall.NAME_MAX with unix.NAME_MAX
For some reason the syscall.NAME_MAX constant does not exist on gccgo, and it does not hurt us to use unix.NAME_MAX instead. #201
1 parent 26ba810 commit 9f8d0d8

File tree

5 files changed

+14
-7
lines changed

5 files changed

+14
-7
lines changed

internal/fusefrontend_reverse/ctlsock_interface.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ package fusefrontend_reverse
33
import (
44
"path/filepath"
55
"strings"
6-
"syscall"
6+
7+
"golang.org/x/sys/unix"
78

89
"github.com/rfjakob/gocryptfs/internal/ctlsock"
910
"github.com/rfjakob/gocryptfs/internal/pathiv"
@@ -23,7 +24,7 @@ func (rfs *ReverseFS) EncryptPath(plainPath string) (string, error) {
2324
for _, part := range parts {
2425
dirIV := pathiv.Derive(cipherPath, pathiv.PurposeDirIV)
2526
encryptedPart := rfs.nameTransform.EncryptName(part, dirIV)
26-
if rfs.args.LongNames && len(encryptedPart) > syscall.NAME_MAX {
27+
if rfs.args.LongNames && len(encryptedPart) > unix.NAME_MAX {
2728
encryptedPart = rfs.nameTransform.HashLongName(encryptedPart)
2829
}
2930
cipherPath = filepath.Join(cipherPath, encryptedPart)

internal/fusefrontend_reverse/reverse_longnames.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
"syscall"
88
"time"
99

10+
"golang.org/x/sys/unix"
11+
1012
"github.com/hanwen/go-fuse/fuse"
1113
"github.com/hanwen/go-fuse/fuse/nodefs"
1214

@@ -80,7 +82,7 @@ func (rfs *ReverseFS) findLongnameParent(dir string, dirIV []byte, longname stri
8082
continue
8183
}
8284
cName := rfs.nameTransform.EncryptName(plaintextName, dirIV)
83-
if len(cName) <= syscall.NAME_MAX {
85+
if len(cName) <= unix.NAME_MAX {
8486
// Entry should have been skipped by the "continue" above
8587
log.Panic("logic error or wrong shortNameMax constant?")
8688
}

internal/fusefrontend_reverse/rfs.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ func (rfs *ReverseFS) OpenDir(cipherPath string, context *fuse.Context) ([]fuse.
288288
cName = configfile.ConfDefaultName
289289
} else {
290290
cName = rfs.nameTransform.EncryptName(entries[i].Name, dirIV)
291-
if len(cName) > syscall.NAME_MAX {
291+
if len(cName) > unix.NAME_MAX {
292292
cName = rfs.nameTransform.HashLongName(cName)
293293
dotNameFile := fuse.DirEntry{
294294
Mode: virtualFileMode,

internal/nametransform/diriv.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"strings"
1010
"syscall"
1111

12+
"golang.org/x/sys/unix"
13+
1214
"github.com/rfjakob/gocryptfs/internal/cryptocore"
1315
"github.com/rfjakob/gocryptfs/internal/syscallcompat"
1416
"github.com/rfjakob/gocryptfs/internal/tlog"
@@ -111,7 +113,7 @@ func WriteDirIV(dirfd *os.File, dir string) error {
111113
// too long.
112114
func (be *NameTransform) encryptAndHashName(name string, iv []byte) string {
113115
cName := be.EncryptName(name, iv)
114-
if be.longNames && len(cName) > syscall.NAME_MAX {
116+
if be.longNames && len(cName) > unix.NAME_MAX {
115117
return be.HashLongName(cName)
116118
}
117119
return cName
@@ -128,7 +130,7 @@ func (be *NameTransform) EncryptPathDirIV(plainPath string, rootDir string) (str
128130
}
129131
// Reject names longer than 255 bytes.
130132
baseName := filepath.Base(plainPath)
131-
if len(baseName) > syscall.NAME_MAX {
133+
if len(baseName) > unix.NAME_MAX {
132134
return "", syscall.ENAMETOOLONG
133135
}
134136
// If we have the iv and the encrypted directory name in the cache, we

internal/syscallcompat/getdents_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"syscall"
1010
"testing"
1111

12+
"golang.org/x/sys/unix"
13+
1214
"github.com/hanwen/go-fuse/fuse"
1315
)
1416

@@ -28,7 +30,7 @@ func testGetdents(t *testing.T) {
2830
if err != nil {
2931
t.Fatal(err)
3032
}
31-
for i := 1; i <= syscall.NAME_MAX; i++ {
33+
for i := 1; i <= unix.NAME_MAX; i++ {
3234
n := strings.Repeat("x", i)
3335
err = ioutil.WriteFile(testDir+"/"+n, nil, 0600)
3436
if err != nil {

0 commit comments

Comments
 (0)