github.com/metacubex/gvisor@v0.0.0-20240320004321-933faba989ec/pkg/sentry/vfs/mount_ring.go (about) 1 package vfs 2 3 // Entry is an element in the circular linked list. 4 // 5 // +stateify savable 6 type mountEntry struct { 7 next *mountEntry 8 prev *mountEntry 9 container *Mount 10 } 11 12 // Init instantiates an Element to be an item in a ring (circularly-linked 13 // list). 14 // 15 //go:nosplit 16 func (e *mountEntry) Init(container *Mount) { 17 e.next = e 18 e.prev = e 19 e.container = container 20 } 21 22 // Add adds new to old's ring. 23 // 24 //go:nosplit 25 func (e *mountEntry) Add(new *mountEntry) { 26 next := e.next 27 prev := e 28 29 next.prev = new 30 new.next = next 31 new.prev = prev 32 e.next = new 33 } 34 35 // Remove removes e from its ring and reinitializes it. 36 // 37 //go:nosplit 38 func (e *mountEntry) Remove() { 39 next := e.next 40 prev := e.prev 41 42 next.prev = prev 43 prev.next = next 44 e.Init(e.container) 45 } 46 47 // Empty returns true if there are no other elements in the ring. 48 // 49 //go:nosplit 50 func (e *mountEntry) Empty() bool { 51 return e.next == e 52 } 53 54 // Next returns the next containing object pointed to by the list. 55 // 56 //go:nosplit 57 func (e *mountEntry) Next() *Mount { 58 return e.next.container 59 } 60 61 // Prev returns the previous containing object pointed to by the list. 62 // 63 //go:nosplit 64 func (e *mountEntry) Prev() *Mount { 65 return e.prev.container 66 }