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.
This commit is contained in:
parent
0b46d58ae8
commit
9bdb54bc76
@ -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));
|
||||
|
@ -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));
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user