github.com/hanwen/go-fuse@v1.0.0/fuse/server_linux.go (about)

     1  // Copyright 2016 the Go-FUSE Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package fuse
     6  
     7  import (
     8  	"log"
     9  	"syscall"
    10  )
    11  
    12  func (ms *Server) systemWrite(req *request, header []byte) Status {
    13  	if req.flatDataSize() == 0 {
    14  		err := handleEINTR(func() error {
    15  			_, err := syscall.Write(ms.mountFd, header)
    16  			return err
    17  		})
    18  		return ToStatus(err)
    19  	}
    20  
    21  	if req.fdData != nil {
    22  		if ms.canSplice {
    23  			err := ms.trySplice(header, req, req.fdData)
    24  			if err == nil {
    25  				req.readResult.Done()
    26  				return OK
    27  			}
    28  			log.Println("trySplice:", err)
    29  		}
    30  
    31  		sz := req.flatDataSize()
    32  		buf := ms.allocOut(req, uint32(sz))
    33  		req.flatData, req.status = req.fdData.Bytes(buf)
    34  		header = req.serializeHeader(len(req.flatData))
    35  	}
    36  
    37  	_, err := writev(ms.mountFd, [][]byte{header, req.flatData})
    38  	if req.readResult != nil {
    39  		req.readResult.Done()
    40  	}
    41  	return ToStatus(err)
    42  }