[vfs] Return EIO when opening /dev/tty.

This is in compliance with VFS1. See pkg/sentry/fs/dev/tty.go in the struct
ttyInodeOperations.

Fixes the failure of python runtime test_ioctl.
Updates #3515

PiperOrigin-RevId: 327042758
This commit is contained in:
Ayush Ranjan
2020-08-17 10:05:43 -07:00
committed by gVisor bot
parent 9a7b5830aa
commit 97263e5053
2 changed files with 4 additions and 44 deletions
+1 -1
View File
@@ -11,6 +11,6 @@ go_library(
"//pkg/context",
"//pkg/sentry/fsimpl/devtmpfs",
"//pkg/sentry/vfs",
"//pkg/usermem",
"//pkg/syserror",
],
)
+3 -43
View File
@@ -12,10 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// Package ttydev implements devices for /dev/tty and (eventually)
// /dev/console.
//
// TODO(b/159623826): Support /dev/console.
// Package ttydev implements an unopenable vfs.Device for /dev/tty.
package ttydev
import (
@@ -23,7 +20,7 @@ import (
"gvisor.dev/gvisor/pkg/context"
"gvisor.dev/gvisor/pkg/sentry/fsimpl/devtmpfs"
"gvisor.dev/gvisor/pkg/sentry/vfs"
"gvisor.dev/gvisor/pkg/usermem"
"gvisor.dev/gvisor/pkg/syserror"
)
const (
@@ -37,44 +34,7 @@ type ttyDevice struct{}
// Open implements vfs.Device.Open.
func (ttyDevice) Open(ctx context.Context, mnt *vfs.Mount, vfsd *vfs.Dentry, opts vfs.OpenOptions) (*vfs.FileDescription, error) {
fd := &ttyFD{}
if err := fd.vfsfd.Init(fd, opts.Flags, mnt, vfsd, &vfs.FileDescriptionOptions{
UseDentryMetadata: true,
}); err != nil {
return nil, err
}
return &fd.vfsfd, nil
}
// ttyFD implements vfs.FileDescriptionImpl for /dev/tty.
type ttyFD struct {
vfsfd vfs.FileDescription
vfs.FileDescriptionDefaultImpl
vfs.DentryMetadataFileDescriptionImpl
vfs.NoLockFD
}
// Release implements vfs.FileDescriptionImpl.Release.
func (fd *ttyFD) Release(context.Context) {}
// PRead implements vfs.FileDescriptionImpl.PRead.
func (fd *ttyFD) PRead(ctx context.Context, dst usermem.IOSequence, offset int64, opts vfs.ReadOptions) (int64, error) {
return 0, nil
}
// Read implements vfs.FileDescriptionImpl.Read.
func (fd *ttyFD) Read(ctx context.Context, dst usermem.IOSequence, opts vfs.ReadOptions) (int64, error) {
return 0, nil
}
// PWrite implements vfs.FileDescriptionImpl.PWrite.
func (fd *ttyFD) PWrite(ctx context.Context, src usermem.IOSequence, offset int64, opts vfs.WriteOptions) (int64, error) {
return src.NumBytes(), nil
}
// Write implements vfs.FileDescriptionImpl.Write.
func (fd *ttyFD) Write(ctx context.Context, src usermem.IOSequence, opts vfs.WriteOptions) (int64, error) {
return src.NumBytes(), nil
return nil, syserror.EIO
}
// Register registers all devices implemented by this package in vfsObj.