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

Move WriteIn/ReadIn to raw/

parent aa91e8c0
......@@ -278,16 +278,16 @@ type RawFileSystem interface {
// File handling.
Create(out *raw.CreateOut, header *raw.InHeader, input *raw.CreateIn, name string) (code Status)
Open(out *raw.OpenOut, header *raw.InHeader, input *raw.OpenIn) (status Status)
Read(*raw.InHeader, *ReadIn, []byte) ReadResult
Read(*raw.InHeader, *raw.ReadIn, []byte) ReadResult
Release(header *raw.InHeader, input *raw.ReleaseIn)
Write(*raw.InHeader, *WriteIn, []byte) (written uint32, code Status)
Write(*raw.InHeader, *raw.WriteIn, []byte) (written uint32, code Status)
Flush(header *raw.InHeader, input *raw.FlushIn) Status
Fsync(*raw.InHeader, *raw.FsyncIn) (code Status)
// Directory handling
OpenDir(out *raw.OpenOut, header *raw.InHeader, input *raw.OpenIn) (status Status)
ReadDir(out *DirEntryList, header *raw.InHeader, input *ReadIn) Status
ReadDir(out *DirEntryList, header *raw.InHeader, input *raw.ReadIn) Status
ReleaseDir(header *raw.InHeader, input *raw.ReleaseIn)
FsyncDir(header *raw.InHeader, input *raw.FsyncIn) (code Status)
......
......@@ -17,10 +17,7 @@ func CopyFile(srcFs, destFs FileSystem, srcFile, destFile string, context *Conte
return code
}
w := WriteIn{
Flags: uint32(os.O_WRONLY | os.O_CREATE | os.O_TRUNC),
}
dst, code := destFs.Create(destFile, w.Flags, attr.Mode, context)
dst, code := destFs.Create(destFile, uint32(os.O_WRONLY | os.O_CREATE | os.O_TRUNC), attr.Mode, context)
if !code.Ok() {
return code
}
......
......@@ -96,14 +96,14 @@ func (fs *DefaultRawFileSystem) OpenDir(out *raw.OpenOut, header *raw.InHeader,
return ENOSYS
}
func (fs *DefaultRawFileSystem) Read(header *raw.InHeader, input *ReadIn, buf []byte) ReadResult {
func (fs *DefaultRawFileSystem) Read(header *raw.InHeader, input *raw.ReadIn, buf []byte) ReadResult {
return ReadResult{}
}
func (fs *DefaultRawFileSystem) Release(header *raw.InHeader, input *raw.ReleaseIn) {
}
func (fs *DefaultRawFileSystem) Write(header *raw.InHeader, input *WriteIn, data []byte) (written uint32, code Status) {
func (fs *DefaultRawFileSystem) Write(header *raw.InHeader, input *raw.WriteIn, data []byte) (written uint32, code Status) {
return 0, ENOSYS
}
......@@ -115,7 +115,7 @@ func (fs *DefaultRawFileSystem) Fsync(header *raw.InHeader, input *raw.FsyncIn)
return ENOSYS
}
func (fs *DefaultRawFileSystem) ReadDir(l *DirEntryList, header *raw.InHeader, input *ReadIn) Status {
func (fs *DefaultRawFileSystem) ReadDir(l *DirEntryList, header *raw.InHeader, input *raw.ReadIn) Status {
return ENOSYS
}
......
......@@ -73,7 +73,7 @@ func (l *DirEntryList) Bytes() []byte {
////////////////////////////////////////////////////////////////
type rawDir interface {
ReadDir(out *DirEntryList, input *ReadIn) Status
ReadDir(out *DirEntryList, input *raw.ReadIn) Status
Release()
}
......@@ -83,7 +83,7 @@ type connectorDir struct {
lastOffset uint64
}
func (d *connectorDir) ReadDir(list *DirEntryList, input *ReadIn) (code Status) {
func (d *connectorDir) ReadDir(list *DirEntryList, input *raw.ReadIn) (code Status) {
if d.stream == nil {
return OK
}
......
......@@ -123,7 +123,7 @@ func (c *FileSystemConnector) OpenDir(out *raw.OpenOut, header *raw.InHeader, in
return OK
}
func (c *FileSystemConnector) ReadDir(l *DirEntryList, header *raw.InHeader, input *ReadIn) Status {
func (c *FileSystemConnector) ReadDir(l *DirEntryList, header *raw.InHeader, input *raw.ReadIn) Status {
node := c.toInode(header.NodeId)
opened := node.mount.getOpenedFile(input.Fh)
return opened.dir.ReadDir(l, input)
......@@ -344,13 +344,13 @@ func (c *FileSystemConnector) ListXAttr(header *raw.InHeader) (data []byte, code
////////////////
// files.
func (c *FileSystemConnector) Write(header *raw.InHeader, input *WriteIn, data []byte) (written uint32, code Status) {
func (c *FileSystemConnector) Write(header *raw.InHeader, input *raw.WriteIn, data []byte) (written uint32, code Status) {
node := c.toInode(header.NodeId)
opened := node.mount.getOpenedFile(input.Fh)
return opened.WithFlags.File.Write(data, int64(input.Offset))
}
func (c *FileSystemConnector) Read(header *raw.InHeader, input *ReadIn, buf []byte) ReadResult {
func (c *FileSystemConnector) Read(header *raw.InHeader, input *raw.ReadIn, buf []byte) ReadResult {
node := c.toInode(header.NodeId)
opened := node.mount.getOpenedFile(input.Fh)
......
......@@ -276,12 +276,12 @@ func (fs *LockingRawFileSystem) ReleaseDir(header *raw.InHeader, h *raw.ReleaseI
fs.RawFileSystem.ReleaseDir(header, h)
}
func (fs *LockingRawFileSystem) Read(header *raw.InHeader, input *ReadIn, buf []byte) ReadResult {
func (fs *LockingRawFileSystem) Read(header *raw.InHeader, input *raw.ReadIn, buf []byte) ReadResult {
defer fs.locked()()
return fs.RawFileSystem.Read(header, input, buf)
}
func (fs *LockingRawFileSystem) Write(header *raw.InHeader, input *WriteIn, data []byte) (written uint32, code Status) {
func (fs *LockingRawFileSystem) Write(header *raw.InHeader, input *raw.WriteIn, data []byte) (written uint32, code Status) {
defer fs.locked()()
return fs.RawFileSystem.Write(header, input, data)
}
......@@ -296,7 +296,7 @@ func (fs *LockingRawFileSystem) Fsync(header *raw.InHeader, input *raw.FsyncIn)
return fs.RawFileSystem.Fsync(header, input)
}
func (fs *LockingRawFileSystem) ReadDir(out *DirEntryList, header *raw.InHeader, input *ReadIn) Status {
func (fs *LockingRawFileSystem) ReadDir(out *DirEntryList, header *raw.InHeader, input *raw.ReadIn) Status {
defer fs.locked()()
return fs.RawFileSystem.ReadDir(out, header, input)
}
......
......@@ -127,7 +127,7 @@ func doCreate(state *MountState, req *request) {
}
func doReadDir(state *MountState, req *request) {
in := (*ReadIn)(req.inData)
in := (*raw.ReadIn)(req.inData)
buf := state.AllocOut(req, in.Size)
entries := NewDirEntryList(buf, uint64(in.Offset))
......@@ -148,7 +148,7 @@ func doSetattr(state *MountState, req *request) {
}
func doWrite(state *MountState, req *request) {
n, status := state.fileSystem.Write(req.inHeader, (*WriteIn)(req.inData), req.arg)
n, status := state.fileSystem.Write(req.inHeader, (*raw.WriteIn)(req.inData), req.arg)
o := (*raw.WriteOut)(req.outData)
o.Size = n
req.status = status
......@@ -267,7 +267,7 @@ func doLink(state *MountState, req *request) {
}
func doRead(state *MountState, req *request) {
in := (*ReadIn)(req.inData)
in := (*raw.ReadIn)(req.inData)
buf := state.AllocOut(req, in.Size)
res := state.fileSystem.Read(req.inHeader, in, buf)
req.flatData = res
......@@ -379,8 +379,8 @@ func init() {
_OP_RENAME: unsafe.Sizeof(raw.RenameIn{}),
_OP_LINK: unsafe.Sizeof(raw.LinkIn{}),
_OP_OPEN: unsafe.Sizeof(raw.OpenIn{}),
_OP_READ: unsafe.Sizeof(ReadIn{}),
_OP_WRITE: unsafe.Sizeof(WriteIn{}),
_OP_READ: unsafe.Sizeof(raw.ReadIn{}),
_OP_WRITE: unsafe.Sizeof(raw.WriteIn{}),
_OP_RELEASE: unsafe.Sizeof(raw.ReleaseIn{}),
_OP_FSYNC: unsafe.Sizeof(raw.FsyncIn{}),
_OP_SETXATTR: unsafe.Sizeof(raw.SetXAttrIn{}),
......@@ -389,7 +389,7 @@ func init() {
_OP_FLUSH: unsafe.Sizeof(raw.FlushIn{}),
_OP_INIT: unsafe.Sizeof(raw.InitIn{}),
_OP_OPENDIR: unsafe.Sizeof(raw.OpenIn{}),
_OP_READDIR: unsafe.Sizeof(ReadIn{}),
_OP_READDIR: unsafe.Sizeof(raw.ReadIn{}),
_OP_RELEASEDIR: unsafe.Sizeof(raw.ReleaseIn{}),
_OP_FSYNCDIR: unsafe.Sizeof(raw.FsyncIn{}),
_OP_ACCESS: unsafe.Sizeof(raw.AccessIn{}),
......@@ -540,8 +540,8 @@ func init() {
_OP_OPEN: func(ptr unsafe.Pointer) interface{} { return (*raw.OpenIn)(ptr) },
_OP_MKNOD: func(ptr unsafe.Pointer) interface{} { return (*raw.MknodIn)(ptr) },
_OP_CREATE: func(ptr unsafe.Pointer) interface{} { return (*raw.CreateIn)(ptr) },
_OP_READ: func(ptr unsafe.Pointer) interface{} { return (*ReadIn)(ptr) },
_OP_READDIR: func(ptr unsafe.Pointer) interface{} { return (*ReadIn)(ptr) },
_OP_READ: func(ptr unsafe.Pointer) interface{} { return (*raw.ReadIn)(ptr) },
_OP_READDIR: func(ptr unsafe.Pointer) interface{} { return (*raw.ReadIn)(ptr) },
_OP_ACCESS: func(ptr unsafe.Pointer) interface{} { return (*raw.AccessIn)(ptr) },
_OP_FORGET: func(ptr unsafe.Pointer) interface{} { return (*raw.ForgetIn)(ptr) },
_OP_BATCH_FORGET: func(ptr unsafe.Pointer) interface{} { return (*raw.BatchForgetIn)(ptr) },
......
......@@ -5,27 +5,6 @@ import (
"github.com/hanwen/go-fuse/raw"
)
var writeFlagNames map[int]string
var readFlagNames map[int]string
func init() {
writeFlagNames = map[int]string{
WRITE_CACHE: "CACHE",
WRITE_LOCKOWNER: "LOCKOWNER",
}
readFlagNames = map[int]string{
READ_LOCKOWNER: "LOCKOWNER",
}
}
func (me *ReadIn) String() string {
return fmt.Sprintf("{Fh %d off %d sz %d %s L %d %s}",
me.Fh, me.Offset, me.Size,
raw.FlagString(readFlagNames, int(me.ReadFlags), ""),
me.LockOwner,
raw.FlagString(raw.OpenFlagNames, int(me.Flags), "RDONLY"))
}
func (me *WithFlags) String() string {
return fmt.Sprintf("File %s (%s) %s %s",
me.File, me.Description, raw.FlagString(raw.OpenFlagNames, int(me.OpenFlags), "O_RDONLY"),
......
......@@ -49,31 +49,3 @@ type Context raw.Context
type StatfsOut raw.StatfsOut
const (
READ_LOCKOWNER = (1 << 1)
)
type ReadIn struct {
Fh uint64
Offset uint64
Size uint32
ReadFlags uint32
LockOwner uint64
Flags uint32
Padding uint32
}
const (
WRITE_CACHE = (1 << 0)
WRITE_LOCKOWNER = (1 << 1)
)
type WriteIn struct {
Fh uint64
Offset uint64
Size uint32
WriteFlags uint32
LockOwner uint64
Flags uint32
Padding uint32
}
......@@ -12,8 +12,18 @@ var releaseFlagNames map[int]string
var OpenFlagNames map[int]string
var FuseOpenFlagNames map[int]string
var accessFlagName map[int]string
var writeFlagNames map[int]string
var readFlagNames map[int]string
func init() {
writeFlagNames = map[int]string{
WRITE_CACHE: "CACHE",
WRITE_LOCKOWNER: "LOCKOWNER",
}
readFlagNames = map[int]string{
READ_LOCKOWNER: "LOCKOWNER",
}
initFlagNames = map[int]string{
CAP_ASYNC_READ: "ASYNC_READ",
CAP_POSIX_LOCKS: "POSIX_LOCKS",
......@@ -218,3 +228,19 @@ func (a *Attr) String() string {
a.Rdev, a.Ino, a.Atime, a.Atimensec, a.Mtime, a.Mtimensec,
a.Ctime, a.Ctimensec)
}
func (me *ReadIn) String() string {
return fmt.Sprintf("{Fh %d off %d sz %d %s L %d %s}",
me.Fh, me.Offset, me.Size,
FlagString(readFlagNames, int(me.ReadFlags), ""),
me.LockOwner,
FlagString(OpenFlagNames, int(me.Flags), "RDONLY"))
}
func (me *WriteIn) String() string {
return fmt.Sprintf("{Fh %d off %d sz %d %s L %d %s}",
me.Fh, me.Offset, me.Size,
FlagString(writeFlagNames, int(me.WriteFlags), ""),
me.LockOwner,
FlagString(OpenFlagNames, int(me.Flags), "RDONLY"))
}
......@@ -389,3 +389,32 @@ type Dirent struct {
NameLen uint32
Typ uint32
}
const (
READ_LOCKOWNER = (1 << 1)
)
type ReadIn struct {
Fh uint64
Offset uint64
Size uint32
ReadFlags uint32
LockOwner uint64
Flags uint32
Padding uint32
}
const (
WRITE_CACHE = (1 << 0)
WRITE_LOCKOWNER = (1 << 1)
)
type WriteIn struct {
Fh uint64
Offset uint64
Size uint32
WriteFlags uint32
LockOwner uint64
Flags 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