From 2de3851abddd26949b72b9b255ce836fc93ed284 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Sun, 4 Nov 2018 22:05:38 +0100 Subject: nametransform: rename WriteLongName() -> WriteLongNameAt() And also rename DeleteLongName() -> DeleteLongNameAt(). The naming follow the names open the openat() etc syscalls. --- internal/fusefrontend/fs.go | 26 +++++++++++++------------- internal/fusefrontend/fs_dir.go | 6 +++--- internal/fusefrontend/xattr.go | 5 ++++- internal/nametransform/longnames.go | 4 ++-- 4 files changed, 22 insertions(+), 19 deletions(-) diff --git a/internal/fusefrontend/fs.go b/internal/fusefrontend/fs.go index 022fd5c..2108ea4 100644 --- a/internal/fusefrontend/fs.go +++ b/internal/fusefrontend/fs.go @@ -226,14 +226,14 @@ func (fs *FS) Create(path string, flags uint32, mode uint32, context *fuse.Conte // Handle long file name if !fs.args.PlaintextNames && nametransform.IsLongContent(cName) { // Create ".name" - err = fs.nameTransform.WriteLongName(dirfd, cName, path) + err = fs.nameTransform.WriteLongNameAt(dirfd, cName, path) if err != nil { return nil, fuse.ToStatus(err) } // Create content fd, err = syscallcompat.Openat(dirfd, cName, newFlags|os.O_CREATE|os.O_EXCL, mode) if err != nil { - nametransform.DeleteLongName(dirfd, cName) + nametransform.DeleteLongNameAt(dirfd, cName) return nil, fuse.ToStatus(err) } @@ -314,14 +314,14 @@ func (fs *FS) Mknod(path string, mode uint32, dev uint32, context *fuse.Context) defer syscall.Close(dirfd) // Create ".name" file to store long file name (except in PlaintextNames mode) if !fs.args.PlaintextNames && nametransform.IsLongContent(cName) { - err = fs.nameTransform.WriteLongName(dirfd, cName, path) + err = fs.nameTransform.WriteLongNameAt(dirfd, cName, path) if err != nil { return fuse.ToStatus(err) } // Create "gocryptfs.longfile." device node err = syscallcompat.Mknodat(dirfd, cName, mode, int(dev)) if err != nil { - nametransform.DeleteLongName(dirfd, cName) + nametransform.DeleteLongNameAt(dirfd, cName) } } else { // Create regular device node @@ -436,7 +436,7 @@ func (fs *FS) Unlink(path string, context *fuse.Context) (code fuse.Status) { } // Delete ".name" file if !fs.args.PlaintextNames && nametransform.IsLongContent(cName) { - err = nametransform.DeleteLongName(dirfd, cName) + err = nametransform.DeleteLongNameAt(dirfd, cName) if err != nil { tlog.Warn.Printf("Unlink: could not delete .name file: %v", err) } @@ -474,14 +474,14 @@ func (fs *FS) Symlink(target string, linkName string, context *fuse.Context) (co } // Create ".name" file to store long file name (except in PlaintextNames mode) if !fs.args.PlaintextNames && nametransform.IsLongContent(cName) { - err = fs.nameTransform.WriteLongName(dirfd, cName, linkName) + err = fs.nameTransform.WriteLongNameAt(dirfd, cName, linkName) if err != nil { return fuse.ToStatus(err) } // Create "gocryptfs.longfile." symlink err = syscallcompat.Symlinkat(cTarget, dirfd, cName) if err != nil { - nametransform.DeleteLongName(dirfd, cName) + nametransform.DeleteLongNameAt(dirfd, cName) } } else { // Create symlink @@ -501,7 +501,7 @@ func (fs *FS) Symlink(target string, linkName string, context *fuse.Context) (co return fuse.OK } -// Rename implements pathfs.Filesystem. +// Rename - FUSE call. func (fs *FS) Rename(oldPath string, newPath string, context *fuse.Context) (code fuse.Status) { if fs.isFiltered(newPath) { return fuse.EPERM @@ -526,7 +526,7 @@ func (fs *FS) Rename(oldPath string, newPath string, context *fuse.Context) (cod // Long destination file name: create .name file nameFileAlreadyThere := false if nametransform.IsLongContent(newCName) { - err = fs.nameTransform.WriteLongName(newDirfd, newCName, newPath) + err = fs.nameTransform.WriteLongNameAt(newDirfd, newCName, newPath) // Failure to write the .name file is expected when the target path already // exists. Since hashes are pretty unique, there is no need to modify the // .name file in this case, and we ignore the error. @@ -553,12 +553,12 @@ func (fs *FS) Rename(oldPath string, newPath string, context *fuse.Context) (cod if err != nil { if nametransform.IsLongContent(newCName) && nameFileAlreadyThere == false { // Roll back .name creation unless the .name file was already there - nametransform.DeleteLongName(newDirfd, newCName) + nametransform.DeleteLongNameAt(newDirfd, newCName) } return fuse.ToStatus(err) } if nametransform.IsLongContent(oldCName) { - nametransform.DeleteLongName(oldDirfd, oldCName) + nametransform.DeleteLongNameAt(oldDirfd, oldCName) } return fuse.OK } @@ -583,14 +583,14 @@ func (fs *FS) Link(oldPath string, newPath string, context *fuse.Context) (code defer syscall.Close(newDirFd) // Handle long file name (except in PlaintextNames mode) if !fs.args.PlaintextNames && nametransform.IsLongContent(cNewName) { - err = fs.nameTransform.WriteLongName(newDirFd, cNewName, newPath) + err = fs.nameTransform.WriteLongNameAt(newDirFd, cNewName, newPath) if err != nil { return fuse.ToStatus(err) } // Create "gocryptfs.longfile." link err = syscallcompat.Linkat(oldDirFd, cOldName, newDirFd, cNewName, 0) if err != nil { - nametransform.DeleteLongName(newDirFd, cNewName) + nametransform.DeleteLongNameAt(newDirFd, cNewName) } } else { // Create regular link diff --git a/internal/fusefrontend/fs_dir.go b/internal/fusefrontend/fs_dir.go index 9486802..5a6bc9d 100644 --- a/internal/fusefrontend/fs_dir.go +++ b/internal/fusefrontend/fs_dir.go @@ -84,7 +84,7 @@ func (fs *FS) Mkdir(newPath string, mode uint32, context *fuse.Context) (code fu // Handle long file name if nametransform.IsLongContent(cName) { // Create ".name" - err = fs.nameTransform.WriteLongName(dirfd, cName, newPath) + err = fs.nameTransform.WriteLongNameAt(dirfd, cName, newPath) if err != nil { return fuse.ToStatus(err) } @@ -92,7 +92,7 @@ func (fs *FS) Mkdir(newPath string, mode uint32, context *fuse.Context) (code fu // Create directory err = fs.mkdirWithIv(dirfd, cName, mode) if err != nil { - nametransform.DeleteLongName(dirfd, cName) + nametransform.DeleteLongNameAt(dirfd, cName) return fuse.ToStatus(err) } } else { @@ -253,7 +253,7 @@ retry: } // Delete .name file if nametransform.IsLongContent(cName) { - nametransform.DeleteLongName(parentDirFd, cName) + nametransform.DeleteLongNameAt(parentDirFd, cName) } // The now-deleted directory may have been in the DirIV cache. Clear it. fs.nameTransform.DirIVCache.Clear() diff --git a/internal/fusefrontend/xattr.go b/internal/fusefrontend/xattr.go index 81cb207..a0f795a 100644 --- a/internal/fusefrontend/xattr.go +++ b/internal/fusefrontend/xattr.go @@ -70,7 +70,10 @@ func (fs *FS) SetXAttr(path string, attr string, data []byte, flags int, context return unpackXattrErr(xattr.LSetWithFlags(cPath, cAttr, cData, flags)) } -// RemoveXAttr implements pathfs.Filesystem. +// RemoveXAttr - FUSE call. +// +// TODO: Make symlink-safe. Blocker: package xattr does not provide +// fremovexattr(2). func (fs *FS) RemoveXAttr(path string, attr string, context *fuse.Context) fuse.Status { if fs.isFiltered(path) { return fuse.EPERM diff --git a/internal/nametransform/longnames.go b/internal/nametransform/longnames.go index 6788ce6..f0f0490 100644 --- a/internal/nametransform/longnames.go +++ b/internal/nametransform/longnames.go @@ -99,7 +99,7 @@ func ReadLongNameAt(dirfd int, cName string) (string, error) { // DeleteLongName deletes "hashName.name" in the directory openend at "dirfd". // // This function is symlink-safe through the use of Unlinkat(). -func DeleteLongName(dirfd int, hashName string) error { +func DeleteLongNameAt(dirfd int, hashName string) error { err := syscallcompat.Unlinkat(dirfd, hashName+LongNameSuffix, 0) if err != nil { tlog.Warn.Printf("DeleteLongName: %v", err) @@ -112,7 +112,7 @@ func DeleteLongName(dirfd int, hashName string) error { // Base()named internally. // // This function is symlink-safe through the use of Openat(). -func (n *NameTransform) WriteLongName(dirfd int, hashName string, plainName string) (err error) { +func (n *NameTransform) WriteLongNameAt(dirfd int, hashName string, plainName string) (err error) { plainName = filepath.Base(plainName) // Encrypt the basename -- cgit v1.2.3