From 7c4af8b07f77f909744b0ee77659e10246df8cc0 Mon Sep 17 00:00:00 2001 From: Steffen Kieß Date: Mon, 17 Apr 2023 11:47:56 +0200 Subject: libext2fs: fix filesystems larger than 2GB on Windows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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ß --- lib/ext2fs/windows_io.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/ext2fs/windows_io.c b/lib/ext2fs/windows_io.c index 83aea68b6..aefef115e 100644 --- a/lib/ext2fs/windows_io.c +++ b/lib/ext2fs/windows_io.c @@ -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; } -- cgit 1.2.3-korg