From f590b14dfdcadb81dbedce81dec30d65b453e555 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Fri, 27 Jul 2007 13:19:41 +0000 Subject: [PATCH] * fhandler_disk_file.cc (fhandler_disk_file::ftruncate): Use NtQueryInformationFile instead of GetFileSize, NtFsControlFile instead of DeviceIoControl. --- winsup/cygwin/ChangeLog | 6 ++++++ winsup/cygwin/fhandler_disk_file.cc | 26 ++++++++++++++------------ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index e8574d5dd..b86eb882e 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,9 @@ +2007-07-27 Corinna Vinschen + + * fhandler_disk_file.cc (fhandler_disk_file::ftruncate): Use + NtQueryInformationFile instead of GetFileSize, NtFsControlFile instead + of DeviceIoControl. + 2007-07-27 Corinna Vinschen * fhandler_disk_file.cc (fhandler_base::fstat_by_name): Use diff --git a/winsup/cygwin/fhandler_disk_file.cc b/winsup/cygwin/fhandler_disk_file.cc index 9264285d6..2ab830bc5 100644 --- a/winsup/cygwin/fhandler_disk_file.cc +++ b/winsup/cygwin/fhandler_disk_file.cc @@ -971,18 +971,22 @@ fhandler_disk_file::ftruncate (_off64_t length, bool allow_truncate) set_errno (EBADF); else { - _off64_t actual_length; - DWORD size_high = 0; NTSTATUS status; IO_STATUS_BLOCK io; + FILE_STANDARD_INFORMATION fsi; FILE_END_OF_FILE_INFORMATION feofi; - actual_length = GetFileSize (get_handle (), &size_high); - actual_length += ((_off64_t) size_high) << 32; + status = NtQueryInformationFile (get_handle (), &io, &fsi, sizeof fsi, + FileStandardInformation); + if (!NT_SUCCESS (status)) + { + __seterrno_from_nt_status (status); + return -1; + } /* If called through posix_fallocate, silently succeed if length is less than the file's actual length. */ - if (!allow_truncate && length < actual_length) + if (!allow_truncate && length < fsi.EndOfFile.QuadPart) return 0; feofi.EndOfFile.QuadPart = length; @@ -990,14 +994,12 @@ fhandler_disk_file::ftruncate (_off64_t length, bool allow_truncate) called through posix_fallocate. */ if (allow_truncate && get_fs_flags (FILE_SUPPORTS_SPARSE_FILES) - && length >= actual_length + (128 * 1024)) + && length >= fsi.EndOfFile.QuadPart + (128 * 1024)) { - DWORD dw; - BOOL r = DeviceIoControl (get_handle (), - FSCTL_SET_SPARSE, NULL, 0, NULL, - 0, &dw, NULL); - syscall_printf ("%d = DeviceIoControl(%p, FSCTL_SET_SPARSE)", - r, get_handle ()); + status = NtFsControlFile (get_handle (), NULL, NULL, NULL, &io, + FSCTL_SET_SPARSE, NULL, 0, NULL, 0); + syscall_printf ("0x%08X = NtFsControlFile (%p, FSCTL_SET_SPARSE)", + status, get_handle ()); } status = NtSetInformationFile (get_handle (), &io, &feofi, sizeof feofi,