Commit 54b42724 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Handle error conditions in ReadResultFd.

parent f165c912
......@@ -191,7 +191,7 @@ type ReadResult interface {
// Returns the raw bytes for the read, possibly using the
// passed buffer. The buffer should be larger than the return
// value from Size.
Bytes(buf []byte) []byte
Bytes(buf []byte) ([]byte, Status)
// Size returns how many bytes this return value takes at most.
Size() int
......
......@@ -31,7 +31,10 @@ func CopyFile(srcFs, destFs FileSystem, srcFile, destFile string, context *Conte
if !code.Ok() {
return code
}
data := res.Bytes(buf)
data, code := res.Bytes(buf)
if !code.Ok() {
return code
}
if len(data) == 0 {
break
......
......@@ -363,7 +363,7 @@ func (ms *MountState) write(req *request) Status {
log.Println("TrySplice:", err)
sz := req.flatDataSize()
buf := ms.AllocOut(req, uint32(sz))
req.flatData = req.fdData.Bytes(buf)
req.flatData, req.status = req.fdData.Bytes(buf)
header = req.serializeHeader(len(req.flatData))
}
}
......@@ -449,7 +449,7 @@ func (ms *MountState) writeDeleteNotify(parent uint64, child uint64, name string
if ms.kernelSettings.Minor < 18 {
return ms.writeEntryNotify(parent, name)
}
req := request{
inHeader: &raw.InHeader{
Opcode: _OP_NOTIFY_DELETE,
......@@ -459,7 +459,7 @@ func (ms *MountState) writeDeleteNotify(parent uint64, child uint64, name string
}
entry := &raw.NotifyInvalDeleteOut{
Parent: parent,
Child: child,
Child: child,
NameLen: uint32(len(name)),
}
......
......@@ -279,7 +279,7 @@ func doRead(state *MountState, req *request) {
req.fdData = fd
req.flatData = nil
} else if r != nil {
req.flatData = r.Bytes(buf)
req.flatData, req.status = r.Bytes(buf)
}
}
......
......@@ -15,8 +15,8 @@ func (r *ReadResultData) Size() int {
return len(r.Data)
}
func (r *ReadResultData) Bytes(buf []byte) []byte {
return r.Data
func (r *ReadResultData) Bytes(buf []byte) ([]byte, Status) {
return r.Data, OK
}
// ReadResultFd is the read return for zero-copy file data.
......@@ -34,7 +34,7 @@ type ReadResultFd struct {
// Reads raw bytes from file descriptor if necessary, using the passed
// buffer as storage.
func (r *ReadResultFd) Bytes(buf []byte) []byte {
func (r *ReadResultFd) Bytes(buf []byte) ([]byte, Status) {
sz := r.Sz
if len(buf) < sz {
sz = len(buf)
......@@ -44,8 +44,12 @@ func (r *ReadResultFd) Bytes(buf []byte) []byte {
if err == io.EOF {
err = nil
}
// TODO - error handling?
return buf[:n]
if n < 0 {
n = 0
}
return buf[:n], ToStatus(err)
}
func (r *ReadResultFd) Size() int {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment