github.com/ttpreport/gvisor-ligolo@v0.0.0-20240123134145-a858404967ba/pkg/sentry/devices/memdev/full.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 memdev 16 17 import ( 18 "github.com/ttpreport/gvisor-ligolo/pkg/context" 19 "github.com/ttpreport/gvisor-ligolo/pkg/errors/linuxerr" 20 "github.com/ttpreport/gvisor-ligolo/pkg/sentry/vfs" 21 "github.com/ttpreport/gvisor-ligolo/pkg/usermem" 22 ) 23 24 const fullDevMinor = 7 25 26 // fullDevice implements vfs.Device for /dev/full. 27 // 28 // +stateify savable 29 type fullDevice struct{} 30 31 // Open implements vfs.Device.Open. 32 func (fullDevice) Open(ctx context.Context, mnt *vfs.Mount, vfsd *vfs.Dentry, opts vfs.OpenOptions) (*vfs.FileDescription, error) { 33 fd := &fullFD{} 34 if err := fd.vfsfd.Init(fd, opts.Flags, mnt, vfsd, &vfs.FileDescriptionOptions{ 35 UseDentryMetadata: true, 36 }); err != nil { 37 return nil, err 38 } 39 return &fd.vfsfd, nil 40 } 41 42 // fullFD implements vfs.FileDescriptionImpl for /dev/full. 43 // 44 // +stateify savable 45 type fullFD struct { 46 vfsfd vfs.FileDescription 47 vfs.FileDescriptionDefaultImpl 48 vfs.DentryMetadataFileDescriptionImpl 49 vfs.NoLockFD 50 } 51 52 // Release implements vfs.FileDescriptionImpl.Release. 53 func (fd *fullFD) Release(context.Context) { 54 // noop 55 } 56 57 // PRead implements vfs.FileDescriptionImpl.PRead. 58 func (fd *fullFD) PRead(ctx context.Context, dst usermem.IOSequence, offset int64, opts vfs.ReadOptions) (int64, error) { 59 return dst.ZeroOut(ctx, dst.NumBytes()) 60 } 61 62 // Read implements vfs.FileDescriptionImpl.Read. 63 func (fd *fullFD) Read(ctx context.Context, dst usermem.IOSequence, opts vfs.ReadOptions) (int64, error) { 64 return dst.ZeroOut(ctx, dst.NumBytes()) 65 } 66 67 // PWrite implements vfs.FileDescriptionImpl.PWrite. 68 func (fd *fullFD) PWrite(ctx context.Context, src usermem.IOSequence, offset int64, opts vfs.WriteOptions) (int64, error) { 69 return 0, linuxerr.ENOSPC 70 } 71 72 // Write implements vfs.FileDescriptionImpl.Write. 73 func (fd *fullFD) Write(ctx context.Context, src usermem.IOSequence, opts vfs.WriteOptions) (int64, error) { 74 return 0, linuxerr.ENOSPC 75 } 76 77 // Seek implements vfs.FileDescriptionImpl.Seek. 78 func (fd *fullFD) Seek(ctx context.Context, offset int64, whence int32) (int64, error) { 79 return 0, nil 80 }