pastebin - collaborative debugging tool
rovema.kpaste.net RSS


msnfs41client: Patch to implement |FileNetworkPhysicalNameInformation|, 2025-03-11
Posted by Anonymous on Tue 11th Mar 2025 19:21
raw | new post

  1. From 79c438f2aef57aef28ee8cf9a04396c5c6231378 Mon Sep 17 00:00:00 2001
  2. From: Roland Mainz <roland.mainz@nrubsig.org>
  3. Date: Tue, 11 Mar 2025 20:11:54 +0100
  4. Subject: [PATCH] sys,tests: Implement |FileNetworkPhysicalNameInformation|
  5.  support
  6.  
  7. Implement |FileNetworkPhysicalNameInformation| support.
  8.  
  9. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  10. ---
  11. sys/nfs41sys_fileinfo.c      | 38 ++++++++++++++++++
  12.  tests/winfsinfo1/winfsinfo.c | 77 ++++++++++++++++++++++++++++++++++++
  13.  2 files changed, 115 insertions(+)
  14.  
  15. diff --git a/sys/nfs41sys_fileinfo.c b/sys/nfs41sys_fileinfo.c
  16. index 6efa067..4c7dceb 100644
  17. --- a/sys/nfs41sys_fileinfo.c
  18. +++ b/sys/nfs41sys_fileinfo.c
  19. @@ -280,6 +280,44 @@ NTSTATUS nfs41_QueryFileInformation(
  20.          goto out;
  21.      }
  22.  #endif /* NFS41_DRIVER_DISABLE_8DOT3_SHORTNAME_GENERATION */
  23. +    /*
  24. +     * |FileNetworkPhysicalNameInformation| - return UNC path -
  25. +     * basically the same logic as |FileNormalizedNameInformation|
  26. +     * above in our case (but without the 8.3 filename
  27. +     * restrictions).
  28. +     */
  29. +    case FileNetworkPhysicalNameInformation:
  30. +    {
  31. +        if (RxContext->Info.LengthRemaining <
  32. +            FIELD_OFFSET(FILE_NAME_INFORMATION, FileName)) {
  33. +            RxContext->Info.Length = 0;
  34. +            status = STATUS_BUFFER_OVERFLOW;
  35. +            goto out;
  36. +        }
  37. +
  38. +        PFILE_NETWORK_PHYSICAL_NAME_INFORMATION fnpni =
  39. +            (PFILE_NETWORK_PHYSICAL_NAME_INFORMATION)
  40. +                RxContext->Info.Buffer;
  41. +        RxContext->Info.LengthRemaining -=
  42. +            FIELD_OFFSET(FILE_NETWORK_PHYSICAL_NAME_INFORMATION,
  43. +            FileName);
  44. +
  45. +        RxConjureOriginalName((PFCB)RxContext->pFcb,
  46. +            (PFOBX)RxContext->pFobx,
  47. +            &fnpni->FileNameLength,
  48. +            &fnpni->FileName[0],
  49. +            &RxContext->Info.Length,
  50. +            VNetRoot_As_UNC_Name);
  51. +
  52. +        if (RxContext->Info.LengthRemaining < 0) {
  53. +            RxContext->Info.Length = 0;
  54. +            status = STATUS_BUFFER_OVERFLOW;
  55. +            goto out;
  56. +        }
  57. +
  58. +        status = STATUS_SUCCESS;
  59. +        goto out;
  60. +    }
  61.      case FileEaInformation:
  62.      {
  63.          if (RxContext->Info.LengthRemaining <
  64. diff --git a/tests/winfsinfo1/winfsinfo.c b/tests/winfsinfo1/winfsinfo.c
  65. index de1d95e..10616ed 100644
  66. --- a/tests/winfsinfo1/winfsinfo.c
  67. +++ b/tests/winfsinfo1/winfsinfo.c
  68. @@ -1194,6 +1194,79 @@ out:
  69.      return retval;
  70.  }
  71.  
  72. +typedef struct _FILE_NETWORK_PHYSICAL_NAME_INFORMATION {
  73. +    ULONG FileNameLength;
  74. +    WCHAR FileName[1];
  75. +} FILE_NETWORK_PHYSICAL_NAME_INFORMATION, *PFILE_NETWORK_PHYSICAL_NAME_INFORMATION;
  76. +
  77. +NTSYSAPI
  78. +NTSTATUS
  79. +NTAPI
  80. +ZwQueryInformationFile(
  81. +    _In_ HANDLE FileHandle,
  82. +    _Out_ PIO_STATUS_BLOCK IoStatusBlock,
  83. +    _Out_writes_bytes_(Length) PVOID FileInformation,
  84. +    _In_ ULONG Length,
  85. +    _In_ FILE_INFORMATION_CLASS FileInformationClass
  86. +);
  87. +
  88. +static
  89. +bool get_filenetworkphysicalnameinfo(const char *progname, const char *filename)
  90. +{
  91. +    int res = EXIT_FAILURE;
  92. +    NTSTATUS status;
  93. +    IO_STATUS_BLOCK iostatus;
  94. +    PFILE_NETWORK_PHYSICAL_NAME_INFORMATION fnpni = NULL;
  95. +
  96. +    HANDLE fileHandle = CreateFileA(filename,
  97. +        GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
  98. +        FILE_FLAG_BACKUP_SEMANTICS, NULL);
  99. +    if (fileHandle == INVALID_HANDLE_VALUE) {
  100. +        (void)fprintf(stderr,
  101. +            "%s: Error opening file '%s'. Last error was %d.\n",
  102. +            progname,
  103. +            filename,
  104. +            (int)GetLastError());
  105. +        return EXIT_FAILURE;
  106. +    }
  107. +
  108. +#define FNPNI_MAXCHARS (16384)
  109. +    fnpni = calloc(1,
  110. +        sizeof(FILE_NETWORK_PHYSICAL_NAME_INFORMATION)+sizeof(wchar_t)*FNPNI_MAXCHARS);
  111. +    if (fnpni == NULL) {
  112. +         (void)fprintf(stderr,
  113. +            "%s: Out of memory.\n",
  114. +            progname);
  115. +        return EXIT_FAILURE;
  116. +    }
  117. +
  118. +    status = ZwQueryInformationFile(fileHandle,
  119. +        &iostatus,
  120. +        fnpni,
  121. +        (sizeof(FILE_NETWORK_PHYSICAL_NAME_INFORMATION)+sizeof(wchar_t)*FNPNI_MAXCHARS),
  122. +        FileNetworkPhysicalNameInformation);
  123. +
  124. +    if (status != STATUS_SUCCESS) {
  125. +        (void)fprintf(stderr, "%s: GetFileInformationByHandleEx() "
  126. +            "error. status==0x%lx.\n",
  127. +            progname,
  128. +            (long)status);
  129. +        res = EXIT_FAILURE;
  130. +        goto done;
  131. +    }
  132. +
  133. +    (void)printf("(\n");
  134. +    (void)printf("\tfilename='%s'\n", filename);
  135. +    (void)printf("\tfnpni_FileName='%S'\n",
  136. +        fnpni->FileName);
  137. +    (void)printf(")\n");
  138. +    res = EXIT_SUCCESS;
  139. +
  140. +done:
  141. +    free(fnpni);
  142. +    (void)CloseHandle(fileHandle);
  143. +    return res;
  144. +}
  145.  
  146.  static
  147.  void usage(void)
  148. @@ -1213,6 +1286,7 @@ void usage(void)
  149.          "nfs3attr|"
  150.          "fileremoteprotocolinfo|"
  151.          "fileidinfo|"
  152. +        "filenetworkphysicalnameinfo|"
  153.          "fsctlqueryallocatedranges"
  154.          "> path\n");
  155.  }
  156. @@ -1275,6 +1349,9 @@ int main(int ac, char *av[])
  157.      else if (!strcmp(subcmd, "fileidinfo")) {
  158.          return get_fileidinfo(av[0], av[2]);
  159.      }
  160. +    else if (!strcmp(subcmd, "filenetworkphysicalnameinfo")) {
  161. +        return get_filenetworkphysicalnameinfo(av[0], av[2]);
  162. +    }
  163.      else if (!strcmp(subcmd, "fsctlqueryallocatedranges")) {
  164.          return fsctlqueryallocatedranges(av[0], av[2]);
  165.      }
  166. --
  167. 2.45.1

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at