Hard,Sym,Junction links & ReparsePoints == Confusing

Topics: Developer Forum
Dec 31, 2006 at 3:58 AM
Let me throw this out as a suggestion because I think the mish-mash of cmdlets we have now is a bit confusing to use.

How about we replace New-Junction, New-HardLink and New-SymLink with one cmdlet New-Link with a parameter specifying the type of link desired. Perhaps we default to Symbolic link on Vista and Junction on everything else. Or just default to Junction for everything.

Replace Get-ReparsePoint with Get-Link and Remove-ReparsePoint with Remove-Link.

In the formatting info I would also change ReparsePointTag to something like LinkType.
Dec 31, 2006 at 5:25 AM
well, the ntfs link features are a bit confusing :)

i dont think we should merge them. the link types don't have much in common, and having New-Junction, New-Hardlink and New-Symlink doesnt seem very confusing to me.

the Get-ReparsePoint is not meant to be used directly; people will access it mostly using the custom formatting.

and we can provide a wrapper function (del, erase, rm, rmdir, ..) that will call Remove-ReparsePoint when used against a junction/symlink, and Remove-Item on standard files.
Dec 31, 2006 at 6:58 AM
So what do you use to remove a hard link? Is that done by Remove-ReparsePoint also? As it is now, it isn't clear what you use to remove a hard link, sym link and junction. IMO the remove cmdlets need to be tied by name to the create/new cmdlets. Perhaps we need trivial Remove-HardLink, Remove-SymLink and Remove-Junction cmdlets that are simple derivations of the remove reparsepoint functionality. Even though links on NT are confusing, we should make an attempt to make it a bit more clear in PSCX.
Dec 31, 2006 at 10:15 AM
no, hard links are removed using Remove-Item. a hard link is not a reparse point. it is more like a copy of the file, deleting the "original" does not affect any of the hard links. to physically remove the file data, you need to delete all hardlinks pointing to it.
Dec 31, 2006 at 4:04 PM
but also remember that making a change to a hardlink changes ALL copies, including the original.
Dec 31, 2006 at 5:25 PM
Thanks for the info on how these work. So how does one go about finding all the hard links to a file and/or the target of a hard link?

I still think we need a set of Remove-Junction/SymLink cmdlets or functions. Or what if we changed the New-SymLink/New-Junction cmdlet names to New-SymReparsePoint/New-JunctionReparsePoint? Any other ideas? Sorry but I find it hard to believe that we can't make this less confusing. :-)
Dec 31, 2006 at 8:11 PM
take a look at the FSUTIL tool that comes with Windows itself:

PS C:\> fsutil
---- Commands Supported ----

behavior Control file system behavior
dirty Manage volume dirty bit
file File specific commands
fsinfo File system information
hardlink Hardlink management
objectid Object ID management
quota Quota management
reparsepoint Reparse point management
sparse Sparse file control
usn USN management
volume Volume management

- Oisin
Jan 1, 2007 at 4:33 AM
you can not find a "target" of a hard link. imagine the file as a pointer to data, stored inside a directory structure. usually, a file has only one name (a single hardlink). when you explicitly create a hardlink, a file entry pointing to the original file stream is created in the containing directory.

ntfs stores only the reference count of each file stream. the stream is deleted when the reference count drops to zero. to get the number of names of a file, you can use GetFileInformationByHandle http://msdn2.microsoft.com/en-us/library/aa364952.aspx

i think the best option would be to to create default alias&function replacements, which would delete only the reparse point (of course, only when used without the -recurse parameter).
Jan 1, 2007 at 6:45 AM
junction, directory symlink = removing forwared to Remove-ReparsePoint by our rmdir, rm, del, erase functions
everything else = removed using Remove-Item

i guess we may write dummy Remove-Junction and Remove-Symlink commands, that would verify the reparse point tag and defer to the base implementation. but i see no way of eliminating the New-Hardlink/Remove-Item dichotomy without only causing more confusion.
Jan 1, 2007 at 7:03 AM
I like the idea of Remove-SymLink/Junction. HardLink seems not so useful in the face of a symbolic link?? So just leave it as is?
Jan 1, 2007 at 7:12 AM
well, we have to implement the wrapper function, and the "alias" commands, if you think they will make it less confusing
Jan 1, 2007 at 7:37 AM
Well then, Dekuji.