pastebin - collaborative debugging tool
rovema.kpaste.net RSS


msnfs41client: Patches for building on Win10/32bit+Win32 locking fixes+tests, 2025-09-30
Posted by Anonymous on Tue 30th Sep 2025 19:36
raw | new post

  1. From d14f195057c89bacd22953cae76f6af2840bfbd6 Mon Sep 17 00:00:00 2001
  2. From: Cedric Blancher <cedric.blancher@gmail.com>
  3. Date: Tue, 30 Sep 2025 13:12:44 +0200
  4. Subject: [PATCH 1/4] tests: Fix Windows 10/32bit+Cygwin3.3 build failures
  5.  
  6. Fix Windows 10/32bit+Cygwin3.3 build failures.
  7.  
  8. Signed-off-by: Roland Mainz <roland.mainz@nrubsig.org>
  9. ---
  10. tests/ea/Makefile            |  4 ++--
  11.  tests/winfsinfo1/winfsinfo.c | 39 +++++++++++++++++++++++++++++++++++-
  12.  2 files changed, 40 insertions(+), 3 deletions(-)
  13.  
  14. diff --git a/tests/ea/Makefile b/tests/ea/Makefile
  15. index e24e0dc..e647cb6 100644
  16. --- a/tests/ea/Makefile
  17. +++ b/tests/ea/Makefile
  18. @@ -8,11 +8,11 @@ SIGNTOOL="/cygdrive/c/Program Files (x86)/Microsoft SDKs/ClickOnce/SignTool/sign
  19.  all: nfs_ea.i686.exe nfs_ea.x86_64.exe nfs_ea.exe
  20.  
  21.  nfs_ea.i686.exe: main.c
  22. -       clang -target i686-pc-windows-gnu -std=gnu17 -municode -Wall -Wextra -D_CRT_STDIO_ISO_WIDE_SPECIFIERS=1 -DUNICODE=1 -D_UNICODE=1 -isystem /usr/include/w32api/ddk -I../../include -g main.c -lntdll -o $@
  23. +       clang -target i686-pc-windows-gnu -std=gnu17 -municode -Wall -Wextra -DSTRSAFE_NO_DEPRECATE=1 -D_CRT_STDIO_ISO_WIDE_SPECIFIERS=1 -DUNICODE=1 -D_UNICODE=1 -isystem /usr/include/w32api/ddk -I../../include -g main.c -lntdll -o $@
  24.         bash -x -c '$(SIGNTOOL) sign /ph /fd "sha256" /sha1 "$${CERTIFICATE_THUMBPRINT%$$(printf "\r")}" $@'
  25.  
  26.  nfs_ea.x86_64.exe: main.c
  27. -       clang -target x86_64-pc-windows-gnu -std=gnu17 -municode -Wall -Wextra -D_CRT_STDIO_ISO_WIDE_SPECIFIERS=1 -DUNICODE=1 -D_UNICODE=1 -isystem /usr/include/w32api/ddk -I../../include -g main.c -lntdll -o $@
  28. +       clang -target x86_64-pc-windows-gnu -std=gnu17 -municode -Wall -Wextra -DSTRSAFE_NO_DEPRECATE=1 -D_CRT_STDIO_ISO_WIDE_SPECIFIERS=1 -DUNICODE=1 -D_UNICODE=1 -isystem /usr/include/w32api/ddk -I../../include -g main.c -lntdll -o $@
  29.         bash -x -c '$(SIGNTOOL) sign /ph /fd "sha256" /sha1 "$${CERTIFICATE_THUMBPRINT%$$(printf "\r")}" $@'
  30.  
  31.  nfs_ea.exe: nfs_ea.x86_64.exe
  32. diff --git a/tests/winfsinfo1/winfsinfo.c b/tests/winfsinfo1/winfsinfo.c
  33. index b36fc6f..ab9ced3 100644
  34. --- a/tests/winfsinfo1/winfsinfo.c
  35. +++ b/tests/winfsinfo1/winfsinfo.c
  36. @@ -504,14 +504,30 @@ int get_file_basic_info(const char *progname, const char *filename)
  37.      TESTFBIA(FILE_ATTRIBUTE_OFFLINE);
  38.      TESTFBIA(FILE_ATTRIBUTE_NOT_CONTENT_INDEXED);
  39.      TESTFBIA(FILE_ATTRIBUTE_ENCRYPTED);
  40. +#ifdef FILE_ATTRIBUTE_INTEGRITY_STREAM
  41.      TESTFBIA(FILE_ATTRIBUTE_INTEGRITY_STREAM);
  42. +#endif /* FILE_ATTRIBUTE_INTEGRITY_STREAM */
  43. +#ifdef FILE_ATTRIBUTE_VIRTUAL
  44.      TESTFBIA(FILE_ATTRIBUTE_VIRTUAL);
  45. +#endif /* FILE_ATTRIBUTE_VIRTUAL */
  46. +#ifdef FILE_ATTRIBUTE_NO_SCRUB_DATA
  47.      TESTFBIA(FILE_ATTRIBUTE_NO_SCRUB_DATA);
  48. +#endif /* FILE_ATTRIBUTE_NO_SCRUB_DATA */
  49. +#ifdef FILE_ATTRIBUTE_EA
  50.      TESTFBIA(FILE_ATTRIBUTE_EA);
  51. +#endif /* FILE_ATTRIBUTE_EA */
  52. +#ifdef FILE_ATTRIBUTE_PINNED
  53.      TESTFBIA(FILE_ATTRIBUTE_PINNED);
  54. +#endif /* FILE_ATTRIBUTE_PINNED */
  55. +#ifdef FILE_ATTRIBUTE_UNPINNED
  56.      TESTFBIA(FILE_ATTRIBUTE_UNPINNED);
  57. +#endif /* FILE_ATTRIBUTE_UNPINNED */
  58. +#ifdef FILE_ATTRIBUTE_RECALL_ON_OPEN
  59.      TESTFBIA(FILE_ATTRIBUTE_RECALL_ON_OPEN);
  60. +#endif /* FILE_ATTRIBUTE_RECALL_ON_OPEN */
  61. +#ifdef FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS
  62.      TESTFBIA(FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS);
  63. +#endif /* FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS */
  64.  
  65.      /*
  66.       * print any leftover flags not covered by |TESTFBIA(FILE_*)|
  67. @@ -602,14 +618,30 @@ int get_fileexinfostandard(const char *progname, const char *filename)
  68.      TESTFEIS(FILE_ATTRIBUTE_OFFLINE);
  69.      TESTFEIS(FILE_ATTRIBUTE_NOT_CONTENT_INDEXED);
  70.      TESTFEIS(FILE_ATTRIBUTE_ENCRYPTED);
  71. +#ifdef FILE_ATTRIBUTE_INTEGRITY_STREAM
  72.      TESTFEIS(FILE_ATTRIBUTE_INTEGRITY_STREAM);
  73. +#endif /* FILE_ATTRIBUTE_INTEGRITY_STREAM */
  74. +#ifdef FILE_ATTRIBUTE_VIRTUAL
  75.      TESTFEIS(FILE_ATTRIBUTE_VIRTUAL);
  76. +#endif /* FILE_ATTRIBUTE_VIRTUAL */
  77. +#ifdef FILE_ATTRIBUTE_NO_SCRUB_DATA
  78.      TESTFEIS(FILE_ATTRIBUTE_NO_SCRUB_DATA);
  79. +#endif /* FILE_ATTRIBUTE_NO_SCRUB_DATA */
  80. +#ifdef FILE_ATTRIBUTE_EA
  81.      TESTFEIS(FILE_ATTRIBUTE_EA);
  82. +#endif /* FILE_ATTRIBUTE_EA */
  83. +#ifdef FILE_ATTRIBUTE_PINNED
  84.      TESTFEIS(FILE_ATTRIBUTE_PINNED);
  85. +#endif /* FILE_ATTRIBUTE_PINNED */
  86. +#ifdef FILE_ATTRIBUTE_UNPINNED
  87.      TESTFEIS(FILE_ATTRIBUTE_UNPINNED);
  88. +#endif /* FILE_ATTRIBUTE_UNPINNED */
  89. +#ifdef FILE_ATTRIBUTE_RECALL_ON_OPEN
  90.      TESTFEIS(FILE_ATTRIBUTE_RECALL_ON_OPEN);
  91. +#endif /* FILE_ATTRIBUTE_RECALL_ON_OPEN */
  92. +#ifdef FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS
  93.      TESTFEIS(FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS);
  94. +#endif /* FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS */
  95.  
  96.      /*
  97.       * print any leftover flags not covered by |TESTFNOI(FILE_*)|
  98. @@ -798,7 +830,7 @@ done:
  99.      return res;
  100.  }
  101.  
  102. -
  103. +#ifdef FILE_CS_FLAG_CASE_SENSITIVE_DIR
  104.  static
  105.  int get_filecasesensitiveinfo(const char *progname, const char *filename)
  106.  {
  107. @@ -863,6 +895,7 @@ done:
  108.      (void)CloseHandle(fileHandle);
  109.      return res;
  110.  }
  111. +#endif /* FILE_CS_FLAG_CASE_SENSITIVE_DIR */
  112.  
  113.  static
  114.  int get_getfiletime(const char *progname, const char *filename)
  115. @@ -1461,7 +1494,9 @@ void usage(void)
  116.          "filestandardinfo|"
  117.          "filenameinfo|"
  118.          "filenormalizednameinfo|"
  119. +#ifdef FILE_CS_FLAG_CASE_SENSITIVE_DIR
  120.          "filecasesensitiveinfo|"
  121. +#endif /* FILE_CS_FLAG_CASE_SENSITIVE_DIR */
  122.          "getfiletime|"
  123.          "nfs3attr|"
  124.          "fileremoteprotocolinfo|"
  125. @@ -1529,9 +1564,11 @@ int main(int ac, char *av[])
  126.      else if (!strcmp(subcmd, "getfiletime")) {
  127.          return get_getfiletime(av[0], av[2]);
  128.      }
  129. +#ifdef FILE_CS_FLAG_CASE_SENSITIVE_DIR
  130.      else if (!strcmp(subcmd, "filecasesensitiveinfo")) {
  131.          return get_filecasesensitiveinfo(av[0], av[2]);
  132.      }
  133. +#endif /* FILE_CS_FLAG_CASE_SENSITIVE_DIR */
  134.      else if (!strcmp(subcmd, "nfs3attr")) {
  135.          return get_nfs3attr(av[0], av[2]);
  136.      }
  137. --
  138. 2.51.0
  139.  
  140. From e99970a349215e8baa5eb4b9d038f382a70f1a50 Mon Sep 17 00:00:00 2001
  141. From: Cedric Blancher <cedric.blancher@gmail.com>
  142. Date: Tue, 30 Sep 2025 13:42:38 +0200
  143. Subject: [PATCH 2/4] tests: nfsbuildtest.ksh93: Fix VS2019 PATH on Windows
  144.  10/32bit
  145.  
  146. Fix VS2019 PATH on Windows 10/32bit.
  147.  
  148. Signed-off-by: Roland Mainz <roland.mainz@nrubsig.org>
  149. ---
  150. tests/nfsbuildtest/nfsbuildtest.ksh93 | 9 +++++++--
  151.  1 file changed, 7 insertions(+), 2 deletions(-)
  152.  
  153. diff --git a/tests/nfsbuildtest/nfsbuildtest.ksh93 b/tests/nfsbuildtest/nfsbuildtest.ksh93
  154. index 234f09f..37024cb 100644
  155. --- a/tests/nfsbuildtest/nfsbuildtest.ksh93
  156. +++ b/tests/nfsbuildtest/nfsbuildtest.ksh93
  157. @@ -552,9 +552,14 @@ function msnfs41client_build
  158.                         time make -j1 -f cygwin/Makefile build64
  159.                         time make -j1 -f cygwin/Makefile installdest64
  160.                         time make -j1 -f cygwin/Makefile bintarball64
  161. -               elif [[ -x '/cygdrive/c/Program Files (x86)/Microsoft Visual Studio/2019/Community/MSBuild/Current/Bin/MSBuild.exe' ]] ; then
  162. +               elif [[ -x '/cygdrive/c/Program Files/Microsoft Visual Studio/2019/Community/MSBuild/Current/Bin/MSBuild.exe' || \
  163. +                       -x '/cygdrive/c/Program Files (x86)/Microsoft Visual Studio/2019/Community/MSBuild/Current/Bin/MSBuild.exe' ]] ; then
  164.                         # Visual Studio 19 64bit+32bit kernel codepath
  165. -                       export PATH="/cygdrive/c/Program Files (x86)/Microsoft Visual Studio/2019/Community/MSBuild/Current/Bin/:$PATH"
  166. +                       if [[ -x '/cygdrive/c/Program Files/Microsoft Visual Studio/2019/Community/MSBuild/Current/Bin/MSBuild.exe' ]] ; then
  167. +                               export PATH="/cygdrive/c/Program Files/Microsoft Visual Studio/2019/Community/MSBuild/Current/Bin/:$PATH"
  168. +                       else
  169. +                               export PATH="/cygdrive/c/Program Files (x86)/Microsoft Visual Studio/2019/Community/MSBuild/Current/Bin/:$PATH"
  170. +                       fi
  171.                         set -o errexit
  172.                         time make -j1 -f cygwin/Makefile build
  173.                         time make -j1 -f cygwin/Makefile installdest
  174. --
  175. 2.51.0
  176.  
  177. From d3f5ad7eab174c6dea6a578063f6ed90b5ba5e92 Mon Sep 17 00:00:00 2001
  178. From: Roland Mainz <roland.mainz@nrubsig.org>
  179. Date: Tue, 30 Sep 2025 17:23:38 +0200
  180. Subject: [PATCH 3/4] daemon: Fix "ASSERTION 'length == 0' in
  181.  '...\ms-nfs41-client\daemon\lock.c'/316 failed."
  182.  
  183. Fix "ASSERTION 'length == 0' in '...\ms-nfs41-client\daemon\lock.c'/316 failed.".
  184.  
  185. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  186. ---
  187. daemon/lock.c | 6 +++---
  188.  1 file changed, 3 insertions(+), 3 deletions(-)
  189.  
  190. diff --git a/daemon/lock.c b/daemon/lock.c
  191. index 4066796..d41ef2c 100644
  192. --- a/daemon/lock.c
  193. +++ b/daemon/lock.c
  194. @@ -312,12 +312,12 @@ static int parse_unlock(unsigned char *buffer, uint32_t length, nfs41_upcall *up
  195.  
  196.      status = safe_read(&buffer, &length, &args->count, sizeof(ULONG));
  197.      if (status) goto out;
  198. +    args->buf_len = args->count*2L*sizeof(LONGLONG);
  199. +    status = get_safe_read_bufferpos(&buffer, &length, args->buf_len, &args->buf);
  200. +    if (status) goto out;
  201.  
  202.      EASSERT(length == 0);
  203.  
  204. -    args->buf = buffer;
  205. -    args->buf_len = length;
  206. -
  207.      DPRINTF(1, ("parsing NFS41_SYSOP_UNLOCK: count=%u\n", args->count));
  208.  out:
  209.      return status;
  210. --
  211. 2.51.0
  212.  
  213. From 583cb2a64714fd0c50d70d5ec4f8bc1dc4aff67d Mon Sep 17 00:00:00 2001
  214. From: Roland Mainz <roland.mainz@nrubsig.org>
  215. Date: Tue, 30 Sep 2025 20:23:04 +0200
  216. Subject: [PATCH 4/4] cygwin,tests: Add new Win32 (multi-client) locking API
  217.  stress test "lockincfile1"
  218.  
  219. Add new Win32 (multi-client) locking API stress test "lockincfile1",
  220. which locks a file, reads the last line which contains a
  221. "<tag> <value>" pair, and writes a new line with "<mytag> <value+1>",
  222. and then unlocks the file.
  223. This is intended to be a stress test running on one (contested)
  224. file from multiple clients.
  225.  
  226. This patch also moves tests/filemmaptests/ into tests/misc/.
  227.  
  228. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  229. ---
  230. cygwin/Makefile                   |   2 +
  231.  cygwin/Makefile.install           |   9 +-
  232.  cygwin/devel/msnfs41client.bash   |   3 +-
  233.  tests/lockincfile1/Makefile       |  29 +++++
  234.  tests/lockincfile1/lockincfile1.c | 170 ++++++++++++++++++++++++++++++
  235.  5 files changed, 208 insertions(+), 5 deletions(-)
  236.  create mode 100644 tests/lockincfile1/Makefile
  237.  create mode 100644 tests/lockincfile1/lockincfile1.c
  238.  
  239. diff --git a/cygwin/Makefile b/cygwin/Makefile
  240. index 5156b5b..3e55f1c 100644
  241. --- a/cygwin/Makefile
  242. +++ b/cygwin/Makefile
  243. @@ -26,6 +26,7 @@ $(PROJECT_BASEDIR_DIR)/tests/ea/nfs_ea.exe \
  244.         $(PROJECT_BASEDIR_DIR)/tests/lssparse/lssparse.exe \
  245.         $(PROJECT_BASEDIR_DIR)/tests/winfsinfo1/winfsinfo.exe \
  246.         $(PROJECT_BASEDIR_DIR)/tests/filemmaptests/qsortonmmapedfile1.exe \
  247. +       $(PROJECT_BASEDIR_DIR)/tests/lockincfile1/lockincfile1.exe \
  248.         $(PROJECT_BASEDIR_DIR)/tests/winclonefile/winclonefile.exe \
  249.         $(PROJECT_BASEDIR_DIR)/tests/winoffloadcopyfile/winoffloadcopyfile.exe \
  250.         $(PROJECT_BASEDIR_DIR)/tests/winrunassystem/winrunassystem.exe \
  251. @@ -132,6 +133,7 @@ installdest_util: \
  252.         $(PROJECT_BASEDIR_DIR)/tests/lssparse/lssparse.exe \
  253.         $(PROJECT_BASEDIR_DIR)/tests/winfsinfo1/winfsinfo.exe \
  254.         $(PROJECT_BASEDIR_DIR)/tests/filemmaptests/qsortonmmapedfile1.exe \
  255. +       $(PROJECT_BASEDIR_DIR)/tests/lockincfile1/lockincfile1.exe \
  256.         $(PROJECT_BASEDIR_DIR)/tests/winclonefile/winclonefile.exe \
  257.         $(PROJECT_BASEDIR_DIR)/tests/winoffloadcopyfile/winoffloadcopyfile.exe \
  258.         $(PROJECT_BASEDIR_DIR)/tests/winrunassystem/winrunassystem.exe \
  259. diff --git a/cygwin/Makefile.install b/cygwin/Makefile.install
  260. index 137f6c8..a25aee8 100644
  261. --- a/cygwin/Makefile.install
  262. +++ b/cygwin/Makefile.install
  263. @@ -39,7 +39,6 @@ installdest:
  264.         mkdir -p $(DESTDIR)/usr/share/msnfs41client/tests
  265.         mkdir -p $(DESTDIR)/usr/share/msnfs41client/tests/misc
  266.         mkdir -p $(DESTDIR)/usr/share/msnfs41client/tests/sparsefiles
  267. -       mkdir -p $(DESTDIR)/usr/share/msnfs41client/tests/filemmaptests
  268.         #
  269.         # copy x86 binaries
  270.         #
  271. @@ -152,9 +151,11 @@ installdest:
  272.         cp "$(PROJECT_BASEDIR_DIR)/tests/winsg/winsg.i686.exe" $(DESTDIR)/bin/winsg.i686.exe
  273.         cp "$(PROJECT_BASEDIR_DIR)/tests/ea/nfs_ea.x86_64.exe" $(DESTDIR)/bin/nfs_ea.x86_64.exe
  274.         cp "$(PROJECT_BASEDIR_DIR)/tests/ea/nfs_ea.i686.exe" $(DESTDIR)/bin/nfs_ea.i686.exe
  275. -       cp "$(PROJECT_BASEDIR_DIR)/tests/filemmaptests/qsortonmmapedfile1.x86_64.exe" $(DESTDIR)/usr/share/msnfs41client/tests/filemmaptests/qsortonmmapedfile1.x86_64.exe
  276. -       cp "$(PROJECT_BASEDIR_DIR)/tests/filemmaptests/qsortonmmapedfile1.i686.exe" $(DESTDIR)/usr/share/msnfs41client/tests/filemmaptests/qsortonmmapedfile1.i686.exe
  277. -       cp $(PROJECT_BASEDIR_DIR)/tests/filemmaptests/testqsortonmmapedfile1.ksh93 $(DESTDIR)/usr/share/msnfs41client/tests/filemmaptests/testqsortonmmapedfile1.ksh93
  278. +       cp "$(PROJECT_BASEDIR_DIR)/tests/filemmaptests/qsortonmmapedfile1.x86_64.exe" $(DESTDIR)/usr/share/msnfs41client/tests/misc/qsortonmmapedfile1.x86_64.exe
  279. +       cp "$(PROJECT_BASEDIR_DIR)/tests/filemmaptests/qsortonmmapedfile1.i686.exe" $(DESTDIR)/usr/share/msnfs41client/tests/misc/qsortonmmapedfile1.i686.exe
  280. +       cp $(PROJECT_BASEDIR_DIR)/tests/filemmaptests/testqsortonmmapedfile1.ksh93 $(DESTDIR)/usr/share/msnfs41client/tests/misc/testqsortonmmapedfile1.ksh93
  281. +       cp "$(PROJECT_BASEDIR_DIR)/tests/lockincfile1/lockincfile1.x86_64.exe" $(DESTDIR)/usr/share/msnfs41client/tests/misc/lockincfile1.x86_64.exe
  282. +       cp "$(PROJECT_BASEDIR_DIR)/tests/lockincfile1/lockincfile1.i686.exe" $(DESTDIR)/usr/share/msnfs41client/tests/misc/lockincfile1.i686.exe
  283.         cp $(PROJECT_BASEDIR_DIR)/tests/nfsbuildtest/nfsbuildtest.ksh93 $(DESTDIR)/usr/share/msnfs41client/tests/misc/nfsbuildtest.ksh93
  284.         cp $(PROJECT_BASEDIR_DIR)/tests/sparsefiles/testsparsefile1.ksh $(DESTDIR)/usr/share/msnfs41client/tests/sparsefiles/testsparsefile1.ksh
  285.         cp $(PROJECT_BASEDIR_DIR)/tests/sparsefiles/testsparseexe1.ksh $(DESTDIR)/usr/share/msnfs41client/tests/sparsefiles/testsparseexe1.ksh
  286. diff --git a/cygwin/devel/msnfs41client.bash b/cygwin/devel/msnfs41client.bash
  287. index 2fbf2cd..4e44571 100755
  288. --- a/cygwin/devel/msnfs41client.bash
  289. +++ b/cygwin/devel/msnfs41client.bash
  290. @@ -251,7 +251,8 @@ function nfsclient_install
  291.                 'bin/nfs_ea'
  292.                 'sbin/winrunassystem'
  293.                 'sbin/nfs_globalmount'
  294. -               'usr/share/msnfs41client/tests/filemmaptests/qsortonmmapedfile1'
  295. +               'usr/share/msnfs41client/tests/misc/qsortonmmapedfile1'
  296. +               'usr/share/msnfs41client/tests/misc/lockincfile1'
  297.         )
  298.  
  299.         if [[ "${kernel_platform}" != 'i686' ]] ; then
  300. diff --git a/tests/lockincfile1/Makefile b/tests/lockincfile1/Makefile
  301. new file mode 100644
  302. index 0000000..ab539dc
  303. --- /dev/null
  304. +++ b/tests/lockincfile1/Makefile
  305. @@ -0,0 +1,29 @@
  306. +#
  307. +# Makefile for lockincfile1
  308. +#
  309. +
  310. +# POSIX Makefile
  311. +SIGNTOOL="/cygdrive/c/Program Files (x86)/Microsoft SDKs/ClickOnce/SignTool/signtool.exe"
  312. +
  313. +all: \
  314. +       lockincfile1.i686.exe \
  315. +       lockincfile1.x86_64.exe \
  316. +       lockincfile1.exe
  317. +
  318. +lockincfile1.i686.exe: lockincfile1.c
  319. +       clang -target i686-pc-windows-gnu -std=gnu17 -Wall -Wextra -DUNICODE=1 -D_UNICODE=1 -g -O lockincfile1.c -o $@
  320. +       bash -x -c '$(SIGNTOOL) sign /ph /fd "sha256" /sha1 "$${CERTIFICATE_THUMBPRINT%$$(printf "\r")}" $@'
  321. +
  322. +lockincfile1.x86_64.exe: lockincfile1.c
  323. +       clang -target x86_64-pc-windows-gnu -std=gnu17 -Wall -Wextra -DUNICODE=1 -D_UNICODE=1 -g -O lockincfile1.c -o $@
  324. +       bash -x -c '$(SIGNTOOL) sign /ph /fd "sha256" /sha1 "$${CERTIFICATE_THUMBPRINT%$$(printf "\r")}" $@'
  325. +
  326. +lockincfile1.exe: lockincfile1.x86_64.exe
  327. +       ln -s lockincfile1.x86_64.exe lockincfile1.exe
  328. +
  329. +clean:
  330. +       rm -fv \
  331. +               lockincfile1.i686.exe \
  332. +               lockincfile1.x86_64.exe \
  333. +               lockincfile1.exe
  334. +# EOF.
  335. diff --git a/tests/lockincfile1/lockincfile1.c b/tests/lockincfile1/lockincfile1.c
  336. new file mode 100644
  337. index 0000000..cde5822
  338. --- /dev/null
  339. +++ b/tests/lockincfile1/lockincfile1.c
  340. @@ -0,0 +1,170 @@
  341. +/*
  342. + * MIT License
  343. + *
  344. + * Copyright (c) 2025 Roland Mainz <roland.mainz@nrubsig.org>
  345. + *
  346. + * Permission is hereby granted, free of charge, to any person obtaining a copy
  347. + * of this software and associated documentation files (the "Software"), to deal
  348. + * in the Software without restriction, including without limitation the rights
  349. + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  350. + * copies of the Software, and to permit persons to whom the Software is
  351. + * furnished to do so, subject to the following conditions:
  352. + *
  353. + * The above copyright notice and this permission notice shall be included in
  354. + * all copies or substantial portions of the Software.
  355. + *
  356. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  357. + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  358. + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  359. + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  360. + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  361. + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  362. + * SOFTWARE.
  363. + */
  364. +
  365. +/*
  366. + * lockincfile1.c - lock file, read last line with "<tag> <value>", and write a new line "<mytag> <value+1>", unlock file
  367. + *
  368. + * Usage:
  369. + * $ clang -Wall -Wextra -O -g lockincfile1.c -o lockincfile1.exe
  370. + * $ rm -f contestedfile1.txt ; touch contestedfile1.txt
  371. + *
  372. + * Test run
  373. + * # on machine 1:
  374. + * $ time bash -c 'set -o errexit ; (for ((i=0 ; i < 400 ; i++)) ; do ./lockincfile1 contestedfile1.txt "aaa"; done) ; echo $?'
  375. + * # on machine 2:
  376. + * $ time bash -c 'set -o errexit ; (for ((i=0 ; i < 400 ; i++)) ; do ./lockincfile1 contestedfile1.txt "bbb"; done) ; echo $?'
  377. + * When both machines are finished the last line should match eregex ".+800"
  378. + */
  379. +#include <windows.h>
  380. +#include <stdio.h>
  381. +#include <stdlib.h>
  382. +#include <stdint.h>
  383. +#include <string.h>
  384. +#include <ctype.h>
  385. +
  386. +#define EXIT_USAGE (2) /* Traditional UNIX exit code for usage */
  387. +
  388. +int main(int argc, char *av[])
  389. +{
  390. +    if (argc != 3) {
  391. +        (void)fprintf(stderr, "Usage:\n%s <filename> <tag>\n", av[0]);
  392. +        return EXIT_USAGE;
  393. +    }
  394. +
  395. +    int retval = EXIT_FAILURE;
  396. +    const char *fileName = av[1];
  397. +    const char *tag = av[2];
  398. +    long last_val = 0;
  399. +    HANDLE h;
  400. +    LARGE_INTEGER liFileSize;
  401. +    char buffer[256];
  402. +    char writeBuffer[256];
  403. +    DWORD bytesRead, bytesWritten;
  404. +
  405. +    h = CreateFileA(fileName,
  406. +        GENERIC_READ | GENERIC_WRITE,
  407. +        FILE_SHARE_READ | FILE_SHARE_WRITE,
  408. +        NULL,
  409. +        OPEN_EXISTING,
  410. +        /*FILE_ATTRIBUTE_NORMAL*/FILE_FLAG_NO_BUFFERING,
  411. +        NULL);
  412. +    if (h == INVALID_HANDLE_VALUE) {
  413. +        (void)fprintf(stderr, "%s: Cannot open file '%s', lasterr=%ld\n",
  414. +            av[0],
  415. +            av[1],
  416. +            (long)GetLastError());
  417. +        (void)CloseHandle(h);
  418. +        return EXIT_FAILURE;
  419. +    }
  420. +
  421. +    OVERLAPPED ov = {
  422. +        .hEvent = 0,
  423. +        .Offset = 0,
  424. +        .OffsetHigh = 0
  425. +    };
  426. +    if (!LockFileEx(h, LOCKFILE_EXCLUSIVE_LOCK, 0, MAXDWORD, MAXDWORD, &ov)) {
  427. +        (void)fprintf(stderr,
  428. +            "%s: Locking failed, lasterr=%ld\n",
  429. +            av[0], (long)GetLastError());
  430. +        (void)CloseHandle(h);
  431. +        return EXIT_FAILURE;
  432. +    }
  433. +
  434. +    (void)GetFileSizeEx(h, &liFileSize);
  435. +
  436. +    if (liFileSize.QuadPart > 0LL) {
  437. +        LARGE_INTEGER liSeekPos;
  438. +        if (liFileSize.QuadPart > (long long)(sizeof(buffer)-1))
  439. +            liSeekPos.QuadPart = (liFileSize.QuadPart - (sizeof(buffer)-1));
  440. +        else
  441. +            liSeekPos.QuadPart = 0LL;
  442. +
  443. +        (void)SetFilePointerEx(h, liSeekPos, NULL, FILE_BEGIN);
  444. +
  445. +        if (!ReadFile(h, buffer, sizeof(buffer)-1, &bytesRead, NULL) || (bytesRead == 0)) {
  446. +            (void)fprintf(stderr,
  447. +                "%s: ReadFile() failed, lasterr=%ld\n",
  448. +                av[0], (long)GetLastError());
  449. +            goto cleanup;
  450. +        }
  451. +        buffer[bytesRead] = '\0';
  452. +
  453. +        char *line_start = buffer;
  454. +        char *p = buffer + bytesRead - 1;
  455. +
  456. +        while ((p >= buffer) &&
  457. +            isspace((unsigned char)*p)) {
  458. +            p--;
  459. +        }
  460. +
  461. +        if (p >= buffer) {
  462. +            line_start = p;
  463. +            while (line_start > buffer && *(line_start - 1) != '\n') {
  464. +                line_start--;
  465. +            }
  466. +
  467. +            char *separator = NULL;
  468. +            char *temp_p = p;
  469. +            while (temp_p >= line_start) {
  470. +                if (*temp_p == ' ' || *temp_p == '\t') {
  471. +                    separator = temp_p;
  472. +                    break;
  473. +                }
  474. +                temp_p--;
  475. +            }
  476. +
  477. +            if (separator && isdigit((unsigned char)*(separator + 1))) {
  478. +                last_val = strtol(separator + 1, NULL, 10);
  479. +            }
  480. +        }
  481. +    }
  482. +
  483. +    LARGE_INTEGER liEndPos = { .QuadPart = 0LL };
  484. +    (void)SetFilePointerEx(h, liEndPos, NULL, FILE_END);
  485. +
  486. +    if (liFileSize.QuadPart > 0LL) {
  487. +        char lastChar;
  488. +        LARGE_INTEGER liLastCharPos;
  489. +        liLastCharPos.QuadPart = -1LL;
  490. +        (void)SetFilePointerEx(h, liLastCharPos, NULL, FILE_END);
  491. +        if (ReadFile(h, &lastChar, 1, &bytesRead, NULL) && (bytesRead == 1)) {
  492. +            if (lastChar != '\n') {
  493. +                 (void)WriteFile(h, "\n", 1, &bytesWritten, NULL);
  494. +            }
  495. +        }
  496. +    }
  497. +
  498. +    int len = snprintf(writeBuffer, sizeof(writeBuffer),
  499. +        "%s\t%ld\n", tag, (last_val + 1));
  500. +    (void)WriteFile(h, writeBuffer, len, &bytesWritten, NULL);
  501. +
  502. +    (void)FlushFileBuffers(h);
  503. +    retval = EXIT_SUCCESS;
  504. +
  505. +cleanup:
  506. +    (void)UnlockFileEx(h, 0, MAXDWORD, MAXDWORD, &ov);
  507. +    (void)CloseHandle(h);
  508. +
  509. +    return retval;
  510. +}
  511. --
  512. 2.51.0

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