pastebin - collaborative debugging tool
rovema.kpaste.net RSS


msnfs41client: Patches for tests+misc, 2025-08-0
Posted by Anonymous on Tue 5th Aug 2025 18:22
raw | new post

  1. From bb3b2ae39883d429524e6e5d3d295bbf13f035b4 Mon Sep 17 00:00:00 2001
  2. From: Roland Mainz <roland.mainz@nrubsig.org>
  3. Date: Tue, 5 Aug 2025 11:00:44 +0200
  4. Subject: [PATCH 1/4] tests: nfsbuildtest gcc build requires /usr/bin/patch
  5.  
  6. Package "patch" needs to be added to the list of required packages
  7. for nfsbuildtest.ksh gcc build, because it uses /usr/bin/patch.
  8.  
  9. Reported-by: Aurelien Couderc <aurelien.couderc2002@gmail.com>
  10. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  11. ---
  12. tests/nfsbuildtest/nfsbuildtest.ksh93 | 2 ++
  13.  1 file changed, 2 insertions(+)
  14.  
  15. diff --git a/tests/nfsbuildtest/nfsbuildtest.ksh93 b/tests/nfsbuildtest/nfsbuildtest.ksh93
  16. index 13aa759..b543938 100644
  17. --- a/tests/nfsbuildtest/nfsbuildtest.ksh93
  18. +++ b/tests/nfsbuildtest/nfsbuildtest.ksh93
  19. @@ -667,6 +667,7 @@ function main
  20.                         is_toolkit_pkg_installed itp 'gcc-core' || (( errc++ ))
  21.                         is_toolkit_pkg_installed itp 'gcc-g++' || (( errc++ ))
  22.                         is_toolkit_pkg_installed itp 'make' || (( errc++ ))
  23. +                       is_toolkit_pkg_installed itp 'patch' || (( errc++ ))
  24.                         is_toolkit_pkg_installed itp 'flex' || (( errc++ ))
  25.                         is_toolkit_pkg_installed itp 'bison' || (( errc++ ))
  26.                         is_toolkit_pkg_installed itp 'libgmp-devel' || (( errc++ ))
  27. @@ -711,6 +712,7 @@ function main
  28.                         else
  29.                                 print '# bash_build: unsupported toolkit'
  30.                         fi
  31. +                       is_toolkit_pkg_installed itp 'patch' || (( errc++ ))
  32.                         is_toolkit_pkg_installed itp 'libncurses-devel' || (( errc++ ))
  33.                         is_toolkit_pkg_installed itp 'gettext' || (( errc++ ))
  34.                         is_toolkit_pkg_installed itp 'gettext-devel' || (( errc++ ))
  35. --
  36. 2.45.1
  37.  
  38. From e9d165871e68de1fcda2e261fcb47caaa1edb351 Mon Sep 17 00:00:00 2001
  39. From: Roland Mainz <roland.mainz@nrubsig.org>
  40. Date: Tue, 5 Aug 2025 11:22:30 +0200
  41. Subject: [PATCH 2/4] tests: Add Win11/VS2022 support to nfsbuildtest
  42.  msnfs41client build
  43.  
  44. Add Windows 11/Visual Studio 2022 support to
  45. $ nfsbuildtest.ksh  msnfs41client build #
  46.  
  47. Reported-by: Aurelien Couderc <aurelien.couderc2002@gmail.com>
  48. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  49. ---
  50. tests/nfsbuildtest/nfsbuildtest.ksh93 | 36 +++++++++++++++++++++------
  51.  1 file changed, 29 insertions(+), 7 deletions(-)
  52.  
  53. diff --git a/tests/nfsbuildtest/nfsbuildtest.ksh93 b/tests/nfsbuildtest/nfsbuildtest.ksh93
  54. index b543938..59cbeb2 100644
  55. --- a/tests/nfsbuildtest/nfsbuildtest.ksh93
  56. +++ b/tests/nfsbuildtest/nfsbuildtest.ksh93
  57. @@ -529,13 +529,35 @@ function msnfs41client_build
  58.         # build ms-nfs41-client
  59.         #
  60.         (
  61. -               # Visual Studio 19 64bit+32bit kernel codepath
  62. -               # fixme: Add support for VS2022 64bit-only codepath
  63. -               export PATH+=":/cygdrive/c/Program Files (x86)/Microsoft Visual Studio/2019/Community/MSBuild/Current/Bin/"
  64. -               set -o errexit
  65. -               time make -j1 -f cygwin/Makefile build
  66. -               time make -j1 -f cygwin/Makefile installdest
  67. -               time make -j1 -f cygwin/Makefile bintarball
  68. +               #
  69. +               # We assume here:
  70. +               # Visual Studio 2019 --> Win10 64bit+32bit build,
  71. +               # Visual Studio 2022 --> Win11/64bit-only build
  72. +               #
  73. +               if [[ -x '/cygdrive/c/Program Files/Microsoft Visual Studio/2022/Community/MSBuild/Current/Bin/MSBuild.exe' ]] ; then
  74. +                       # Visual Studio 19 64bit+32bit kernel codepath
  75. +                       export PATH="/cygdrive/c/Program Files/Microsoft Visual Studio/2022/Community/MSBuild/Current/Bin/:$PATH"
  76. +                       set -o errexit
  77. +
  78. +                       # "retarget" VS platform toolset to "v143"
  79. +                       # ("v142" should remain the default when comitting)
  80. +                       sed -i -E 's/<PlatformToolset>v142<\/PlatformToolset>/<PlatformToolset>v143<\/PlatformToolset>/g' $(find 'build.vc19' -name \*.vcxproj)
  81. +
  82. +                       # build
  83. +                       time make -j1 -f cygwin/Makefile build64
  84. +                       time make -j1 -f cygwin/Makefile installdest64
  85. +                       time make -j1 -f cygwin/Makefile bintarball64
  86. +               elif [[ -x '/cygdrive/c/Program Files (x86)/Microsoft Visual Studio/2019/Community/MSBuild/Current/Bin/MSBuild.exe' ]] ; then
  87. +                       # Visual Studio 19 64bit+32bit kernel codepath
  88. +                       export PATH="/cygdrive/c/Program Files (x86)/Microsoft Visual Studio/2019/Community/MSBuild/Current/Bin/:$PATH"
  89. +                       set -o errexit
  90. +                       time make -j1 -f cygwin/Makefile build
  91. +                       time make -j1 -f cygwin/Makefile installdest
  92. +                       time make -j1 -f cygwin/Makefile bintarball
  93. +               else
  94. +                       print -u2 -f "%s: Unknown compiler.\n" "$0"
  95. +                       exit 5
  96. +               fi
  97.         )
  98.         echo $?
  99.  
  100. --
  101. 2.45.1
  102.  
  103. From 169699249f887bad22ee1c52198c4b9913cbf1cf Mon Sep 17 00:00:00 2001
  104. From: Roland Mainz <roland.mainz@nrubsig.org>
  105. Date: Tue, 5 Aug 2025 12:22:26 +0200
  106. Subject: [PATCH 3/4] tests: nfsbuildtest bash build should use a git release
  107.  tag and not "master"
  108.  
  109. nfsbuildtest.ksh  bash build should use a git release tag and not the
  110. "master" branch. Otherwise build results can vary between commits made
  111. on "master."
  112.  
  113. Reported-by: Aurelien Couderc <aurelien.couderc2002@gmail.com>
  114. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  115. ---
  116. tests/nfsbuildtest/nfsbuildtest.ksh93 | 3 ++-
  117.  1 file changed, 2 insertions(+), 1 deletion(-)
  118.  
  119. diff --git a/tests/nfsbuildtest/nfsbuildtest.ksh93 b/tests/nfsbuildtest/nfsbuildtest.ksh93
  120. index 59cbeb2..14ee651 100644
  121. --- a/tests/nfsbuildtest/nfsbuildtest.ksh93
  122. +++ b/tests/nfsbuildtest/nfsbuildtest.ksh93
  123. @@ -292,7 +292,8 @@ function bash_build
  124.         compound gitdata=(
  125.                 typeset url='https://github.com/bminor/bash.git'
  126.                 # use fixed git tag, so build times are compareable
  127. -               typeset tag='master'
  128. +               # (make sure to test this with Windows 10/32bit+Cygwin 3.4!!)
  129. +               typeset tag='bash-5.0'
  130.         )
  131.  
  132.         typeset -a configure_options=(
  133. --
  134. 2.45.1
  135.  
  136. From 1f6a7bdd429a0103e6fd8a37e4d1d4771fff184a Mon Sep 17 00:00:00 2001
  137. From: Roland Mainz <roland.mainz@nrubsig.org>
  138. Date: Tue, 5 Aug 2025 18:08:21 +0200
  139. Subject: [PATCH 4/4] cygwin,tests: Add test for r/w memory-mapped files
  140.  
  141. Add test for r/w memory-mapped files.
  142.  
  143. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  144. ---
  145. cygwin/Makefile                               |   4 +
  146.  cygwin/Makefile.install                       |   9 +
  147.  tests/filemmaptests/Makefile                  |  26 +++
  148.  tests/filemmaptests/qsortonmmapedfile1.c      | 183 ++++++++++++++++++
  149.  .../testqsortonmmapedfile1.ksh93              |  44 +++++
  150.  5 files changed, 266 insertions(+)
  151.  create mode 100644 tests/filemmaptests/Makefile
  152.  create mode 100644 tests/filemmaptests/qsortonmmapedfile1.c
  153.  create mode 100755 tests/filemmaptests/testqsortonmmapedfile1.ksh93
  154.  
  155. diff --git a/cygwin/Makefile b/cygwin/Makefile
  156. index f570023..4cff33b 100644
  157. --- a/cygwin/Makefile
  158. +++ b/cygwin/Makefile
  159. @@ -22,6 +22,7 @@ VS_BUILD_DIR64:=$(PROJECT_BASEDIR_DIR)/build.vc19/x64/Debug/
  160.  $(PROJECT_BASEDIR_DIR)/tests/ea/nfs_ea.exe \
  161.         $(PROJECT_BASEDIR_DIR)/tests/lssparse/lssparse.exe \
  162.         $(PROJECT_BASEDIR_DIR)/tests/winfsinfo1/winfsinfo.exe \
  163. +       $(PROJECT_BASEDIR_DIR)/tests/filemmaptests/qsortonmmapedfile1.exe \
  164.         $(PROJECT_BASEDIR_DIR)/tests/winclonefile/winclonefile.exe \
  165.         $(PROJECT_BASEDIR_DIR)/tests/winsg/winsg.exe: build_testutils
  166.  
  167. @@ -67,6 +68,7 @@ build_testutils:
  168.         (cd "$(PROJECT_BASEDIR_DIR)/tests/ea" && make all)
  169.         (cd "$(PROJECT_BASEDIR_DIR)/tests/lssparse" && make all)
  170.         (cd "$(PROJECT_BASEDIR_DIR)/tests/winfsinfo1" && make all)
  171. +       (cd "$(PROJECT_BASEDIR_DIR)/tests/filemmaptests" && make all)
  172.         (cd "$(PROJECT_BASEDIR_DIR)/tests/winclonefile" && make all)
  173.         (cd "$(PROJECT_BASEDIR_DIR)/tests/winsg" && make all)
  174.  
  175. @@ -102,6 +104,7 @@ clean:
  176.         (cd "$(PROJECT_BASEDIR_DIR)/tests/ea" && make clean)
  177.         (cd "$(PROJECT_BASEDIR_DIR)/tests/lssparse" && make clean)
  178.         (cd "$(PROJECT_BASEDIR_DIR)/tests/winfsinfo1" && make clean)
  179. +       (cd "$(PROJECT_BASEDIR_DIR)/tests/filemmaptests" && make clean)
  180.         (cd "$(PROJECT_BASEDIR_DIR)/tests/winclonefile" && make clean)
  181.         (cd "$(PROJECT_BASEDIR_DIR)/tests/winsg" && make clean)
  182.  
  183. @@ -112,6 +115,7 @@ installdest_util: \
  184.         $(PROJECT_BASEDIR_DIR)/tests/ea/nfs_ea.exe \
  185.         $(PROJECT_BASEDIR_DIR)/tests/lssparse/lssparse.exe \
  186.         $(PROJECT_BASEDIR_DIR)/tests/winfsinfo1/winfsinfo.exe \
  187. +       $(PROJECT_BASEDIR_DIR)/tests/filemmaptests/qsortonmmapedfile1.exe \
  188.         $(PROJECT_BASEDIR_DIR)/tests/winclonefile/winclonefile.exe \
  189.         $(PROJECT_BASEDIR_DIR)/tests/winsg/winsg.exe \
  190.         $(CYGWIN_MAKEFILE_DIR)/devel/msnfs41client.bash
  191. diff --git a/cygwin/Makefile.install b/cygwin/Makefile.install
  192. index ba7d0ed..c361190 100644
  193. --- a/cygwin/Makefile.install
  194. +++ b/cygwin/Makefile.install
  195. @@ -43,6 +43,7 @@ installdest:
  196.         mkdir -p $(DESTDIR)/$(CYGWIN_BASEPATH)/usr/share/msnfs41client/tests
  197.         mkdir -p $(DESTDIR)/$(CYGWIN_BASEPATH)/usr/share/msnfs41client/tests/misc
  198.         mkdir -p $(DESTDIR)/$(CYGWIN_BASEPATH)/usr/share/msnfs41client/tests/sparsefiles
  199. +       mkdir -p $(DESTDIR)/$(CYGWIN_BASEPATH)/usr/share/msnfs41client/tests/filemmaptests
  200.         cp $(VS_BUILD_DIR)/nfsd.exe             $(DESTDIR)/$(CYGWIN_BASEPATH)/sbin/nfsd_debug.exe
  201.         cp $(VS_BUILD_DIR)/nfsd.pdb             $(DESTDIR)/$(CYGWIN_BASEPATH)/sbin/nfsd_debug.pdb
  202.         cp $(VS_BUILD_DIR)/nfs_mount.*  $(DESTDIR)/$(CYGWIN_BASEPATH)/sbin/.
  203. @@ -136,6 +137,14 @@ installdest:
  204.         else \
  205.                 (cd $(DESTDIR)/$(CYGWIN_BASEPATH)/bin/ && $(LINKEXE) nfs_ea.i686.exe nfs_ea.exe) \
  206.         fi
  207. +       cp "$(PROJECT_BASEDIR_DIR)/tests/filemmaptests/qsortonmmapedfile1.x86_64.exe" $(DESTDIR)/$(CYGWIN_BASEPATH)/usr/share/msnfs41client/tests/filemmaptests/qsortonmmapedfile1.x86_64.exe
  208. +       cp "$(PROJECT_BASEDIR_DIR)/tests/filemmaptests/qsortonmmapedfile1.i686.exe" $(DESTDIR)/$(CYGWIN_BASEPATH)/usr/share/msnfs41client/tests/filemmaptests/qsortonmmapedfile1.i686.exe
  209. +       if [[ "$(CYGWIN_BASEPATH)" == *64* ]] ; then \
  210. +               (cd $(DESTDIR)/$(CYGWIN_BASEPATH)/usr/share/msnfs41client/tests/filemmaptests/ && $(LINKEXE) qsortonmmapedfile1.x86_64.exe qsortonmmapedfile1.exe) \
  211. +       else \
  212. +               (cd $(DESTDIR)/$(CYGWIN_BASEPATH)/usr/share/msnfs41client/tests/filemmaptests/ && $(LINKEXE) qsortonmmapedfile1.i686.exe qsortonmmapedfile1.exe) \
  213. +       fi
  214. +       cp $(PROJECT_BASEDIR_DIR)/tests/filemmaptests/testqsortonmmapedfile1.ksh93 $(DESTDIR)/$(CYGWIN_BASEPATH)/usr/share/msnfs41client/tests/filemmaptests/testqsortonmmapedfile1.ksh93
  215.         cp $(PROJECT_BASEDIR_DIR)/tests/nfsbuildtest/nfsbuildtest.ksh93 $(DESTDIR)/$(CYGWIN_BASEPATH)/usr/share/msnfs41client/tests/misc/nfsbuildtest.ksh93
  216.         cp $(PROJECT_BASEDIR_DIR)/tests/sparsefiles/testsparsefile1.ksh $(DESTDIR)/$(CYGWIN_BASEPATH)/usr/share/msnfs41client/tests/sparsefiles/testsparsefile1.ksh
  217.         cp $(PROJECT_BASEDIR_DIR)/tests/sparsefiles/testsparseexe1.ksh $(DESTDIR)/$(CYGWIN_BASEPATH)/usr/share/msnfs41client/tests/sparsefiles/testsparseexe1.ksh
  218. diff --git a/tests/filemmaptests/Makefile b/tests/filemmaptests/Makefile
  219. new file mode 100644
  220. index 0000000..651f1bd
  221. --- /dev/null
  222. +++ b/tests/filemmaptests/Makefile
  223. @@ -0,0 +1,26 @@
  224. +#
  225. +# Makefile for qsortonmmapedfile1
  226. +#
  227. +
  228. +# POSIX Makefile
  229. +
  230. +all: \
  231. +       qsortonmmapedfile1.i686.exe \
  232. +       qsortonmmapedfile1.x86_64.exe \
  233. +       qsortonmmapedfile1.exe
  234. +
  235. +qsortonmmapedfile1.i686.exe: qsortonmmapedfile1.c
  236. +       clang -target i686-pc-windows-gnu -Wall -Wextra -DUNICODE=1 -D_UNICODE=1 -g -O qsortonmmapedfile1.c -o qsortonmmapedfile1.i686.exe
  237. +
  238. +qsortonmmapedfile1.x86_64.exe: qsortonmmapedfile1.c
  239. +       clang -target x86_64-pc-windows-gnu -Wall -Wextra -DUNICODE=1 -D_UNICODE=1 -g -O qsortonmmapedfile1.c -o qsortonmmapedfile1.x86_64.exe
  240. +
  241. +qsortonmmapedfile1.exe: qsortonmmapedfile1.x86_64.exe
  242. +       ln -s qsortonmmapedfile1.x86_64.exe qsortonmmapedfile1.exe
  243. +
  244. +clean:
  245. +       rm -fv \
  246. +               qsortonmmapedfile1.i686.exe \
  247. +               qsortonmmapedfile1.x86_64.exe \
  248. +               qsortonmmapedfile1.exe
  249. +# EOF.
  250. diff --git a/tests/filemmaptests/qsortonmmapedfile1.c b/tests/filemmaptests/qsortonmmapedfile1.c
  251. new file mode 100644
  252. index 0000000..976c325
  253. --- /dev/null
  254. +++ b/tests/filemmaptests/qsortonmmapedfile1.c
  255. @@ -0,0 +1,183 @@
  256. +
  257. +/*
  258. + * MIT License
  259. + *
  260. + * Copyright (c) 2025 Roland Mainz <roland.mainz@nrubsig.org>
  261. + *
  262. + * Permission is hereby granted, free of charge, to any person obtaining a copy
  263. + * of this software and associated documentation files (the "Software"), to deal
  264. + * in the Software without restriction, including without limitation the rights
  265. + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  266. + * copies of the Software, and to permit persons to whom the Software is
  267. + * furnished to do so, subject to the following conditions:
  268. + *
  269. + * The above copyright notice and this permission notice shall be included in
  270. + * all copies or substantial portions of the Software.
  271. + *
  272. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  273. + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  274. + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  275. + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  276. + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  277. + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  278. + * SOFTWARE.
  279. + */
  280. +
  281. +/*
  282. + * qsortonmmapedfile1.c - test |qsort()| on memory mapped file
  283. + *
  284. + * Written by Roland Mainz <roland.mainz@nrubsig.org>
  285. + */
  286. +
  287. +/*
  288. + * Example usage:
  289. + *
  290. + * builtin cat
  291. + * builtin rm
  292. + * if [[ -f numfile1_orig ]] ; then
  293. + *     for ((i=1*1024*1024 ; i > 0 ; i--)) ; do
  294. + *         printf "%15.15d\n" i
  295. + *     # cat is used for buffering
  296. + *     done | cat >"numfile1_orig"
  297. + * fi
  298. + * set -o xtrace
  299. + *
  300. + * rm -f numfile1
  301. + * cp numfile1_orig numfile1
  302. + * time sort numfile1 -o numfile1_sort_out
  303. + * ls -l numfile1
  304. + * head numfile1
  305. + * time ./qsortonmmapedfile1.exe numfile1
  306. + * head numfile1
  307. + * ls -l numfile1
  308. + * diff -u numfile1 numfile1_sort_out
  309. + */
  310. +
  311. +#define _CRT_SECURE_NO_WARNINGS 1
  312. +
  313. +#include <windows.h>
  314. +#include <locale.h>
  315. +#include <stdio.h>
  316. +#include <stdlib.h>
  317. +#include <string.h>
  318. +
  319. +#define EXIT_USAGE 2
  320. +
  321. +#define RECORD_DATA_SIZE 15
  322. +#define RECORD_SIZE (RECORD_DATA_SIZE+1)
  323. +
  324. +static
  325. +int compare_records_strcmp(const void *a, const void *b)
  326. +{
  327. +    return strncmp(a, b, RECORD_DATA_SIZE);
  328. +}
  329. +
  330. +int main(int argc, char *argv[])
  331. +{
  332. +    int res;
  333. +
  334. +    (void)setlocale(LC_ALL, "C");
  335. +
  336. +    if (argc != 2) {
  337. +        (void)fprintf(stderr, "Usage: %s <filename>\n", argv[0]);
  338. +        (void)fprintf(stderr,
  339. +            "Note: File must contain 10 ASCII characters per line.\n");
  340. +        return EXIT_USAGE;
  341. +    }
  342. +
  343. +    const char *filename = argv[1];
  344. +    HANDLE hFile = NULL;
  345. +    HANDLE hMapping = NULL;
  346. +    char *fileView = NULL;
  347. +
  348. +    hFile = CreateFileA(filename,
  349. +        GENERIC_READ | GENERIC_WRITE,
  350. +        0,
  351. +        NULL,
  352. +        OPEN_EXISTING,
  353. +        FILE_ATTRIBUTE_NORMAL,
  354. +        NULL
  355. +    );
  356. +
  357. +    if (hFile == INVALID_HANDLE_VALUE) {
  358. +        (void)fprintf(stderr,
  359. +            "Error: Could not open file '%s' for writing (lasterr=%ld)\n",
  360. +            filename, (long)GetLastError());
  361. +        res = EXIT_FAILURE;
  362. +        goto cleanup;
  363. +    }
  364. +
  365. +    hMapping = CreateFileMappingA(hFile, NULL, PAGE_READWRITE, 0, 0, NULL);
  366. +    if (hMapping == NULL) {
  367. +        (void)fprintf(stderr,
  368. +            "Error: CreateFileMapping failed (lasterr=%ld)\n",
  369. +            (long)GetLastError());
  370. +        res = EXIT_FAILURE;
  371. +        goto cleanup;
  372. +    }
  373. +
  374. +    fileView = (char *)MapViewOfFile(hMapping, FILE_MAP_WRITE, 0, 0, 0);
  375. +    if (fileView == NULL) {
  376. +        (void)fprintf(stderr,
  377. +            "Error: MapViewOfFile failed (lasterr=%ld)\n",
  378. +            (long)GetLastError());
  379. +        res = EXIT_FAILURE;
  380. +        goto cleanup;
  381. +    }
  382. +
  383. +    LARGE_INTEGER fileSize;
  384. +    if (!GetFileSizeEx(hFile, &fileSize)) {
  385. +        (void)fprintf(stderr,
  386. +            "Error: Could not get file size (lasterr=%lu)\n",
  387. +            (long)GetLastError());
  388. +        res = EXIT_FAILURE;
  389. +        goto cleanup;
  390. +    }
  391. +
  392. +    if (fileSize.QuadPart == 0) {
  393. +        printf("File is empty.\n");
  394. +        res = EXIT_FAILURE;
  395. +        goto cleanup;
  396. +    }
  397. +
  398. +    if (fileSize.QuadPart % RECORD_SIZE != 0) {
  399. +        (void)fprintf(stderr,
  400. +            "Error: File size (%lld) "
  401. +            "is not a multiple of the expected record size (%d).\n",
  402. +            (long long)fileSize.QuadPart, RECORD_SIZE);
  403. +        (void)fprintf(stderr,
  404. +            "Please ensure the file uses LF (\\n) line endings "
  405. +            "and has 10 chars per line.\n");
  406. +        res = EXIT_FAILURE;
  407. +        goto cleanup;
  408. +    }
  409. +
  410. +    size_t record_count = fileSize.QuadPart / RECORD_SIZE;
  411. +    (void)printf("File mapped successfully. Found %zu records to sort.\n",
  412. +        record_count);
  413. +
  414. +    (void)printf("Sorting records in-place (lexicographically)...\n");
  415. +    qsort(fileView, record_count, RECORD_SIZE, compare_records_strcmp);
  416. +
  417. +    if (!FlushViewOfFile(fileView, 0)) {
  418. +        (void)fprintf(stderr,
  419. +            "Warning: Could not flush changes to disk (lassterr=%ld)\n",
  420. +            (long)GetLastError());
  421. +    }
  422. +
  423. +    (void)printf("\nFile has been sorted and saved successfully.\n");
  424. +    res = EXIT_SUCCESS;
  425. +
  426. +cleanup:
  427. +    if (fileView != NULL) {
  428. +        (void)UnmapViewOfFile(fileView);
  429. +    }
  430. +    if (hMapping != NULL) {
  431. +        (void)CloseHandle(hMapping);
  432. +    }
  433. +    if (hFile != INVALID_HANDLE_VALUE) {
  434. +        (void)CloseHandle(hFile);
  435. +    }
  436. +
  437. +    return res;
  438. +}
  439. diff --git a/tests/filemmaptests/testqsortonmmapedfile1.ksh93 b/tests/filemmaptests/testqsortonmmapedfile1.ksh93
  440. new file mode 100755
  441. index 0000000..fcc865d
  442. --- /dev/null
  443. +++ b/tests/filemmaptests/testqsortonmmapedfile1.ksh93
  444. @@ -0,0 +1,44 @@
  445. +#!/bin/ksh93
  446. +
  447. +#
  448. +# testqsortonmmapedfile1.ksh93 - Test |qsort()| on memory mapped file
  449. +#
  450. +
  451. +set -o errexit
  452. +
  453. +builtin cat
  454. +builtin cmp
  455. +builtin rm
  456. +
  457. +integer res=0
  458. +
  459. +which qsortonmmapedfile1.exe || exit 1
  460. +
  461. +if [[ ! -f 'numfile1_orig' ]] ; then
  462. +    for ((i=32*1024*1024 ; i > 0 ; i--)) ; do
  463. +        printf "%15.15d\n" i
  464. +    # cat is used for buffering
  465. +    done | cat >'numfile1_orig'
  466. +fi
  467. +set -o xtrace
  468. +
  469. +rm -f 'numfile1' 'numfile1_sort_out'
  470. +cp 'numfile1_orig' 'numfile1'
  471. +time sort 'numfile1' -o 'numfile1_sort_out'
  472. +ls -l 'numfile1'
  473. +head 'numfile1'
  474. +time qsortonmmapedfile1.exe 'numfile1'
  475. +head 'numfile1'
  476. +ls -l 'numfile1'
  477. +if cmp 'numfile1' 'numfile1_sort_out' ; then
  478. +    printf '#\n# test OK\n#\n'
  479. +    (( res=0 ))
  480. +else
  481. +    printf '#\n# test FAILED\n#\n'
  482. +    (( res=1 ))
  483. +
  484. +    diff -u 'numfile1' 'numfile1_sort_out'
  485. +fi
  486. +
  487. +exit $res
  488. +# EOF.
  489. --
  490. 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