set up requests from server side
This commit is contained in:
parent
a4f53875bc
commit
4015bc3896
3 changed files with 143 additions and 30 deletions
|
|
@ -240,7 +240,7 @@ func (fs *WsFs) Truncate(name string, offset uint64, context *fuse.Context) (cod
|
||||||
r := Request{
|
r := Request{
|
||||||
Method: MethodChown,
|
Method: MethodChown,
|
||||||
Path: name,
|
Path: name,
|
||||||
Offset: offset,
|
Offset: int64(offset),
|
||||||
}
|
}
|
||||||
resp, ok := fs.getResponse(&r)
|
resp, ok := fs.getResponse(&r)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|
@ -275,7 +275,10 @@ func (fs *WsFs) Open(name string, flags uint32, context *fuse.Context) (file nod
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fuse.ENOSYS
|
return nil, fuse.ENOSYS
|
||||||
}
|
}
|
||||||
return newWsFsFile(*resp.FileHandle, fs), resp.Code
|
if resp.Code != fuse.OK {
|
||||||
|
return nil, resp.Code
|
||||||
|
}
|
||||||
|
return newWsFsFile(resp.FileHandle, fs), resp.Code
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fs *WsFs) Create(name string, flags uint32, mode uint32, context *fuse.Context) (file nodefs.File, code fuse.Status) {
|
func (fs *WsFs) Create(name string, flags uint32, mode uint32, context *fuse.Context) (file nodefs.File, code fuse.Status) {
|
||||||
|
|
@ -288,5 +291,8 @@ func (fs *WsFs) Create(name string, flags uint32, mode uint32, context *fuse.Con
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fuse.ENOSYS
|
return nil, fuse.ENOSYS
|
||||||
}
|
}
|
||||||
return newWsFsFile(*resp.FileHandle, fs), resp.Code
|
if resp.Code != fuse.OK {
|
||||||
|
return nil, resp.Code
|
||||||
|
}
|
||||||
|
return newWsFsFile(resp.FileHandle, fs), resp.Code
|
||||||
}
|
}
|
||||||
|
|
|
||||||
120
fs_file.go
120
fs_file.go
|
|
@ -1,6 +1,7 @@
|
||||||
package kubelwagen
|
package kubelwagen
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/hanwen/go-fuse/fuse"
|
"github.com/hanwen/go-fuse/fuse"
|
||||||
|
|
@ -21,32 +22,87 @@ func newWsFsFile(handle int, fs *WsFs) *WsFsFile {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func (f *WsFsFile) String() string {
|
func (f *WsFsFile) String() string {
|
||||||
return "WsFsFile"
|
return fmt.Sprintf("WsFsFile:%d", f.h)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *WsFsFile) Read(buf []byte, off int64) (fuse.ReadResult, fuse.Status) {
|
func (f *WsFsFile) Read(buf []byte, off int64) (fuse.ReadResult, fuse.Status) {
|
||||||
return nil, fuse.ENOSYS
|
r := Request{
|
||||||
|
Method: MethodFileRead,
|
||||||
|
FileHandle: f.h,
|
||||||
|
Offset: off,
|
||||||
|
}
|
||||||
|
resp, ok := f.fs.getResponse(&r)
|
||||||
|
if !ok {
|
||||||
|
return nil, fuse.ENOSYS
|
||||||
|
}
|
||||||
|
return fuse.ReadResultData(resp.Data), resp.Code
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *WsFsFile) Write(data []byte, off int64) (uint32, fuse.Status) {
|
func (f *WsFsFile) Write(data []byte, off int64) (uint32, fuse.Status) {
|
||||||
return 0, fuse.ENOSYS
|
r := Request{
|
||||||
|
Method: MethodFileWrite,
|
||||||
|
FileHandle: f.h,
|
||||||
|
Offset: off,
|
||||||
|
Data: data,
|
||||||
|
}
|
||||||
|
resp, ok := f.fs.getResponse(&r)
|
||||||
|
if !ok {
|
||||||
|
return 0, fuse.ENOSYS
|
||||||
|
}
|
||||||
|
return uint32(resp.WriteSize), resp.Code
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *WsFsFile) Flock(flags int) fuse.Status {
|
||||||
|
r := Request{
|
||||||
|
Method: MethodFileFlock,
|
||||||
|
FileHandle: f.h,
|
||||||
|
Flags: uint32(flags),
|
||||||
|
}
|
||||||
|
resp, ok := f.fs.getResponse(&r)
|
||||||
|
if !ok {
|
||||||
|
return fuse.ENOSYS
|
||||||
|
}
|
||||||
|
return resp.Code
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *WsFsFile) Flock(flags int) fuse.Status { return fuse.ENOSYS }
|
|
||||||
func (f *WsFsFile) Flush() fuse.Status {
|
func (f *WsFsFile) Flush() fuse.Status {
|
||||||
return fuse.OK
|
return f.Fsync(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *WsFsFile) Release() {
|
func (f *WsFsFile) Release() {
|
||||||
|
r := Request{
|
||||||
|
Method: MethodFileRelease,
|
||||||
|
FileHandle: f.h,
|
||||||
|
}
|
||||||
|
f.fs.getResponse(&r)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *WsFsFile) GetAttr(*fuse.Attr) fuse.Status {
|
func (f *WsFsFile) GetAttr(attr *fuse.Attr) fuse.Status {
|
||||||
return fuse.ENOSYS
|
r := Request{
|
||||||
|
Method: MethodFileGetAttr,
|
||||||
|
FileHandle: f.h,
|
||||||
|
}
|
||||||
|
resp, ok := f.fs.getResponse(&r)
|
||||||
|
if !ok {
|
||||||
|
return fuse.ENOSYS
|
||||||
|
}
|
||||||
|
if resp.Stat != nil {
|
||||||
|
*attr = *resp.Stat
|
||||||
|
}
|
||||||
|
return resp.Code
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *WsFsFile) Fsync(flags int) (code fuse.Status) {
|
func (f *WsFsFile) Fsync(flags int) (code fuse.Status) {
|
||||||
return fuse.ENOSYS
|
r := Request{
|
||||||
|
Method: MethodFileFsync,
|
||||||
|
FileHandle: f.h,
|
||||||
|
Flags: uint32(flags),
|
||||||
|
}
|
||||||
|
resp, ok := f.fs.getResponse(&r)
|
||||||
|
if !ok {
|
||||||
|
return fuse.ENOSYS
|
||||||
|
}
|
||||||
|
return resp.Code
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *WsFsFile) Utimens(atime *time.Time, mtime *time.Time) fuse.Status {
|
func (f *WsFsFile) Utimens(atime *time.Time, mtime *time.Time) fuse.Status {
|
||||||
|
|
@ -54,17 +110,55 @@ func (f *WsFsFile) Utimens(atime *time.Time, mtime *time.Time) fuse.Status {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *WsFsFile) Truncate(size uint64) fuse.Status {
|
func (f *WsFsFile) Truncate(size uint64) fuse.Status {
|
||||||
return fuse.ENOSYS
|
r := Request{
|
||||||
|
Method: MethodFileTruncate,
|
||||||
|
FileHandle: f.h,
|
||||||
|
Size: uint32(size),
|
||||||
|
}
|
||||||
|
resp, ok := f.fs.getResponse(&r)
|
||||||
|
if !ok {
|
||||||
|
return fuse.ENOSYS
|
||||||
|
}
|
||||||
|
return resp.Code
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *WsFsFile) Chown(uid uint32, gid uint32) fuse.Status {
|
func (f *WsFsFile) Chown(uid uint32, gid uint32) fuse.Status {
|
||||||
return fuse.ENOSYS
|
r := Request{
|
||||||
|
Method: MethodFileChown,
|
||||||
|
FileHandle: f.h,
|
||||||
|
UID: uid,
|
||||||
|
GID: gid,
|
||||||
|
}
|
||||||
|
resp, ok := f.fs.getResponse(&r)
|
||||||
|
if !ok {
|
||||||
|
return fuse.ENOSYS
|
||||||
|
}
|
||||||
|
return resp.Code
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *WsFsFile) Chmod(perms uint32) fuse.Status {
|
func (f *WsFsFile) Chmod(perms uint32) fuse.Status {
|
||||||
return fuse.ENOSYS
|
r := Request{
|
||||||
|
Method: MethodFileChmod,
|
||||||
|
FileHandle: f.h,
|
||||||
|
Flags: perms,
|
||||||
|
}
|
||||||
|
resp, ok := f.fs.getResponse(&r)
|
||||||
|
if !ok {
|
||||||
|
return fuse.ENOSYS
|
||||||
|
}
|
||||||
|
return resp.Code
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *WsFsFile) Allocate(off uint64, size uint64, mode uint32) (code fuse.Status) {
|
func (f *WsFsFile) Allocate(off uint64, size uint64, mode uint32) (code fuse.Status) {
|
||||||
return fuse.ENOSYS
|
r := Request{
|
||||||
|
Method: MethodFileAllocate,
|
||||||
|
FileHandle: f.h,
|
||||||
|
Mode: mode,
|
||||||
|
Size: uint32(size),
|
||||||
|
}
|
||||||
|
resp, ok := f.fs.getResponse(&r)
|
||||||
|
if !ok {
|
||||||
|
return fuse.ENOSYS
|
||||||
|
}
|
||||||
|
return resp.Code
|
||||||
}
|
}
|
||||||
|
|
|
||||||
41
request.go
41
request.go
|
|
@ -23,22 +23,34 @@ const (
|
||||||
MethodAccess
|
MethodAccess
|
||||||
MethodOpen
|
MethodOpen
|
||||||
MethodCreate
|
MethodCreate
|
||||||
|
|
||||||
|
MethodFileRead
|
||||||
|
MethodFileWrite
|
||||||
|
MethodFileFlock
|
||||||
|
MethodFileRelease
|
||||||
|
MethodFileGetAttr
|
||||||
|
MethodFileFsync
|
||||||
|
MethodFileTruncate
|
||||||
|
MethodFileChown
|
||||||
|
MethodFileChmod
|
||||||
|
MethodFileAllocate
|
||||||
)
|
)
|
||||||
|
|
||||||
type Request struct {
|
type Request struct {
|
||||||
ID int `json:"id"`
|
ID int `json:"id"`
|
||||||
Method Method `json:"method"`
|
Method Method `json:"method"`
|
||||||
Path string `json:"path"`
|
Path string `json:"path"`
|
||||||
Mode uint32
|
Mode uint32
|
||||||
UID uint32
|
UID uint32
|
||||||
GID uint32
|
GID uint32
|
||||||
Size uint32
|
Size uint32
|
||||||
Dev int32
|
Dev int32
|
||||||
Flags uint32
|
Flags uint32
|
||||||
Offset uint64
|
Offset int64
|
||||||
NewPath string `json:"newpath,omitempty"`
|
NewPath string `json:"newpath,omitempty"`
|
||||||
Attr string `json:"attr,omitempty"`
|
Attr string `json:"attr,omitempty"`
|
||||||
Data []byte `json:"data,omitempty"`
|
Data []byte `json:"data,omitempty"`
|
||||||
|
FileHandle int `json:"handle,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type RequestCallback struct {
|
type RequestCallback struct {
|
||||||
|
|
@ -55,5 +67,6 @@ type Response struct {
|
||||||
Dirents []fuse.DirEntry `json:"dirents,omitempty"`
|
Dirents []fuse.DirEntry `json:"dirents,omitempty"`
|
||||||
LinkStr string `json:"linkstr,omitempty"`
|
LinkStr string `json:"linkstr,omitempty"`
|
||||||
Statfs *fuse.StatfsOut `json:"statfs,omitempty"`
|
Statfs *fuse.StatfsOut `json:"statfs,omitempty"`
|
||||||
FileHandle *int `json:"filehandle,omitempty"`
|
FileHandle int `json:"filehandle,omitempty"`
|
||||||
|
WriteSize int `json:"wsize,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue