*nix file systems

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Kevin Brown
Date:  
Subject: *nix file systems
Trent Shipley wrote:

> What it means is that you can't write a naive recursive tree traversal program
> when working with directories. (Eg. I want to write a PHP program that
> gives me a flat alphabetic index for an entire web site.)
>
> Any idea about how to build a hash of i-nodes so that you traverse a cycle in
> the directory structure one-and-only one time?
>
> (It's an elemental data structure problem--how to visit each node in a cyclic
> graph one-and-only one time.)
>
> On Thursday 2004-02-19 16:17, Joe Toon wrote:
>
>>I did the following for #1:
>>
>>$ ln -s filea fileb
>>$ ln -s fileb filea
>>$ cat filea # symlink to a symlink
>>cat: files: Too many levels of symbolic links
>>
>>Then I did the following for #2:
>>
>>$ mkdir test
>>$ cd test
>>$ ln -s ../test dirsym
>>$ cd dirsym
>>
>>This allows me to enter dirsym indefinitely -- i could see something
>>getting hung up over this if it followed the sym links..
>>
>>I would imagine this would be true for the final scenario as well.
>>
>>Trent Shipley wrote:
>>
>>>Is a *nix file system guranteed to be acyclic?
>>>
>>>That is no:
>>>
>>>File-a links to file-b and file-b links to file-a
>>>
>>>And more important
>>>
>>>No directory-a contains link-b where link-b points to directory-a.
>>>
>>>Also
>>>
>>>Directory-a contains no link-b to directory-c where directory-c contains
>>>link-d to directory-a.


That might be why a lot of things that do need to traverse a directory tree have
options like to not follow symbolic links. They may miss something because of
that option, but they won't get caught up in a self-recursive loop.