From 9bdb54bc762f93c9edaf91920bf88a8b90b81354 Mon Sep 17 00:00:00 2001 From: janwas Date: Sat, 30 Apr 2011 09:13:10 +0000 Subject: [PATCH] fix failure to preallocate disk space on Windows by always rounding up the file size regardless of the io::Parameters This was SVN commit r9358. --- source/lib/file/io/io.h | 2 +- source/lib/sysdep/os/win/wposix/waio.cpp | 8 +++++--- source/lib/sysdep/os/win/wposix/waio.h | 8 ++++---- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/source/lib/file/io/io.h b/source/lib/file/io/io.h index b808c412de..8827aedc2d 100644 --- a/source/lib/file/io/io.h +++ b/source/lib/file/io/io.h @@ -284,7 +284,7 @@ static inline LibError Store(const OsPath& pathname, const void* data, size_t si io::Operation op(file, (void*)data, size); #if OS_WIN && CONFIG2_FILE_ENABLE_AIO - (void)waio_Preallocate(op.fd, (off_t)size, p.alignment); + (void)waio_Preallocate(op.fd, (off_t)size); #endif RETURN_ERR(io::Run(op, p, completedHook, issueHook)); diff --git a/source/lib/sysdep/os/win/wposix/waio.cpp b/source/lib/sysdep/os/win/wposix/waio.cpp index bb0ea21b90..3d3ea077f1 100644 --- a/source/lib/sysdep/os/win/wposix/waio.cpp +++ b/source/lib/sysdep/os/win/wposix/waio.cpp @@ -32,6 +32,7 @@ #include "precompiled.h" #include "lib/sysdep/os/win/wposix/waio.h" +#include "lib/bits.h" // round_up #include "lib/alignment.h" // IsAligned #include "lib/module_init.h" #include "lib/sysdep/cpu.h" // cpu_AtomicAdd @@ -411,15 +412,16 @@ LibError waio_close(int fd) } -LibError waio_Preallocate(int fd, off_t alignedSize, off_t alignment) +LibError waio_Preallocate(int fd, off_t size) { - debug_assert(IsAligned(alignedSize, alignment)); - FileControlBlock* fcb = FindFileControlBlock(fd); if(!fcb) WARN_RETURN(ERR::INVALID_HANDLE); const HANDLE hFile = fcb->hFile; + // Windows requires sector alignment (see discussion in header) + const off_t alignedSize = round_up(size, (off_t)maxSectorSize); + // allocate all space up front to reduce fragmentation LARGE_INTEGER size64; size64.QuadPart = alignedSize; WARN_IF_FALSE(SetFilePointerEx(hFile, size64, 0, FILE_BEGIN)); diff --git a/source/lib/sysdep/os/win/wposix/waio.h b/source/lib/sysdep/os/win/wposix/waio.h index 6030cca7ed..2cac058432 100644 --- a/source/lib/sysdep/os/win/wposix/waio.h +++ b/source/lib/sysdep/os/win/wposix/waio.h @@ -130,10 +130,10 @@ extern LibError waio_close(int fd); // call this before writing a large file to preallocate clusters, thus // reducing fragmentation. // -// @param alignedSize must be a multiple of alignment (SetEndOfFile requires -// sector alignment; this could be avoided by using the undocumented +// @param size is rounded up to a multiple of maxSectorSize (required by +// SetEndOfFile; this could be avoided by using the undocumented // NtSetInformationFile or SetFileInformationByHandle on Vista and later). -// use wtruncate after I/O is complete to chop off any excess padding. +// use wtruncate after I/O is complete to chop off the excess padding. // // NB: writes that extend a file (i.e. ALL WRITES when creating new files) // are synchronous, which prevents overlapping I/O and other work. @@ -143,6 +143,6 @@ extern LibError waio_close(int fd); // note that this exposes the previous disk contents (possibly even to // other users since the waio_reopen design cannot deny file sharing) until // the application successfully writes to the file. -LIB_API LibError waio_Preallocate(int fd, off_t alignedSize, off_t alignment); +LIB_API LibError waio_Preallocate(int fd, off_t size); #endif // #ifndef INCLUDED_WAIO