Contents

tryReclaim(_:)

Reclaims the item by executing the given block, if conditions allow.

Declaration

func tryReclaim(_ reclaimBlock: @escaping () -> Void) -> Bool

Return Value

true (Swift) or YES (Obj-C) if the reclaim block ran; otherwise, false (Swift) or NO (Obj-C). When your reclaimItem(_:replyHandler:) implementation receives a false/NO return value, call replyHandler(nil).

Discussion

Invoke this method in your implementation of the reclaimItem(_:replyHandler:) operation.

FSKit internally maintains a count of how many times it returns each FSItem to the kernel, via either a creation operation or a lookup. The kernel file system also maintains a count of how many times a create or a lookup operation returned a vnode. When the kernel reclaims the vnode associated with an FSItem, the FSItem is only eligible for reclaiming when both the kernel and user space counts agree. This mechanism addresses a potential race condition in which concurrent reclaim and lookup operations might lead to a lookup returning a deallocated FSItem, and as a result, induce undefined behavior. File systems that don’t invoke this method during reclaim are exposed to this race condition.

Example Usage: