aboutsummaryrefslogtreecommitdiff
path: root/internal/nametransform
diff options
context:
space:
mode:
authorJakob Unterwurzacher2018-09-22 20:10:34 +0200
committerJakob Unterwurzacher2018-09-23 12:17:26 +0200
commitc270b21efc1d9ecbe5c913c733204f826e263747 (patch)
treef001342e38ab81eeea1292c7a405d30321624b6d /internal/nametransform
parent22fba4ac3ed09ba07d1defb60436fb7a17095d09 (diff)
fusefrontend: get rid of os.File* wrapping
Directly use int file descriptors for the dirfd and get rid of one level of indirection.
Diffstat (limited to 'internal/nametransform')
-rw-r--r--internal/nametransform/diriv.go14
-rw-r--r--internal/nametransform/longnames.go8
2 files changed, 11 insertions, 11 deletions
diff --git a/internal/nametransform/diriv.go b/internal/nametransform/diriv.go
index 1a72d2a..81e44da 100644
--- a/internal/nametransform/diriv.go
+++ b/internal/nametransform/diriv.go
@@ -44,8 +44,8 @@ func ReadDirIV(dir string) (iv []byte, err error) {
// ReadDirIVAt reads "gocryptfs.diriv" from the directory that is opened as "dirfd".
// Using the dirfd makes it immune to concurrent renames of the directory.
-func ReadDirIVAt(dirfd *os.File) (iv []byte, err error) {
- fdRaw, err := syscallcompat.Openat(int(dirfd.Fd()), DirIVFilename,
+func ReadDirIVAt(dirfd int) (iv []byte, err error) {
+ fdRaw, err := syscallcompat.Openat(dirfd, DirIVFilename,
syscall.O_RDONLY|syscall.O_NOFOLLOW, 0)
if err != nil {
return nil, fmt.Errorf("openat failed: %v", err)
@@ -82,16 +82,16 @@ func fdReadDirIV(fd *os.File) (iv []byte, err error) {
// "dir" should be a path (without slashes) relative to the directory
// described by "dirfd". This function is exported because it is used from
// pathfs_frontend, main, and also the automated tests.
-func WriteDirIV(dirfd *os.File, dir string) error {
+func WriteDirIV(dirfd int, dir string) error {
// For relative paths we do not expect that "dir" contains slashes
- if dirfd != nil && strings.Contains(dir, "/") {
+ if dirfd >= 0 && strings.Contains(dir, "/") {
log.Panicf("WriteDirIV: Relative path should not contain slashes: %v", dir)
}
iv := cryptocore.RandBytes(DirIVLen)
file := filepath.Join(dir, DirIVFilename)
// 0400 permissions: gocryptfs.diriv should never be modified after creation.
// Don't use "ioutil.WriteFile", it causes trouble on NFS: https://github.com/rfjakob/gocryptfs/issues/105
- fdRaw, err := syscallcompat.Openat(int(dirfd.Fd()), file, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0400)
+ fdRaw, err := syscallcompat.Openat(dirfd, file, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0400)
if err != nil {
tlog.Warn.Printf("WriteDirIV: Openat: %v", err)
return err
@@ -105,14 +105,14 @@ func WriteDirIV(dirfd *os.File, dir string) error {
tlog.Warn.Printf("WriteDirIV: Write: %v", err)
}
// Delete incomplete gocryptfs.diriv file
- syscallcompat.Unlinkat(int(dirfd.Fd()), file, 0)
+ syscallcompat.Unlinkat(dirfd, file, 0)
return err
}
err = fd.Close()
if err != nil {
tlog.Warn.Printf("WriteDirIV: Close: %v", err)
// Delete incomplete gocryptfs.diriv file
- syscallcompat.Unlinkat(int(dirfd.Fd()), file, 0)
+ syscallcompat.Unlinkat(dirfd, file, 0)
return err
}
return nil
diff --git a/internal/nametransform/longnames.go b/internal/nametransform/longnames.go
index 614af47..01280a8 100644
--- a/internal/nametransform/longnames.go
+++ b/internal/nametransform/longnames.go
@@ -89,8 +89,8 @@ func ReadLongName(path string) (string, error) {
}
// DeleteLongName deletes "hashName.name".
-func DeleteLongName(dirfd *os.File, hashName string) error {
- err := syscallcompat.Unlinkat(int(dirfd.Fd()), hashName+LongNameSuffix, 0)
+func DeleteLongName(dirfd int, hashName string) error {
+ err := syscallcompat.Unlinkat(dirfd, hashName+LongNameSuffix, 0)
if err != nil {
tlog.Warn.Printf("DeleteLongName: %v", err)
}
@@ -100,7 +100,7 @@ func DeleteLongName(dirfd *os.File, hashName string) error {
// WriteLongName encrypts plainName and writes it into "hashName.name".
// For the convenience of the caller, plainName may also be a path and will be
// converted internally.
-func (n *NameTransform) WriteLongName(dirfd *os.File, hashName string, plainName string) (err error) {
+func (n *NameTransform) WriteLongName(dirfd int, hashName string, plainName string) (err error) {
plainName = filepath.Base(plainName)
// Encrypt the basename
@@ -111,7 +111,7 @@ func (n *NameTransform) WriteLongName(dirfd *os.File, hashName string, plainName
cName := n.EncryptName(plainName, dirIV)
// Write the encrypted name into hashName.name
- fdRaw, err := syscallcompat.Openat(int(dirfd.Fd()), hashName+LongNameSuffix,
+ fdRaw, err := syscallcompat.Openat(dirfd, hashName+LongNameSuffix,
syscall.O_WRONLY|syscall.O_CREAT|syscall.O_EXCL, 0600)
if err != nil {
// Don't warn if the file already exists - this is allowed for renames