From: Qian Hong qhong@codeweavers.com
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- This patch had a corresponding entry in the old wine-staging bug tracker (bug 471). I could not find any details relating to the bug, except that it is related to msys2.
dlls/kernel32/tests/file.c | 18 +++++++++--------- server/fd.c | 21 ++++++++++++++++++++- 2 files changed, 29 insertions(+), 10 deletions(-)
diff --git a/dlls/kernel32/tests/file.c b/dlls/kernel32/tests/file.c index c09438e09bd..ea0a32f258d 100644 --- a/dlls/kernel32/tests/file.c +++ b/dlls/kernel32/tests/file.c @@ -6052,11 +6052,11 @@ static void test_eof(void) SetLastError(0xdeadbeef); SetFilePointer(file, 6, NULL, SEEK_SET); ret = SetEndOfFile(file); - todo_wine ok(!ret, "expected failure\n"); - todo_wine ok(GetLastError() == ERROR_USER_MAPPED_FILE, "got error %u\n", GetLastError()); + ok(!ret, "expected failure\n"); + ok(GetLastError() == ERROR_USER_MAPPED_FILE, "got error %u\n", GetLastError()); ret = GetFileSizeEx(file, &file_size); ok(ret, "failed to get size, error %u\n", GetLastError()); - todo_wine ok(file_size.QuadPart == 8, "got size %I64d\n", file_size.QuadPart); + ok(file_size.QuadPart == 8, "got size %I64d\n", file_size.QuadPart);
SetFilePointer(file, 8192, NULL, SEEK_SET); ret = SetEndOfFile(file); @@ -6067,11 +6067,11 @@ static void test_eof(void)
SetFilePointer(file, 8191, NULL, SEEK_SET); ret = SetEndOfFile(file); - todo_wine ok(!ret, "expected failure\n"); - todo_wine ok(GetLastError() == ERROR_USER_MAPPED_FILE, "got error %u\n", GetLastError()); + ok(!ret, "expected failure\n"); + ok(GetLastError() == ERROR_USER_MAPPED_FILE, "got error %u\n", GetLastError()); ret = GetFileSizeEx(file, &file_size); ok(ret, "failed to get size, error %u\n", GetLastError()); - todo_wine ok(file_size.QuadPart == 8192, "got size %I64d\n", file_size.QuadPart); + ok(file_size.QuadPart == 8192, "got size %I64d\n", file_size.QuadPart);
view = MapViewOfFile(mapping, map_tests[i].view_access, 0, 0, 4); ok(!!view, "failed to map view, error %u\n", GetLastError()); @@ -6087,11 +6087,11 @@ static void test_eof(void)
SetFilePointer(file, 16383, NULL, SEEK_SET); ret = SetEndOfFile(file); - todo_wine ok(!ret, "expected failure\n"); - todo_wine ok(GetLastError() == ERROR_USER_MAPPED_FILE, "got error %u\n", GetLastError()); + ok(!ret, "expected failure\n"); + ok(GetLastError() == ERROR_USER_MAPPED_FILE, "got error %u\n", GetLastError()); ret = GetFileSizeEx(file, &file_size); ok(ret, "failed to get size, error %u\n", GetLastError()); - todo_wine ok(file_size.QuadPart == 16384, "got size %I64d\n", file_size.QuadPart); + ok(file_size.QuadPart == 16384, "got size %I64d\n", file_size.QuadPart);
ret = UnmapViewOfFile(view); ok(ret, "failed to unmap view, error %u\n", GetLastError()); diff --git a/server/fd.c b/server/fd.c index fe97ca01c98..99fe103c87c 100644 --- a/server/fd.c +++ b/server/fd.c @@ -2647,11 +2647,30 @@ static void set_fd_eof( struct fd *fd, file_pos_t eof ) return; }
+ if (fstat( fd->unix_fd, &st) == -1) + { + file_set_error(); + return; + } + + if (eof < st.st_size) + { + struct fd *fd_ptr; + LIST_FOR_EACH_ENTRY( fd_ptr, &fd->inode->open, struct fd, inode_entry ) + { + if (fd_ptr->access & FILE_MAPPING_ACCESS) + { + set_error( STATUS_USER_MAPPED_FILE ); + return; + } + } + } + /* first try normal truncate */ if (ftruncate( fd->unix_fd, eof ) != -1) return;
/* now check for the need to extend the file */ - if (fstat( fd->unix_fd, &st ) != -1 && eof > st.st_size) + if (eof > st.st_size) { /* extend the file one byte beyond the requested size and then truncate it */ /* this should work around ftruncate implementations that can't extend files */