* fhandler_proc.cc (format_proc_partitions): Use modern IOCTLs

to determine drive size as far as possible.
This commit is contained in:
Corinna Vinschen 2005-12-07 20:32:27 +00:00
parent 14d2d90cff
commit c09178b052
2 changed files with 43 additions and 21 deletions

View File

@ -1,3 +1,8 @@
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> 2005-12-07 Corinna Vinschen <corinna@vinschen.de>
* fhandler_raw.cc (fhandler_dev_raw::ioctl): Fix INVALID_PARAMETER * fhandler_raw.cc (fhandler_dev_raw::ioctl): Fix INVALID_PARAMETER

View File

@ -951,13 +951,9 @@ format_proc_partitions (char *destbuf, size_t maxsize)
CHAR szDriveName[CYG_MAX_PATH]; CHAR szDriveName[CYG_MAX_PATH];
__small_sprintf (szDriveName, "\\\\.\\PHYSICALDRIVE%d", drive_number); __small_sprintf (szDriveName, "\\\\.\\PHYSICALDRIVE%d", drive_number);
HANDLE hDevice; HANDLE hDevice;
hDevice = CreateFile (szDriveName, hDevice = CreateFile (szDriveName, GENERIC_READ,
GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, NULL, OPEN_EXISTING, 0, NULL);
OPEN_EXISTING,
0,
NULL);
if (hDevice == INVALID_HANDLE_VALUE) if (hDevice == INVALID_HANDLE_VALUE)
{ {
if (GetLastError () == ERROR_PATH_NOT_FOUND) if (GetLastError () == ERROR_PATH_NOT_FOUND)
@ -968,27 +964,48 @@ format_proc_partitions (char *destbuf, size_t maxsize)
} }
else else
{ {
DWORD dwBytesReturned, dwRetCode; DWORD dwBytesReturned;
DISK_GEOMETRY dg; /* Use a buffer since some ioctl buffers aren't fixed size. */
dwRetCode = DeviceIoControl (hDevice, char buf[256];
IOCTL_DISK_GET_DRIVE_GEOMETRY, PARTITION_INFORMATION *pi = NULL;
NULL, PARTITION_INFORMATION_EX *pix = NULL;
0, DISK_GEOMETRY *dg = NULL;
&dg, unsigned long long drive_size;
sizeof (dg),
&dwBytesReturned, if (wincap.has_disk_ex_ioctls ()
NULL); && DeviceIoControl (hDevice, IOCTL_DISK_GET_PARTITION_INFO_EX,
if (!dwRetCode) 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"); debug_printf ("DeviceIoControl %E");
else else
{ {
device dev; device dev;
dev.parsedisk (drive_number, 0); dev.parsedisk (drive_number, 0);
bufptr += __small_sprintf (bufptr, "%5d %5d %9U %s\n", bufptr += __small_sprintf (bufptr, "%5d %5d %9U %s\n",
dev.major, dev.major, dev.minor,
dev.minor, drive_size >> 10,
(long long)((dg.Cylinders.QuadPart * dg.TracksPerCylinder *
dg.SectorsPerTrack * dg.BytesPerSector) >> 10),
dev.name + 5); dev.name + 5);
} }
size_t buf_size = 8192; size_t buf_size = 8192;