Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,16 @@ func convertInMessage(
}

case fusekernel.OpOpen:
type input fusekernel.OpenIn
in := (*input)(inMsg.Consume(unsafe.Sizeof(input{})))

if in == nil {
err = errors.New("Corrupt OpOpen")
return
}
o = &fuseops.OpenFileOp{
Inode: fuseops.InodeID(inMsg.Header().Nodeid),
Flag: int(in.Flags),
}

case fusekernel.OpOpendir:
Expand Down
3 changes: 3 additions & 0 deletions fuseops/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

// User-provided flags to open(2). See http://go/godoc/os/#OpenFile.
Flag int
}

// Read data from a file previously opened with CreateFile or OpenFile.
Expand Down
18 changes: 18 additions & 0 deletions samples/memfs/memfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/jacobsa/fuse/fuseops"
"github.com/jacobsa/fuse/fuseutil"
"github.com/jacobsa/syncutil"
"golang.org/x/sys/unix"
)

type memFS struct {
Expand Down Expand Up @@ -615,6 +616,23 @@ func (fs *memFS) OpenFile(
if !inode.isFile() {
panic("Found non-file.")
}
// The flags are not a bitmask, they are a 2-bit field
// with, technically, only 3 legal values. But testing shows
// that there are 4 legal values, so we accomodate that.
var perm int
switch op.Flag & unix.O_ACCMODE {
case unix.O_RDONLY:
perm = 0400
case unix.O_WRONLY:
perm = 0200
case unix.O_RDWR, unix.O_ACCMODE:
perm = 0600
}

// We only check user permissions, since this is a sample FS
if int(inode.attrs.Mode.Perm())&perm != perm {
err = unix.EACCES
}

return
}
Expand Down
25 changes: 25 additions & 0 deletions samples/memfs/memfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
. "github.com/jacobsa/oglematchers"
. "github.com/jacobsa/ogletest"
"github.com/kahing/go-xattr"
"golang.org/x/sys/unix"
)

func TestMemFS(t *testing.T) { RunTests(t) }
Expand Down Expand Up @@ -1706,6 +1707,30 @@ func (t *MemFSTest) RenameIntoFileSystem() {
ExpectThat(err, Error(HasSubstr("cross-device")))
}

func (t *MemFSTest) TestPermissions() {
var e = unix.EACCES
var test = []struct {
name string
mode int
res [4]error
}{
{name: "ro", mode: 0400, res: [4]error{nil, e, e, e}},
{name: "wo", mode: 0200, res: [4]error{e, nil, e, e}},
{name: "rw", mode: 0600, res: [4]error{nil, nil, nil, nil}},
}

for _, tt := range test {
n := path.Join(t.Dir, tt.name)
err := ioutil.WriteFile(n, []byte(""), os.FileMode(tt.mode))
AssertEq(nil, err)
for f, r := range tt.res {
fd, err := unix.Open(n, f, 0)
unix.Close(fd)
AssertEq(r, err)
}
}
}

func (t *MemFSTest) RenameOverExistingFile() {
var err error

Expand Down