aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteffen Kieß <kiess@ki4.de>2023-04-17 11:47:56 +0200
committerSteffen Kieß <kiess@ki4.de>2023-04-17 11:47:56 +0200
commit7c4af8b07f77f909744b0ee77659e10246df8cc0 (patch)
treeaa5c95eedd260dd88a63a38ab402285a6352e401
parent25ad8a431331b4d1d444a70b6079456cc612ac40 (diff)
downloade2fsprogs-7c4af8b07f77f909744b0ee77659e10246df8cc0.tar.gz
libext2fs: fix filesystems larger than 2GB on Windows
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>
-rw-r--r--lib/ext2fs/windows_io.c18
1 files 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;
}