github.com/SagerNet/gvisor@v0.0.0-20210707092255-7731c139d75c/pkg/sentry/fs/tmpfs/file_regular.go (about) 1 // Copyright 2018 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 tmpfs 16 17 import ( 18 "github.com/SagerNet/gvisor/pkg/context" 19 "github.com/SagerNet/gvisor/pkg/sentry/fs" 20 "github.com/SagerNet/gvisor/pkg/sentry/fs/fsutil" 21 "github.com/SagerNet/gvisor/pkg/sentry/memmap" 22 "github.com/SagerNet/gvisor/pkg/usermem" 23 "github.com/SagerNet/gvisor/pkg/waiter" 24 ) 25 26 // regularFileOperations implements fs.FileOperations for a regular 27 // tmpfs file. 28 // 29 // +stateify savable 30 type regularFileOperations struct { 31 fsutil.FileNoopRelease `state:"nosave"` 32 fsutil.FileGenericSeek `state:"nosave"` 33 fsutil.FileNotDirReaddir `state:"nosave"` 34 fsutil.FileNoopFsync `state:"nosave"` 35 fsutil.FileNoopFlush `state:"nosave"` 36 fsutil.FileNoIoctl `state:"nosave"` 37 fsutil.FileNoSplice `state:"nosave"` 38 fsutil.FileUseInodeUnstableAttr `state:"nosave"` 39 waiter.AlwaysReady `state:"nosave"` 40 41 // iops is the InodeOperations of a regular tmpfs file. It is 42 // guaranteed to be the same as file.Dirent.Inode.InodeOperations, 43 // see operations that take fs.File below. 44 iops *fileInodeOperations 45 } 46 47 // Read implements fs.FileOperations.Read. 48 func (r *regularFileOperations) Read(ctx context.Context, file *fs.File, dst usermem.IOSequence, offset int64) (int64, error) { 49 return r.iops.read(ctx, file, dst, offset) 50 } 51 52 // Write implements fs.FileOperations.Write. 53 func (r *regularFileOperations) Write(ctx context.Context, file *fs.File, src usermem.IOSequence, offset int64) (int64, error) { 54 return r.iops.write(ctx, src, offset) 55 } 56 57 // ConfigureMMap implements fs.FileOperations.ConfigureMMap. 58 func (r *regularFileOperations) ConfigureMMap(ctx context.Context, file *fs.File, opts *memmap.MMapOpts) error { 59 return fsutil.GenericConfigureMMap(file, r.iops, opts) 60 }