2019-04-29 21:25:05 +00:00
|
|
|
// Copyright 2018 The gVisor Authors.
|
2018-04-27 17:37:02 +00:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package pipe
|
|
|
|
|
|
|
|
import (
|
2019-09-13 00:42:14 +00:00
|
|
|
"io"
|
2018-04-27 17:37:02 +00:00
|
|
|
|
2019-06-13 23:49:09 +00:00
|
|
|
"gvisor.dev/gvisor/pkg/sentry/arch"
|
|
|
|
"gvisor.dev/gvisor/pkg/sentry/context"
|
|
|
|
"gvisor.dev/gvisor/pkg/sentry/fs"
|
|
|
|
"gvisor.dev/gvisor/pkg/sentry/fs/fsutil"
|
|
|
|
"gvisor.dev/gvisor/pkg/sentry/usermem"
|
2018-04-27 17:37:02 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// ReaderWriter satisfies the FileOperations interface and services both
|
|
|
|
// read and write requests. This should only be used directly for named pipes.
|
|
|
|
// pipe(2) and pipe2(2) only support unidirectional pipes and should use
|
|
|
|
// either pipe.Reader or pipe.Writer.
|
2018-08-02 17:41:44 +00:00
|
|
|
//
|
|
|
|
// +stateify savable
|
2018-04-27 17:37:02 +00:00
|
|
|
type ReaderWriter struct {
|
2019-04-11 07:41:42 +00:00
|
|
|
fsutil.FilePipeSeek `state:"nosave"`
|
|
|
|
fsutil.FileNotDirReaddir `state:"nosave"`
|
|
|
|
fsutil.FileNoFsync `state:"nosave"`
|
|
|
|
fsutil.FileNoMMap `state:"nosave"`
|
2019-05-21 22:17:05 +00:00
|
|
|
fsutil.FileNoSplice `state:"nosave"`
|
|
|
|
fsutil.FileNoopFlush `state:"nosave"`
|
2019-04-11 07:41:42 +00:00
|
|
|
fsutil.FileUseInodeUnstableAttr `state:"nosave"`
|
2018-04-27 17:37:02 +00:00
|
|
|
*Pipe
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read implements fs.FileOperations.Read.
|
|
|
|
func (rw *ReaderWriter) Read(ctx context.Context, _ *fs.File, dst usermem.IOSequence, _ int64) (int64, error) {
|
2019-10-17 20:08:27 +00:00
|
|
|
return rw.Pipe.Read(ctx, dst)
|
2019-09-13 00:42:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// WriteTo implements fs.FileOperations.WriteTo.
|
|
|
|
func (rw *ReaderWriter) WriteTo(ctx context.Context, _ *fs.File, w io.Writer, count int64, dup bool) (int64, error) {
|
2019-10-17 20:08:27 +00:00
|
|
|
return rw.Pipe.WriteTo(ctx, w, count, dup)
|
2018-04-27 17:37:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Write implements fs.FileOperations.Write.
|
|
|
|
func (rw *ReaderWriter) Write(ctx context.Context, _ *fs.File, src usermem.IOSequence, _ int64) (int64, error) {
|
2019-10-17 20:08:27 +00:00
|
|
|
return rw.Pipe.Write(ctx, src)
|
2019-09-13 00:42:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ReadFrom implements fs.FileOperations.WriteTo.
|
|
|
|
func (rw *ReaderWriter) ReadFrom(ctx context.Context, _ *fs.File, r io.Reader, count int64) (int64, error) {
|
2019-10-17 20:08:27 +00:00
|
|
|
return rw.Pipe.ReadFrom(ctx, r, count)
|
2018-04-27 17:37:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Ioctl implements fs.FileOperations.Ioctl.
|
2019-06-28 00:21:34 +00:00
|
|
|
func (rw *ReaderWriter) Ioctl(ctx context.Context, _ *fs.File, io usermem.IO, args arch.SyscallArguments) (uintptr, error) {
|
2019-10-17 20:08:27 +00:00
|
|
|
return rw.Pipe.Ioctl(ctx, io, args)
|
2018-04-27 17:37:02 +00:00
|
|
|
}
|