diff --git a/cmd/p9/mount.go b/cmd/p9/mount.go index eb979a2..a7905a2 100644 --- a/cmd/p9/mount.go +++ b/cmd/p9/mount.go @@ -104,7 +104,7 @@ func (node *fuseNode) flags(f fuse.OpenFlags) (flags uint8) { func (node *fuseNode) Attr(ctx context.Context, attr *fuse.Attr) error { s, err := node.n.Stat(node.p) if err != nil { - fmt.Printf("Error statting file: %v", err) + log.Printf("Error statting file: %v", err) return err } @@ -124,7 +124,7 @@ func (node *fuseNode) Lookup(ctx context.Context, name string) (fs.Node, error) return nil, fuse.ENOENT } - return &fuseNode{node.n, p}, nil + return &fuseNode{n: node.n, p: p}, nil } func (node *fuseNode) Open(ctx context.Context, req *fuse.OpenRequest, rsp *fuse.OpenResponse) (fs.Handle, error) { @@ -136,6 +136,33 @@ func (node *fuseNode) Open(ctx context.Context, req *fuse.OpenRequest, rsp *fuse return &fuseNode{n: n}, nil } +func (node *fuseNode) Create(ctx context.Context, req *fuse.CreateRequest, rsp *fuse.CreateResponse) (fs.Handle, error) { + n, err := node.n.Create(path.Join(node.p, req.Name), p9.ModeFromOS(req.Mode), node.flags(req.Flags)) + if err != nil { + log.Printf("Error creating file: %v", err) + return nil, err + } + return &fuseNode{n: n}, nil +} + +func (node *fuseNode) Mkdir(ctx context.Context, req *fuse.MkdirRequest) (fs.Node, error) { + p := path.Join(node.p, req.Name) + + n, err := node.n.Create(p, p9.ModeFromOS(req.Mode)|p9.ModeDir, 0) + if err != nil { + log.Printf("Error creating directory: %v", err) + return nil, err + } + + err = n.Close() + if err != nil { + log.Printf("Error closing newly-created directory: %v", err) + return nil, err + } + + return &fuseNode{n: n, p: p}, nil +} + func (node *fuseNode) direntType(m p9.FileMode) fuse.DirentType { switch { case m&p9.ModeDir != 0: @@ -165,6 +192,16 @@ func (node *fuseNode) Read(ctx context.Context, req *fuse.ReadRequest, rsp *fuse return nil } +func (node *fuseNode) Write(ctx context.Context, req *fuse.WriteRequest, rsp *fuse.WriteResponse) error { + n, err := node.n.WriteAt(req.Data, req.Offset) + rsp.Size = n + if err != nil { + log.Printf("Error writing file: %v", err) + return err + } + return nil +} + func (node *fuseNode) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) { e, err := node.n.Readdir() if err != nil { diff --git a/proto/client.go b/proto/client.go index b4af3d5..6dcb959 100644 --- a/proto/client.go +++ b/proto/client.go @@ -163,7 +163,7 @@ func (c *Client) SetMsize(size uint32) { // concurrently, and each will return when the response to that // request has been received. func (c *Client) Send(msg interface{}) (interface{}, error) { - debug.Log("client -> %T\n", msg) + debug.Log("client -> %#v\n", msg) tag := NoTag if _, ok := msg.(P9NoTag); !ok { @@ -198,7 +198,7 @@ func (c *Client) Send(msg interface{}) (interface{}, error) { case <-c.done: return nil, ErrClientClosed case rsp := <-ret: - debug.Log("client <- %T\n", rsp) + debug.Log("client <- %#v\n", rsp) if err, ok := rsp.(error); ok { return nil, err