Commit 5610b3e4 authored by Ivan Krasin's avatar Ivan Krasin

FileSystem.GetAttr has now easy arguments. Return value is still hard

parent 34b6d99b
...@@ -16,7 +16,7 @@ const ( ...@@ -16,7 +16,7 @@ const (
type FileSystem interface { type FileSystem interface {
List(parent string) (names []string, code Error, err os.Error) List(parent string) (names []string, code Error, err os.Error)
Lookup(parent, filename string) (out *Attr, code Error, err os.Error) Lookup(parent, filename string) (out *Attr, code Error, err os.Error)
GetAttr(h *InHeader, in *GetAttrIn) (out *AttrOut, code Error, err os.Error) GetAttr(path string, id *Identity, flags uint32) (out *AttrOut, code Error, err os.Error)
} }
type Mounted interface { type Mounted interface {
...@@ -41,7 +41,7 @@ func loop(f *os.File, fs FileSystem, errors chan os.Error) { ...@@ -41,7 +41,7 @@ func loop(f *os.File, fs FileSystem, errors chan os.Error) {
go writer(f, toW, errors) go writer(f, toW, errors)
managerReq := make(chan *managerRequest, 100) managerReq := make(chan *managerRequest, 100)
startManager(fs, managerReq) startManager(fs, managerReq)
c := &managerClient{ managerReq } c := &managerClient{managerReq}
defer close(managerReq) defer close(managerReq)
for { for {
n, err := f.Read(buf) n, err := f.Read(buf)
...@@ -166,10 +166,21 @@ func getAttr(fs FileSystem, h *InHeader, r io.Reader, c *managerClient) (data [] ...@@ -166,10 +166,21 @@ func getAttr(fs FileSystem, h *InHeader, r io.Reader, c *managerClient) (data []
} }
fmt.Printf("FUSE_GETATTR: %v, Fh: %d\n", in, in.Fh) fmt.Printf("FUSE_GETATTR: %v, Fh: %d\n", in, in.Fh)
var out *AttrOut var out *AttrOut
out, res, err := fs.GetAttr(h, in) resp := c.getPath(in.Fh)
if resp.err != nil {
err = resp.err
return
}
if resp.code != OK {
return serialize(h, resp.code, nil)
}
out, res, err := fs.GetAttr(resp.path, &h.Identity, in.GetAttrFlags)
if err != nil { if err != nil {
return return
} }
if out != nil {
out.Ino = h.NodeId
}
data, err = serialize(h, res, out) data, err = serialize(h, res, out)
return return
} }
...@@ -319,6 +330,7 @@ const ( ...@@ -319,6 +330,7 @@ const (
getHandleOp = FileOp(2) getHandleOp = FileOp(2)
closeDirOp = FileOp(3) closeDirOp = FileOp(3)
lookupOp = FileOp(4) lookupOp = FileOp(4)
getPathOp = FileOp(5)
) )
type managerRequest struct { type managerRequest struct {
...@@ -336,17 +348,18 @@ type managerResponse struct { ...@@ -336,17 +348,18 @@ type managerResponse struct {
err os.Error err os.Error
code Error code Error
attr *Attr attr *Attr
path string
} }
type dirEntry struct { type dirEntry struct {
nodeId uint64 nodeId uint64
name string name string
mode uint32 mode uint32
} }
type dirRequest struct { type dirRequest struct {
isClose bool isClose bool
nodeId uint64 nodeId uint64
offset uint64 offset uint64
resp chan *dirResponse resp chan *dirResponse
} }
...@@ -364,7 +377,7 @@ type dirHandle struct { ...@@ -364,7 +377,7 @@ type dirHandle struct {
type manager struct { type manager struct {
fs FileSystem fs FileSystem
client *managerClient client *managerClient
dirHandles map[uint64]*dirHandle dirHandles map[uint64]*dirHandle
cnt uint64 cnt uint64
nodes map[uint64]string nodes map[uint64]string
...@@ -375,7 +388,7 @@ type manager struct { ...@@ -375,7 +388,7 @@ type manager struct {
func startManager(fs FileSystem, requests chan *managerRequest) { func startManager(fs FileSystem, requests chan *managerRequest) {
m := new(manager) m := new(manager)
m.fs = fs m.fs = fs
m.client = &managerClient { requests } m.client = &managerClient{requests}
m.dirHandles = make(map[uint64]*dirHandle) m.dirHandles = make(map[uint64]*dirHandle)
m.nodes = make(map[uint64]string) m.nodes = make(map[uint64]string)
m.nodes[1] = "" // Root m.nodes[1] = "" // Root
...@@ -410,6 +423,10 @@ func (c *managerClient) getDirReader(nodeId, fh uint64) (resp *managerResponse) ...@@ -410,6 +423,10 @@ func (c *managerClient) getDirReader(nodeId, fh uint64) (resp *managerResponse)
return c.makeManagerRequest(nodeId, fh, getHandleOp, "") return c.makeManagerRequest(nodeId, fh, getHandleOp, "")
} }
func (c *managerClient) getPath(fh uint64) (resp *managerResponse) {
return c.makeManagerRequest(0, fh, getPathOp, "")
}
func (c *managerClient) closeDir(nodeId, fh uint64) (resp *managerResponse) { func (c *managerClient) closeDir(nodeId, fh uint64) (resp *managerResponse) {
return c.makeManagerRequest(nodeId, fh, closeDirOp, "") return c.makeManagerRequest(nodeId, fh, closeDirOp, "")
} }
...@@ -426,6 +443,8 @@ func (m *manager) run(requests chan *managerRequest) { ...@@ -426,6 +443,8 @@ func (m *manager) run(requests chan *managerRequest) {
resp = m.closeDir(req) resp = m.closeDir(req)
case lookupOp: case lookupOp:
resp = m.lookup(req) resp = m.lookup(req)
case getPathOp:
resp = m.getPath(req)
default: default:
resp := new(managerResponse) resp := new(managerResponse)
resp.err = os.NewError(fmt.Sprintf("Unknown FileOp: %v", req.op)) resp.err = os.NewError(fmt.Sprintf("Unknown FileOp: %v", req.op))
...@@ -506,6 +525,22 @@ func (m *manager) lookup(req *managerRequest) (resp *managerResponse) { ...@@ -506,6 +525,22 @@ func (m *manager) lookup(req *managerRequest) (resp *managerResponse) {
return return
} }
func (m *manager) getPath(req *managerRequest) (resp *managerResponse) {
resp = new(managerResponse)
h, ok := m.dirHandles[req.fh]
if !ok {
resp.err = os.NewError(fmt.Sprintf("Can't find fh: %d", req.fh))
return
}
path, ok := m.nodes[h.nodeId]
if !ok {
resp.err = os.NewError(fmt.Sprintf("Fh = %d points to unknown nodeId: %d", req.fh, h.nodeId))
return
}
resp.path = path
return
}
func readDirRoutine(dir string, fs FileSystem, c *managerClient, requests chan *dirRequest) { func readDirRoutine(dir string, fs FileSystem, c *managerClient, requests chan *dirRequest) {
defer close(requests) defer close(requests)
dir = path.Clean(dir) dir = path.Clean(dir)
...@@ -513,11 +548,11 @@ func readDirRoutine(dir string, fs FileSystem, c *managerClient, requests chan * ...@@ -513,11 +548,11 @@ func readDirRoutine(dir string, fs FileSystem, c *managerClient, requests chan *
i := uint64(0) i := uint64(0)
for req := range requests { for req := range requests {
if err != nil { if err != nil {
req.resp <- &dirResponse{ nil, err } req.resp <- &dirResponse{nil, err}
return return
} }
if code != OK { if code != OK {
req.resp <- &dirResponse { nil, os.NewError(fmt.Sprintf("fs.List returned code: %d", code))} req.resp <- &dirResponse{nil, os.NewError(fmt.Sprintf("fs.List returned code: %d", code))}
return return
} }
if req.offset != i { if req.offset != i {
...@@ -532,7 +567,7 @@ func readDirRoutine(dir string, fs FileSystem, c *managerClient, requests chan * ...@@ -532,7 +567,7 @@ func readDirRoutine(dir string, fs FileSystem, c *managerClient, requests chan *
entry.name = names[i] entry.name = names[i]
lookupResp := c.lookup(req.nodeId, entry.name) lookupResp := c.lookup(req.nodeId, entry.name)
if lookupResp.err != nil { if lookupResp.err != nil {
req.resp <- &dirResponse { nil, lookupResp.err } req.resp <- &dirResponse{nil, lookupResp.err}
return return
} }
entry.nodeId = lookupResp.nodeId entry.nodeId = lookupResp.nodeId
......
...@@ -13,15 +13,15 @@ import ( ...@@ -13,15 +13,15 @@ import (
const ( const (
tempMountDir = "./.testMountDir" tempMountDir = "./.testMountDir"
) )
var ( var (
testFileNames = []string { "one", "two", "three3" } testFileNames = []string{"one", "two", "three3"}
) )
type testFuse struct{} type testFuse struct{}
func (fs *testFuse) GetAttr(h *InHeader, in *GetAttrIn) (out *AttrOut, code Error, err os.Error) { func (fs *testFuse) GetAttr(path string, id *Identity, flags uint32) (out *AttrOut, code Error, err os.Error) {
out = new(AttrOut) out = new(AttrOut)
out.Ino = h.NodeId
out.Mode = S_IFDIR out.Mode = S_IFDIR
return return
} }
......
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