pastebin - collaborative debugging tool
rovema.kpaste.net RSS


msnfs41client: Patches to fix comment about QueryAllocatedRanges API bug, adding lssparse+misc, 2025-03-05
Posted by Anonymous on Wed 5th Mar 2025 11:58
raw | new post

  1. From 0f621332a78d3ee2758c4445edbddae07aacbebf Mon Sep 17 00:00:00 2001
  2. From: Roland Mainz <roland.mainz@nrubsig.org>
  3. Date: Tue, 4 Mar 2025 12:53:18 +0100
  4. Subject: [PATCH 1/3] daemon: Remove comment about Windows issue in
  5.  |query_sparsefile_datasections()|
  6.  
  7. Remove comment about Windows issue in |query_sparsefile_datasections()|,
  8. this was a misinterpretation how the API should work.
  9.  
  10. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  11. ---
  12. daemon/fsctl.c | 34 ++++++++++++++--------------------
  13.  1 file changed, 14 insertions(+), 20 deletions(-)
  14.  
  15. diff --git a/daemon/fsctl.c b/daemon/fsctl.c
  16. index bc74363..87937cc 100644
  17. --- a/daemon/fsctl.c
  18. +++ b/daemon/fsctl.c
  19. @@ -178,29 +178,23 @@ int query_sparsefile_datasections(nfs41_open_state *state,
  20.              outbuffer[i].Length.QuadPart = data_size;
  21.          }
  22.          else {
  23. -            error_more_data = true;
  24. -
  25. -            /* Windows bug:
  26. -             * Technically we should continue until we reach
  27. -             * |end_offset| to return the correct size of the
  28. -             * buffer with |DeviceIoControl(...,
  29. -             * FSCTL_QUERY_ALLOCATED_RANGES,...)| ==
  30. -             * |ERROR_MORE_DATA|.
  31. +            /*
  32. +             * Return |ERROR_MORE_DATA| if we reach end of the
  33. +             * caller-supplied record array and still have more
  34. +             * data sections (i.e. no EOF from
  35. +             + |NFS4_CONTENT_HOLE|/|NFS4_CONTENT_DATA| yet).
  36.               *
  37. -             * Unfortunaely Win10 fsutil will then return
  38. -             * random values after the first 64 entries, so the
  39. -             * best we can do for bug-by-bug compatibility is
  40. -             * to do the same: Stop counting here, and
  41. -             * therefore return
  42. -             * |out_maxrecords*sizeof(FILE_ALLOCATED_RANGE_BUFFER)|,
  43. -             * which is exactly the same number of bytes of the
  44. -             * original buffer passed as argument
  45. +             * FIXME: We should also implement |out_maxrecords==0|,
  46. +             * and then return the size for an array to store
  47. +             * all records.
  48. +             * This can still be too small if between the first
  49. +             * FSCTL call (to get the needed size of the array)
  50. +             * and second FSCTL call to enumerate the
  51. +             * |FILE_ALLOCATED_RANGE_BUFFER| someone adds more
  52. +             * data sections.
  53.               */
  54. -#define WINDOWS_FSUTILSPARSEQUERYRANGE_MOREDATA_BUG 1
  55. -
  56. -#ifdef WINDOWS_FSUTILSPARSEQUERYRANGE_MOREDATA_BUG
  57. +            error_more_data = true;
  58.              break;
  59. -#endif /* WINDOWS_FSUTILSPARSEQUERYRANGE_MOREDATA_BUG */
  60.          }
  61.  
  62.          (*res_num_records)++;
  63. --
  64. 2.45.1
  65.  
  66. From c636968805c73f9c224fd8f14c557bb23d7ba155 Mon Sep 17 00:00:00 2001
  67. From: Roland Mainz <roland.mainz@nrubsig.org>
  68. Date: Wed, 5 Mar 2025 09:59:55 +0100
  69. Subject: [PATCH 2/3] sys: Add more argument checks in FSCTL code
  70.  
  71. Add more argument checks in FSCTL code.
  72.  
  73. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  74. ---
  75. sys/nfs41sys_fsctl.c | 43 ++++++++++++++++++++++++++++++++++---------
  76.  1 file changed, 34 insertions(+), 9 deletions(-)
  77.  
  78. diff --git a/sys/nfs41sys_fsctl.c b/sys/nfs41sys_fsctl.c
  79. index 274bf29..ede33e3 100644
  80. --- a/sys/nfs41sys_fsctl.c
  81. +++ b/sys/nfs41sys_fsctl.c
  82. @@ -76,8 +76,31 @@ NTSTATUS check_nfs41_queryallocatedranges_args(
  83.      XXCTL_LOWIO_COMPONENT *FsCtl =
  84.          &RxContext->LowIoContext.ParamsFor.FsCtl;
  85.      const USHORT HeaderLen = sizeof(FILE_ALLOCATED_RANGE_BUFFER);
  86. +    __notnull PFILE_ALLOCATED_RANGE_BUFFER in_range_buffer =
  87. +        (PFILE_ALLOCATED_RANGE_BUFFER)FsCtl->pInputBuffer;
  88. +
  89. +    if (FsCtl->pInputBuffer == NULL) {
  90. +        status = STATUS_INVALID_USER_BUFFER;
  91. +        goto out;
  92. +    }
  93. +
  94. +    if (FsCtl->InputBufferLength <
  95. +        sizeof(FILE_ALLOCATED_RANGE_BUFFER)) {
  96. +        DbgP("check_nfs41_queryallocatedranges_args: "
  97. +            "in_range_buffer to small\n");
  98. +        status = STATUS_BUFFER_TOO_SMALL;
  99. +        goto out;
  100. +    }
  101. +
  102. +    if ((in_range_buffer->FileOffset.QuadPart < 0LL) ||
  103. +        (in_range_buffer->Length.QuadPart < 0LL) ||
  104. +        (in_range_buffer->Length.QuadPart >
  105. +            (MAXLONGLONG - in_range_buffer->FileOffset.QuadPart))) {
  106. +        status = STATUS_INVALID_PARAMETER;
  107. +        goto out;
  108. +    }
  109.  
  110. -    if (!FsCtl->pOutputBuffer) {
  111. +    if (FsCtl->pOutputBuffer == NULL) {
  112.          status = STATUS_INVALID_USER_BUFFER;
  113.          goto out;
  114.      }
  115. @@ -87,6 +110,7 @@ NTSTATUS check_nfs41_queryallocatedranges_args(
  116.          status = STATUS_BUFFER_TOO_SMALL;
  117.          goto out;
  118.      }
  119. +
  120.  out:
  121.      return status;
  122.  }
  123. @@ -116,18 +140,14 @@ NTSTATUS nfs41_QueryAllocatedRanges(
  124.      RxContext->IoStatusBlock.Information = 0;
  125.  
  126.      status = check_nfs41_queryallocatedranges_args(RxContext);
  127. -    if (status)
  128. -        goto out;
  129. -
  130. -    if (FsCtl->InputBufferLength <
  131. -        sizeof(FILE_ALLOCATED_RANGE_BUFFER)) {
  132. +    if (status) {
  133.          DbgP("nfs41_QueryAllocatedRanges: "
  134. -            "in_range_buffer to small\n");
  135. -        status = STATUS_BUFFER_TOO_SMALL;
  136. +            "check_nfs41_queryallocatedranges_args() failed with status=0x%lx\n",
  137. +            (long)status);
  138.          goto out;
  139.      }
  140.  
  141. -    DbgP("nfs41_QueryAllocatedRanges/REAL: "
  142. +    DbgP("nfs41_QueryAllocatedRanges: "
  143.          "in_range_buffer=(FileOffset=%lld,Length=%lld)\n",
  144.          (long long)in_range_buffer->FileOffset.QuadPart,
  145.          (long long)in_range_buffer->Length.QuadPart);
  146. @@ -443,6 +463,11 @@ NTSTATUS nfs41_SetZeroData(
  147.      if (status)
  148.          goto out;
  149.  
  150. +    if (FsCtl->pInputBuffer == NULL) {
  151. +        status = STATUS_INVALID_USER_BUFFER;
  152. +        goto out;
  153. +    }
  154. +
  155.      if (FsCtl->InputBufferLength <
  156.          sizeof(FILE_ZERO_DATA_INFORMATION)) {
  157.          DbgP("nfs41_SetZeroData: "
  158. --
  159. 2.45.1
  160.  
  161. From c12d0baaeefaae252f1a78cf5137fa65e8fdce40 Mon Sep 17 00:00:00 2001
  162. From: Roland Mainz <roland.mainz@nrubsig.org>
  163. Date: Wed, 5 Mar 2025 12:50:01 +0100
  164. Subject: [PATCH 3/3] cygwin,tests: Add lssparse(1) utility to test the POSIX
  165.  SEEK_DATA/SEEK_HOLE sparse file API
  166.  
  167. Add lssparse(1) utility to test the POSIX SEEK_DATA/SEEK_HOLE
  168. sparse file API
  169. (see https://pubs.opengroup.org/onlinepubs/9799919799/functions/lseek.html).
  170.  
  171. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  172. ---
  173. cygwin/Makefile                       |   4 +
  174.  cygwin/Makefile.install               |   7 +
  175.  tests/lssparse/Makefile               |  23 +++
  176.  tests/lssparse/lssparse.c             | 238 ++++++++++++++++++++++++++
  177.  tests/sparsefiles/testsparsefile1.ksh |  65 ++++---
  178.  5 files changed, 317 insertions(+), 20 deletions(-)
  179.  create mode 100644 tests/lssparse/Makefile
  180.  create mode 100644 tests/lssparse/lssparse.c
  181.  
  182. diff --git a/cygwin/Makefile b/cygwin/Makefile
  183. index a239eb1..9ae5b84 100644
  184. --- a/cygwin/Makefile
  185. +++ b/cygwin/Makefile
  186. @@ -20,6 +20,7 @@ VS_BUILD_DIR64:=$(PROJECT_BASEDIR_DIR)/build.vc19/x64/Debug/
  187.  
  188.  # trigger "build_testutils" target when these binaries are needed
  189.  $(PROJECT_BASEDIR_DIR)/tests/ea/nfs_ea.exe \
  190. +       $(PROJECT_BASEDIR_DIR)/tests/lssparse/lssparse.exe \
  191.         $(PROJECT_BASEDIR_DIR)/tests/winfsinfo1/winfsinfo.exe \
  192.         $(PROJECT_BASEDIR_DIR)/tests/winsg/winsg.exe: build_testutils
  193.  
  194. @@ -63,6 +64,7 @@ build_arm_64bit_debug:
  195.  
  196.  build_testutils:
  197.         (cd "$(PROJECT_BASEDIR_DIR)/tests/ea" && make all)
  198. +       (cd "$(PROJECT_BASEDIR_DIR)/tests/lssparse" && make all)
  199.         (cd "$(PROJECT_BASEDIR_DIR)/tests/winfsinfo1" && make all)
  200.         (cd "$(PROJECT_BASEDIR_DIR)/tests/winsg" && make all)
  201.  
  202. @@ -96,6 +98,7 @@ build64: \
  203.  clean:
  204.         rm -vRf $$(find "$(PROJECT_BASEDIR_DIR)/build.vc19" -name Debug -o -name Release)
  205.         (cd "$(PROJECT_BASEDIR_DIR)/tests/ea" && make clean)
  206. +       (cd "$(PROJECT_BASEDIR_DIR)/tests/lssparse" && make clean)
  207.         (cd "$(PROJECT_BASEDIR_DIR)/tests/winfsinfo1" && make clean)
  208.         (cd "$(PROJECT_BASEDIR_DIR)/tests/winsg" && make clean)
  209.  
  210. @@ -104,6 +107,7 @@ installdest_util: \
  211.         $(PROJECT_BASEDIR_DIR)/etc_netconfig \
  212.         $(PROJECT_BASEDIR_DIR)/ms-nfs41-idmap.conf \
  213.         $(PROJECT_BASEDIR_DIR)/tests/ea/nfs_ea.exe \
  214. +       $(PROJECT_BASEDIR_DIR)/tests/lssparse/lssparse.exe \
  215.         $(PROJECT_BASEDIR_DIR)/tests/winfsinfo1/winfsinfo.exe \
  216.         $(PROJECT_BASEDIR_DIR)/tests/winsg/winsg.exe \
  217.         $(CYGWIN_MAKEFILE_DIR)/devel/msnfs41client.bash
  218. diff --git a/cygwin/Makefile.install b/cygwin/Makefile.install
  219. index c722344..1a1005a 100644
  220. --- a/cygwin/Makefile.install
  221. +++ b/cygwin/Makefile.install
  222. @@ -103,6 +103,13 @@ installdest:
  223.         else \
  224.                 (cd $(DESTDIR)/$(CYGWIN_BASEPATH)/bin/ && ln -sf winfsinfo.i686.exe winfsinfo.exe) \
  225.         fi
  226. +       cp "$(PROJECT_BASEDIR_DIR)/tests/lssparse/lssparse.x86_64.exe" $(DESTDIR)/$(CYGWIN_BASEPATH)/bin/lssparse.x86_64.exe
  227. +       cp "$(PROJECT_BASEDIR_DIR)/tests/lssparse/lssparse.i686.exe" $(DESTDIR)/$(CYGWIN_BASEPATH)/bin/lssparse.i686.exe
  228. +       if [[ "$(CYGWIN_BASEPATH)" == *64* ]] ; then \
  229. +               (cd $(DESTDIR)/$(CYGWIN_BASEPATH)/bin/ && ln -sf lssparse.x86_64.exe lssparse.exe) \
  230. +       else \
  231. +               (cd $(DESTDIR)/$(CYGWIN_BASEPATH)/bin/ && ln -sf lssparse.i686.exe lssparse.exe) \
  232. +       fi
  233.         if [[ "$(CYGWIN_BASEPATH)" == *64* ]] ; then \
  234.                 cp "$(PROJECT_BASEDIR_DIR)/tests/winsg/winsg.x86_64.exe" $(DESTDIR)/$(CYGWIN_BASEPATH)/bin/winsg.exe ; \
  235.         else \
  236. diff --git a/tests/lssparse/Makefile b/tests/lssparse/Makefile
  237. new file mode 100644
  238. index 0000000..199d5d2
  239. --- /dev/null
  240. +++ b/tests/lssparse/Makefile
  241. @@ -0,0 +1,23 @@
  242. +#
  243. +# Makefile for lssparse
  244. +#
  245. +
  246. +# POSIX Makefile
  247. +
  248. +all: lssparse.i686.exe lssparse.x86_64.exe lssparse.exe
  249. +
  250. +lssparse.i686.exe: lssparse.c
  251. +       gcc -std=gnu17 -Wall -Wextra -DUNICODE=1 -D_UNICODE=1 -I../../include -g lssparse.c -lntdll -o lssparse.i686.exe
  252. +
  253. +lssparse.x86_64.exe: lssparse.c
  254. +       gcc -std=gnu17 -Wall -Wextra -DUNICODE=1 -D_UNICODE=1 -I../../include -g lssparse.c -lntdll -o lssparse.x86_64.exe
  255. +
  256. +lssparse.exe: lssparse.x86_64.exe
  257. +       ln -s lssparse.x86_64.exe lssparse.exe
  258. +
  259. +clean:
  260. +       rm -fv \
  261. +               lssparse.i686.exe \
  262. +               lssparse.x86_64.exe \
  263. +               lssparse.exe \
  264. +# EOF.
  265. diff --git a/tests/lssparse/lssparse.c b/tests/lssparse/lssparse.c
  266. new file mode 100644
  267. index 0000000..4adb200
  268. --- /dev/null
  269. +++ b/tests/lssparse/lssparse.c
  270. @@ -0,0 +1,238 @@
  271. +
  272. +/*
  273. + * MIT License
  274. + *
  275. + * Copyright (c) 2011-2012 Roland Mainz <roland.mainz@nrubsig.org>
  276. + *
  277. + * Permission is hereby granted, free of charge, to any person obtaining a copy
  278. + * of this software and associated documentation files (the "Software"), to deal
  279. + * in the Software without restriction, including without limitation the rights
  280. + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  281. + * copies of the Software, and to permit persons to whom the Software is
  282. + * furnished to do so, subject to the following conditions:
  283. + *
  284. + * The above copyright notice and this permission notice shall be included in all
  285. + * copies or substantial portions of the Software.
  286. + *
  287. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  288. + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  289. + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  290. + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  291. + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  292. + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  293. + * SOFTWARE.
  294. + */
  295. +
  296. +/*
  297. + * lssparse.c - print sparse file hole+data layout information
  298. + *
  299. + * Written by Roland Mainz <roland.mainz@nrubsig.org>
  300. + */
  301. +
  302. +#include <stdio.h>
  303. +#include <stdlib.h>
  304. +#include <stdbool.h>
  305. +#include <string.h>
  306. +#include <fcntl.h>
  307. +#include <unistd.h>
  308. +#include <errno.h>
  309. +
  310. +#define EXIT_USAGE (2)
  311. +
  312. +static
  313. +void usage(const char *progname)
  314. +{
  315. +    (void)fprintf(stderr, "Usage: %s [-h] <sparse_file>\n"
  316. +        "  -h: Display this help message\n"
  317. +        "  -x: Print offsets in hexadecimal (base 16)\n"
  318. +        "  -d: Print offsets in decimal (base 10)\n"
  319. +        "  -H: Print hole information\n",
  320. +        progname);
  321. +}
  322. +
  323. +typedef enum _printbase {
  324. +    pb_hex = 1,
  325. +    pb_dec = 2
  326. +} printbase;
  327. +
  328. +int main(int argc, char *argv[])
  329. +{
  330. +    /* Arguments */
  331. +    const char *progname = argv[0];
  332. +    printbase pb = pb_hex;
  333. +    bool print_holes = false;
  334. +    const char *filename;
  335. +
  336. +    int retval;
  337. +    int opt;
  338. +    int fd;
  339. +
  340. +    size_t i;
  341. +    off_t offset = 0;
  342. +    off_t data_start;
  343. +    off_t hole_start;
  344. +    off_t hole_end;
  345. +    off_t file_size;
  346. +    off_t data_len;
  347. +    off_t hole_len;
  348. +
  349. +    while ((opt = getopt(argc, argv, "hxdH")) != -1) {
  350. +        switch (opt) {
  351. +            case '?':
  352. +            case 'h':
  353. +                usage(progname);
  354. +                return EXIT_USAGE;
  355. +            case 'x':
  356. +                pb = pb_hex;
  357. +                break;
  358. +            case 'd':
  359. +                pb = pb_dec;
  360. +                break;
  361. +            case 'H':
  362. +                print_holes = true;
  363. +                break;
  364. +            default:
  365. +                break;
  366. +        }
  367. +    }
  368. +
  369. +    if (optind >= argc) {
  370. +        usage(progname);
  371. +        return EXIT_USAGE;
  372. +    }
  373. +
  374. +    filename = argv[optind];
  375. +
  376. +    fd = open(filename, O_RDONLY);
  377. +    if (fd == -1) {
  378. +        (void)fprintf(stderr, "%s: Open file failed with [%s]\n",
  379. +            progname,
  380. +            strerror(errno));
  381. +        return EXIT_FAILURE;
  382. +    }
  383. +
  384. +    /* Get file size */
  385. +    file_size = lseek(fd, 0, SEEK_END);
  386. +    if (file_size == -1) {
  387. +        (void)fprintf(stderr, "%s: Cannot seek [%s]\n",
  388. +            progname,
  389. +            strerror(errno));
  390. +        return EXIT_FAILURE;
  391. +    }
  392. +    (void)lseek(fd, 0, SEEK_SET);
  393. +
  394. +
  395. +    /*
  396. +     * Loop over hole&&data sections
  397. +     *
  398. +     * This loop must handle:
  399. +     * - normal files with no holes
  400. +     * - sparse files which start with data
  401. +     * - sparse files which start with a hole
  402. +     * - sparse files with multiple holes
  403. +     * - sparse files which end with data
  404. +     * - sparse files which end with a hole
  405. +     *
  406. +     * Note we start with index |1| for compatibility
  407. +     * with SUN's original sparse file debuggung tools
  408. +     * and Win32's
  409. +     * $ /cygdrive/c/Windows/system32/fsutil sparse queryrange ... #
  410. +     * output
  411. +     */
  412. +    for (i=1 ;;) {
  413. +        data_start = lseek(fd, offset, SEEK_DATA);
  414. +        if (data_start == -1)
  415. +            break;
  416. +        hole_start = lseek(fd, data_start, SEEK_HOLE);
  417. +
  418. +        if (hole_start == -1) {
  419. +            if (errno == ENXIO) {
  420. +                /* No more holes ? Use file site as pos of next hole */
  421. +                hole_start = file_size;
  422. +            } else {
  423. +                (void)fprintf(stderr,
  424. +                    "%s: lseek(..., SEEK_HOLE, ...) failed with [%s]\n",
  425. +                    progname,
  426. +                    strerror(errno));
  427. +                    retval = EXIT_FAILURE;
  428. +                goto done;
  429. +            }
  430. +        }
  431. +
  432. +        if (print_holes && (i == 0) && (data_start > 0)) {
  433. +            (void)printf((pb == pb_hex)?
  434. +                "Hole range[%ld]: offset=0x%llx,\tlength=0x%llx\n":
  435. +                "Hole range[%ld]: offset=%lld,\tlength=%lld\n",
  436. +                (long)i,
  437. +                (long long)0,
  438. +                (long long)data_start);
  439. +            i++;
  440. +        }
  441. +
  442. +        data_len = hole_start - data_start;
  443. +
  444. +        (void)printf((pb == pb_hex)?
  445. +            "Data range[%ld]: offset=0x%llx,\tlength=0x%llx\n":
  446. +            "Data range[%ld]: offset=%lld,\tlength=%lld\n",
  447. +            (long)i,
  448. +            (long long)data_start,
  449. +            (long long)data_len);
  450. +        i++;
  451. +
  452. +        hole_end = lseek(fd, hole_start, SEEK_DATA);
  453. +
  454. +        if (hole_end == -1) {
  455. +            if (errno == ENXIO) {
  456. +                /* No more holes ? */
  457. +                hole_end = file_size;
  458. +            } else {
  459. +                (void)fprintf(stderr,
  460. +                    "%s: lseek(..., SEEK_DATA, ...) failed with [%s]\n",
  461. +                    progname,
  462. +                    strerror(errno));
  463. +                retval = EXIT_FAILURE;
  464. +                goto done;
  465. +            }
  466. +        }
  467. +
  468. +        hole_len = hole_end - hole_start;
  469. +
  470. +        if (print_holes && (hole_len > 0LL)) {
  471. +            (void)printf((pb == pb_hex)?
  472. +                "Hole range[%ld]: offset=0x%llx,\tlength=0x%llx\n":
  473. +                "Hole range[%ld]: offset=%lld,\tlength=%lld\n",
  474. +                (long)i,
  475. +                (long long)hole_start,
  476. +                (long long)hole_len);
  477. +            i++;
  478. +        }
  479. +
  480. +        offset = hole_end;
  481. +    }
  482. +
  483. +    if ((data_start == -1) && (errno == ENXIO) && (offset == 0)) {
  484. +        if (print_holes) {
  485. +            (void)printf((pb == pb_hex)?
  486. +                "Hole range[%ld]: offset=0x%llx,\tlength=0x%llx\n":
  487. +                "Hole range[%ld]: offset=%lld,\tlength=%lld\n",
  488. +                (long)0,
  489. +                (long long)0LL,
  490. +                (long long)file_size);
  491. +        }
  492. +
  493. +        retval = EXIT_SUCCESS;
  494. +    } else if ((data_start == -1) && (errno != ENXIO)) {
  495. +        (void)fprintf(stderr,
  496. +            "%s: lseek(..., SEEK_DATA, ...) failed with [%s]\n",
  497. +            progname,
  498. +            strerror(errno));
  499. +            retval = EXIT_FAILURE;
  500. +    }
  501. +    else {
  502. +        retval = EXIT_SUCCESS;
  503. +    }
  504. +
  505. +done:
  506. +    (void)close(fd);
  507. +    return retval;
  508. +}
  509. diff --git a/tests/sparsefiles/testsparsefile1.ksh b/tests/sparsefiles/testsparsefile1.ksh
  510. index 2427af2..ee45def 100644
  511. --- a/tests/sparsefiles/testsparsefile1.ksh
  512. +++ b/tests/sparsefiles/testsparsefile1.ksh
  513. @@ -47,22 +47,27 @@ function test_sparse_holeonly_dd
  514.  
  515.      integer fsutil_num_data_sections="$(/cygdrive/c/Windows/system32/fsutil sparse queryrange 'sparse_file_hole_only' | wc -l)"
  516.      integer winfsinfo_num_data_sections="$(winfsinfo fsctlqueryallocatedranges 'sparse_file_hole_only' | wc -l)"
  517. +    integer lssparse_num_data_sections="$(lssparse 'sparse_file_hole_only' | wc -l)"
  518.  
  519.      #
  520.      # test whether the file is OK
  521.      #
  522. -    if (( (fsutil_num_data_sections != 0) || (winfsinfo_num_data_sections != 0) )) ; then
  523. -        printf "# TEST failed, found fsutil=%d/winfsinfo=%d data sections, expected %d\n" \
  524. +    if (( (fsutil_num_data_sections != 0) || \
  525. +        (winfsinfo_num_data_sections != 0) || \
  526. +        (lssparse_num_data_sections != 0) )) ; then
  527. +        printf "# TEST failed, found fsutil=%d/winfsinfo=%d/lssparse=%d data sections, expected %d\n" \
  528.              fsutil_num_data_sections \
  529.              winfsinfo_num_data_sections \
  530. +            lssparse_num_data_sections \
  531.              0
  532.          return 1
  533.      fi
  534.  
  535. -    printf "\n#\n# TEST %q OK, found fsutil=%d/winfsinfo=%d data sections\n#\n" \
  536. +    printf "\n#\n# TEST %q OK, found fsutil=%d/winfsinfo=%d/lssparse=%d data sections\n#\n" \
  537.          "$0" \
  538.          fsutil_num_data_sections \
  539. -        winfsinfo_num_data_sections
  540. +        winfsinfo_num_data_sections \
  541. +        lssparse_num_data_sections
  542.  
  543.      return 0
  544.  }
  545. @@ -84,22 +89,27 @@ function test_sparse_holeonly_truncate
  546.  
  547.      integer fsutil_num_data_sections="$(/cygdrive/c/Windows/system32/fsutil sparse queryrange 'sparse_file_hole_only_trunc' | wc -l)"
  548.      integer winfsinfo_num_data_sections="$(winfsinfo fsctlqueryallocatedranges 'sparse_file_hole_only_trunc' | wc -l)"
  549. +    integer lssparse_num_data_sections="$(lssparse 'sparse_file_hole_only_trunc' | wc -l)"
  550.  
  551.      #
  552.      # test whether the file is OK
  553.      #
  554. -    if (( (fsutil_num_data_sections != 0) || (winfsinfo_num_data_sections != 0) )) ; then
  555. -        printf "# TEST failed, found fsutil=%d/winfsinfo=%d data sections, expected %d\n" \
  556. +    if (( (fsutil_num_data_sections != 0) || \
  557. +        (winfsinfo_num_data_sections != 0) || \
  558. +        (lssparse_num_data_sections != 0) )) ; then
  559. +        printf "# TEST failed, found fsutil=%d/winfsinfo=%d/lssparse=%d data sections, expected %d\n" \
  560.              fsutil_num_data_sections \
  561.              winfsinfo_num_data_sections \
  562. +            lssparse_num_data_sections \
  563.              0
  564.          return 1
  565.      fi
  566.  
  567. -    printf "\n#\n# TEST %q OK, found fsutil=%d/winfsinfo=%d data sections\n#\n" \
  568. +    printf "\n#\n# TEST %q OK, found fsutil=%d/winfsinfo=%d/lssparse=%d data sections\n#\n" \
  569.          "$0" \
  570.          fsutil_num_data_sections \
  571. -        winfsinfo_num_data_sections
  572. +        winfsinfo_num_data_sections \
  573. +        lssparse_num_data_sections
  574.  
  575.      return 0
  576.  }
  577. @@ -119,22 +129,27 @@ function test_normal_file
  578.  
  579.      integer fsutil_num_data_sections="$(/cygdrive/c/Windows/system32/fsutil sparse queryrange 'test_normal_file' | wc -l)"
  580.      integer winfsinfo_num_data_sections="$(winfsinfo fsctlqueryallocatedranges 'test_normal_file' | wc -l)"
  581. +    integer lssparse_num_data_sections="$(lssparse 'test_normal_file' | wc -l)"
  582.  
  583.      #
  584.      # test whether the file is OK
  585.      #
  586. -    if (( (fsutil_num_data_sections != 1) || (winfsinfo_num_data_sections != 1) )) ; then
  587. -        printf "# TEST failed, found fsutil=%d/winfsinfo=%d data sections, expected %d\n" \
  588. +    if (( (fsutil_num_data_sections != 1) || \
  589. +        (winfsinfo_num_data_sections != 1) || \
  590. +        (lssparse_num_data_sections != 1) )) ; then
  591. +        printf "# TEST failed, found fsutil=%d/winfsinfo=%d/lssparse=%d data sections, expected %d\n" \
  592.              fsutil_num_data_sections \
  593.              winfsinfo_num_data_sections \
  594. +            lssparse_num_data_sections \
  595.              1
  596.          return 1
  597.      fi
  598.  
  599. -    printf "\n#\n# TEST %q OK, found fsutil=%d/winfsinfo=%d data sections\n#\n" \
  600. +    printf "\n#\n# TEST %q OK, found fsutil=%d/winfsinfo=%d/lssparse=%d data sections\n#\n" \
  601.          "$0" \
  602.          fsutil_num_data_sections \
  603. -        winfsinfo_num_data_sections
  604. +        winfsinfo_num_data_sections \
  605. +        lssparse_num_data_sections
  606.  
  607.      return 0
  608.  }
  609. @@ -203,24 +218,29 @@ function test_multihole_sparsefile1
  610.  
  611.      integer fsutil_num_data_sections="$(/cygdrive/c/Windows/system32/fsutil sparse queryrange 'mysparsefile' | wc -l)"
  612.      integer winfsinfo_num_data_sections="$(winfsinfo fsctlqueryallocatedranges 'mysparsefile' | wc -l)"
  613. +    integer lssparse_num_data_sections="$(lssparse 'mysparsefile' | wc -l)"
  614.  
  615.  
  616.      #
  617.      # test whether the file is OK
  618.      #
  619.      if (( (fsutil_num_data_sections != (c.end_data_section-c.start_data_section)) || \
  620. -        (winfsinfo_num_data_sections != (c.end_data_section-c.start_data_section)) )) ; then
  621. -        printf "# TEST failed, found fsutil=%d/winfsinfo=%d data sections, expected %d\n" \
  622. +        (winfsinfo_num_data_sections != (c.end_data_section-c.start_data_section)) || \
  623. +        (lssparse_num_data_sections != (c.end_data_section-c.start_data_section)) )) ; then
  624. +        printf "# TEST failed, found fsutil=%d/winfsinfo=%d/lssparse=%d data sections, expected %d\n" \
  625.              fsutil_num_data_sections \
  626.              winfsinfo_num_data_sections \
  627. +            lssparse_num_data_sections \
  628.              $((c.end_data_section-c.start_data_section))
  629.          return 1
  630.      fi
  631.  
  632. -    printf "\n#\n# TEST %q OK, found fsutil=%d/winfsinfo=%d data sections\n#\n" \
  633. +    printf "\n#\n# TEST %q OK, found fsutil=%d/winfsinfo=%d/lssparse=%d data sections\n#\n" \
  634.          "$0" \
  635.          fsutil_num_data_sections \
  636. -        winfsinfo_num_data_sections
  637. +        winfsinfo_num_data_sections \
  638. +        lssparse_num_data_sections
  639. +
  640.      return 0
  641.  }
  642.  
  643. @@ -246,22 +266,27 @@ function test_sparse_punchhole1
  644.  
  645.      integer fsutil_num_data_sections="$(/cygdrive/c/Windows/system32/fsutil sparse queryrange 'sparse_file_punchhole' | wc -l)"
  646.      integer winfsinfo_num_data_sections="$(winfsinfo fsctlqueryallocatedranges 'sparse_file_punchhole' | wc -l)"
  647. +    integer lssparse_num_data_sections="$(lssparse 'sparse_file_punchhole' | wc -l)"
  648.  
  649.      #
  650.      # test whether the file is OK
  651.      #
  652. -    if (( (fsutil_num_data_sections != 2) || (winfsinfo_num_data_sections != 2) )) ; then
  653. -        printf "# TEST failed, found fsutil=%d/winfsinfo=%d data sections, expected %d\n" \
  654. +    if (( (fsutil_num_data_sections != 2) || \
  655. +        (winfsinfo_num_data_sections != 2) || \
  656. +        (lssparse_num_data_sections != 2) )) ; then
  657. +        printf "# TEST failed, found fsutil=%d/winfsinfo=%d/lssparse=%d data sections, expected %d\n" \
  658.              fsutil_num_data_sections \
  659.              winfsinfo_num_data_sections \
  660. +            lssparse_num_data_sections \
  661.              2
  662.          return 1
  663.      fi
  664.  
  665. -    printf "\n#\n# TEST %q OK, found fsutil=%d/winfsinfo=%d data sections\n#\n" \
  666. +    printf "\n#\n# TEST %q OK, found fsutil=%d/winfsinfo=%d/lssparse=%d data sections\n#\n" \
  667.          "$0" \
  668.          fsutil_num_data_sections \
  669. -        winfsinfo_num_data_sections
  670. +        winfsinfo_num_data_sections \
  671. +        lssparse_num_data_sections
  672.  
  673.      return 0
  674.  }
  675. --
  676. 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