From 28605268713e6c49c9d7a0377f38307277e409bd Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Fri, 24 Jul 2015 16:01:45 +1000 Subject: [PATCH] Updated newConnection. --- connection.go | 18 +++++++++++++++--- internal/fuseshim/fuse.go | 11 +++++++---- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/connection.go b/connection.go index 4e83b8b..878f302 100644 --- a/connection.go +++ b/connection.go @@ -58,15 +58,27 @@ type Connection struct { cancelFuncs map[uint64]func() } -// Responsibility for closing the wrapped connection is transferred to the -// result. You must call c.close() eventually. +// Create a connection wrapping the supplied file descriptor connected to the +// kernel. You must eventually call c.close(). // // The loggers may be nil. func newConnection( parentCtx context.Context, debugLogger *log.Logger, errorLogger *log.Logger, - wrapped *fuseshim.Conn) (c *Connection, err error) { + dev *os.File) (c *Connection, err error) { + // Create an initialized a wrapped fuseshim connection. + wrapped := &fuseshim.Conn{ + Dev: dev, + } + + err = fuseshim.InitMount(wrapped, TODO, TODO) + if err != nil { + err = fmt.Errorf("fuseshim.InitMount: %v", err) + return + } + + // Create an object wrapping it. c = &Connection{ debugLogger: debugLogger, errorLogger: errorLogger, diff --git a/internal/fuseshim/fuse.go b/internal/fuseshim/fuse.go index 22fde82..8b2d3a1 100644 --- a/internal/fuseshim/fuse.go +++ b/internal/fuseshim/fuse.go @@ -164,7 +164,7 @@ func Mount(dir string, options ...MountOption) (*Conn, error) { } c.Dev = f - if err := initMount(c, &conf); err != nil { + if err := InitMount(c, conf.maxReadahead, conf.initFlags); err != nil { c.Close() return nil, err } @@ -181,7 +181,10 @@ func (e *OldVersionError) Error() string { return fmt.Sprintf("kernel FUSE version is too old: %v < %v", e.Kernel, e.LibraryMin) } -func initMount(c *Conn, conf *mountConfig) error { +func InitMount( + c *Conn, + maxReadahead uint32, + initFlags fusekernel.InitFlags) error { req, err := c.ReadRequest() if err != nil { if err == io.EOF { @@ -213,9 +216,9 @@ func initMount(c *Conn, conf *mountConfig) error { s := &InitResponse{ Library: proto, - MaxReadahead: conf.maxReadahead, + MaxReadahead: maxReadahead, MaxWrite: maxWrite, - Flags: fusekernel.InitBigWrites | conf.initFlags, + Flags: fusekernel.InitBigWrites | initFlags, } r.Respond(s) return nil