Skip to content

Commit

Permalink
fuse: public type ProtocolServer
Browse files Browse the repository at this point in the history
Change-Id: I235f12d1e3a3915c631dd8c3912b035a71c7d664
  • Loading branch information
hanwen committed Nov 1, 2024
1 parent 06e0ac3 commit f7467d4
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions fuse/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,51 @@ type protocolServer struct {
opts *MountOptions
}

type ProtocolServer struct {
protocolServer
}

func NewProtocolServer(fs RawFileSystem, opts *MountOptions) *ProtocolServer {
return &ProtocolServer{
protocolServer: protocolServer{
fileSystem: fs,
retrieveTab: make(map[uint64]*retrieveCacheRequest),
opts: opts,
},
}
}

func (ps *ProtocolServer) HandleRequest(in [][]byte,
out [][]byte) (int, Status) {

inTogether := make([]byte, len(in[0])+len(in[1]))
copy(inTogether, in[0])
copy(inTogether[len(in[0]):], in[1])
h, inSize, outSize, payloadSize, errno := parseRequest(inTogether, nil)
if errno != 0 {
return 0, errno
}

log.Printf("h: %v %d %d %d %v", h, inSize, outSize, payloadSize, errno)
req := request{
cancel: make(chan struct{}),
inputBuf: inTogether[:inSize],
outputBuf: make([]byte, outSize+int(sizeOfOutHeader)),
inPayload: make([]byte, payloadSize),
}

ps.protocolServer.handleRequest(h, &req)

copy(out[0], req.outputBuf)
if len(req.outputBuf) > len(out[0]) {
copy(out[1], req.outputBuf[len(out[0]):])
}
if payloadSize > 0 {
copy(out[len(out)-1], req.outPayload)
}
return len(req.outPayload) + len(req.outputBuf), 0
}

// Server contains the logic for reading from the FUSE device and
// translating it to RawFileSystem interface calls.
type Server struct {
Expand Down

0 comments on commit f7467d4

Please sign in to comment.