github.com/SagerNet/gvisor@v0.0.0-20210707092255-7731c139d75c/pkg/sentry/fsimpl/ext/dentry.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 ext 16 17 import ( 18 "github.com/SagerNet/gvisor/pkg/context" 19 "github.com/SagerNet/gvisor/pkg/sentry/vfs" 20 ) 21 22 // dentry implements vfs.DentryImpl. 23 // 24 // +stateify savable 25 type dentry struct { 26 vfsd vfs.Dentry 27 28 // Protected by filesystem.mu. 29 parent *dentry 30 name string 31 32 // inode is the inode represented by this dentry. Multiple Dentries may 33 // share a single non-directory Inode (with hard links). inode is 34 // immutable. 35 inode *inode 36 } 37 38 // Compiles only if dentry implements vfs.DentryImpl. 39 var _ vfs.DentryImpl = (*dentry)(nil) 40 41 // newDentry is the dentry constructor. 42 func newDentry(in *inode) *dentry { 43 d := &dentry{ 44 inode: in, 45 } 46 d.vfsd.Init(d) 47 return d 48 } 49 50 // IncRef implements vfs.DentryImpl.IncRef. 51 func (d *dentry) IncRef() { 52 d.inode.incRef() 53 } 54 55 // TryIncRef implements vfs.DentryImpl.TryIncRef. 56 func (d *dentry) TryIncRef() bool { 57 return d.inode.tryIncRef() 58 } 59 60 // DecRef implements vfs.DentryImpl.DecRef. 61 func (d *dentry) DecRef(ctx context.Context) { 62 // FIXME(b/134676337): filesystem.mu may not be locked as required by 63 // inode.decRef(). 64 d.inode.decRef() 65 } 66 67 // InotifyWithParent implements vfs.DentryImpl.InotifyWithParent. 68 // 69 // TODO(b/134676337): Implement inotify. 70 func (d *dentry) InotifyWithParent(ctx context.Context, events, cookie uint32, et vfs.EventType) {} 71 72 // Watches implements vfs.DentryImpl.Watches. 73 // 74 // TODO(b/134676337): Implement inotify. 75 func (d *dentry) Watches() *vfs.Watches { 76 return nil 77 } 78 79 // OnZeroWatches implements vfs.Dentry.OnZeroWatches. 80 // 81 // TODO(b/134676337): Implement inotify. 82 func (d *dentry) OnZeroWatches(context.Context) {}