diff options
| author | Jakob Unterwurzacher | 2018-09-22 20:10:34 +0200 | 
|---|---|---|
| committer | Jakob Unterwurzacher | 2018-09-23 12:17:26 +0200 | 
| commit | c270b21efc1d9ecbe5c913c733204f826e263747 (patch) | |
| tree | f001342e38ab81eeea1292c7a405d30321624b6d /internal/nametransform/diriv.go | |
| parent | 22fba4ac3ed09ba07d1defb60436fb7a17095d09 (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/diriv.go')
| -rw-r--r-- | internal/nametransform/diriv.go | 14 | 
1 files changed, 7 insertions, 7 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 | 
