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

Go-FUSE for Darwin: runs a first test.

parent 088ea6ab
...@@ -18,5 +18,4 @@ func (a *Attr) FromStat(s *syscall.Stat_t) { ...@@ -18,5 +18,4 @@ func (a *Attr) FromStat(s *syscall.Stat_t) {
a.Uid = uint32(s.Uid) a.Uid = uint32(s.Uid)
a.Gid = uint32(s.Gid) a.Gid = uint32(s.Gid)
a.Rdev = uint32(s.Rdev) a.Rdev = uint32(s.Rdev)
a.Blksize = uint32(s.Blksize)
} }
...@@ -105,8 +105,8 @@ func (c *FileSystemConnector) GetAttr(out *raw.AttrOut, context *Context, input ...@@ -105,8 +105,8 @@ func (c *FileSystemConnector) GetAttr(out *raw.AttrOut, context *Context, input
node := c.toInode(context.NodeId) node := c.toInode(context.NodeId)
var f File var f File
if input.Flags&raw.FUSE_GETATTR_FH != 0 { if input.Flags() & raw.FUSE_GETATTR_FH != 0 {
if opened := node.mount.getOpenedFile(input.Fh); opened != nil { if opened := node.mount.getOpenedFile(input.Fh()); opened != nil {
f = opened.WithFlags.File f = opened.WithFlags.File
} }
} }
......
package fuse
import (
"syscall"
)
func (fs *LoopbackFileSystem) StatFs(name string) *StatfsOut {
s := syscall.Statfs_t{}
err := syscall.Statfs(fs.GetPath(name), &s)
if err == nil {
return &StatfsOut{
Blocks: s.Blocks,
Bsize: uint32(s.Bsize),
Bfree: s.Bfree,
Bavail: s.Bavail,
Files: s.Files,
Ffree: s.Ffree,
}
}
return nil
}
package fuse
import (
"syscall"
)
func clearStatfs(s *syscall.Statfs_t) {
empty := syscall.Statfs_t{}
s.Type = 0
s.Fsid = empty.Fsid
// s.Spare = empty.Spare
// TODO - figure out what this is for.
s.Flags = 0
}
...@@ -66,20 +66,14 @@ const ( ...@@ -66,20 +66,14 @@ const (
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
func doInit(state *MountState, req *request) { func doInit(state *MountState, req *request) {
const (
FUSE_KERNEL_VERSION = 7
MINIMUM_MINOR_VERSION = 13
OUR_MINOR_VERSION = 16
)
input := (*raw.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
return return
} }
if input.Minor < MINIMUM_MINOR_VERSION { if input.Minor < _MINIMUM_MINOR_VERSION {
log.Printf("Minor version is less than we support. Given %d, want at least %d\n", input.Minor, MINIMUM_MINOR_VERSION) log.Printf("Minor version is less than we support. Given %d, want at least %d\n", input.Minor, _MINIMUM_MINOR_VERSION)
req.status = EIO req.status = EIO
return return
} }
...@@ -93,8 +87,8 @@ func doInit(state *MountState, req *request) { ...@@ -93,8 +87,8 @@ func doInit(state *MountState, req *request) {
state.reqMu.Unlock() state.reqMu.Unlock()
out := &raw.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,
Flags: state.kernelSettings.Flags, Flags: state.kernelSettings.Flags,
MaxWrite: uint32(state.opts.MaxWrite), MaxWrite: uint32(state.opts.MaxWrite),
...@@ -339,6 +333,10 @@ func doIoctl(state *MountState, req *request) { ...@@ -339,6 +333,10 @@ func doIoctl(state *MountState, req *request) {
req.status = ENOSYS req.status = ENOSYS
} }
func doDestroy(state *MountState, req *request) {
req.status = OK
}
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
type operationFunc func(*MountState, *request) type operationFunc func(*MountState, *request)
...@@ -522,6 +520,7 @@ func init() { ...@@ -522,6 +520,7 @@ func init() {
_OP_RENAME: doRename, _OP_RENAME: doRename,
_OP_STATFS: doStatFs, _OP_STATFS: doStatFs,
_OP_IOCTL: doIoctl, _OP_IOCTL: doIoctl,
_OP_DESTROY: doDestroy,
} { } {
operationHandlers[op].Func = v operationHandlers[op].Func = v
} }
......
...@@ -11,7 +11,7 @@ import ( ...@@ -11,7 +11,7 @@ import (
) )
var sizeOfOutHeader = unsafe.Sizeof(raw.OutHeader{}) var sizeOfOutHeader = unsafe.Sizeof(raw.OutHeader{})
var zeroOutBuf [160]byte var zeroOutBuf [outputHeaderSize]byte
type request struct { type request struct {
inputBuf []byte inputBuf []byte
...@@ -49,7 +49,7 @@ type request struct { ...@@ -49,7 +49,7 @@ type request struct {
// arrays: // arrays:
// //
// Output header and structured data. // Output header and structured data.
outBuf [160]byte outBuf [outputHeaderSize]byte
// Input, if small enough to fit here. // Input, if small enough to fit here.
smallInputBuf [128]byte smallInputBuf [128]byte
......
package fuse
const outputHeaderSize = 200
const (
_FUSE_KERNEL_VERSION = 7
_MINIMUM_MINOR_VERSION = 8
_OUR_MINOR_VERSION = 8
)
\ No newline at end of file
package fuse
const outputHeaderSize = 160
const (
_FUSE_KERNEL_VERSION = 7
_MINIMUM_MINOR_VERSION = 13
_OUR_MINOR_VERSION = 16
)
...@@ -129,10 +129,6 @@ func (me *SetAttrIn) String() string { ...@@ -129,10 +129,6 @@ func (me *SetAttrIn) String() string {
return fmt.Sprintf("{%s}", strings.Join(s, ", ")) return fmt.Sprintf("{%s}", strings.Join(s, ", "))
} }
func (me *GetAttrIn) String() string {
return fmt.Sprintf("{Fh %d}", me.Fh)
}
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), ""),
......
package raw package raw
import ( import (
"fmt" "fmt"
"syscall"
) )
func (a *Attr) String() string { func (a *Attr) String() string {
...@@ -18,3 +18,5 @@ func (a *Attr) String() string { ...@@ -18,3 +18,5 @@ func (a *Attr) String() string {
a.Rdev, a.Ino, a.Atime, a.Atimensec, a.Mtime, a.Mtimensec, a.Rdev, a.Ino, a.Atime, a.Atimensec, a.Mtime, a.Mtimensec,
a.Ctime, a.Ctimensec) a.Ctime, a.Ctimensec)
} }
func (me *GetAttrIn) String() string { return "" }
\ No newline at end of file
...@@ -25,3 +25,7 @@ func (a *Attr) String() string { ...@@ -25,3 +25,7 @@ func (a *Attr) String() string {
a.Rdev, a.Ino, a.Atime, a.Atimensec, a.Mtime, a.Mtimensec, a.Rdev, a.Ino, a.Atime, a.Atimensec, a.Mtime, a.Mtimensec,
a.Ctime, a.Ctimensec) a.Ctime, a.Ctimensec)
} }
func (me *GetAttrIn) String() string {
return fmt.Sprintf("{Fh %d}", me.Fh_)
}
...@@ -73,17 +73,6 @@ type SetAttrInCommon struct { ...@@ -73,17 +73,6 @@ type SetAttrInCommon struct {
Unused5 uint32 Unused5 uint32
} }
const (
// Mask for GetAttrIn.Flags. If set, GetAttrIn has a file handle set.
FUSE_GETATTR_FH = (1 << 0)
)
type GetAttrIn struct {
Flags uint32
Dummy uint32
Fh uint64
}
const RELEASE_FLUSH = (1 << 0) const RELEASE_FLUSH = (1 << 0)
type ReleaseIn struct { type ReleaseIn struct {
......
...@@ -32,3 +32,20 @@ type SetAttrIn struct { ...@@ -32,3 +32,20 @@ type SetAttrIn struct {
CrtimeNsec uint32 CrtimeNsec uint32
Flags_ uint32 // see chflags(2) Flags_ uint32 // see chflags(2)
} }
// compat with linux.
const (
// Mask for GetAttrIn.Flags. If set, GetAttrIn has a file handle set.
FUSE_GETATTR_FH = (1 << 0)
)
type GetAttrIn struct {
}
func (g *GetAttrIn) Flags() uint32 {
return 0
}
func (g *GetAttrIn) Fh() uint64 {
return 0
}
\ No newline at end of file
...@@ -21,3 +21,22 @@ type Attr struct { ...@@ -21,3 +21,22 @@ type Attr struct {
type SetAttrIn struct { type SetAttrIn struct {
SetAttrInCommon SetAttrInCommon
} }
const (
// Mask for GetAttrIn.Flags. If set, GetAttrIn has a file handle set.
FUSE_GETATTR_FH = (1 << 0)
)
type GetAttrIn struct {
Flags_ uint32
Dummy uint32
Fh_ uint64
}
func (g *GetAttrIn) Flags() uint32 {
return g.Flags_
}
func (g *GetAttrIn) Fh() uint64 {
return g.Fh_
}
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