github.com/SagerNet/gvisor@v0.0.0-20210707092255-7731c139d75c/pkg/sentry/fsbridge/bridge.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 fsbridge provides common interfaces to bridge between VFS1 and VFS2
    16  // files.
    17  package fsbridge
    18  
    19  import (
    20  	"github.com/SagerNet/gvisor/pkg/abi/linux"
    21  	"github.com/SagerNet/gvisor/pkg/context"
    22  	"github.com/SagerNet/gvisor/pkg/sentry/memmap"
    23  	"github.com/SagerNet/gvisor/pkg/sentry/vfs"
    24  	"github.com/SagerNet/gvisor/pkg/usermem"
    25  )
    26  
    27  // File provides a common interface to bridge between VFS1 and VFS2 files.
    28  type File interface {
    29  	// PathnameWithDeleted returns an absolute pathname to vd, consistent with
    30  	// Linux's d_path(). In particular, if vd.Dentry() has been disowned,
    31  	// PathnameWithDeleted appends " (deleted)" to the returned pathname.
    32  	PathnameWithDeleted(ctx context.Context) string
    33  
    34  	// ReadFull read all contents from the file.
    35  	ReadFull(ctx context.Context, dst usermem.IOSequence, offset int64) (int64, error)
    36  
    37  	// ConfigureMMap mutates opts to implement mmap(2) for the file.
    38  	ConfigureMMap(context.Context, *memmap.MMapOpts) error
    39  
    40  	// Type returns the file type, e.g. linux.S_IFREG.
    41  	Type(context.Context) (linux.FileMode, error)
    42  
    43  	// IncRef increments reference.
    44  	IncRef()
    45  
    46  	// DecRef decrements reference.
    47  	DecRef(ctx context.Context)
    48  }
    49  
    50  // Lookup provides a common interface to open files.
    51  type Lookup interface {
    52  	// OpenPath opens a file.
    53  	OpenPath(ctx context.Context, path string, opts vfs.OpenOptions, remainingTraversals *uint, resolveFinal bool) (File, error)
    54  }