pastebin - collaborative debugging tool
rovema.kpaste.net RSS


msnfs41client: Patch for FCB-no-attr-updates-for-already-opened-FCB hack, Storage32 probe locking hack+misc, 2025-03-24
Posted by Anonymous on Mon 24th Mar 2025 18:20
raw | new post

  1. From 7ba53b52ad9f78959263b1bc6a7de9cc9ce7f39a Mon Sep 17 00:00:00 2001
  2. From: Roland Mainz <roland.mainz@nrubsig.org>
  3. Date: Mon, 24 Mar 2025 13:21:58 +0100
  4. Subject: [PATCH 1/3] nfs41_build_features.h,sys: Add hack to avoid updating
  5.  FCB attributes we open an already opened FCB
  6.  
  7. Add build option (|NFS41_DRIVER_HACK_DISABLE_FCB_ATTR_UPDATE_ON_OPEN|,
  8. "enabled" by default) for a hack to avoid updating FCB attributes if
  9. opened for an already opened FCB.
  10.  
  11. This is a hack for now, until we can figure out how
  12. to do this correctly (best guess is not to update FCB
  13. attributes if the file is opened for writing, because
  14. the kernel keeps updating the FCB data. The userland
  15. is not affected by this, they get all information from
  16. |nfs41_fcb->BasicInfo| and |nfs41_fcb->StandardInfo|).
  17.  
  18. We keep this as a build flag for further testing.
  19.  
  20. The hack passes cthon04, winfstest, building gcc, bash with gcc/clang
  21. and building ms-nfs41-client with Visual Studio 2019.
  22.  
  23. Without this hack
  24. $ '/cygdrive/c/Program Files/Git/cmd/git' clone ... # will
  25. fail with read errors.
  26.  
  27. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  28. ---
  29. nfs41_build_features.h   | 24 ++++++++++++-
  30.  sys/nfs41sys_openclose.c | 76 ++++++++++++++++++++++++++++++----------
  31.  2 files changed, 81 insertions(+), 19 deletions(-)
  32.  
  33. diff --git a/nfs41_build_features.h b/nfs41_build_features.h
  34. index 0024d58..7f5c261 100644
  35. --- a/nfs41_build_features.h
  36. +++ b/nfs41_build_features.h
  37. @@ -1,5 +1,6 @@
  38.  /* NFSv4.1 client for Windows
  39. - * Copyright (C) 2012 The Regents of the University of Michigan
  40. + * Copyright (C) 2012 The Regents of the University of Michigan
  41. + * Copyright (C) 2023-2025 Roland Mainz <roland.mainz@nrubsig.org>
  42.   *
  43.   * Olga Kornievskaia <aglo@umich.edu>
  44.   * Casey Bodley <cbodley@umich.edu>
  45. @@ -205,4 +206,25 @@
  46.   */
  47.  #define NFS41_DRIVER_TREAT_UNRESOLVEABLE_SYMLINKS_AS_DIRS 1
  48.  
  49. +/*
  50. + * NFS41_DRIVER_HACK_DISABLE_FCB_ATTR_UPDATE_ON_OPEN -
  51. + * disable updating of FCB attributes for an already
  52. + * opened FCB
  53. + * This is a hack for now, until we can figure out how
  54. + * to do this correctly (best guess is not to update FCB
  55. + * attributes if the file is opened for writing, because
  56. + * the kernel keeps updating the FCB data. The userland
  57. + * is not affected by this, they get all information from
  58. + * |nfs41_fcb->BasicInfo| and |nfs41_fcb->StandardInfo|).
  59. + *
  60. + * We keep this as a build flag for further testing.
  61. + *
  62. + * Without this hack
  63. + * $ '/cygdrive/c/Program Files/Git/cmd/git' clone ... # will
  64. + * fail with read errors.
  65. + *
  66. + */
  67. +#define NFS41_DRIVER_HACK_DISABLE_FCB_ATTR_UPDATE_ON_OPEN 1
  68. +
  69. +
  70.  #endif /* !_NFS41_DRIVER_BUILDFEATURES_ */
  71. diff --git a/sys/nfs41sys_openclose.c b/sys/nfs41sys_openclose.c
  72. index 54ac9cb..d0cc36f 100644
  73. --- a/sys/nfs41sys_openclose.c
  74. +++ b/sys/nfs41sys_openclose.c
  75. @@ -870,24 +870,64 @@ retry_on_link:
  76.                  !pVNetRootContext->read_only) || oldDeletePending)
  77.              nfs41_fcb->StandardInfo.DeletePending = TRUE;
  78.  
  79. -        RxFormInitPacket(InitPacket,
  80. -            &entry->u.Open.binfo.FileAttributes,
  81. -            &entry->u.Open.sinfo.NumberOfLinks,
  82. -            &entry->u.Open.binfo.CreationTime,
  83. -            &entry->u.Open.binfo.LastAccessTime,
  84. -            &entry->u.Open.binfo.LastWriteTime,
  85. -            &entry->u.Open.binfo.ChangeTime,
  86. -            &entry->u.Open.sinfo.AllocationSize,
  87. -            &entry->u.Open.sinfo.EndOfFile,
  88. -            &entry->u.Open.sinfo.EndOfFile);
  89. -
  90. -        if (entry->u.Open.sinfo.Directory)
  91. -            StorageType = FileTypeDirectory;
  92. -        else
  93. -            StorageType = FileTypeFile;
  94. -
  95. -        RxFinishFcbInitialization(Fcb, RDBSS_STORAGE_NTC(StorageType),
  96. -                                    &InitPacket);
  97. +        if (Fcb->OpenCount == 0) {
  98. +            /* Init FCB attributes */
  99. +            RxFormInitPacket(InitPacket,
  100. +                &entry->u.Open.binfo.FileAttributes,
  101. +                &entry->u.Open.sinfo.NumberOfLinks,
  102. +                &entry->u.Open.binfo.CreationTime,
  103. +                &entry->u.Open.binfo.LastAccessTime,
  104. +                &entry->u.Open.binfo.LastWriteTime,
  105. +                &entry->u.Open.binfo.ChangeTime,
  106. +                &entry->u.Open.sinfo.AllocationSize,
  107. +                &entry->u.Open.sinfo.EndOfFile,
  108. +                &entry->u.Open.sinfo.EndOfFile);
  109. +
  110. +            if (entry->u.Open.sinfo.Directory)
  111. +                StorageType = FileTypeDirectory;
  112. +            else
  113. +                StorageType = FileTypeFile;
  114. +
  115. +            RxFinishFcbInitialization(Fcb,
  116. +                RDBSS_STORAGE_NTC(StorageType),
  117. +                &InitPacket);
  118. +        }
  119. +        else {
  120. +#ifndef NFS41_DRIVER_HACK_DISABLE_FCB_ATTR_UPDATE_ON_OPEN
  121. +            /*
  122. +             * NFS41_DRIVER_HACK_DISABLE_FCB_ATTR_UPDATE_ON_OPEN -
  123. +             * disable updating of FCB attributes for an already
  124. +             * opened FCB
  125. +             * This is a hack for now, until we can figure out how
  126. +             * to do this correctly (best guess is not to update FCB
  127. +             * attributes if the file is opened for writing, because
  128. +             * the kernel keeps updating the FCB data. The userland
  129. +             * is not affected by this, they get all information from
  130. +             * |nfs41_fcb->BasicInfo| and |nfs41_fcb->StandardInfo|).
  131. +             *
  132. +             * Without this hack
  133. +             * $ '/cygdrive/c/Program Files/Git/cmd/git' clone ... #
  134. +             * will fail with read errors.
  135. +             *
  136. +             */
  137. +            PFCB pFcb = (PFCB)RxContext->pFcb;
  138. +
  139. +            /* Update FCB attributes */
  140. +            pFcb->Attributes = entry->u.Open.binfo.FileAttributes;
  141. +            pFcb->NumberOfLinks = entry->u.Open.sinfo.NumberOfLinks;
  142. +            pFcb->CreationTime = entry->u.Open.binfo.CreationTime;
  143. +            pFcb->LastAccessTime = entry->u.Open.binfo.LastAccessTime;
  144. +            pFcb->LastWriteTime = entry->u.Open.binfo.LastWriteTime;
  145. +            pFcb->LastChangeTime = entry->u.Open.binfo.ChangeTime;
  146. +            pFcb->ActualAllocationLength =
  147. +                entry->u.Open.sinfo.AllocationSize.QuadPart;
  148. +            pFcb->Header.AllocationSize =
  149. +                entry->u.Open.sinfo.AllocationSize;
  150. +            pFcb->Header.FileSize  = entry->u.Open.sinfo.EndOfFile;
  151. +            pFcb->Header.ValidDataLength =
  152. +                entry->u.Open.sinfo.EndOfFile;
  153. +#endif /* !NFS41_DRIVER_HACK_DISABLE_FCB_ATTR_UPDATE_ON_OPEN */
  154. +        }
  155.      }
  156.  #ifdef DEBUG_OPEN
  157.      else
  158. --
  159. 2.45.1
  160.  
  161. From 9e9e7758e0426ea480b4702e5feb9eed58415fb7 Mon Sep 17 00:00:00 2001
  162. From: Roland Mainz <roland.mainz@nrubsig.org>
  163. Date: Mon, 24 Mar 2025 17:23:52 +0100
  164. Subject: [PATCH 2/3] sys: |map_lock_errors()| shoud map |ERROR_ACCESS_DENIED|
  165.  
  166. |map_lock_errors()| shoud map |ERROR_ACCESS_DENIED| to |STATUS_ACCESS_DENIED|
  167.  
  168. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  169. ---
  170. sys/nfs41sys_lock.c | 3 ++-
  171.  1 file changed, 2 insertions(+), 1 deletion(-)
  172.  
  173. diff --git a/sys/nfs41sys_lock.c b/sys/nfs41sys_lock.c
  174. index 12e5a45..19ff831 100644
  175. --- a/sys/nfs41sys_lock.c
  176. +++ b/sys/nfs41sys_lock.c
  177. @@ -1,6 +1,6 @@
  178.  /* NFSv4.1 client for Windows
  179.   * Copyright (C) 2012 The Regents of the University of Michigan
  180. - * Copyright (C) 2023-2024 Roland Mainz <roland.mainz@nrubsig.org>
  181. + * Copyright (C) 2023-2025 Roland Mainz <roland.mainz@nrubsig.org>
  182.   *
  183.   * Olga Kornievskaia <aglo@umich.edu>
  184.   * Casey Bodley <cbodley@umich.edu>
  185. @@ -188,6 +188,7 @@ NTSTATUS map_lock_errors(
  186.      case ERROR_OUTOFMEMORY:         return STATUS_INSUFFICIENT_RESOURCES;
  187.      case ERROR_SHARING_VIOLATION:   return STATUS_SHARING_VIOLATION;
  188.      case ERROR_FILE_INVALID:        return STATUS_FILE_INVALID;
  189. +    case ERROR_ACCESS_DENIED:       return STATUS_ACCESS_DENIED;
  190.      /* if we return ERROR_INVALID_PARAMETER, Windows translates that to
  191.       * success!! */
  192.      case ERROR_INVALID_PARAMETER:   return STATUS_LOCK_NOT_GRANTED;
  193. --
  194. 2.45.1
  195.  
  196. From e7408c2c3645599e4be2154aadbe32b5db6f87ec Mon Sep 17 00:00:00 2001
  197. From: Roland Mainz <roland.mainz@nrubsig.org>
  198. Date: Mon, 24 Mar 2025 19:03:48 +0100
  199. Subject: [PATCH 3/3] nfs41_build_features.h,sys,tests: Add hack for Storage32
  200.  API probing locks outside filesize
  201.  
  202. Add a hack for Storage32 API probing locks with offsets outside a file's
  203. filesize (see
  204. https://doxygen.reactos.org/d6/d7b/storage32_8h_source.html#l00497).
  205.  
  206. The Storage32 API uses locking outside a file's size in the
  207. offset range of 0x7ffffe00 - 0x7fffffff for it's internal
  208. machinery. Since NFSv4.1 locking API will return failure for
  209. locking attempts outside a file's size we have to add a workaround
  210. here, otherwise applications using the Storage32 API can fail.
  211.  
  212. Without this hack
  213. $ msiexec /i DrMemory-Windows-2.6.20167.msi # will
  214. fail with read errors.
  215.  
  216. Reported-by: Martin Wege <martin.l.wege@gmail.com>
  217. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  218. ---
  219. nfs41_build_features.h   | 18 +++++++++++++
  220.  sys/nfs41sys_lock.c      | 55 ++++++++++++++++++++++++++++++++++++++++
  221.  tests/manual_testing.txt | 10 ++++++++
  222.  3 files changed, 83 insertions(+)
  223.  
  224. diff --git a/nfs41_build_features.h b/nfs41_build_features.h
  225. index 7f5c261..b15cbdf 100644
  226. --- a/nfs41_build_features.h
  227. +++ b/nfs41_build_features.h
  228. @@ -227,4 +227,22 @@
  229.  #define NFS41_DRIVER_HACK_DISABLE_FCB_ATTR_UPDATE_ON_OPEN 1
  230.  
  231.  
  232. +/*
  233. + * |NFS41_DRIVER_HACK_LOCKING_STORAGE32_RANGELOCK_PROBING| - handle
  234. + * rangelock probing for Storage32 API
  235. + * (see https://doxygen.reactos.org/d6/d7b/storage32_8h_source.html#l00497)
  236. + *
  237. + * The Storage32 API uses locking outside a file's size in the
  238. + * offset range of 0x7ffffe00 - 0x7fffffff for it's internal
  239. + * machinery. Since NFSv4.1 locking API will return failure for
  240. + * locking attempts outside a file's size we have to add a workaround
  241. + * here, otherwise applications using the Storage32 API can fail.
  242. + *
  243. + * Without this hack
  244. + * $ msiexec /i DrMemory-Windows-2.6.20167.msi # will
  245. + * fail with read errors.
  246. + *
  247. + */
  248. +#define NFS41_DRIVER_HACK_LOCKING_STORAGE32_RANGELOCK_PROBING 1
  249. +
  250.  #endif /* !_NFS41_DRIVER_BUILDFEATURES_ */
  251. diff --git a/sys/nfs41sys_lock.c b/sys/nfs41sys_lock.c
  252. index 19ff831..e6a2016 100644
  253. --- a/sys/nfs41sys_lock.c
  254. +++ b/sys/nfs41sys_lock.c
  255. @@ -56,6 +56,7 @@
  256.  #include <rx.h>
  257.  #include <windef.h>
  258.  #include <winerror.h>
  259. +#include <stdbool.h>
  260.  
  261.  #include <Ntstrsafe.h>
  262.  
  263. @@ -233,6 +234,29 @@ static void denied_lock_backoff(
  264.          delay->QuadPart = MAX_LOCK_POLL_WAIT;
  265.  }
  266.  
  267. +#ifdef NFS41_DRIVER_HACK_LOCKING_STORAGE32_RANGELOCK_PROBING
  268. +static
  269. +bool rangelock_hack_skiplock(
  270. +    PLOWIO_CONTEXT LowIoContext,
  271. +    PNFS41_FCB nfs41_fcb)
  272. +{
  273. +    /*
  274. +     * Hack for |RANGELOCK_*| constants - see
  275. +     * https://doxygen.reactos.org/d6/d7b/storage32_8h_source.html#l00497
  276. +     *
  277. +     * FIXME: No clue why these constants show up here as lock offsets
  278. +     */
  279. +    if (nfs41_fcb->StandardInfo.EndOfFile.QuadPart <= 0x7fffffff) {
  280. +        if ((LowIoContext->ParamsFor.Locks.ByteOffset >= 0x7ffffe00) &&
  281. +            (LowIoContext->ParamsFor.Locks.ByteOffset <= 0x7fffffff)) {
  282. +            return true;
  283. +        }
  284. +    }
  285. +
  286. +    return false;
  287. +}
  288. +#endif /* NFS41_DRIVER_HACK_LOCKING_STORAGE32_RANGELOCK_PROBING */
  289. +
  290.  NTSTATUS nfs41_Lock(
  291.      IN OUT PRX_CONTEXT RxContext)
  292.  {
  293. @@ -245,6 +269,10 @@ NTSTATUS nfs41_Lock(
  294.          NFS41GetVNetRootExtension(SrvOpen->pVNetRoot);
  295.      __notnull PNFS41_NETROOT_EXTENSION pNetRootContext =
  296.          NFS41GetNetRootExtension(SrvOpen->pVNetRoot->pNetRoot);
  297. +#ifdef NFS41_DRIVER_HACK_LOCKING_STORAGE32_RANGELOCK_PROBING
  298. +    __notnull PMRX_FCB Fcb = RxContext->pFcb;
  299. +    __notnull PNFS41_FCB nfs41_fcb = (PNFS41_FCB)Fcb->Context;
  300. +#endif /* NFS41_DRIVER_HACK_LOCKING_STORAGE32_RANGELOCK_PROBING */
  301.      const ULONG flags = LowIoContext->ParamsFor.Locks.Flags;
  302.      LARGE_INTEGER poll_delay = {0};
  303.  #ifdef ENABLE_TIMINGS
  304. @@ -262,6 +290,15 @@ NTSTATUS nfs41_Lock(
  305.  /*  RxReleaseFcbResourceForThreadInMRx(RxContext, RxContext->pFcb,
  306.          LowIoContext->ResourceThreadId); */
  307.  
  308. +#ifdef NFS41_DRIVER_HACK_LOCKING_STORAGE32_RANGELOCK_PROBING
  309. +    if (rangelock_hack_skiplock(LowIoContext, nfs41_fcb)) {
  310. +        DbgP("nfs41_Lock: RANGELOCK hack 0x%ld\n",
  311. +            (long)LowIoContext->ParamsFor.Locks.ByteOffset);
  312. +        status = STATUS_SUCCESS;
  313. +        goto out;
  314. +    }
  315. +#endif /* NFS41_DRIVER_HACK_LOCKING_STORAGE32_RANGELOCK_PROBING */
  316. +
  317.      status = nfs41_UpcallCreate(NFS41_SYSOP_LOCK, &nfs41_fobx->sec_ctx,
  318.          pVNetRootContext->session, nfs41_fobx->nfs41_open_state,
  319.          pNetRootContext->nfs41d_version, SrvOpen->pAlreadyPrefixedName, &entry);
  320. @@ -349,6 +386,10 @@ NTSTATUS nfs41_Unlock(
  321.          NFS41GetVNetRootExtension(SrvOpen->pVNetRoot);
  322.      __notnull PNFS41_NETROOT_EXTENSION pNetRootContext =
  323.          NFS41GetNetRootExtension(SrvOpen->pVNetRoot->pNetRoot);
  324. +#ifdef NFS41_DRIVER_HACK_LOCKING_STORAGE32_RANGELOCK_PROBING
  325. +    __notnull PMRX_FCB Fcb = RxContext->pFcb;
  326. +    __notnull PNFS41_FCB nfs41_fcb = (PNFS41_FCB)Fcb->Context;
  327. +#endif /* NFS41_DRIVER_HACK_LOCKING_STORAGE32_RANGELOCK_PROBING */
  328.  #ifdef ENABLE_TIMINGS
  329.      LARGE_INTEGER t1, t2;
  330.      t1 = KeQueryPerformanceCounter(NULL);
  331. @@ -361,6 +402,20 @@ NTSTATUS nfs41_Unlock(
  332.  /*  RxReleaseFcbResourceForThreadInMRx(RxContext, RxContext->pFcb,
  333.          LowIoContext->ResourceThreadId); */
  334.  
  335. +#ifdef NFS41_DRIVER_HACK_LOCKING_STORAGE32_RANGELOCK_PROBING
  336. +    /*
  337. +     * FIXME: This does NOT handle |LOWIO_OP_UNLOCK_MULTIPLE|
  338. +     * correctly, but the Storage32 API in ReactOS does not
  339. +     * use it
  340. +     */
  341. +    if (rangelock_hack_skiplock(LowIoContext, nfs41_fcb)) {
  342. +        DbgP("nfs41_Unlock: RANGELOCK hack 0x%ld\n",
  343. +            (long)LowIoContext->ParamsFor.Locks.ByteOffset);
  344. +        status = STATUS_SUCCESS;
  345. +        goto out;
  346. +    }
  347. +#endif /* NFS41_DRIVER_HACK_LOCKING_STORAGE32_RANGELOCK_PROBING */
  348. +
  349.      status = nfs41_UpcallCreate(NFS41_SYSOP_UNLOCK, &nfs41_fobx->sec_ctx,
  350.          pVNetRootContext->session, nfs41_fobx->nfs41_open_state,
  351.          pNetRootContext->nfs41d_version, SrvOpen->pAlreadyPrefixedName, &entry);
  352. diff --git a/tests/manual_testing.txt b/tests/manual_testing.txt
  353. index 4740a5d..12fba86 100644
  354. --- a/tests/manual_testing.txt
  355. +++ b/tests/manual_testing.txt
  356. @@ -691,5 +691,15 @@ $ apt-get install clang gcc gdb nedit emacs vim x11-apps xterm ksh traceroute st
  357.  #
  358.  ksh93 tests/sparsefiles/testsparsefile1.ksh
  359.  
  360. +
  361. +#
  362. +# MSI installation from network driver
  363. +#
  364. +
  365. +# cd /cygdrive/l/download/
  366. +# from https://github.com/DynamoRIO/drmemory/releases/tag/cronbuild-2.6.20167
  367. +wget 'https://github.com/DynamoRIO/drmemory/releases/download/cronbuild-2.6.20167/DrMemory-Windows-2.6.20167.msi'
  368. +msiexec /i DrMemory-Windows-2.6.20167.msi
  369. +
  370.  #
  371.  # EOF.
  372. --
  373. 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