gvisor.dev/gvisor@v0.0.0-20240520182842-f9d4d51c7e0f/pkg/sentry/devices/ttydev/ttydev.go (about)

     1  // Copyright 2020 The gVisor Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  // Package ttydev implements an unopenable vfs.Device for /dev/tty.
    16  package ttydev
    17  
    18  import (
    19  	"gvisor.dev/gvisor/pkg/abi/linux"
    20  	"gvisor.dev/gvisor/pkg/context"
    21  	"gvisor.dev/gvisor/pkg/errors/linuxerr"
    22  	"gvisor.dev/gvisor/pkg/sentry/vfs"
    23  )
    24  
    25  const (
    26  	// See drivers/tty/tty_io.c:tty_init().
    27  	ttyDevMinor     = 0
    28  	consoleDevMinor = 1
    29  )
    30  
    31  // ttyDevice implements vfs.Device for /dev/tty.
    32  //
    33  // +stateify savable
    34  type ttyDevice struct{}
    35  
    36  // Open implements vfs.Device.Open.
    37  func (ttyDevice) Open(ctx context.Context, mnt *vfs.Mount, vfsd *vfs.Dentry, opts vfs.OpenOptions) (*vfs.FileDescription, error) {
    38  	return nil, linuxerr.EIO
    39  }
    40  
    41  // Register registers all devices implemented by this package in vfsObj.
    42  func Register(vfsObj *vfs.VirtualFilesystem) error {
    43  	return vfsObj.RegisterDevice(vfs.CharDevice, linux.TTYAUX_MAJOR, ttyDevMinor, ttyDevice{}, &vfs.RegisterDeviceOptions{
    44  		GroupName: "tty",
    45  		Pathname:  "tty",
    46  		FilePerms: 0666,
    47  	})
    48  }