From 57a52d6aef9b320800a42f9a12fd7e1f47f63073 Mon Sep 17 00:00:00 2001 From: Sebastian Lackner Date: Mon, 7 Jan 2019 18:59:22 +0100 Subject: fusefrontend: Clarify access mode check related to O_WRONLY handling. Use O_ACCMODE mask in openWriteOnlyFile for improved readability. --- internal/fusefrontend/fs.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'internal/fusefrontend') diff --git a/internal/fusefrontend/fs.go b/internal/fusefrontend/fs.go index e379465..7671215 100644 --- a/internal/fusefrontend/fs.go +++ b/internal/fusefrontend/fs.go @@ -114,7 +114,7 @@ func (fs *FS) GetAttr(relPath string, context *fuse.Context) (*fuse.Attr, fuse.S func (fs *FS) mangleOpenFlags(flags uint32) (newFlags int) { newFlags = int(flags) // Convert WRONLY to RDWR. We always need read access to do read-modify-write cycles. - if newFlags&os.O_WRONLY > 0 { + if (newFlags & syscall.O_ACCMODE) == syscall.O_WRONLY { newFlags = newFlags ^ os.O_WRONLY | os.O_RDWR } // We also cannot open the file in append mode, we need to seek back for RMW @@ -157,7 +157,7 @@ func (fs *FS) Open(path string, flags uint32, context *fuse.Context) (fuseFile n syscall.Getrlimit(syscall.RLIMIT_NOFILE, &lim) tlog.Warn.Printf("Open %q: too many open files. Current \"ulimit -n\": %d", cName, lim.Cur) } - if err == syscall.EACCES && (int(flags)&os.O_WRONLY > 0) { + if err == syscall.EACCES && (int(flags)&syscall.O_ACCMODE) == syscall.O_WRONLY { return fs.openWriteOnlyFile(dirfd, cName, newFlags) } return nil, fuse.ToStatus(err) -- cgit v1.2.3