summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2007-07-27 13:19:41 +0000
committerCorinna Vinschen <corinna@vinschen.de>2007-07-27 13:19:41 +0000
commitf590b14dfdcadb81dbedce81dec30d65b453e555 (patch)
treeb4357610b60f68050f13fc14a57e7770f0b644fb
parentceaf31f416220413feedcad1cc3e9f30f57dc28f (diff)
downloadcygnal-f590b14dfdcadb81dbedce81dec30d65b453e555.tar.gz
cygnal-f590b14dfdcadb81dbedce81dec30d65b453e555.tar.bz2
cygnal-f590b14dfdcadb81dbedce81dec30d65b453e555.zip
* fhandler_disk_file.cc (fhandler_disk_file::ftruncate): Use
NtQueryInformationFile instead of GetFileSize, NtFsControlFile instead of DeviceIoControl.
-rw-r--r--winsup/cygwin/ChangeLog6
-rw-r--r--winsup/cygwin/fhandler_disk_file.cc26
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,5 +1,11 @@
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>
+
* fhandler_disk_file.cc (fhandler_base::fstat_by_name): Use
RtlSplitUnicodePath.
(fhandler_disk_file::fstat): Rename oret to opened. Open file using NT
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,