Commit 2f9c4b1d authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

nodefs: split up interface futher

* MutableDirOperations
* XAttrOperations
* LockOperations
parent 17f8f123
......@@ -67,22 +67,6 @@ func InodeOf(node Operations) *Inode {
return node.inode()
}
// DirStream lists directory entries.
type DirStream interface {
// HasNext indicates if there are further entries. HasNext
// might be called on already closed streams.
HasNext() bool
// Next retrieves the next entry. It is only called if HasNext
// has previously returned true. The Status may be used to
// indicate I/O errors
Next() (fuse.DirEntry, fuse.Status)
// Close releases resources related to this directory
// stream.
Close()
}
// Operations is the interface that implements the filesystem. Each
// Operations instance must embed DefaultNode.
type Operations interface {
......@@ -106,7 +90,16 @@ type Operations interface {
// susan gets the UID and GID for susan here.
Access(ctx context.Context, mask uint32) fuse.Status
// Extended attributes
// GetAttr reads attributes for an Inode
GetAttr(ctx context.Context, out *fuse.AttrOut) fuse.Status
// SetAttr sets attributes for an Inode.
SetAttr(ctx context.Context, in *fuse.SetAttrIn, out *fuse.AttrOut) fuse.Status
}
// XAttrOperations is as collection of methods used to implement extended attributes.
type XAttrOperations interface {
Operations
// GetXAttr should read data for the given attribute into
// `dest` and return the number of bytes. If `dest` is too
......@@ -124,12 +117,6 @@ type Operations interface {
// `dest`. If the `dest` buffer is too small, it should return
// ERANGE and the correct size.
ListXAttr(ctx context.Context, dest []byte) (uint32, fuse.Status)
// GetAttr reads attributes for an Inode
GetAttr(ctx context.Context, out *fuse.AttrOut) fuse.Status
// SetAttr sets attributes for an Inode
SetAttr(ctx context.Context, in *fuse.SetAttrIn, out *fuse.AttrOut) fuse.Status
}
// SymlinkOperations holds operations specific to symlinks.
......@@ -143,8 +130,6 @@ type SymlinkOperations interface {
// FileOperations holds operations that apply to regular files. The
// default implementation, as returned from NewFileOperations forwards
// to the passed-in FileHandle.
//
// XXX Mknod output too?
type FileOperations interface {
Operations
......@@ -154,19 +139,6 @@ type FileOperations interface {
// File locking
// GetLk returns locks that would conflict with the given
// input lock. If no locks conflict, the output has type
// L_UNLCK. See fcntl(2) for more information.
GetLk(ctx context.Context, f FileHandle, owner uint64, lk *fuse.FileLock, flags uint32, out *fuse.FileLock) (status fuse.Status)
// Obtain a lock on a file, or fail if the lock could not
// obtained. See fcntl(2) for more information.
SetLk(ctx context.Context, f FileHandle, owner uint64, lk *fuse.FileLock, flags uint32) (status fuse.Status)
// Obtain a lock on a file, waiting if necessary. See fcntl(2)
// for more information.
SetLkw(ctx context.Context, f FileHandle, owner uint64, lk *fuse.FileLock, flags uint32) (status fuse.Status)
// Reads data from a file. The data should be returned as
// ReadResult, which may be constructed from the incoming
// `dest` buffer. If the file was opened without FileHandle,
......@@ -206,6 +178,40 @@ type FileOperations interface {
FSetAttr(ctx context.Context, f FileHandle, in *fuse.SetAttrIn, out *fuse.AttrOut) fuse.Status
}
// LockOperations are operations for locking regions of regular files.
type LockOperations interface {
FileOperations
// GetLk returns locks that would conflict with the given
// input lock. If no locks conflict, the output has type
// L_UNLCK. See fcntl(2) for more information.
GetLk(ctx context.Context, f FileHandle, owner uint64, lk *fuse.FileLock, flags uint32, out *fuse.FileLock) (status fuse.Status)
// Obtain a lock on a file, or fail if the lock could not
// obtained. See fcntl(2) for more information.
SetLk(ctx context.Context, f FileHandle, owner uint64, lk *fuse.FileLock, flags uint32) (status fuse.Status)
// Obtain a lock on a file, waiting if necessary. See fcntl(2)
// for more information.
SetLkw(ctx context.Context, f FileHandle, owner uint64, lk *fuse.FileLock, flags uint32) (status fuse.Status)
}
// DirStream lists directory entries.
type DirStream interface {
// HasNext indicates if there are further entries. HasNext
// might be called on already closed streams.
HasNext() bool
// Next retrieves the next entry. It is only called if HasNext
// has previously returned true. The Status may be used to
// indicate I/O errors
Next() (fuse.DirEntry, fuse.Status)
// Close releases resources related to this directory
// stream.
Close()
}
// DirOperations are operations for directory nodes in the filesystem.
type DirOperations interface {
Operations
......@@ -219,6 +225,20 @@ type DirOperations interface {
// tree automatically if the return status is OK.
Lookup(ctx context.Context, name string, out *fuse.EntryOut) (*Inode, fuse.Status)
// OpenDir opens a directory Inode for reading its
// contents. The actual reading is driven from ReadDir, so
// this method is just for performing sanity/permission
// checks.
OpenDir(ctx context.Context) fuse.Status
// ReadDir opens a stream of directory entries.
ReadDir(ctx context.Context) (DirStream, fuse.Status)
}
// MutableDirOperations are operations that change the hierarchy of a file system.
type MutableDirOperations interface {
DirOperations
// Mkdir is similar to Lookup, but must create a directory entry and Inode.
Mkdir(ctx context.Context, name string, mode uint32, out *fuse.EntryOut) (*Inode, fuse.Status)
......@@ -248,15 +268,6 @@ type DirOperations interface {
// different one. The changes is effected in the FS tree if
// the return status is OK
Rename(ctx context.Context, name string, newParent Operations, newName string, flags uint32) fuse.Status
// OpenDir opens a directory Inode for reading its
// contents. The actual reading is driven from ReadDir, so
// this method is just for performing sanity/permission
// checks.
OpenDir(ctx context.Context) fuse.Status
// ReadDir opens a stream of directory entries.
ReadDir(ctx context.Context) (DirStream, fuse.Status)
}
// FileHandle is a resource identifier for opened files. For a
......
This diff is collapsed.
......@@ -8,7 +8,6 @@ import (
"context"
"log"
"sync/atomic"
"time"
"unsafe"
"github.com/hanwen/go-fuse/fuse"
......@@ -47,15 +46,37 @@ func (n *DefaultOperations) setInode(inode *Inode) bool {
nil, unsafe.Pointer(inode))
}
func (n *DefaultOperations) inode() *Inode {
return (*Inode)(atomic.LoadPointer(
(*unsafe.Pointer)(unsafe.Pointer(&n.inode_))))
}
func (n *DefaultOperations) StatFs(ctx context.Context, out *fuse.StatfsOut) fuse.Status {
// this should be defined on OSX, or the FS won't mount
*out = fuse.StatfsOut{}
return fuse.OK
}
func (n *DefaultOperations) inode() *Inode {
return (*Inode)(atomic.LoadPointer(
(*unsafe.Pointer)(unsafe.Pointer(&n.inode_))))
func (n *DefaultOperations) GetAttr(ctx context.Context, out *fuse.AttrOut) fuse.Status {
return fuse.ENOSYS
}
func (n *DefaultOperations) SetAttr(ctx context.Context, in *fuse.SetAttrIn, out *fuse.AttrOut) fuse.Status {
return fuse.ENOSYS
}
func (n *DefaultOperations) Access(ctx context.Context, mask uint32) fuse.Status {
return fuse.ENOSYS
}
// ****************************************************************
func (n *DefaultOperations) FSetAttr(ctx context.Context, f FileHandle, in *fuse.SetAttrIn, out *fuse.AttrOut) fuse.Status {
if f != nil {
return f.SetAttr(ctx, in, out)
}
return fuse.ENOSYS
}
func (n *DefaultOperations) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (*Inode, fuse.Status) {
......@@ -165,10 +186,6 @@ func (n *DefaultOperations) Allocate(ctx context.Context, f FileHandle, off uint
return fuse.ENOSYS
}
func (n *DefaultOperations) GetAttr(ctx context.Context, out *fuse.AttrOut) fuse.Status {
return fuse.ENOSYS
}
func (n *DefaultOperations) FGetAttr(ctx context.Context, f FileHandle, out *fuse.AttrOut) fuse.Status {
if f != nil {
f.GetAttr(ctx, out)
......@@ -176,18 +193,6 @@ func (n *DefaultOperations) FGetAttr(ctx context.Context, f FileHandle, out *fus
return fuse.ENOSYS
}
func (n *DefaultOperations) SetAttr(ctx context.Context, in *fuse.SetAttrIn, out *fuse.AttrOut) fuse.Status {
return fuse.ENOSYS
}
func (n *DefaultOperations) FSetAttr(ctx context.Context, f FileHandle, in *fuse.SetAttrIn, out *fuse.AttrOut) fuse.Status {
if f != nil {
return f.SetAttr(ctx, in, out)
}
return fuse.ENOSYS
}
func (n *DefaultOperations) Open(ctx context.Context, flags uint32) (fh FileHandle, fuseFlags uint32, status fuse.Status) {
return nil, 0, fuse.ENOSYS
}
......@@ -211,10 +216,6 @@ func (n *DefaultOperations) RemoveXAttr(ctx context.Context, attr string) fuse.S
return fuse.ENOATTR
}
func (n *DefaultOperations) Access(ctx context.Context, mask uint32) fuse.Status {
return fuse.ENOSYS
}
func (n *DefaultOperations) ListXAttr(ctx context.Context, dest []byte) (uint32, fuse.Status) {
return 0, fuse.OK
}
......@@ -260,23 +261,6 @@ func (f *DefaultFile) SetAttr(ctx context.Context, in *fuse.SetAttrIn, out *fuse
return fuse.ENOSYS
}
func (f *DefaultFile) Truncate(ctx context.Context, size uint64) fuse.Status {
return fuse.ENOSYS
}
func (f *DefaultFile) Chown(ctx context.Context, uid uint32, gid uint32) fuse.Status {
return fuse.ENOSYS
}
func (f *DefaultFile) Chmod(ctx context.Context, perms uint32) fuse.Status {
return fuse.ENOSYS
}
func (f *DefaultFile) Utimens(ctx context.Context, atime *time.Time, mtime *time.Time) fuse.Status {
return fuse.ENOSYS
}
func (f *DefaultFile) Allocate(ctx context.Context, off uint64, size uint64, mode uint32) (status fuse.Status) {
return fuse.ENOSYS
}
......
......@@ -682,3 +682,5 @@ func TestGetAttrParallel(t *testing.T) {
}
wg.Wait()
}
// XXX test mknod.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment