* fhandler_disk_file.cc (fhandler_disk_file::ftruncate): Use

NtQueryInformationFile instead of GetFileSize, NtFsControlFile instead
	of DeviceIoControl.
This commit is contained in:
Corinna Vinschen 2007-07-27 13:19:41 +00:00
parent ceaf31f416
commit f590b14dfd
2 changed files with 20 additions and 12 deletions

View File

@ -1,3 +1,9 @@
2007-07-27 Corinna Vinschen <corinna@vinschen.de>
* fhandler_disk_file.cc (fhandler_disk_file::ftruncate): Use
NtQueryInformationFile instead of GetFileSize, NtFsControlFile instead
of DeviceIoControl.
2007-07-27 Corinna Vinschen <corinna@vinschen.de> 2007-07-27 Corinna Vinschen <corinna@vinschen.de>
* fhandler_disk_file.cc (fhandler_base::fstat_by_name): Use * fhandler_disk_file.cc (fhandler_base::fstat_by_name): Use

View File

@ -971,18 +971,22 @@ fhandler_disk_file::ftruncate (_off64_t length, bool allow_truncate)
set_errno (EBADF); set_errno (EBADF);
else else
{ {
_off64_t actual_length;
DWORD size_high = 0;
NTSTATUS status; NTSTATUS status;
IO_STATUS_BLOCK io; IO_STATUS_BLOCK io;
FILE_STANDARD_INFORMATION fsi;
FILE_END_OF_FILE_INFORMATION feofi; FILE_END_OF_FILE_INFORMATION feofi;
actual_length = GetFileSize (get_handle (), &size_high); status = NtQueryInformationFile (get_handle (), &io, &fsi, sizeof fsi,
actual_length += ((_off64_t) size_high) << 32; FileStandardInformation);
if (!NT_SUCCESS (status))
{
__seterrno_from_nt_status (status);
return -1;
}
/* If called through posix_fallocate, silently succeed if length /* If called through posix_fallocate, silently succeed if length
is less than the file's actual length. */ is less than the file's actual length. */
if (!allow_truncate && length < actual_length) if (!allow_truncate && length < fsi.EndOfFile.QuadPart)
return 0; return 0;
feofi.EndOfFile.QuadPart = length; feofi.EndOfFile.QuadPart = length;
@ -990,14 +994,12 @@ fhandler_disk_file::ftruncate (_off64_t length, bool allow_truncate)
called through posix_fallocate. */ called through posix_fallocate. */
if (allow_truncate if (allow_truncate
&& get_fs_flags (FILE_SUPPORTS_SPARSE_FILES) && get_fs_flags (FILE_SUPPORTS_SPARSE_FILES)
&& length >= actual_length + (128 * 1024)) && length >= fsi.EndOfFile.QuadPart + (128 * 1024))
{ {
DWORD dw; status = NtFsControlFile (get_handle (), NULL, NULL, NULL, &io,
BOOL r = DeviceIoControl (get_handle (), FSCTL_SET_SPARSE, NULL, 0, NULL, 0);
FSCTL_SET_SPARSE, NULL, 0, NULL, syscall_printf ("0x%08X = NtFsControlFile (%p, FSCTL_SET_SPARSE)",
0, &dw, NULL); status, get_handle ());
syscall_printf ("%d = DeviceIoControl(%p, FSCTL_SET_SPARSE)",
r, get_handle ());
} }
status = NtSetInformationFile (get_handle (), &io, status = NtSetInformationFile (get_handle (), &io,
&feofi, sizeof feofi, &feofi, sizeof feofi,