]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
libext2fs: fix filesystems larger than 2GB on Windows
authorSteffen Kieß <kiess@ki4.de>
Mon, 17 Apr 2023 09:47:56 +0000 (11:47 +0200)
committerSteffen Kieß <kiess@ki4.de>
Mon, 17 Apr 2023 09:47:56 +0000 (11:47 +0200)
SetFilePointer requires the upper 32 bit of the position to be passed
separately, which the code did not do, causing the position to be
interpreted as a 32-bit value. Use SetFilePointerEx instead and pass the
entire 64-bit value.

Signed-off-by: Steffen Kieß <kiess@ki4.de>
lib/ext2fs/windows_io.c

index 83aea68b653c6b337cd03c7717965255ef82b51b..aefef115e43e7a1d24ae7f90729f8bf57fd3523f 100644 (file)
@@ -154,6 +154,14 @@ static errcode_t windows_get_stats(io_channel channel, io_stats *stats)
        return retval;
 }
 
+static LARGE_INTEGER make_large_integer(LONGLONG value)
+{
+       LARGE_INTEGER   li;
+
+       li.QuadPart = value;
+       return li;
+}
+
 /*
  * Here are the raw I/O functions
  */
@@ -174,14 +182,14 @@ static errcode_t raw_read_blk(io_channel channel,
        location = ((ext2_loff_t) block * channel->block_size) + data->offset;
 
        if (data->flags & IO_FLAG_FORCE_BOUNCE) {
-               if (SetFilePointer(data->handle, location, NULL, FILE_BEGIN) == INVALID_SET_FILE_POINTER) {
+               if (!SetFilePointerEx(data->handle, make_large_integer(location), NULL, FILE_BEGIN)) {
                        retval = GetLastError();
                        goto error_out;
                }
                goto bounce_read;
        }
 
-       if (SetFilePointer(data->handle, location, NULL, FILE_BEGIN) == INVALID_SET_FILE_POINTER) {
+       if (!SetFilePointerEx(data->handle, make_large_integer(location), NULL, FILE_BEGIN)) {
                retval = GetLastError();
                goto error_out;
        }
@@ -261,14 +269,14 @@ static errcode_t raw_write_blk(io_channel channel,
        location = ((ext2_loff_t) block * channel->block_size) + data->offset;
 
        if (data->flags & IO_FLAG_FORCE_BOUNCE) {
-               if (SetFilePointer(data->handle, location, NULL, FILE_BEGIN) == INVALID_SET_FILE_POINTER) {
+               if (!SetFilePointerEx(data->handle, make_large_integer(location), NULL, FILE_BEGIN)) {
                        retval = GetLastError();
                        goto error_out;
                }
        goto bounce_write;
        }
 
-               if (SetFilePointer(data->handle, location, NULL, FILE_BEGIN) == INVALID_SET_FILE_POINTER) {
+               if (!SetFilePointerEx(data->handle, make_large_integer(location), NULL, FILE_BEGIN)) {
                        retval = GetLastError();
                goto error_out;
        }
@@ -313,7 +321,7 @@ bounce_write:
                if (size > channel->block_size)
                        actual = channel->block_size;
                memcpy(data->bounce, buf, actual);
-               if (SetFilePointer(data->handle, location, NULL, FILE_BEGIN) == INVALID_SET_FILE_POINTER) {
+               if (!SetFilePointerEx(data->handle, make_large_integer(location), NULL, FILE_BEGIN)) {
                        retval = GetLastError();
                        goto error_out;
                }