Skip to content

Commit

Permalink
p9: write support for mount (#69)
Browse files Browse the repository at this point in the history
* proto: Cleaner debugging messages.

* cmd/p9: Add support for Write(), Mkdir(), and Create() to `mount`.
  • Loading branch information
DeedleFake authored Nov 1, 2019
1 parent 54caf18 commit a49adef
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
41 changes: 39 additions & 2 deletions cmd/p9/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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) {
Expand All @@ -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:
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions proto/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a49adef

Please sign in to comment.