github.com/SagerNet/gvisor@v0.0.0-20210707092255-7731c139d75c/pkg/sentry/fs/dev/tty.go (about)

     1  // Copyright 2019 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 dev
    16  
    17  import (
    18  	"github.com/SagerNet/gvisor/pkg/abi/linux"
    19  	"github.com/SagerNet/gvisor/pkg/context"
    20  	"github.com/SagerNet/gvisor/pkg/sentry/fs"
    21  	"github.com/SagerNet/gvisor/pkg/sentry/fs/fsutil"
    22  	"github.com/SagerNet/gvisor/pkg/waiter"
    23  )
    24  
    25  // +stateify savable
    26  type ttyInodeOperations struct {
    27  	fsutil.InodeGenericChecker       `state:"nosave"`
    28  	fsutil.InodeNoExtendedAttributes `state:"nosave"`
    29  	fsutil.InodeNoopAllocate         `state:"nosave"`
    30  	fsutil.InodeNoopRelease          `state:"nosave"`
    31  	fsutil.InodeNoopTruncate         `state:"nosave"`
    32  	fsutil.InodeNoopWriteOut         `state:"nosave"`
    33  	fsutil.InodeNotDirectory         `state:"nosave"`
    34  	fsutil.InodeNotMappable          `state:"nosave"`
    35  	fsutil.InodeNotOpenable          `state:"nosave"`
    36  	fsutil.InodeNotSocket            `state:"nosave"`
    37  	fsutil.InodeNotSymlink           `state:"nosave"`
    38  	fsutil.InodeVirtual              `state:"nosave"`
    39  
    40  	fsutil.InodeSimpleAttributes
    41  }
    42  
    43  var _ fs.InodeOperations = (*ttyInodeOperations)(nil)
    44  
    45  func newTTYDevice(ctx context.Context, owner fs.FileOwner, mode linux.FileMode) *ttyInodeOperations {
    46  	return &ttyInodeOperations{
    47  		InodeSimpleAttributes: fsutil.NewInodeSimpleAttributes(ctx, owner, fs.FilePermsFromMode(mode), linux.TMPFS_MAGIC),
    48  	}
    49  }
    50  
    51  // +stateify savable
    52  type ttyFileOperations struct {
    53  	fsutil.FileNoSeek               `state:"nosave"`
    54  	fsutil.FileNoIoctl              `state:"nosave"`
    55  	fsutil.FileNoMMap               `state:"nosave"`
    56  	fsutil.FileNoSplice             `state:"nosave"`
    57  	fsutil.FileNoopFlush            `state:"nosave"`
    58  	fsutil.FileNoopFsync            `state:"nosave"`
    59  	fsutil.FileNoopRelease          `state:"nosave"`
    60  	fsutil.FileNoopWrite            `state:"nosave"`
    61  	fsutil.FileNoopRead             `state:"nosave"`
    62  	fsutil.FileNotDirReaddir        `state:"nosave"`
    63  	fsutil.FileUseInodeUnstableAttr `state:"nosave"`
    64  	waiter.AlwaysReady              `state:"nosave"`
    65  }
    66  
    67  var _ fs.FileOperations = (*ttyFileOperations)(nil)