Cygwin tool to differ junctions from soft links?

Brian Inglis Brian.Inglis@Shaw.ca
Fri Nov 17 14:56:53 GMT 2023


On 2023-11-16 22:54, Thomas Wolff via Cygwin wrote:
> Am 16.11.2023 um 21:30 schrieb Brian Inglis via Cygwin:
>> On 2023-11-16 11:55, matthew patton via Cygwin wrote:
>>> On Thursday, November 16, 2023 at 03:50:24 AM EST, Andrey Repin wrote:
>>>>> Does Cygwin have a command line tool (Scriptable!) which can be used to
>>>>> differ between soft links and Windows junctions?
>> Distinguishing between types of Windows reparse points is not a POSIX or 
>> emulation function, so not of interest to Cygwin developers.
>> I thought about it when support was added, but then realized there was no nice 
>> place to add it within the platform, without going the non-portable Windows 
>> specific utility route, as in lsattr.
>> You could in a function or script by running lsattr -d which seems to fail on 
>> reparse points, then ls -dl which shows a Symbolic Link with a relative path, 
>> and a Junction with an absolute path, although it could just be a Symbolic 
>> Link with an absolute path.

> lsattr has an explicit flag:
>               'r', 'Reparse':       file or directory that has a reparse point
> I don't know whether it's the same as a junction, otherwise a 'j' flag could be 
> added.

Notice that the flag is the same as 'r' "Readonly" and lsattr does not work on 
Windows Reparse Points which are Junctions, Directory or File Symbolic Links 
[sanitized]:
$ cd ~
$ cmd /c dir /a:l | grep '>'
2021-04-13  10:41    <JUNCTION>     Application Data [$HOME/AppData/Roaming]
2021-06-21  21:07    <JUNCTION>     Bookshelf [...]
2021-04-13  10:41    <JUNCTION>     Cookies 
[$HOME/AppData/Local/Microsoft/Windows/INetCookies]
2021-09-15  10:23    <JUNCTION>     cygwin-64t [...]
2021-04-13  10:41    <JUNCTION>     Local Settings [$HOME/AppData/Local]
2020-04-21  03:33    <SYMLINKD>     Mail [AppData/Roaming/...]
2021-04-13  10:41    <JUNCTION>     My Documents [$HOME/Documents]
2021-04-13  10:41    <JUNCTION>     NetHood 
[$HOME/AppData/Roaming/Microsoft/Windows/Network Shortcuts]
2023-05-27  07:30    <JUNCTION>     ntp-dev [...]
2023-05-27  07:30    <JUNCTION>     ntp-stable [...]
2021-04-13  10:41    <JUNCTION>     PrintHood 
[$HOME/AppData/Roaming/Microsoft/Windows/Printer Shortcuts]
2021-04-13  10:41    <JUNCTION>     Recent 
[$HOME/AppData/Roaming/Microsoft/Windows/Recent]
2021-04-13  10:41    <JUNCTION>     SendTo 
[$HOME/AppData/Roaming/Microsoft/Windows/SendTo]
2021-04-13  10:41    <JUNCTION>     Start Menu 
[$HOME/AppData/Roaming/Microsoft/Windows/Start Menu]
2021-02-10  21:19    <JUNCTION>     Tech [...]
2021-04-13  10:41    <JUNCTION>     Templates 
[$HOME/AppData/Roaming/Microsoft/Windows/Templates]
2022-05-27  19:15    <JUNCTION>     weather [...]
2020-06-20  01:19    <SYMLINK>      _gvimrc [.vim/gvimrc]
2020-06-20  01:06    <SYMLINKD>     _vim [.vim]
2020-06-20  00:51    <SYMLINK>      _viminfo [.vim/viminfo]
2020-06-20  00:51    <SYMLINK>      _vimrc [.vim/vimrc]
$ cmd /c dir /a:l /b "$HOMEPATH" | d2u | xargs -I@ lsattr -d '@'
lsattr: Not supported on Application Data
lsattr: Not supported on Bookshelf
lsattr: Not supported on Cookies
lsattr: Not supported on cygwin-64t
lsattr: Not supported on Local Settings
lsattr: Not supported on Mail
lsattr: Not supported on My Documents
lsattr: Not supported on NetHood
lsattr: Not supported on ntp-dev
lsattr: Not supported on ntp-stable
lsattr: Not supported on PrintHood
lsattr: Not supported on Recent
lsattr: Not supported on SendTo
lsattr: Not supported on Start Menu
lsattr: Not supported on Tech
lsattr: Not supported on Templates
lsattr: Not supported on weather
lsattr: Not supported on _gvimrc
lsattr: Not supported on _vim
lsattr: Not supported on _viminfo
lsattr: Not supported on _vimrc

>> Perhaps something like the following would be useful to Windows users who want 
>> to know this stuff:
>>     https://schinagl.priv.at/nt/hardlinkshellext/hardlinkshellext.html
>>>> It would be easier to help you, if you specify the purpose of your
>>>> request. I.e. what you want to achieve with such tool.
>>> AFAIK no. what I do is re-implement 'ln' with a wrapper because the Cygwin
>>> behavior (Junctions) was driving me up the wall.
>>> https://github.com/tb3088/shell-environment/blob/ccf7aa161899c2c4ebe2d9e980e674bc726a3ef3/.functions_os.CYGWIN_NT#L9
>> Cygwin never creates Windows Directory or Filesystem Junction reparse points, 
>> and by default it uses its own version of Unix path symlink files, preceded by 
>> a flag ("magic cookie") value, and with system attribute, to allow 
>> compatibility with FAT file system limitations, or else NFS symlinks on NFS 
>> filesystems.
>> CYGWIN env var settings allow creation of Windows shortcuts and symbolic link 
>> reparse points instead of its default (equivalent to winsymlinks:sys), when 
>> supported by the file system and Windows release:
>>     https://cygwin.com/cygwin-ug-net/using-cygwinenv.html
>>     https://cygwin.com/cygwin-ug-net/using.html#pathnames-symlinks

-- 
Take care. Thanks, Brian Inglis              Calgary, Alberta, Canada

La perfection est atteinte                   Perfection is achieved
non pas lorsqu'il n'y a plus rien à ajouter  not when there is no more to add
mais lorsqu'il n'y a plus rien à retirer     but when there is no more to cut
                                 -- Antoine de Saint-Exupéry



More information about the Cygwin mailing list