Hard linking

View: New views
3 Messages — Rating Filter:   Alert me  

Hard linking

by Magikat :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Could anyone tell me if hard-linking on both Linux and Windows is supported under the .Net Framework.

If not, could you perhaps point to some information that might help writing something to help with hard-linking in C#.

Thanks.

Mag.

Re: Hard linking

by Adrien Dessemond :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I would have a look there :

http://www.go-mono.com/docs/index.aspx?tlink=0@N%3AMono.Posix

(Mono specific !)

On Windows you can import and p/invoke CreateHardLink() in the worst case,
see http://msdn.microsoft.com/en-us/library/aa363860(VS.85).aspx and
http://community.bartdesmet.net/blogs/bart/archive/2006/10/24/Windows-Vista-_2D00_-Creating-symbolic-links-with-C_2300_.aspx
for further details. Altought a better approach would be to use an
existing wrapper, at least if that one would exist (maybe somewhere in the
Microsoft.* namespace ?).


Cheers,

--


On Tue, September 2, 2008 10:30 am, Magikat wrote:

>
> Could anyone tell me if hard-linking on both Linux and Windows is
> supported
> under the .Net Framework.
>
> If not, could you perhaps point to some information that might help
> writing
> something to help with hard-linking in C#.
>
> Thanks.
>
> Mag.
> --
> View this message in context:
> http://www.nabble.com/Hard-linking-tp19271316p19271316.html
> Sent from the Mono - General mailing list archive at Nabble.com.
>
> _______________________________________________
> Mono-list maillist  -  Mono-list@...
> http://lists.ximian.com/mailman/listinfo/mono-list
>


_______________________________________________
Mono-list maillist  -  Mono-list@...
http://lists.ximian.com/mailman/listinfo/mono-list

Re: Hard linking

by Jonathan Pryor :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, 2008-09-02 at 07:30 -0700, Magikat wrote:
> Could anyone tell me if hard-linking on both Linux and Windows is supported
> under the .Net Framework.

As far as I'm aware, symbolic links and hard links are NOT supported as
distinct entities under .NET.  That is, you can read a hard link or
symbolic link normally, but there is no way to determine that the file
is a hard link or symbolic link from within .NET.

> If not, could you perhaps point to some information that might help writing
> something to help with hard-linking in C#.

On Mono/Linux, you can use the various Mono.Unix classes in
Mono.Posix.dll:

        UnixFileSystemInfo e =
                UnixFileSystemInfo.GetFileSystemEntry(file);
        if (e.IsSymbolicLink)
                // file is a symbolic link
        else if (e.IsRegularFile && e.LinkCount > 1)
                // file is a hard link
        ...

Or you can use Mono.Unix.Native.Syscall for the ~actual POSIX APIs.

This doesn't work for Win32, though, so for Win32 support you'd need to
P/Invoke to the corresponding Win32 APIs, such as CreateHardLink() [1]
and CreateSymbolicLink() [2].

 - Jon

[0] http://www.go-mono.com/docs/index.aspx?tlink=0@ecma%3a105%23UnixFileSystemInfo%2f
[1] http://msdn.microsoft.com/en-us/library/aa363860(VS.85).aspx
[2] http://msdn.microsoft.com/en-us/library/aa363866(VS.85).aspx


_______________________________________________
Mono-list maillist  -  Mono-list@...
http://lists.ximian.com/mailman/listinfo/mono-list