Commit 7dd16a5e authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Move Bmap/Ioctl/Init/Interrupt types.

parent dd86d881
...@@ -292,7 +292,7 @@ type RawFileSystem interface { ...@@ -292,7 +292,7 @@ type RawFileSystem interface {
FsyncDir(header *InHeader, input *FsyncIn) (code Status) FsyncDir(header *InHeader, input *FsyncIn) (code Status)
// //
Ioctl(header *InHeader, input *IoctlIn) (output *IoctlOut, data []byte, code Status) Ioctl(header *InHeader, input *raw.IoctlIn) (output *raw.IoctlOut, data []byte, code Status)
StatFs(header *InHeader) *StatfsOut StatFs(header *InHeader) *StatfsOut
// Provide callbacks for pushing notifications to the kernel. // Provide callbacks for pushing notifications to the kernel.
......
...@@ -2,6 +2,8 @@ package fuse ...@@ -2,6 +2,8 @@ package fuse
import ( import (
"log" "log"
"github.com/hanwen/go-fuse/raw"
) )
var _ = log.Println var _ = log.Println
...@@ -57,6 +59,6 @@ func (me *DefaultFile) Chmod(perms uint32) Status { ...@@ -57,6 +59,6 @@ func (me *DefaultFile) Chmod(perms uint32) Status {
return ENOSYS return ENOSYS
} }
func (me *DefaultFile) Ioctl(input *IoctlIn) (output *IoctlOut, data []byte, code Status) { func (me *DefaultFile) Ioctl(input *raw.IoctlIn) (output *raw.IoctlOut, data []byte, code Status) {
return nil, nil, ENOSYS return nil, nil, ENOSYS
} }
...@@ -90,11 +90,11 @@ func (me *DefaultRawFileSystem) Create(header *InHeader, input *CreateIn, name s ...@@ -90,11 +90,11 @@ func (me *DefaultRawFileSystem) Create(header *InHeader, input *CreateIn, name s
return 0, 0, nil, ENOSYS return 0, 0, nil, ENOSYS
} }
func (me *DefaultRawFileSystem) Bmap(header *InHeader, input *BmapIn) (out *BmapOut, code Status) { func (me *DefaultRawFileSystem) Bmap(header *InHeader, input *raw.BmapIn) (out *raw.BmapOut, code Status) {
return nil, ENOSYS return nil, ENOSYS
} }
func (me *DefaultRawFileSystem) Poll(header *InHeader, input *PollIn) (out *PollOut, code Status) { func (me *DefaultRawFileSystem) Poll(header *InHeader, input *raw.PollIn) (out *raw.PollOut, code Status) {
return nil, ENOSYS return nil, ENOSYS
} }
...@@ -132,6 +132,6 @@ func (me *DefaultRawFileSystem) FsyncDir(header *InHeader, input *FsyncIn) (code ...@@ -132,6 +132,6 @@ func (me *DefaultRawFileSystem) FsyncDir(header *InHeader, input *FsyncIn) (code
return ENOSYS return ENOSYS
} }
func (me *DefaultRawFileSystem) Ioctl(header *InHeader, input *IoctlIn) (output *IoctlOut, data []byte, code Status) { func (me *DefaultRawFileSystem) Ioctl(header *InHeader, input *raw.IoctlIn) (output *raw.IoctlOut, data []byte, code Status) {
return nil, nil, ENOSYS return nil, nil, ENOSYS
} }
...@@ -6,6 +6,8 @@ import ( ...@@ -6,6 +6,8 @@ import (
"syscall" "syscall"
"testing" "testing"
"time" "time"
"github.com/hanwen/go-fuse/raw"
) )
type MutableDataFile struct { type MutableDataFile struct {
...@@ -135,7 +137,7 @@ func setupFAttrTest(t *testing.T, fs FileSystem) (dir string, clean func()) { ...@@ -135,7 +137,7 @@ func setupFAttrTest(t *testing.T, fs FileSystem) (dir string, clean func()) {
// Trigger INIT. // Trigger INIT.
os.Lstat(dir) os.Lstat(dir)
if state.KernelSettings().Flags&CAP_FILE_OPS == 0 { if state.KernelSettings().Flags&raw.CAP_FILE_OPS == 0 {
t.Log("Mount does not support file operations") t.Log("Mount does not support file operations")
} }
......
...@@ -6,6 +6,8 @@ import ( ...@@ -6,6 +6,8 @@ import (
"strings" "strings"
"time" "time"
"unsafe" "unsafe"
"github.com/hanwen/go-fuse/raw"
) )
const ( const (
...@@ -32,10 +34,10 @@ type MountState struct { ...@@ -32,10 +34,10 @@ type MountState struct {
latencies *LatencyMap latencies *LatencyMap
opts *MountOptions opts *MountOptions
kernelSettings InitIn kernelSettings raw.InitIn
} }
func (me *MountState) KernelSettings() InitIn { func (me *MountState) KernelSettings() raw.InitIn {
return me.kernelSettings return me.kernelSettings
} }
......
...@@ -73,7 +73,7 @@ func doInit(state *MountState, req *request) { ...@@ -73,7 +73,7 @@ func doInit(state *MountState, req *request) {
OUR_MINOR_VERSION = 16 OUR_MINOR_VERSION = 16
) )
input := (*InitIn)(req.inData) input := (*raw.InitIn)(req.inData)
if input.Major != FUSE_KERNEL_VERSION { if input.Major != FUSE_KERNEL_VERSION {
log.Printf("Major versions does not match. Given %d, want %d\n", input.Major, FUSE_KERNEL_VERSION) log.Printf("Major versions does not match. Given %d, want %d\n", input.Major, FUSE_KERNEL_VERSION)
req.status = EIO req.status = EIO
...@@ -86,8 +86,8 @@ func doInit(state *MountState, req *request) { ...@@ -86,8 +86,8 @@ func doInit(state *MountState, req *request) {
} }
state.kernelSettings = *input state.kernelSettings = *input
state.kernelSettings.Flags = input.Flags & (CAP_ASYNC_READ | CAP_BIG_WRITES | CAP_FILE_OPS) state.kernelSettings.Flags = input.Flags & (raw.CAP_ASYNC_READ | raw.CAP_BIG_WRITES | raw.CAP_FILE_OPS)
out := &InitOut{ out := &raw.InitOut{
Major: FUSE_KERNEL_VERSION, Major: FUSE_KERNEL_VERSION,
Minor: OUR_MINOR_VERSION, Minor: OUR_MINOR_VERSION,
MaxReadAhead: input.MaxReadAhead, MaxReadAhead: input.MaxReadAhead,
...@@ -333,7 +333,7 @@ func doStatFs(state *MountState, req *request) { ...@@ -333,7 +333,7 @@ func doStatFs(state *MountState, req *request) {
} }
func doIoctl(state *MountState, req *request) { func doIoctl(state *MountState, req *request) {
out, data, stat := state.fileSystem.Ioctl(req.inHeader, (*IoctlIn)(req.inData)) out, data, stat := state.fileSystem.Ioctl(req.inHeader, (*raw.IoctlIn)(req.inData))
req.outData = unsafe.Pointer(out) req.outData = unsafe.Pointer(out)
req.flatData = data req.flatData = data
req.status = stat req.status = stat
...@@ -405,17 +405,17 @@ func init() { ...@@ -405,17 +405,17 @@ func init() {
_OP_GETXATTR: unsafe.Sizeof(GetXAttrIn{}), _OP_GETXATTR: unsafe.Sizeof(GetXAttrIn{}),
_OP_LISTXATTR: unsafe.Sizeof(GetXAttrIn{}), _OP_LISTXATTR: unsafe.Sizeof(GetXAttrIn{}),
_OP_FLUSH: unsafe.Sizeof(FlushIn{}), _OP_FLUSH: unsafe.Sizeof(FlushIn{}),
_OP_INIT: unsafe.Sizeof(InitIn{}), _OP_INIT: unsafe.Sizeof(raw.InitIn{}),
_OP_OPENDIR: unsafe.Sizeof(raw.OpenIn{}), _OP_OPENDIR: unsafe.Sizeof(raw.OpenIn{}),
_OP_READDIR: unsafe.Sizeof(ReadIn{}), _OP_READDIR: unsafe.Sizeof(ReadIn{}),
_OP_RELEASEDIR: unsafe.Sizeof(raw.ReleaseIn{}), _OP_RELEASEDIR: unsafe.Sizeof(raw.ReleaseIn{}),
_OP_FSYNCDIR: unsafe.Sizeof(FsyncIn{}), _OP_FSYNCDIR: unsafe.Sizeof(FsyncIn{}),
_OP_ACCESS: unsafe.Sizeof(AccessIn{}), _OP_ACCESS: unsafe.Sizeof(AccessIn{}),
_OP_CREATE: unsafe.Sizeof(CreateIn{}), _OP_CREATE: unsafe.Sizeof(CreateIn{}),
_OP_INTERRUPT: unsafe.Sizeof(InterruptIn{}), _OP_INTERRUPT: unsafe.Sizeof(raw.InterruptIn{}),
_OP_BMAP: unsafe.Sizeof(BmapIn{}), _OP_BMAP: unsafe.Sizeof(raw.BmapIn{}),
_OP_IOCTL: unsafe.Sizeof(IoctlIn{}), _OP_IOCTL: unsafe.Sizeof(raw.IoctlIn{}),
_OP_POLL: unsafe.Sizeof(PollIn{}), _OP_POLL: unsafe.Sizeof(raw.PollIn{}),
} { } {
operationHandlers[op].InputSize = sz operationHandlers[op].InputSize = sz
} }
...@@ -433,12 +433,12 @@ func init() { ...@@ -433,12 +433,12 @@ func init() {
_OP_STATFS: unsafe.Sizeof(StatfsOut{}), _OP_STATFS: unsafe.Sizeof(StatfsOut{}),
_OP_GETXATTR: unsafe.Sizeof(GetXAttrOut{}), _OP_GETXATTR: unsafe.Sizeof(GetXAttrOut{}),
_OP_LISTXATTR: unsafe.Sizeof(GetXAttrOut{}), _OP_LISTXATTR: unsafe.Sizeof(GetXAttrOut{}),
_OP_INIT: unsafe.Sizeof(InitOut{}), _OP_INIT: unsafe.Sizeof(raw.InitOut{}),
_OP_OPENDIR: unsafe.Sizeof(raw.OpenOut{}), _OP_OPENDIR: unsafe.Sizeof(raw.OpenOut{}),
_OP_CREATE: unsafe.Sizeof(CreateOut{}), _OP_CREATE: unsafe.Sizeof(CreateOut{}),
_OP_BMAP: unsafe.Sizeof(BmapOut{}), _OP_BMAP: unsafe.Sizeof(raw.BmapOut{}),
_OP_IOCTL: unsafe.Sizeof(IoctlOut{}), _OP_IOCTL: unsafe.Sizeof(raw.IoctlOut{}),
_OP_POLL: unsafe.Sizeof(PollOut{}), _OP_POLL: unsafe.Sizeof(raw.PollOut{}),
_OP_NOTIFY_ENTRY: unsafe.Sizeof(NotifyInvalEntryOut{}), _OP_NOTIFY_ENTRY: unsafe.Sizeof(NotifyInvalEntryOut{}),
_OP_NOTIFY_INODE: unsafe.Sizeof(NotifyInvalInodeOut{}), _OP_NOTIFY_INODE: unsafe.Sizeof(NotifyInvalInodeOut{}),
} { } {
...@@ -537,7 +537,7 @@ func init() { ...@@ -537,7 +537,7 @@ func init() {
_OP_CREATE: func(ptr unsafe.Pointer) interface{} { return (*CreateOut)(ptr) }, _OP_CREATE: func(ptr unsafe.Pointer) interface{} { return (*CreateOut)(ptr) },
_OP_LINK: func(ptr unsafe.Pointer) interface{} { return (*EntryOut)(ptr) }, _OP_LINK: func(ptr unsafe.Pointer) interface{} { return (*EntryOut)(ptr) },
_OP_SETATTR: func(ptr unsafe.Pointer) interface{} { return (*AttrOut)(ptr) }, _OP_SETATTR: func(ptr unsafe.Pointer) interface{} { return (*AttrOut)(ptr) },
_OP_INIT: func(ptr unsafe.Pointer) interface{} { return (*InitOut)(ptr) }, _OP_INIT: func(ptr unsafe.Pointer) interface{} { return (*raw.InitOut)(ptr) },
_OP_MKDIR: func(ptr unsafe.Pointer) interface{} { return (*EntryOut)(ptr) }, _OP_MKDIR: func(ptr unsafe.Pointer) interface{} { return (*EntryOut)(ptr) },
_OP_NOTIFY_ENTRY: func(ptr unsafe.Pointer) interface{} { return (*NotifyInvalEntryOut)(ptr) }, _OP_NOTIFY_ENTRY: func(ptr unsafe.Pointer) interface{} { return (*NotifyInvalEntryOut)(ptr) },
_OP_NOTIFY_INODE: func(ptr unsafe.Pointer) interface{} { return (*NotifyInvalInodeOut)(ptr) }, _OP_NOTIFY_INODE: func(ptr unsafe.Pointer) interface{} { return (*NotifyInvalInodeOut)(ptr) },
...@@ -551,8 +551,8 @@ func init() { ...@@ -551,8 +551,8 @@ func init() {
_OP_FLUSH: func(ptr unsafe.Pointer) interface{} { return (*FlushIn)(ptr) }, _OP_FLUSH: func(ptr unsafe.Pointer) interface{} { return (*FlushIn)(ptr) },
_OP_GETATTR: func(ptr unsafe.Pointer) interface{} { return (*raw.GetAttrIn)(ptr) }, _OP_GETATTR: func(ptr unsafe.Pointer) interface{} { return (*raw.GetAttrIn)(ptr) },
_OP_SETATTR: func(ptr unsafe.Pointer) interface{} { return (*raw.SetAttrIn)(ptr) }, _OP_SETATTR: func(ptr unsafe.Pointer) interface{} { return (*raw.SetAttrIn)(ptr) },
_OP_INIT: func(ptr unsafe.Pointer) interface{} { return (*InitIn)(ptr) }, _OP_INIT: func(ptr unsafe.Pointer) interface{} { return (*raw.InitIn)(ptr) },
_OP_IOCTL: func(ptr unsafe.Pointer) interface{} { return (*IoctlIn)(ptr) }, _OP_IOCTL: func(ptr unsafe.Pointer) interface{} { return (*raw.IoctlIn)(ptr) },
_OP_OPEN: func(ptr unsafe.Pointer) interface{} { return (*raw.OpenIn)(ptr) }, _OP_OPEN: func(ptr unsafe.Pointer) interface{} { return (*raw.OpenIn)(ptr) },
_OP_MKNOD: func(ptr unsafe.Pointer) interface{} { return (*raw.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) },
......
...@@ -5,24 +5,11 @@ import ( ...@@ -5,24 +5,11 @@ import (
"github.com/hanwen/go-fuse/raw" "github.com/hanwen/go-fuse/raw"
) )
var initFlagNames map[int]string
var writeFlagNames map[int]string var writeFlagNames map[int]string
var readFlagNames map[int]string var readFlagNames map[int]string
var accessFlagName map[int]string var accessFlagName map[int]string
func init() { func init() {
initFlagNames = map[int]string{
CAP_ASYNC_READ: "ASYNC_READ",
CAP_POSIX_LOCKS: "POSIX_LOCKS",
CAP_FILE_OPS: "FILE_OPS",
CAP_ATOMIC_O_TRUNC: "ATOMIC_O_TRUNC",
CAP_EXPORT_SUPPORT: "EXPORT_SUPPORT",
CAP_BIG_WRITES: "BIG_WRITES",
CAP_DONT_MASK: "DONT_MASK",
CAP_SPLICE_WRITE: "SPLICE_WRITE",
CAP_SPLICE_MOVE: "SPLICE_MOVE",
CAP_SPLICE_READ: "SPLICE_READ",
}
writeFlagNames = map[int]string{ writeFlagNames = map[int]string{
WRITE_CACHE: "CACHE", WRITE_CACHE: "CACHE",
WRITE_LOCKOWNER: "LOCKOWNER", WRITE_LOCKOWNER: "LOCKOWNER",
...@@ -74,17 +61,6 @@ func (me *CreateOut) String() string { ...@@ -74,17 +61,6 @@ func (me *CreateOut) String() string {
return fmt.Sprintf("{%v %v}", &me.EntryOut, &me.OpenOut) return fmt.Sprintf("{%v %v}", &me.EntryOut, &me.OpenOut)
} }
func (me *InitIn) String() string {
return fmt.Sprintf("{%d.%d Ra 0x%x %s}",
me.Major, me.Minor, me.MaxReadAhead,
raw.FlagString(initFlagNames, int(me.Flags), ""))
}
func (me *InitOut) String() string {
return fmt.Sprintf("{%d.%d Ra 0x%x %s %d/%d Wr 0x%x}",
me.Major, me.Minor, me.MaxReadAhead,
raw.FlagString(initFlagNames, int(me.Flags), ""),
me.CongestionThreshold, me.MaxBackground, me.MaxWrite)
}
func (me *ReadIn) String() string { func (me *ReadIn) String() string {
return fmt.Sprintf("{Fh %d off %d sz %d %s L %d %s}", return fmt.Sprintf("{Fh %d off %d sz %d %s L %d %s}",
......
...@@ -234,108 +234,6 @@ type AccessIn struct { ...@@ -234,108 +234,6 @@ type AccessIn struct {
Padding uint32 Padding uint32
} }
// To be set in InitIn/InitOut.Flags.
const (
CAP_ASYNC_READ = (1 << 0)
CAP_POSIX_LOCKS = (1 << 1)
CAP_FILE_OPS = (1 << 2)
CAP_ATOMIC_O_TRUNC = (1 << 3)
CAP_EXPORT_SUPPORT = (1 << 4)
CAP_BIG_WRITES = (1 << 5)
CAP_DONT_MASK = (1 << 6)
CAP_SPLICE_WRITE = (1 << 7)
CAP_SPLICE_MOVE = (1 << 8)
CAP_SPLICE_READ = (1 << 9)
)
type InitIn struct {
Major uint32
Minor uint32
MaxReadAhead uint32
Flags uint32
}
type InitOut struct {
Major uint32
Minor uint32
MaxReadAhead uint32
Flags uint32
MaxBackground uint16
CongestionThreshold uint16
MaxWrite uint32
}
type CuseInitIn struct {
Major uint32
Minor uint32
Unused uint32
Flags uint32
}
type CuseInitOut struct {
Major uint32
Minor uint32
Unused uint32
Flags uint32
MaxRead uint32
MaxWrite uint32
DevMajor uint32
DevMinor uint32
Spare [10]uint32
}
type InterruptIn struct {
Unique uint64
}
type BmapIn struct {
Block uint64
Blocksize uint32
Padding uint32
}
type BmapOut struct {
Block uint64
}
const (
FUSE_IOCTL_COMPAT = (1 << 0)
FUSE_IOCTL_UNRESTRICTED = (1 << 1)
FUSE_IOCTL_RETRY = (1 << 2)
)
type IoctlIn struct {
Fh uint64
Flags uint32
Cmd uint32
Arg uint64
InSize uint32
OutSize uint32
}
type IoctlOut struct {
Result int32
Flags uint32
InIovs uint32
OutIovs uint32
}
type PollIn struct {
Fh uint64
Kh uint64
Flags uint32
Padding uint32
}
type PollOut struct {
Revents uint32
Padding uint32
}
type NotifyPollWakeupOut struct {
Kh uint64
}
type InHeader struct { type InHeader struct {
Length uint32 Length uint32
opcode opcode
......
...@@ -6,11 +6,24 @@ import ( ...@@ -6,11 +6,24 @@ import (
"syscall" "syscall"
) )
var initFlagNames map[int]string
var releaseFlagNames map[int]string var releaseFlagNames map[int]string
var OpenFlagNames map[int]string var OpenFlagNames map[int]string
var FuseOpenFlagNames map[int]string var FuseOpenFlagNames map[int]string
func init() { func init() {
initFlagNames = map[int]string{
CAP_ASYNC_READ: "ASYNC_READ",
CAP_POSIX_LOCKS: "POSIX_LOCKS",
CAP_FILE_OPS: "FILE_OPS",
CAP_ATOMIC_O_TRUNC: "ATOMIC_O_TRUNC",
CAP_EXPORT_SUPPORT: "EXPORT_SUPPORT",
CAP_BIG_WRITES: "BIG_WRITES",
CAP_DONT_MASK: "DONT_MASK",
CAP_SPLICE_WRITE: "SPLICE_WRITE",
CAP_SPLICE_MOVE: "SPLICE_MOVE",
CAP_SPLICE_READ: "SPLICE_READ",
}
releaseFlagNames = map[int]string{ releaseFlagNames = map[int]string{
RELEASE_FLUSH: "FLUSH", RELEASE_FLUSH: "FLUSH",
} }
...@@ -122,5 +135,15 @@ func (me *OpenOut) String() string { ...@@ -122,5 +135,15 @@ func (me *OpenOut) String() string {
FlagString(FuseOpenFlagNames, int(me.OpenFlags), "")) FlagString(FuseOpenFlagNames, int(me.OpenFlags), ""))
} }
func (me *InitIn) String() string {
return fmt.Sprintf("{%d.%d Ra 0x%x %s}",
me.Major, me.Minor, me.MaxReadAhead,
FlagString(initFlagNames, int(me.Flags), ""))
}
func (me *InitOut) String() string {
return fmt.Sprintf("{%d.%d Ra 0x%x %s %d/%d Wr 0x%x}",
me.Major, me.Minor, me.MaxReadAhead,
FlagString(initFlagNames, int(me.Flags), ""),
me.CongestionThreshold, me.MaxBackground, me.MaxWrite)
}
...@@ -110,3 +110,105 @@ type OpenOut struct { ...@@ -110,3 +110,105 @@ type OpenOut struct {
OpenFlags uint32 OpenFlags uint32
Padding uint32 Padding uint32
} }
// To be set in InitIn/InitOut.Flags.
const (
CAP_ASYNC_READ = (1 << 0)
CAP_POSIX_LOCKS = (1 << 1)
CAP_FILE_OPS = (1 << 2)
CAP_ATOMIC_O_TRUNC = (1 << 3)
CAP_EXPORT_SUPPORT = (1 << 4)
CAP_BIG_WRITES = (1 << 5)
CAP_DONT_MASK = (1 << 6)
CAP_SPLICE_WRITE = (1 << 7)
CAP_SPLICE_MOVE = (1 << 8)
CAP_SPLICE_READ = (1 << 9)
)
type InitIn struct {
Major uint32
Minor uint32
MaxReadAhead uint32
Flags uint32
}
type InitOut struct {
Major uint32
Minor uint32
MaxReadAhead uint32
Flags uint32
MaxBackground uint16
CongestionThreshold uint16
MaxWrite uint32
}
type CuseInitIn struct {
Major uint32
Minor uint32
Unused uint32
Flags uint32
}
type CuseInitOut struct {
Major uint32
Minor uint32
Unused uint32
Flags uint32
MaxRead uint32
MaxWrite uint32
DevMajor uint32
DevMinor uint32
Spare [10]uint32
}
type InterruptIn struct {
Unique uint64
}
type BmapIn struct {
Block uint64
Blocksize uint32
Padding uint32
}
type BmapOut struct {
Block uint64
}
const (
FUSE_IOCTL_COMPAT = (1 << 0)
FUSE_IOCTL_UNRESTRICTED = (1 << 1)
FUSE_IOCTL_RETRY = (1 << 2)
)
type IoctlIn struct {
Fh uint64
Flags uint32
Cmd uint32
Arg uint64
InSize uint32
OutSize uint32
}
type IoctlOut struct {
Result int32
Flags uint32
InIovs uint32
OutIovs uint32
}
type PollIn struct {
Fh uint64
Kh uint64
Flags uint32
Padding uint32
}
type PollOut struct {
Revents uint32
Padding uint32
}
type NotifyPollWakeupOut struct {
Kh uint64
}
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