On Wed, Apr 2, 2025 at 4:01 PM Christian Franke via Cygwin
<cygwin@cygwin.com> wrote:
>
> Testcase for a minor issue:
>
> $ > sparse_file
>
> $ chattr +S sparse_file
>
> $ dd if=/dev/zero bs=1M count=1 conv=sparse,notrunc of=sparse_file
> ...
> $ lssparse sparse_file # OK
>
> $ lssparse -H sparse_file # OK
> Hole range[0]: offset=0x0,      length=0x100000
>
> $ printf X >> sparse_file
>
> $ lssparse sparse_file # OK
> Data range[1]: offset=0x100000, length=0x1
>
> $ lssparse -H sparse_file # Missing 'Hole range[0]'
> Data range[1]: offset=0x100000, length=0x1
>
> The condition at lssparse.c:161 is never true:
>
>     141      for (i=1 ;;) {
>     ...
>     161          if (print_holes && (i == 0) && (data_start > 0)) {
>
> Possible patch attached. Important: Not tested with other corner cases.

1. *Thanks* ... :-)

2. New version is available from
http://svn.nrubsig.org/svn/people/gisburn/code/sparsefiles/lssparse.c

3. I did these two changes (GoogleMail might ruin the whitespaces,
please use http://svn.nrubsig.org/svn/people/gisburn/code/sparsefiles/lssparse.c
for the original version):
-------- snip --------
From ed7f138e1682b7da95d606125b81abf754653a0f Mon Sep 17 00:00:00 2001
From: Roland Mainz <roland.ma...@nrubsig.org>
Date: Sat, 5 Apr 2025 16:43:13 +0200
Subject: [PATCH 1/2] lssparse -H does not print hole at offset 0 if
more data exists

lssparse -H does not print hole at offset 0 if more data exists.

Fixes: https://cygwin.com/pipermail/cygwin/2025-April/257843.html
Reported-by: Christian Franke <christian.fra...@t-online.de>
---
lssparse.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)

index 4adb200..6fc269e 100644
--- a/lssparse.c
+++ b/lssparse.c
@@ -2,7 +2,7 @@
/*
 * MIT License
 *
- * Copyright (c) 2011-2012 Roland Mainz <roland.ma...@nrubsig.org>
+ * Copyright (c) 2011-2025 Roland Mainz <roland.ma...@nrubsig.org>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
@@ -139,7 +139,8 @@ int main(int argc, char *argv[])
     * $ /cygdrive/c/Windows/system32/fsutil sparse queryrange ... #
     * output
     */
-    for (i=1 ;;) {
+#define LSSPARSE_START_INDEX 1
+    for (i=LSSPARSE_START_INDEX ;;) {
        data_start = lseek(fd, offset, SEEK_DATA);
        if (data_start == -1)
            break;
@@ -159,7 +160,8 @@ int main(int argc, char *argv[])
            }
        }

-        if (print_holes && (i == 0) && (data_start > 0)) {
+        if (print_holes &&
+            (i == LSSPARSE_START_INDEX) && (data_start > 0)) {
            (void)printf((pb == pb_hex)?
                "Hole range[%ld]: offset=0x%llx,\tlength=0x%llx\n":
                "Hole range[%ld]: offset=%lld,\tlength=%lld\n",
@@ -215,7 +217,7 @@ int main(int argc, char *argv[])
            (void)printf((pb == pb_hex)?
                "Hole range[%ld]: offset=0x%llx,\tlength=0x%llx\n":
                "Hole range[%ld]: offset=%lld,\tlength=%lld\n",
-                (long)0,
+                (long)LSSPARSE_START_INDEX,
                (long long)0LL,
                (long long)file_size);
        }
--
2.45.1

From 1b23534234fa58633bc96137220a9b9b32d4aa5f Mon Sep 17 00:00:00 2001
From: Roland Mainz <roland.ma...@nrubsig.org>
Date: Sat, 5 Apr 2025 16:48:36 +0200
Subject: [PATCH 2/2] lssparse usage message should print all options in
short form line

lssparse usage message should print all options in short form line.
---
lssparse.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

index 6fc269e..399ac75 100644
--- a/lssparse.c
+++ b/lssparse.c
@@ -42,7 +42,7 @@
static
void usage(const char *progname)
{
-    (void)fprintf(stderr, "Usage: %s [-h] <sparse_file>\n"
+    (void)fprintf(stderr, "Usage: %s [-h] [-xdH] <sparse_file>\n"
        "  -h: Display this help message\n"
        "  -x: Print offsets in hexadecimal (base 16)\n"
        "  -d: Print offsets in decimal (base 10)\n"
-------- snip --------

----

Bye,
Roland
-- 
  __ .  . __
 (o.\ \/ /.o) roland.ma...@nrubsig.org
  \__\/\/__/  MPEG specialist, C&&JAVA&&Sun&&Unix programmer
  /O /==\ O\  TEL +49 641 3992797
 (;O/ \/ \O;)

-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple

Reply via email to