is to limit arbitrarily the number of directories that will be accessed during a search.
A similar problem exists when we are trying to determine when a file can be deleted.
With acyclic-graph directory structures, a value of 0 in the reference count means that there are no more references to the file or directory, and the file can be deleted.
However, when cycles exist, the reference count may not be 0 even when it is no longer possible to refer to a directory or file.
This anomaly results from the possibility of self-referencing (or a cycle) in the directory structure.
In this case, we generally need to use a garbage collection scheme to determine when the last reference has been deleted and the disk space can be reallocated.
Garbage collection involves traversing the entire file system, marking everything that can be accessed.
Then, a second pass collects everything that is not marked onto a list of free space.
(A similar marking procedure can be used to ensure that a traversal or search will cover everything in the file system once and only once.)
Garbage collection for a disk-based file system, however, is extremely time consuming and is thus seldom attempted.
Garbage collection is necessary only because of possible cycles in the graph. Thus, an acyclic-graph structure is much easier to work with.
The difficulty is to avoid cycles as new links are added to the structure.
How do we know when a new link will complete a cycle? There are algorithms to detect cycles in graphs; however, they are computationally expensive, especially when the graph is on disk storage.
A simpler algorithm in the special case of directories and links is to bypass links during directory traversal. Cycles are avoided, and no extra overhead is incurred.