# Win7 System folder contains infinitely looping SYSTEM(!) directory

My Windows 7 Enterprise computer has been crashing fairly frequently recently, so I decided to boot up in safe mode and run the TrendMicro client I have installed. It froze about 10 minutes into the full system scan, so in the spirit of http://whathaveyoutried.com, I started scanning each folder individually. When I got to ProgramData, the AV failed with an uncaught exception. I then went down a level and tried scanning Application Data, which failed as well. Imagine my surprise when I open the folder just to see the same folder again!

As far as I can tell, this folder loop continues indefinitely. (If you are trying to recreate this, keep in mind that ProgramData is a hidden folder.) I'm actually a bit concerned that these are system folders, as this is a brand-new computer with a clean installation.

I guess I have three questions:

1. Has anyone else seen/experienced this before? I'm running Win7 SP1.
2. How do I fix this? I've run CHKDSK \F with no success (although it was incredibly slow).
3. What are the ramifications of an infinitely recursive directory? Theoretically speaking, each link takes up memory, so shouldn't I have no space available on my hard drive? (I've got about 180GB left.) I noticed that the tree view on the left only shows the "linked folder" icon on the deeper folders--does this mean anything special? (I've circled the icons or lack thereof in red.) How can the OS even resolve this aberration? And above all, what would happen if I were to select "Expand all folders"??? :P

Matt

-
–  EBGreen Aug 15 '12 at 14:06
@EBGreen Thanks, but what about my last question? –  Matt Aug 15 '12 at 14:14

1. Regarding "shouldn't I have no space left": No, because they are not "physical" directories. They are "computed" directories, in the sense that, when you try to navigate to it, you just end up at the next deeper one. It's kind of like mathematical induction: you don't have to keep doing induction to infinity even though the hypothesis "lets you" do so...

Or think of it this way: if you have a linked list with node A pointing to node B, node B pointing to node C, and node C pointing to node B, how many nodes are in the list? The answer is 3, but if you naively try and follow the nodes' next pointer to infinity until you find a node that doesn't have a next pointer, you will either crash when you overflow the counter you're storing the number of nodes in, or you will keep counting to infinity (or until you run out of time / patience / space to store the count).

The problem arises if you run a program that is trying to navigate your entire directory tree, and has no support for detecting circular junctions or circular symbolic links. That program is frankly broken IMHO because any program that earnestly tries to walk your entire directory tree needs to anticipate this possibility and handle it intelligently.

Your Trend Micro is basically doing what I said about the linked list with B pointing to C and C pointing to B. It's just following the pointers without realizing it's jumping between two nodes rather than navigating a directory hierarchy that's infinity directories deep.

Overall: Circular filesystem constructs -- things like directory A having directory B as a subdirectory, which has directory A as a subdirectory (and A and B can in fact be the same directory) -- are usually a valid, albeit unusual, phenomenon. They are in the same class of "stuff you don't see every day" as files which have the "Read Only" checkbox checked; files that are compressed at the filesystem layer; files with weird custom ACLs; and special hidden files like the ones Office creates when you open a document. All of these types of file properties require special handling and knowledge when a program is trying to "walk" an arbitrary filesystem. Circular constructs are just one more thing that, while acceptable and not indicative of a filesystem error, require special handling by programs.

-

I also have the same issue,

I think that these circular referencing links are normal, but under usual circumstances, they are hidden by the operating system. I had forced a permissions and ownership change of all files on my C:\ some time ago, and I think in the process that these links became 'unhidden'.

-

Myself I had such appearing by Making changes to a profile, also Windows 7. I avoided it simply by copying the data to a new created profile.

You TrendMicro just runs in an infinity loop reopening the link to the own directory again and again... and crashes that way.

-