none
stat hangs on windows 7 when used for symbolic link RRS feed

  • Question

  • When I tried to use DeviceIoControl for creation of Junction points, it passes but when I tried to perform stat on path, it hangs.
    The usage is as below:
    I used the mechanism described at link http://www.codeproject.com/Articles/194/Windows-2000-Junction-Points to create Directory Junction Points.
    The code structure is as below:

    here new path is directory name of approximately 130 chars.

      CreateDirectory(newpath, 0);

       dirhandle = CreateFile(newpath, GENERIC_READ | GENERIC_WRITE,

      0, 0, OPEN_EXISTING,

      FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS, 0);

    if (dirhandle == INVALID_HANDLE_VALUE)

    return -1;

    /* make sure we have an unparsed native win32 path */

    if (memcmp("\\??\\", oldpath, 4))

    sprintf(nativeTarget, "\\??\\%s", oldpath);

    else

    strcpy(nativeTarget, oldpath);

    while ((p = strchr(p, '/')) != NULL)

    *p++ = '\\';

    len = strlen(nativeTarget) * sizeof(WCHAR);

    reparseBuf->ReparseTag = IO_REPARSE_TAG_MOUNT_POINT;

    reparseBuf->ReparseDataLength = len + 12;

    reparseBuf->Reserved = 0;

    reparseBuf->SubstituteNameOffset = 0;

    reparseBuf->SubstituteNameLength = len;

    reparseBuf->PrintNameOffset = len + sizeof(WCHAR);

    reparseBuf->PrintNameLength = 0;

    MultiByteToWideChar(CP_ACP, 0, nativeTarget, -1,

    reparseBuf->PathBuffer, MAX_PATH);

    if (!DeviceIoControl(dirhandle,

    CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 41, METHOD_BUFFERED, FILE_ANY_ACCESS),

    reparseBuf,

    reparseBuf->ReparseDataLength + REPARSE_JUNCTION_DATA_BUFFER_HEADER_SIZE,

    0, 0, &len, 0))

            {

            }

            if (true)

            {

             sprintf(location_with_version_dir, "%s/%s", newpath,

    "XX_9.2_21031008");

            if (stat(newpath, &st) == 0)

    {

    if (stat(location_with_version_dir, &st) == 0)  //hangs in this stat command.

    i = 1;

    }

            }

    This hang occurs on Windows 7 64bit, when I tried it on winxp 32bit, it didn't hanged. Also the hang occurs only when newpath is long approx 130 chars.

    In   CreateDirectory(newpath, 0), new path is of format "abcde/12345" which means CreateDirectory will prepend current working directory path to it. 
    Instead of that if I try to use full path "d:/aaaaaaaaaa/abcde/12345", then it doesn't hang in stat.
    Is there any problem with using relative paths and then creating junction points based on it for long paths in Windows7?

     
    Friday, October 11, 2013 9:03 AM