Finding junction points in cygwin

View: New views
20 Messages — Rating Filter:   Alert me  
< Prev | 1 - 2 | Next >

Finding junction points in cygwin

by aputerguy :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Does cygwin have any ability to find/identify NTFS junction points?
This would be useful so that you don't inadvertently mistreat them thinking they are regular files or directories.

Also, is there any native cygwin utilities with functionality similar to junction.exe allowing you to make or delete junction points? (I know that cygwin doesn't like them too much philosophically and they seem to be on their way out anyway but...)


Re: Finding junction points in cygwin

by Andy Koppe :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2009/11/9 aputerguy:
> Does cygwin have any ability to find/identify NTFS junction points?
> This would be useful so that you don't inadvertently mistreat them thinking
> they are regular files or directories.

They appear as symbolic links. Dunno how to tell them from other sorts
of shortcuts.

> Also, is there any native cygwin utilities with functionality similar to
> junction.exe allowing you to make or delete junction points?

No. Use junction.exe, or linkd.exe from the Windows resource kit tools.

Andy

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


Re: Finding junction points in cygwin

by Corinna Vinschen-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Nov  9 07:51, Andy Koppe wrote:
> 2009/11/9 aputerguy:
> > Does cygwin have any ability to find/identify NTFS junction points?
> > This would be useful so that you don't inadvertently mistreat them thinking
> > they are regular files or directories.
>
> They appear as symbolic links. Dunno how to tell them from other sorts
> of shortcuts.

Not quite.  Directory junctions appear as symlinks.  Volume junctions
are treated as simple directories since they are for all practically
purposes the same as Unix mount points.


Corinna

--
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


Re: Finding junction points in cygwin

by aputerguy :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Corinna Vinschen writes
> Not quite.  Directory junctions appear as symlinks.  Volume junctions
> are treated as simple directories since they are for all practically
> purposes the same as Unix mount points.

But I still see several issues at least with directory junctions.
1. When I use junction.exe to make a junction with a regular file, the junction shows up as a regular file under cygwin. When I make a junction to a directory, the junction shows up as a directory. In particular, I don't see symlinks in either case.

2. Shouldn't we have a way of identify and/or differentiating junctions from their targets. For example, cygwin (appropriately) doesn't allow you to remove junctions using 'rm' (either files or directories). But if I am writing code to manipulate files, I would like to be able to identify junctions pro-actively rather than retroactively by the fact that I can't remove them.

3. Moving a junction, moves the target file. And leaves the junction itself 'unlinked'. I'm not sure this is the logical behavior expected, particularly if it is supposed to act like a symlink. Because with symlinks, 'mv' moves the link not the target.

Re: Finding junction points in cygwin

by aputerguy :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Actually the behavior is even stranger... renaming and then deleting junctions creates spurious directories.

echo "This is a test file" >| targetfile
mkdir targetdir
echo "This is a test dir file" >| targetdir/targetdirfile

junction.exe junctionfile targetfile
junction.exe junctiondir targetdir

ls -Ag
drwxr-xr-x 1 None  0 2009-11-09 11:56 junctiondir/
-rw-r--r-- 1 None 20 2009-11-09 11:55 junctionfile
drwxr-xr-x 1 None  0 2009-11-09 11:56 targetdir/
-rw-r--r-- 1 None 20 2009-11-09 11:55 targetfile

mv junctionfile newjunctionfile
mv junctiondir newjunctiondir

ls -Ag
drwxr-xr-x 1 ????????  0 2009-11-09 11:57 junctiondir/
drwxr-xr-x 1 ????????  0 2009-11-09 11:57 junctionfile/
drwxr-xr-x 1 None      0 2009-11-09 11:56 newjunctiondir/
-rw-r--r-- 1 None     20 2009-11-09 11:55 newjunctionfile

junction.exe -d junctionfile
junction.exe -d junctiondir

ls -Ag
drwxr-xr-x  1 None  0 2009-11-09 11:56 newjunctiondir/
-rw-r--r--  1 None 20 2009-11-09 11:55 newjunctionfile
drwx------+ 1 None  0 2009-11-09 12:01 targetdir/
drwx------+ 1 None  0 2009-11-09 12:01 targetfile/

Now this seems to be sheer madness.
The original file and directory names have reappeared!
However 'targetdir' is now empty and 'targetfile' is also an (empty) directory!


ls -Ag targetdir targetfile newjunctiondir
newjunctiondir:
total 1
-rw-r--r-- 1 None 24 2009-11-09 11:56 targetdirfile

targetdir:
total 0

Interestingly, in Windows explorer, renaming seems to do the right thing - it renames the target.

Interestingly, Windows explorer allows both file and directory junctions to be removed (though it displays file junctions as non-openable directories). Not sure why it does this since I thought junctions could only be deleted using '-d'.

So it seems to me, we have the following conclusions:
- cygwin treatment of junctions is not consistent with Windows or with notion of symlinks. It also leaves weird residua after renaming junctions.
- Windows junctions are also messed up but not as much




targetfile:
total 0




Re: Finding junction points in cygwin

by Corinna Vinschen-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Nov  9 08:51, aputerguy wrote:

>
> Corinna Vinschen writes
> > Not quite.  Directory junctions appear as symlinks.  Volume junctions
> > are treated as simple directories since they are for all practically
> > purposes the same as Unix mount points.
>
> But I still see several issues at least with directory junctions.
> 1. When I use junction.exe to make a junction with a regular file, the
> junction shows up as a regular file under cygwin. When I make a junction to
> a directory, the junction shows up as a directory. In particular, I don't
> see symlinks in either case.

Are you running Cygwin 1.5.25?  If so, yes, Cygwin 1.5.25 doesn't know
anything about junctions or native symlinks.  It only sees what is
visible through the Win32 API.

Btw., while directory junctions can point to files, they are always
treated as directories by the Win32 API.  There's no way to access the
target file of such a directory junction from non-Cygwin applications
like Windows Explorer or CMD.  It's not really supported to do so, and
it's kind of schizophrenic that the CMD builtin command mklink allows
to create such directory junctions pointing to files.

> 2. Shouldn't we have a way of identify and/or differentiating junctions from
> their targets. For example, cygwin (appropriately) doesn't allow you to
> remove junctions using 'rm' (either files or directories). But if I am
> writing code to manipulate files, I would like to be able to identify
> junctions pro-actively rather than retroactively by the fact that I can't
> remove them.

Try Cygwin 1.7.  It recognizes directory junctions as symlinks.

> 3. Moving a junction, moves the target file. And leaves the junction itself
> 'unlinked'. I'm not sure this is the logical behavior expected, particularly
> if it is supposed to act like a symlink. Because with symlinks, 'mv' moves
> the link not the target.

Try Cygwin 1.7.  It recognizes directory junctions as symlinks.


Corinna

--
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


Re: Finding junction points in cygwin

by Corinna Vinschen-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Nov  9 09:17, aputerguy wrote:

>
> Actually the behavior is even stranger... renaming and then deleting
> junctions creates spurious directories.
>
> echo "This is a test file" >| targetfile
> mkdir targetdir
> echo "This is a test dir file" >| targetdir/targetdirfile
>
> junction.exe junctionfile targetfile
> junction.exe junctiondir targetdir
>
> ls -Ag
> drwxr-xr-x 1 None  0 2009-11-09 11:56 junctiondir/
> -rw-r--r-- 1 None 20 2009-11-09 11:55 junctionfile
> drwxr-xr-x 1 None  0 2009-11-09 11:56 targetdir/
> -rw-r--r-- 1 None 20 2009-11-09 11:55 targetfile
>
> mv junctionfile newjunctionfile
> mv junctiondir newjunctiondir
>
> ls -Ag
> drwxr-xr-x 1 ????????  0 2009-11-09 11:57 junctiondir/
> drwxr-xr-x 1 ????????  0 2009-11-09 11:57 junctionfile/
> drwxr-xr-x 1 None      0 2009-11-09 11:56 newjunctiondir/
> -rw-r--r-- 1 None     20 2009-11-09 11:55 newjunctionfile
>
> junction.exe -d junctionfile
> junction.exe -d junctiondir
>
> ls -Ag
> drwxr-xr-x  1 None  0 2009-11-09 11:56 newjunctiondir/
> -rw-r--r--  1 None 20 2009-11-09 11:55 newjunctionfile
> drwx------+ 1 None  0 2009-11-09 12:01 targetdir/
> drwx------+ 1 None  0 2009-11-09 12:01 targetfile/
>
> Now this seems to be sheer madness.

Indeed, and I can't reproduce this, neither in Cygwin 1.5.25, nor in
Cygwin 1.7.  The only difference between your and my run is that I'm
using the cmd mklink builtin rather than the junction tool, like this:

 $ cmd /c mklink /j junctionfile targetfile
 Junction created for junctionfile <<===>> targetfile
 $ cmd /c mklink /j junctiondir targetdir
 Junction created for junctiondir <<===>> targetdir

BLODA?


Corinna

--
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


Re: Finding junction points in cygwin

by aputerguy :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Corinna writes..
> Try Cygwin 1.7.  It recognizes directory junctions as symlinks.

$ uname -r
1.7.0(0.214/5/3)

But don't see any symlinks...

Re: Finding junction points in cygwin

by aputerguy :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Corinna Vinschen writes...
> Indeed, and I can't reproduce this, neither in Cygwin 1.5.25, nor in
> Cygwin 1.7.  The only difference between your and my run is that I'm
> using the cmd mklink builtin rather than the junction tool, like this:

> BLODA?

I don't know... I don't have a lot of BLODA on my machine...

I found the problem once and then I reproduced it in order to cut & paste the problem to the list.
But when I just tried to reproduce it again, I couldn't. So let's ignore that problem for now or maybe it is related to whatever weirdness is causing my Cygwin 1.7 not to recognize junctions as symlinks.

Any suggestions on how to troubleshoot why I'm not seeing the symlinks?

And just to confirm, 'find' also recognizes the junctions as files and directories - not as symlinks.

Re: Finding junction points in cygwin

by Corinna Vinschen-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Nov  9 09:39, aputerguy wrote:
>
> Corinna writes..
> > Try Cygwin 1.7.  It recognizes directory junctions as symlinks.
>
> $ uname -r
> 1.7.0(0.214/5/3)
>
> But don't see any symlinks...

Uh, I see.  Don't use the junction tool, use cmd's mklink instead.
junction.exe creates directory symlinks which can't be easily recognized
as directory junctions, at least not using the default technique.

I'll look into supporting these weird junctions as well.


Corinna

--
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


Re: Finding junction points in cygwin

by Andy Koppe :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2009/11/9 Corinna Vinschen:
> aputerguy:
>> But don't see any symlinks..
> Uh, I see.  Don't use the junction tool, use cmd's mklink instead.

Was mklink introduced with Vista? It's not present on XP. The
alternative there is linkd.exe, available as part of the freely
downloadable Windows Server 2003 Resource Kit Tools.

I checked again that Cygwin recognizes links created by linkd.exe as
symlinks. Sorry for not trying junction.exe before posting.

Andy

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


Re: Finding junction points in cygwin

by aputerguy :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Corinna writes:
> Uh, I see.  Don't use the junction tool, use cmd's mklink instead.
> junction.exe creates directory symlinks which can't be easily recognized
> as directory junctions, at least not using the default technique.

> I'll look into supporting these weird junctions as well.

Thanks. Something should be done here I think because otherwise you can really unwittingly create a mess if someone else has created junctions and you start renaming and moving files around. The behavior seems to be unexpected and potentially destructive. Better to not allow any (destructive) cygwin operations on such files than to have such unnatural behavior.

I will look into getting mklink for XP in the meantime.

Re: Finding junction points in cygwin

by aputerguy :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I have been googling on junction.exe and mklink.
Since they both create reparse points, in what way are the reparse points different to the extent that cygwin recognizes those from mklink but not those form junction.exe.

The nice thing though about junction.exe is that it uses the *nix like '-d' flag rather than the dos-like '/D' flag that mklink seems to use.

Re: Finding junction points in cygwin

by Corinna Vinschen-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Nov  9 19:09, Corinna Vinschen wrote:

> On Nov  9 09:39, aputerguy wrote:
> >
> > Corinna writes..
> > > Try Cygwin 1.7.  It recognizes directory junctions as symlinks.
> >
> > $ uname -r
> > 1.7.0(0.214/5/3)
> >
> > But don't see any symlinks...
>
> Uh, I see.  Don't use the junction tool, use cmd's mklink instead.
> junction.exe creates directory symlinks which can't be easily recognized
> as directory junctions, at least not using the default technique.
>
> I'll look into supporting these weird junctions as well.

Not quite as weird.  The test got actually simpler now.  I also set the
return code of rename(2) to EBUSY when you try to rename a volume
junction.  Otherwise Windows returns an error code equivalent to EXDEV
and mv(1) starts to move the directory over by copying its entire
content (cross-device mv).


HTH,
Corinna

--
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


Re: Finding junction points in cygwin

by Corinna Vinschen-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Nov  9 18:59, Andy Koppe wrote:
> 2009/11/9 Corinna Vinschen:
> > aputerguy:
> >> But don't see any symlinks..
> > Uh, I see.  Don't use the junction tool, use cmd's mklink instead.
>
> Was mklink introduced with Vista? It's not present on XP. The

Yes, it has been added to cmd in Vista.  Unfortunately it's a
builtin, not a stand-alone tool.


Corinna

--
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


Re: Finding junction points in cygwin

by Corinna Vinschen-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Nov  9 11:16, aputerguy wrote:
> I will look into getting mklink for XP in the meantime.

There's no mklink for XP.  It's a cmd builtin in Vista and later.


Corinna

--
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


Re: Finding junction points in cygwin

by Corinna Vinschen-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Nov  9 11:27, aputerguy wrote:
> The nice thing though about junction.exe is that it uses the *nix like '-d'
> flag rather than the dos-like '/D' flag that mklink seems to use.

mklink /d creates a symlink with a directory DOS attribute, it does
not delete the symlink.


Corinna

--
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


Re: Finding junction points in cygwin

by aputerguy :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

More generally, could someone point me to a single source that can accurately compare and contrast the following notions of "links" in cygwin/windoze:

1. Hard links (ln)
2. Soft links (ln -s)
    - Old style
    - New style
3. Windows shortcuts
4. Junctions created by junction.exe
5. Reparse points created by linkd.exe
6. Other types of reparse points?
5. Mount points created by cygwin mount
6. Mount points created by mountvol
7. Letter drives created by dosdev
8. Letter drives created using Administrative Tools computer management
9. Other types of mounting?

I know that some of the above only work on files, some only on directories, some only on shares, etc.
but there is a lot of overlap and a nice table would be very helpful.

Personally, I'm sure I don't understand all the differences, subtleties, limitations, and when to use which one. I'm also left with the feeling that Microsoft just keeps throwing new flavors of links and mounts rather than going with a consistent approach but maybe I'm just biased to *nix.


Re: Finding junction points in cygwin

by aputerguy :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Corinna Vinschen writes:
>On Nov  9 11:27, aputerguy wrote:
>> The nice thing though about junction.exe is that it uses the *nix like '-d'
>> flag rather than the dos-like '/D' flag that mklink seems to use.

>mklink /d creates a symlink with a directory DOS attribute, it does
>not delete the symlink.

I'm sorry I meant linkd.exe.
It uses the '/D' flag to delete rather than *nix-like '-d'

Re: Finding junction points in cygwin

by aputerguy :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

And also add to the below list:
10. mklink
--------------------------
More generally, could someone point me to a single source that can accurately compare and contrast the following notions of "links" in cygwin/windoze:

1. Hard links (ln)
2. Soft links (ln -s)
    - Old style
    - New style
3. Windows shortcuts
4. Junctions created by junction.exe
5. Reparse points created by linkd.exe
6. Other types of reparse points?
5. Mount points created by cygwin mount
6. Mount points created by mountvol
7. Letter drives created by dosdev
8. Letter drives created using Administrative Tools computer management
9. Other types of mounting?

I know that some of the above only work on files, some only on directories, some only on shares, etc.
but there is a lot of overlap and a nice table would be very helpful.

Personally, I'm sure I don't understand all the differences, subtleties, limitations, and when to use which one. I'm also left with the feeling that Microsoft just keeps throwing new flavors of links and mounts rather than going with a consistent approach but maybe I'm just biased to *nix.



< Prev | 1 - 2 | Next >