server: Forbid shrinking files which are mapped to memory.
Signed-off-by: Zebediah Figura <z.figura12@gmail.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
4e84a553a8
commit
be55038f3d
|
@ -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());
|
||||
|
|
26
server/fd.c
26
server/fd.c
|
@ -2645,15 +2645,25 @@ static void set_fd_eof( struct fd *fd, file_pos_t eof )
|
|||
set_error( fd->no_fd_status );
|
||||
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)
|
||||
grow_file( fd->unix_fd, eof );
|
||||
else
|
||||
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;
|
||||
}
|
||||
}
|
||||
if (ftruncate( fd->unix_fd, eof ) == -1) file_set_error();
|
||||
}
|
||||
else grow_file( fd->unix_fd, eof );
|
||||
}
|
||||
|
||||
struct completion *fd_get_completion( struct fd *fd, apc_param_t *p_key )
|
||||
|
|
Loading…
Reference in New Issue