Commit bf05480f authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Move some raw types to new directory raw/

parent 4558b459
...@@ -6,6 +6,8 @@ package fuse ...@@ -6,6 +6,8 @@ package fuse
import ( import (
"time" "time"
"github.com/hanwen/go-fuse/raw"
) )
// Types for users to implement. // Types for users to implement.
...@@ -255,12 +257,12 @@ type RawFileSystem interface { ...@@ -255,12 +257,12 @@ type RawFileSystem interface {
SetAttr(header *InHeader, input *SetAttrIn) (out *AttrOut, code Status) SetAttr(header *InHeader, input *SetAttrIn) (out *AttrOut, code Status)
// Modifying structure. // Modifying structure.
Mknod(header *InHeader, input *MknodIn, name string) (out *EntryOut, code Status) Mknod(header *InHeader, input *raw.MknodIn, name string) (out *EntryOut, code Status)
Mkdir(header *InHeader, input *MkdirIn, name string) (out *EntryOut, code Status) Mkdir(header *InHeader, input *raw.MkdirIn, name string) (out *EntryOut, code Status)
Unlink(header *InHeader, name string) (code Status) Unlink(header *InHeader, name string) (code Status)
Rmdir(header *InHeader, name string) (code Status) Rmdir(header *InHeader, name string) (code Status)
Rename(header *InHeader, input *RenameIn, oldName string, newName string) (code Status) Rename(header *InHeader, input *raw.RenameIn, oldName string, newName string) (code Status)
Link(header *InHeader, input *LinkIn, filename string) (out *EntryOut, code Status) Link(header *InHeader, input *raw.LinkIn, filename string) (out *EntryOut, code Status)
Symlink(header *InHeader, pointedTo string, linkName string) (out *EntryOut, code Status) Symlink(header *InHeader, pointedTo string, linkName string) (out *EntryOut, code Status)
Readlink(header *InHeader) (out []byte, code Status) Readlink(header *InHeader) (out []byte, code Status)
......
package fuse package fuse
import (
"github.com/hanwen/go-fuse/raw"
)
func (me *DefaultRawFileSystem) Init(init *RawFsInit) { func (me *DefaultRawFileSystem) Init(init *RawFsInit) {
} }
...@@ -30,11 +34,11 @@ func (me *DefaultRawFileSystem) Readlink(header *InHeader) (out []byte, code Sta ...@@ -30,11 +34,11 @@ func (me *DefaultRawFileSystem) Readlink(header *InHeader) (out []byte, code Sta
return nil, ENOSYS return nil, ENOSYS
} }
func (me *DefaultRawFileSystem) Mknod(header *InHeader, input *MknodIn, name string) (out *EntryOut, code Status) { func (me *DefaultRawFileSystem) Mknod(header *InHeader, input *raw.MknodIn, name string) (out *EntryOut, code Status) {
return new(EntryOut), ENOSYS return new(EntryOut), ENOSYS
} }
func (me *DefaultRawFileSystem) Mkdir(header *InHeader, input *MkdirIn, name string) (out *EntryOut, code Status) { func (me *DefaultRawFileSystem) Mkdir(header *InHeader, input *raw.MkdirIn, name string) (out *EntryOut, code Status) {
return nil, ENOSYS return nil, ENOSYS
} }
...@@ -50,11 +54,11 @@ func (me *DefaultRawFileSystem) Symlink(header *InHeader, pointedTo string, link ...@@ -50,11 +54,11 @@ func (me *DefaultRawFileSystem) Symlink(header *InHeader, pointedTo string, link
return nil, ENOSYS return nil, ENOSYS
} }
func (me *DefaultRawFileSystem) Rename(header *InHeader, input *RenameIn, oldName string, newName string) (code Status) { func (me *DefaultRawFileSystem) Rename(header *InHeader, input *raw.RenameIn, oldName string, newName string) (code Status) {
return ENOSYS return ENOSYS
} }
func (me *DefaultRawFileSystem) Link(header *InHeader, input *LinkIn, name string) (out *EntryOut, code Status) { func (me *DefaultRawFileSystem) Link(header *InHeader, input *raw.LinkIn, name string) (out *EntryOut, code Status) {
return nil, ENOSYS return nil, ENOSYS
} }
......
...@@ -6,6 +6,8 @@ import ( ...@@ -6,6 +6,8 @@ import (
"bytes" "bytes"
"log" "log"
"time" "time"
"github.com/hanwen/go-fuse/raw"
) )
var _ = log.Println var _ = log.Println
...@@ -191,7 +193,7 @@ func (me *FileSystemConnector) Readlink(header *InHeader) (out []byte, code Stat ...@@ -191,7 +193,7 @@ func (me *FileSystemConnector) Readlink(header *InHeader) (out []byte, code Stat
return n.fsInode.Readlink(&header.Context) return n.fsInode.Readlink(&header.Context)
} }
func (me *FileSystemConnector) Mknod(header *InHeader, input *MknodIn, name string) (out *EntryOut, code Status) { func (me *FileSystemConnector) Mknod(header *InHeader, input *raw.MknodIn, name string) (out *EntryOut, code Status) {
parent := me.toInode(header.NodeId) parent := me.toInode(header.NodeId)
fi, fsNode, code := parent.fsInode.Mknod(name, input.Mode, uint32(input.Rdev), &header.Context) fi, fsNode, code := parent.fsInode.Mknod(name, input.Mode, uint32(input.Rdev), &header.Context)
if code.Ok() { if code.Ok() {
...@@ -200,7 +202,7 @@ func (me *FileSystemConnector) Mknod(header *InHeader, input *MknodIn, name stri ...@@ -200,7 +202,7 @@ func (me *FileSystemConnector) Mknod(header *InHeader, input *MknodIn, name stri
return out, code return out, code
} }
func (me *FileSystemConnector) Mkdir(header *InHeader, input *MkdirIn, name string) (out *EntryOut, code Status) { func (me *FileSystemConnector) Mkdir(header *InHeader, input *raw.MkdirIn, name string) (out *EntryOut, code Status) {
parent := me.toInode(header.NodeId) parent := me.toInode(header.NodeId)
fi, fsInode, code := parent.fsInode.Mkdir(name, input.Mode, &header.Context) fi, fsInode, code := parent.fsInode.Mkdir(name, input.Mode, &header.Context)
...@@ -229,7 +231,7 @@ func (me *FileSystemConnector) Symlink(header *InHeader, pointedTo string, linkN ...@@ -229,7 +231,7 @@ func (me *FileSystemConnector) Symlink(header *InHeader, pointedTo string, linkN
return out, code return out, code
} }
func (me *FileSystemConnector) Rename(header *InHeader, input *RenameIn, oldName string, newName string) (code Status) { func (me *FileSystemConnector) Rename(header *InHeader, input *raw.RenameIn, oldName string, newName string) (code Status) {
oldParent := me.toInode(header.NodeId) oldParent := me.toInode(header.NodeId)
isMountPoint := me.findMount(oldParent, oldName) != nil isMountPoint := me.findMount(oldParent, oldName) != nil
if isMountPoint { if isMountPoint {
...@@ -244,7 +246,7 @@ func (me *FileSystemConnector) Rename(header *InHeader, input *RenameIn, oldName ...@@ -244,7 +246,7 @@ func (me *FileSystemConnector) Rename(header *InHeader, input *RenameIn, oldName
return oldParent.fsInode.Rename(oldName, newParent.fsInode, newName, &header.Context) return oldParent.fsInode.Rename(oldName, newParent.fsInode, newName, &header.Context)
} }
func (me *FileSystemConnector) Link(header *InHeader, input *LinkIn, name string) (out *EntryOut, code Status) { func (me *FileSystemConnector) Link(header *InHeader, input *raw.LinkIn, name string) (out *EntryOut, code Status) {
existing := me.toInode(input.Oldnodeid) existing := me.toInode(input.Oldnodeid)
parent := me.toInode(header.NodeId) parent := me.toInode(header.NodeId)
......
...@@ -2,6 +2,8 @@ package fuse ...@@ -2,6 +2,8 @@ package fuse
import ( import (
"sync" "sync"
"github.com/hanwen/go-fuse/raw"
) )
// This is a wrapper that makes a FileSystem threadsafe by // This is a wrapper that makes a FileSystem threadsafe by
...@@ -188,12 +190,12 @@ func (me *LockingRawFileSystem) Readlink(header *InHeader) (out []byte, code Sta ...@@ -188,12 +190,12 @@ func (me *LockingRawFileSystem) Readlink(header *InHeader) (out []byte, code Sta
return me.RawFileSystem.Readlink(header) return me.RawFileSystem.Readlink(header)
} }
func (me *LockingRawFileSystem) Mknod(header *InHeader, input *MknodIn, name string) (out *EntryOut, code Status) { func (me *LockingRawFileSystem) Mknod(header *InHeader, input *raw.MknodIn, name string) (out *EntryOut, code Status) {
defer me.locked()() defer me.locked()()
return me.RawFileSystem.Mknod(header, input, name) return me.RawFileSystem.Mknod(header, input, name)
} }
func (me *LockingRawFileSystem) Mkdir(header *InHeader, input *MkdirIn, name string) (out *EntryOut, code Status) { func (me *LockingRawFileSystem) Mkdir(header *InHeader, input *raw.MkdirIn, name string) (out *EntryOut, code Status) {
defer me.locked()() defer me.locked()()
return me.RawFileSystem.Mkdir(header, input, name) return me.RawFileSystem.Mkdir(header, input, name)
} }
...@@ -213,12 +215,12 @@ func (me *LockingRawFileSystem) Symlink(header *InHeader, pointedTo string, link ...@@ -213,12 +215,12 @@ func (me *LockingRawFileSystem) Symlink(header *InHeader, pointedTo string, link
return me.RawFileSystem.Symlink(header, pointedTo, linkName) return me.RawFileSystem.Symlink(header, pointedTo, linkName)
} }
func (me *LockingRawFileSystem) Rename(header *InHeader, input *RenameIn, oldName string, newName string) (code Status) { func (me *LockingRawFileSystem) Rename(header *InHeader, input *raw.RenameIn, oldName string, newName string) (code Status) {
defer me.locked()() defer me.locked()()
return me.RawFileSystem.Rename(header, input, oldName, newName) return me.RawFileSystem.Rename(header, input, oldName, newName)
} }
func (me *LockingRawFileSystem) Link(header *InHeader, input *LinkIn, name string) (out *EntryOut, code Status) { func (me *LockingRawFileSystem) Link(header *InHeader, input *raw.LinkIn, name string) (out *EntryOut, code Status) {
defer me.locked()() defer me.locked()()
return me.RawFileSystem.Link(header, input, name) return me.RawFileSystem.Link(header, input, name)
} }
......
...@@ -6,6 +6,8 @@ import ( ...@@ -6,6 +6,8 @@ import (
"log" "log"
"reflect" "reflect"
"unsafe" "unsafe"
"github.com/hanwen/go-fuse/raw"
) )
var _ = log.Printf var _ = log.Printf
...@@ -217,12 +219,12 @@ func doGetAttr(state *MountState, req *request) { ...@@ -217,12 +219,12 @@ func doGetAttr(state *MountState, req *request) {
} }
func doForget(state *MountState, req *request) { func doForget(state *MountState, req *request) {
state.fileSystem.Forget(req.inHeader.NodeId, (*ForgetIn)(req.inData).Nlookup) state.fileSystem.Forget(req.inHeader.NodeId, (*raw.ForgetIn)(req.inData).Nlookup)
} }
func doBatchForget(state *MountState, req *request) { func doBatchForget(state *MountState, req *request) {
in := (*BatchForgetIn)(req.inData) in := (*raw.BatchForgetIn)(req.inData)
wantBytes := uintptr(in.Count)*unsafe.Sizeof(BatchForgetIn{}) wantBytes := uintptr(in.Count)*unsafe.Sizeof(raw.BatchForgetIn{})
if uintptr(len(req.arg)) < wantBytes { if uintptr(len(req.arg)) < wantBytes {
// We have no return value to complain, so log an error. // We have no return value to complain, so log an error.
log.Printf("Too few bytes for batch forget. Got %d bytes, want %d (%d entries)", log.Printf("Too few bytes for batch forget. Got %d bytes, want %d (%d entries)",
...@@ -231,7 +233,7 @@ func doBatchForget(state *MountState, req *request) { ...@@ -231,7 +233,7 @@ func doBatchForget(state *MountState, req *request) {
h := &reflect.SliceHeader{uintptr(unsafe.Pointer(&req.arg[0])), int(in.Count), int(in.Count)} h := &reflect.SliceHeader{uintptr(unsafe.Pointer(&req.arg[0])), int(in.Count), int(in.Count)}
forgets := *(*[]ForgetOne)(unsafe.Pointer(h)) forgets := *(*[]raw.ForgetOne)(unsafe.Pointer(h))
for _, f := range forgets { for _, f := range forgets {
state.fileSystem.Forget(f.NodeId, f.Nlookup) state.fileSystem.Forget(f.NodeId, f.Nlookup)
} }
...@@ -248,13 +250,13 @@ func doLookup(state *MountState, req *request) { ...@@ -248,13 +250,13 @@ func doLookup(state *MountState, req *request) {
} }
func doMknod(state *MountState, req *request) { func doMknod(state *MountState, req *request) {
entryOut, s := state.fileSystem.Mknod(req.inHeader, (*MknodIn)(req.inData), req.filenames[0]) entryOut, s := state.fileSystem.Mknod(req.inHeader, (*raw.MknodIn)(req.inData), req.filenames[0])
req.status = s req.status = s
req.outData = unsafe.Pointer(entryOut) req.outData = unsafe.Pointer(entryOut)
} }
func doMkdir(state *MountState, req *request) { func doMkdir(state *MountState, req *request) {
entryOut, s := state.fileSystem.Mkdir(req.inHeader, (*MkdirIn)(req.inData), req.filenames[0]) entryOut, s := state.fileSystem.Mkdir(req.inHeader, (*raw.MkdirIn)(req.inData), req.filenames[0])
req.status = s req.status = s
req.outData = unsafe.Pointer(entryOut) req.outData = unsafe.Pointer(entryOut)
} }
...@@ -268,7 +270,7 @@ func doRmdir(state *MountState, req *request) { ...@@ -268,7 +270,7 @@ func doRmdir(state *MountState, req *request) {
} }
func doLink(state *MountState, req *request) { func doLink(state *MountState, req *request) {
entryOut, s := state.fileSystem.Link(req.inHeader, (*LinkIn)(req.inData), req.filenames[0]) entryOut, s := state.fileSystem.Link(req.inHeader, (*raw.LinkIn)(req.inData), req.filenames[0])
req.status = s req.status = s
req.outData = unsafe.Pointer(entryOut) req.outData = unsafe.Pointer(entryOut)
} }
...@@ -317,7 +319,7 @@ func doSymlink(state *MountState, req *request) { ...@@ -317,7 +319,7 @@ func doSymlink(state *MountState, req *request) {
} }
func doRename(state *MountState, req *request) { func doRename(state *MountState, req *request) {
req.status = state.fileSystem.Rename(req.inHeader, (*RenameIn)(req.inData), req.filenames[0], req.filenames[1]) req.status = state.fileSystem.Rename(req.inHeader, (*raw.RenameIn)(req.inData), req.filenames[0], req.filenames[1])
} }
func doStatFs(state *MountState, req *request) { func doStatFs(state *MountState, req *request) {
...@@ -386,14 +388,14 @@ func init() { ...@@ -386,14 +388,14 @@ func init() {
} }
for op, sz := range map[opcode]uintptr{ for op, sz := range map[opcode]uintptr{
_OP_FORGET: unsafe.Sizeof(ForgetIn{}), _OP_FORGET: unsafe.Sizeof(raw.ForgetIn{}),
_OP_BATCH_FORGET: unsafe.Sizeof(BatchForgetIn{}), _OP_BATCH_FORGET: unsafe.Sizeof(raw.BatchForgetIn{}),
_OP_GETATTR: unsafe.Sizeof(GetAttrIn{}), _OP_GETATTR: unsafe.Sizeof(GetAttrIn{}),
_OP_SETATTR: unsafe.Sizeof(SetAttrIn{}), _OP_SETATTR: unsafe.Sizeof(SetAttrIn{}),
_OP_MKNOD: unsafe.Sizeof(MknodIn{}), _OP_MKNOD: unsafe.Sizeof(raw.MknodIn{}),
_OP_MKDIR: unsafe.Sizeof(MkdirIn{}), _OP_MKDIR: unsafe.Sizeof(raw.MkdirIn{}),
_OP_RENAME: unsafe.Sizeof(RenameIn{}), _OP_RENAME: unsafe.Sizeof(raw.RenameIn{}),
_OP_LINK: unsafe.Sizeof(LinkIn{}), _OP_LINK: unsafe.Sizeof(raw.LinkIn{}),
_OP_OPEN: unsafe.Sizeof(OpenIn{}), _OP_OPEN: unsafe.Sizeof(OpenIn{}),
_OP_READ: unsafe.Sizeof(ReadIn{}), _OP_READ: unsafe.Sizeof(ReadIn{}),
_OP_WRITE: unsafe.Sizeof(WriteIn{}), _OP_WRITE: unsafe.Sizeof(WriteIn{}),
...@@ -552,15 +554,15 @@ func init() { ...@@ -552,15 +554,15 @@ func init() {
_OP_INIT: func(ptr unsafe.Pointer) interface{} { return (*InitIn)(ptr) }, _OP_INIT: func(ptr unsafe.Pointer) interface{} { return (*InitIn)(ptr) },
_OP_IOCTL: func(ptr unsafe.Pointer) interface{} { return (*IoctlIn)(ptr) }, _OP_IOCTL: func(ptr unsafe.Pointer) interface{} { return (*IoctlIn)(ptr) },
_OP_OPEN: func(ptr unsafe.Pointer) interface{} { return (*OpenIn)(ptr) }, _OP_OPEN: func(ptr unsafe.Pointer) interface{} { return (*OpenIn)(ptr) },
_OP_MKNOD: func(ptr unsafe.Pointer) interface{} { return (*MknodIn)(ptr) }, _OP_MKNOD: func(ptr unsafe.Pointer) interface{} { return (*raw.MknodIn)(ptr) },
_OP_CREATE: func(ptr unsafe.Pointer) interface{} { return (*CreateIn)(ptr) }, _OP_CREATE: func(ptr unsafe.Pointer) interface{} { return (*CreateIn)(ptr) },
_OP_READ: func(ptr unsafe.Pointer) interface{} { return (*ReadIn)(ptr) }, _OP_READ: func(ptr unsafe.Pointer) interface{} { return (*ReadIn)(ptr) },
_OP_READDIR: func(ptr unsafe.Pointer) interface{} { return (*ReadIn)(ptr) }, _OP_READDIR: func(ptr unsafe.Pointer) interface{} { return (*ReadIn)(ptr) },
_OP_ACCESS: func(ptr unsafe.Pointer) interface{} { return (*AccessIn)(ptr) }, _OP_ACCESS: func(ptr unsafe.Pointer) interface{} { return (*AccessIn)(ptr) },
_OP_FORGET: func(ptr unsafe.Pointer) interface{} { return (*ForgetIn)(ptr) }, _OP_FORGET: func(ptr unsafe.Pointer) interface{} { return (*raw.ForgetIn)(ptr) },
_OP_BATCH_FORGET: func(ptr unsafe.Pointer) interface{} { return (*BatchForgetIn)(ptr) }, _OP_BATCH_FORGET: func(ptr unsafe.Pointer) interface{} { return (*raw.BatchForgetIn)(ptr) },
_OP_LINK: func(ptr unsafe.Pointer) interface{} { return (*LinkIn)(ptr) }, _OP_LINK: func(ptr unsafe.Pointer) interface{} { return (*raw.LinkIn)(ptr) },
_OP_MKDIR: func(ptr unsafe.Pointer) interface{} { return (*MkdirIn)(ptr) }, _OP_MKDIR: func(ptr unsafe.Pointer) interface{} { return (*raw.MkdirIn)(ptr) },
_OP_RELEASE: func(ptr unsafe.Pointer) interface{} { return (*ReleaseIn)(ptr) }, _OP_RELEASE: func(ptr unsafe.Pointer) interface{} { return (*ReleaseIn)(ptr) },
_OP_RELEASEDIR: func(ptr unsafe.Pointer) interface{} { return (*ReleaseIn)(ptr) }, _OP_RELEASEDIR: func(ptr unsafe.Pointer) interface{} { return (*ReleaseIn)(ptr) },
} { } {
......
...@@ -184,14 +184,6 @@ func (me *ReadIn) String() string { ...@@ -184,14 +184,6 @@ func (me *ReadIn) String() string {
flagString(openFlagNames, int(me.Flags), "RDONLY")) flagString(openFlagNames, int(me.Flags), "RDONLY"))
} }
func (me *MkdirIn) String() string {
return fmt.Sprintf("{0%o (0%o)}", me.Mode, me.Umask)
}
func (me *MknodIn) String() string {
return fmt.Sprintf("{0%o (0%o), %d}", me.Mode, me.Umask, me.Rdev)
}
func (me *ReleaseIn) String() string { func (me *ReleaseIn) String() string {
return fmt.Sprintf("{Fh %d %s %s L%d}", return fmt.Sprintf("{Fh %d %s %s L%d}",
me.Fh, flagString(openFlagNames, int(me.Flags), ""), me.Fh, flagString(openFlagNames, int(me.Flags), ""),
...@@ -232,10 +224,3 @@ func (me *WithFlags) String() string { ...@@ -232,10 +224,3 @@ func (me *WithFlags) String() string {
flagString(fuseOpenFlagNames, int(me.FuseFlags), "")) flagString(fuseOpenFlagNames, int(me.FuseFlags), ""))
} }
func (me *ForgetIn) String() string {
return fmt.Sprintf("{%d}", me.Nlookup)
}
func (me *BatchForgetIn) String() string {
return fmt.Sprintf("{%d}", me.Count)
}
...@@ -123,20 +123,6 @@ type EntryOut struct { ...@@ -123,20 +123,6 @@ type EntryOut struct {
Attr Attr
} }
type ForgetIn struct {
Nlookup uint64
}
type ForgetOne struct {
NodeId uint64
Nlookup uint64
}
type BatchForgetIn struct {
Count uint32
Dummy uint32
}
const ( const (
// Mask for GetAttrIn.Flags. If set, GetAttrIn has a file handle set. // Mask for GetAttrIn.Flags. If set, GetAttrIn has a file handle set.
FUSE_GETATTR_FH = (1 << 0) FUSE_GETATTR_FH = (1 << 0)
...@@ -155,26 +141,6 @@ type AttrOut struct { ...@@ -155,26 +141,6 @@ type AttrOut struct {
Attr Attr
} }
type MknodIn struct {
Mode uint32
Rdev uint32
Umask uint32
Padding uint32
}
type MkdirIn struct {
Mode uint32
Umask uint32
}
type RenameIn struct {
Newdir uint64
}
type LinkIn struct {
Oldnodeid uint64
}
const ( // SetAttrIn.Valid const ( // SetAttrIn.Valid
FATTR_MODE = (1 << 0) FATTR_MODE = (1 << 0)
FATTR_UID = (1 << 1) FATTR_UID = (1 << 1)
......
package raw
import "fmt"
func (me *ForgetIn) String() string {
return fmt.Sprintf("{%d}", me.Nlookup)
}
func (me *BatchForgetIn) String() string {
return fmt.Sprintf("{%d}", me.Count)
}
func (me *MkdirIn) String() string {
return fmt.Sprintf("{0%o (0%o)}", me.Mode, me.Umask)
}
func (me *MknodIn) String() string {
return fmt.Sprintf("{0%o (0%o), %d}", me.Mode, me.Umask, me.Rdev)
}
package raw
type ForgetIn struct {
Nlookup uint64
}
type ForgetOne struct {
NodeId uint64
Nlookup uint64
}
type BatchForgetIn struct {
Count uint32
Dummy uint32
}
type MkdirIn struct {
Mode uint32
Umask uint32
}
type RenameIn struct {
Newdir uint64
}
type LinkIn struct {
Oldnodeid uint64
}
type MknodIn struct {
Mode uint32
Rdev uint32
Umask uint32
Padding uint32
}
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