WSL symbolic links

Corinna Vinschen corinna-cygwin@cygwin.com
Thu Mar 26 11:00:59 GMT 2020


On Mar 26 10:00, Thomas Wolff wrote:
> A symbolic link created with WSL is neither interpreted in cygwin nor can it
> be deleted:
> > touch file
> > wsl ln -s file link
> > wsl ls -l link
> lrwxrwxrwx    1 towo     towo             1 Mar 26 08:56 link -> file
> > ls -l link
> -rw-r----- 1 Unknown+User Unknown+Group 0 Mar 26 00:00 link

What kind of file are they in the real world?  Reparse points?  If so,
what content do they have?  I attached a Q&D source from my vault
of old test apps to check on reparse point content.  Please compile with

  gcc -g ../src/rd-reparse.c -o rd-reparse -lntdll

It takes a single native NT path as parameter, kind of like this:

  ./rd-reparse '\??\C:\cygwin64\home\corinna\link'


Thanks,
Corinna

-- 
Corinna Vinschen
Cygwin Maintainer
-------------- next part --------------
#include <stdio.h>
#include <wchar.h>
#include <windows.h>
#include <winternl.h>

typedef struct {
    DWORD  ReparseTag;
    WORD   ReparseDataLength;
    WORD   Reserved;
    union {
        struct {
            WORD   SubstituteNameOffset;
            WORD   SubstituteNameLength;
            WORD   PrintNameOffset;
            WORD   PrintNameLength;
	    DWORD  Flag;
            WCHAR PathBuffer[1];
        } SymbolicLinkReparseBuffer;
        struct {
            WORD   SubstituteNameOffset;
            WORD   SubstituteNameLength;
            WORD   PrintNameOffset;
            WORD   PrintNameLength;
            WCHAR PathBuffer[1];
        } MountPointReparseBuffer;
        struct {
            BYTE   DataBuffer[1];
        } GenericReparseBuffer;
    };
} MY_REPARSE_DATA_BUFFER, *MY_PREPARSE_DATA_BUFFER;

//ULONG WINAPI RtlCreateUnicodeStringFromAsciiz (PUNICODE_STRING, PCSTR);

int
main (int argc, char **argv)
{
  HANDLE fh;
  char buf[MAXIMUM_REPARSE_DATA_BUFFER_SIZE];
  DWORD siz;
  MY_PREPARSE_DATA_BUFFER rp;
  char *pbuf;
  char name[32768];
  NTSTATUS status;
  IO_STATUS_BLOCK io;
  UNICODE_STRING fname;
  OBJECT_ATTRIBUTES attr;

  RtlCreateUnicodeStringFromAsciiz (&fname, argv[1]);
  InitializeObjectAttributes(&attr, &fname, OBJ_CASE_INSENSITIVE, NULL, 0);
  status = NtOpenFile (&fh, FILE_READ_EA | FILE_READ_ATTRIBUTES | SYNCHRONIZE,
		       &attr, &io,
		       FILE_SHARE_VALID_FLAGS,
		       FILE_SYNCHRONOUS_IO_NONALERT
		       | FILE_OPEN_FOR_BACKUP_INTENT
		       | FILE_OPEN_REPARSE_POINT);
  if (!NT_SUCCESS (status))
    {
      fprintf (stderr, "NtOpenFile: %08X\n", status);
      return 1;
    }
  status = NtFsControlFile (fh, NULL, NULL, NULL, &io,
			    FSCTL_GET_REPARSE_POINT, NULL, 0,
			    (LPVOID) buf, sizeof buf);
  if (!NT_SUCCESS (status))
    {
      fprintf (stderr, "NtDeviceIoControlFile: %08lX\n", status);
      CloseHandle (fh);
      return 1;
    }

  rp = (MY_PREPARSE_DATA_BUFFER) buf;
  printf ("ReparseTag:           0x%08x\n", rp->ReparseTag);
  printf ("ReparseDataLength:    %10d\n", rp->ReparseDataLength);
  printf ("Reserved:             %10d\n", rp->Reserved);
  if (rp->ReparseTag == IO_REPARSE_TAG_SYMLINK
      || rp->ReparseTag == IO_REPARSE_TAG_SYMLINK)
    {
      printf ("SubstituteNameOffset: %10d\n",
	      rp->SymbolicLinkReparseBuffer.SubstituteNameOffset);
      printf ("SubstituteNameLength: %10d\n",
	      rp->SymbolicLinkReparseBuffer.SubstituteNameLength);
      printf ("PrintNameOffset:      %10d\n",
	      rp->SymbolicLinkReparseBuffer.PrintNameOffset);
      printf ("PrintNameLength:      %10d\n",
	      rp->SymbolicLinkReparseBuffer.PrintNameLength);
      if (rp->ReparseTag == IO_REPARSE_TAG_SYMLINK)
	{
	  printf ("Flag:                 0x%08x\n",
		  rp->SymbolicLinkReparseBuffer.Flag);
	  pbuf = (char *) rp->SymbolicLinkReparseBuffer.PathBuffer;
	}
      else
	pbuf = (char *) rp->MountPointReparseBuffer.PathBuffer;
      wcstombs (name,
		(PWCHAR) (pbuf + rp->SymbolicLinkReparseBuffer.SubstituteNameOffset),
		rp->SymbolicLinkReparseBuffer.SubstituteNameLength / 2);
      name[rp->SymbolicLinkReparseBuffer.SubstituteNameLength / 2] = '\0';
      printf("SubstituteName:       %s\n", name);
      wcstombs (name,
		(PWCHAR) (pbuf + rp->SymbolicLinkReparseBuffer.PrintNameOffset),
		rp->SymbolicLinkReparseBuffer.PrintNameLength / 2);
      name[rp->SymbolicLinkReparseBuffer.PrintNameLength / 2] = '\0';
      printf("PrintName:            %s\n", name);
    }
  else
    {
      WORD i;

      for (i = 0; i < rp->ReparseDataLength; ++i)
	{
	  printf ("%02x ", rp->GenericReparseBuffer.DataBuffer[i]);
	  if ((i + 1) % 16 == 0)
	    putchar ('\n');
	}
    }

  CloseHandle (fh);
  return 0;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin/attachments/20200326/5992226b/attachment.sig>


More information about the Cygwin mailing list