From: Stéphane Bacri frisou76@yahoo.fr
--- dlls/ntdll/tests/file.c | 25 ++++++++++++++++++++++--- dlls/ntdll/unix/file.c | 12 ++---------- 2 files changed, 24 insertions(+), 13 deletions(-)
diff --git a/dlls/ntdll/tests/file.c b/dlls/ntdll/tests/file.c index 553fc1eb160..56f572cb418 100644 --- a/dlls/ntdll/tests/file.c +++ b/dlls/ntdll/tests/file.c @@ -1340,11 +1340,16 @@ static void test_file_setFileAllocationInformation(void) { IO_STATUS_BLOCK io; HANDLE handle; int res; + char* buffer; + DWORD bytesWritten, bytesRead; + DWORD length = 64*1024; + LARGE_INTEGER distanceToMove; + distanceToMove.QuadPart = 0;
if( !(handle = create_temp_file(0)) ) return;
memset( &fas, 0, sizeof(fas) ); - fas.AllocationSize.QuadPart = 1024 * 1024; + fas.AllocationSize.QuadPart = length; res = pNtSetInformationFile( handle, &io, &fas, sizeof fas, FileAllocationInformation );
ok ( res == STATUS_SUCCESS, "file allocation failed, NtSetInformationFile returned %x\n", res ); @@ -1353,8 +1358,22 @@ static void test_file_setFileAllocationInformation(void) { memset( &info, 0x22, sizeof(info) ); res = GetFileInformationByHandle( handle, &info ); ok( res, "GetFileInformationByHandle failed\n" ); - ok( info.nFileSizeLow == fas.AllocationSize.QuadPart, "incorrect file size after allocation\n" ); - + ok( info.nFileSizeLow == 0, "incorrect file size after allocation: should be 0, got %lx\n", info.nFileSizeLow ); + + buffer = malloc(length); + memset( buffer, 0xa5, length ); + res = WriteFile( handle, buffer, length, &bytesWritten, NULL ); + ok ( res != 0 , "couldn't write to file after allocation\n"); + ok ( bytesWritten == length, "couldn't write to whole or part of file after allocation: allocated %lx, written %lx\n", length, bytesWritten ); + + memset( buffer, 0, length ); + SetFilePointerEx( handle, distanceToMove, NULL, FILE_BEGIN ); + res = ReadFile( handle, buffer, length, &bytesRead, NULL ); + ok ( res != 0 , "couldn't read file after allocation\n" ); + ok ( bytesRead == length, "couldn't read whole or part of file after allocation: allocated %lx, read %lx\n", length, bytesRead ); + ok ( *buffer == (char)0xa5, "data read from allocated file doesn't match written pattern: wrote 0xa5, got 0x%x\n", *buffer & 0xff ); + + free(buffer); CloseHandle( handle ); }
diff --git a/dlls/ntdll/unix/file.c b/dlls/ntdll/unix/file.c index 177e343a311..ddbe927a6be 100644 --- a/dlls/ntdll/unix/file.c +++ b/dlls/ntdll/unix/file.c @@ -4672,20 +4672,12 @@ NTSTATUS WINAPI NtSetInformationFile( HANDLE handle, IO_STATUS_BLOCK *io, if (len >= sizeof(FILE_ALLOCATION_INFORMATION)) { const FILE_ALLOCATION_INFORMATION *info = ptr; - int err;
if ((status = server_get_unix_fd( handle, 0, &fd, &needs_close, NULL, NULL ))) return io->Status = status;
-#ifdef HAVE_POSIX_FALLOCATE - if ((err = posix_fallocate( fd, 0, (off_t)info->AllocationSize.QuadPart )) != 0) - { - if (err == EOPNOTSUPP) WARN( "posix_fallocate not supported on this filesystem\n" ); - else status = errno_to_status( err ); - } -#else - WARN( "setting file allocation information not supported\n" ); -#endif + if (fallocate( fd, FALLOC_FL_KEEP_SIZE | FALLOC_FL_ZERO_RANGE, 0, (off_t)info->AllocationSize.QuadPart ) == -1) + status = errno_to_status( errno );
if (needs_close) close( fd ); }