Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add open flags to OpenFileOp #63

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rminnich
Copy link

The open flag indicates the type of access we need.

Add a test to the memfs server to make sure an open
is blocked if the flags and permissions don't match.

Signed-off-by: Ronald G. Minnich [email protected]

fuseops/ops.go Outdated
@@ -593,6 +593,9 @@ type OpenFileOp struct {
// layer. This allows for filesystems whose file sizes are not known in
// advance, for example, because contents are generated on the fly.
UseDirectIO bool

// Open flags. See os.OpenFile
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Open flags. See os.OpenFile
// User-provided flags to open(2). See http://go/godoc/os/#OpenFile.

@@ -615,6 +616,24 @@ func (fs *memFS) OpenFile(
if !inode.isFile() {
panic("Found non-file.")
}
// What perms do we need?
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had trouble understanding what you were doing here at first. Could you make
the code read something like:

// Check that the open mode is legal according to the file
// permissions.
var permissionBits int
switch (...) {
    ...
}

if (...) {
  err = EACCESS
  return
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should not be checking attributes, since they can change behind our back.

case unix.O_RDWR:
perm = 0600
// This is legal, at least on linux
case unix.O_ACCMODE:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case is weird, and I think it's just an artifact of using a switch
statement, right? Why not something like:

if flags & unix.O_RDONLY && !(inode.attrs.Mode()&unix.O_RDONLY) {
  return EACCESS
}

// Ditto with O_WRONLY and O_RDWR
...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yeah, and that case is very deliberate: I tested it on linux before I added it. Again, I broke it out b/c it's not obvious.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, I was thinking about the fs I am writing, not memfs, sorry. nvm.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but if you want it to work your proposed way that's fine too.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I'm totally lost at this point. All I want you to do in memfs_test is somehow confirm that the open(2) flags correctly come through to the file system. Maybe you are attempting to do that here, but I don't understand how. Could you please improve the commenting, here or in the test, to explain how you're confirming this?

The open flag indicates the type of access we need.

Add a test to the memfs server to make sure an open
is blocked if the flags and permissions don't match.

Signed-off-by: Ronald G. Minnich <[email protected]>
complyue added a commit to complyue/jdfs that referenced this pull request Jun 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants