diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2005-12-07 20:32:27 +0000 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2005-12-07 20:32:27 +0000 |
commit | c09178b052512d51998d03b1a26991192d239ac5 (patch) | |
tree | b7178dd27d8ada3e2ddc484ed54695898674ba0c | |
parent | 14d2d90cff23b33dc889a551ae1cc929311495fa (diff) | |
download | newlib-c09178b052512d51998d03b1a26991192d239ac5.zip newlib-c09178b052512d51998d03b1a26991192d239ac5.tar.gz newlib-c09178b052512d51998d03b1a26991192d239ac5.tar.bz2 |
* fhandler_proc.cc (format_proc_partitions): Use modern IOCTLs
to determine drive size as far as possible.
-rw-r--r-- | winsup/cygwin/ChangeLog | 5 | ||||
-rw-r--r-- | winsup/cygwin/fhandler_proc.cc | 59 |
2 files changed, 43 insertions, 21 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 27b677b..d96be78 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,5 +1,10 @@ 2005-12-07 Corinna Vinschen <corinna@vinschen.de> + * fhandler_proc.cc (format_proc_partitions): Use modern IOCTLs + to determine drive size as far as possible. + +2005-12-07 Corinna Vinschen <corinna@vinschen.de> + * fhandler_raw.cc (fhandler_dev_raw::ioctl): Fix INVALID_PARAMETER condition. Only copy devbuf to buf if buf is non-NULL. diff --git a/winsup/cygwin/fhandler_proc.cc b/winsup/cygwin/fhandler_proc.cc index c34150d..af603ad 100644 --- a/winsup/cygwin/fhandler_proc.cc +++ b/winsup/cygwin/fhandler_proc.cc @@ -951,13 +951,9 @@ format_proc_partitions (char *destbuf, size_t maxsize) CHAR szDriveName[CYG_MAX_PATH]; __small_sprintf (szDriveName, "\\\\.\\PHYSICALDRIVE%d", drive_number); HANDLE hDevice; - hDevice = CreateFile (szDriveName, - GENERIC_READ, + hDevice = CreateFile (szDriveName, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, - OPEN_EXISTING, - 0, - NULL); + NULL, OPEN_EXISTING, 0, NULL); if (hDevice == INVALID_HANDLE_VALUE) { if (GetLastError () == ERROR_PATH_NOT_FOUND) @@ -968,27 +964,48 @@ format_proc_partitions (char *destbuf, size_t maxsize) } else { - DWORD dwBytesReturned, dwRetCode; - DISK_GEOMETRY dg; - dwRetCode = DeviceIoControl (hDevice, - IOCTL_DISK_GET_DRIVE_GEOMETRY, - NULL, - 0, - &dg, - sizeof (dg), - &dwBytesReturned, - NULL); - if (!dwRetCode) + DWORD dwBytesReturned; + /* Use a buffer since some ioctl buffers aren't fixed size. */ + char buf[256]; + PARTITION_INFORMATION *pi = NULL; + PARTITION_INFORMATION_EX *pix = NULL; + DISK_GEOMETRY *dg = NULL; + unsigned long long drive_size; + + if (wincap.has_disk_ex_ioctls () + && DeviceIoControl (hDevice, IOCTL_DISK_GET_PARTITION_INFO_EX, + NULL, 0, buf, 256, &dwBytesReturned, + NULL)) + { + pix = (PARTITION_INFORMATION_EX *) buf; + drive_size = pix->PartitionLength.QuadPart; + } + else if (DeviceIoControl (hDevice, IOCTL_DISK_GET_PARTITION_INFO, + NULL, 0, buf, 256, &dwBytesReturned, + NULL)) + { + pi = (PARTITION_INFORMATION *) buf; + drive_size = pi->PartitionLength.QuadPart; + } + else if (DeviceIoControl (hDevice, IOCTL_DISK_GET_DRIVE_GEOMETRY, + NULL, 0, buf, 256, &dwBytesReturned, + NULL)) + { + dg = (DISK_GEOMETRY *) buf; + drive_size = (unsigned long long) dg->Cylinders.QuadPart + * dg->TracksPerCylinder + * dg->SectorsPerTrack + * dg->BytesPerSector; + } + if (!pi && !pix && !dg) debug_printf ("DeviceIoControl %E"); else { device dev; dev.parsedisk (drive_number, 0); bufptr += __small_sprintf (bufptr, "%5d %5d %9U %s\n", - dev.major, - dev.minor, - (long long)((dg.Cylinders.QuadPart * dg.TracksPerCylinder * - dg.SectorsPerTrack * dg.BytesPerSector) >> 10), + dev.major, dev.minor, + drive_size >> 10, dev.name + 5); } size_t buf_size = 8192; |