views:

518

answers:

1

Hi,

does anyone know how to check if a file or directory is either a Symbolic Link, Junction Point, Mount Point or Hard Link?

As far as i know a symbolic links are detected by checking a file for its "ReparsePoint" attribute. Junction points are detected by checking a directory for the "ReparsePoint" attribute. So if the "ReparsePoint" attribute is set on a file it must be a symbolic link, otherwise if its set on a directory it can only be a junktion point...right?

Good so far, but i have still no idea how to detect "Mount Points" and "Hard Links". Can anyone tell me how to do this?

+1  A: 

Symbolic Links, Junction Points, and Mount Points are all examples of different reparse points. Hard Links, however, are just regular files. On NTFS all files are hard links. You can detect that a file has multiple hard links pointing to it, but there's no "real file" that it points to. You can think of hard links as just different names for the same file.

Here's some information on accessing reparse points from C#: http://www.codeproject.com/KB/vista/ReparsePointID.aspx?display=Print

Here's some information on how to do it in C: http://blog.kalmbach-software.de/2008/02/

Gabe
Ok, this means if a have FileA.txt and a hard link FileB.txt pointing to FileA.txt there is no way to detect that FileB.txt is a hard Link?
Alexander
They BOTH are hard links.
akappa
Ok, so is there a way to detect Mount Points?
Alexander
I don't think there is a portable way to do it, since it's an OS-defined concept. On linux, you can just access to /proc/mounts and take the second field of each line.
akappa
Mount points are reparse points just like junctions. Are you asking how to tell the difference between different kinds of reparse points? Or do you want to know what they point to?
Gabe
In truth, every filename is a hard link to the file content. Hard links are always linking names to content, symbolic links (which are themselves a form of content) are links to other names, that's the difference.
Ben Voigt