diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2005-12-07 23:32:27 +0300 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2005-12-07 23:32:27 +0300 |
commit | c09178b052512d51998d03b1a26991192d239ac5 (patch) | |
tree | b7178dd27d8ada3e2ddc484ed54695898674ba0c /winsup/cygwin/fhandler_proc.cc | |
parent | 14d2d90cff23b33dc889a551ae1cc929311495fa (diff) |
* fhandler_proc.cc (format_proc_partitions): Use modern IOCTLs
to determine drive size as far as possible.
Diffstat (limited to 'winsup/cygwin/fhandler_proc.cc')
-rw-r--r-- | winsup/cygwin/fhandler_proc.cc | 59 |
1 files changed, 38 insertions, 21 deletions
diff --git a/winsup/cygwin/fhandler_proc.cc b/winsup/cygwin/fhandler_proc.cc index c34150dc9..af603ade2 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; |