Merge 12735:15568 from xmlbuildsystem branch
[reactos.git] / rosapps / tests / diskspeed / diskspeed.c
1 /*
2 * Copyright (C) 2004 ReactOS Team
3 *
4 * COPYRIGHT: See COPYING in the top level directory
5 * PROJECT: ReactOS diskspeed.exe
6 * FILE: apps/tests/diskspeed/diskspeed.c
7 * PURPOSE: Determines disk transfer rates
8 * PROGRAMMER: Hartmut Birr
9 */
10
11 #include <windows.h>
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <ddk/ntddk.h>
15 #include <ddk/ntddscsi.h>
16 #include <ddk/scsi.h>
17
18 BOOL GetInquiryData(HANDLE hDevice, PINQUIRYDATA InquiryData)
19 {
20 BOOL Result;
21 DWORD dwReturned;
22 SCSI_ADDRESS ScsiAddress;
23 PSCSI_ADAPTER_BUS_INFO AdapterInfo;
24 PSCSI_INQUIRY_DATA InquiryBuffer;
25 BYTE Buffer[4096];
26 int i;
27
28 Result = DeviceIoControl(hDevice,
29 IOCTL_SCSI_GET_ADDRESS,
30 NULL,
31 0,
32 &ScsiAddress,
33 sizeof(ScsiAddress),
34 &dwReturned,
35 FALSE);
36 if (Result == FALSE)
37 {
38 return FALSE;
39 }
40 Result = DeviceIoControl(hDevice,
41 IOCTL_SCSI_GET_INQUIRY_DATA,
42 NULL,
43 0,
44 Buffer,
45 sizeof(Buffer),
46 &dwReturned,
47 FALSE);
48 if (Result)
49 {
50 AdapterInfo = (PSCSI_ADAPTER_BUS_INFO)Buffer;
51 for (i = 0; i < AdapterInfo->NumberOfBuses; i++)
52 {
53 InquiryBuffer = (PSCSI_INQUIRY_DATA) (Buffer + AdapterInfo->BusData[i].InquiryDataOffset);
54 if (AdapterInfo->BusData[i].InquiryDataOffset)
55 {
56 while (1)
57 {
58 if (InquiryBuffer->PathId == ScsiAddress.PathId &&
59 InquiryBuffer->TargetId == ScsiAddress.TargetId &&
60 InquiryBuffer->Lun == ScsiAddress.Lun)
61 {
62 memcpy(InquiryData, InquiryBuffer->InquiryData, sizeof(INQUIRYDATA));
63 return TRUE;
64 }
65 if (InquiryBuffer->NextInquiryDataOffset == 0)
66 {
67 break;
68 }
69 InquiryBuffer = (PSCSI_INQUIRY_DATA) (Buffer + InquiryBuffer->NextInquiryDataOffset);
70 }
71 }
72 }
73 }
74 return FALSE;
75 }
76
77
78
79 int main(void)
80 {
81 HANDLE hDevice;
82 OVERLAPPED ov;
83
84 PBYTE Buffer = NULL ;
85 DWORD Start;
86 DWORD dwReturned;
87 DWORD dwReadTotal;
88 DWORD Size;
89 BOOL Result;
90 ULONG Drive;
91 CHAR Name[20];
92
93 INQUIRYDATA InquiryData;
94
95
96 Drive = 0;
97 while (1)
98 {
99 sprintf(Name, "\\\\.\\PHYSICALDRIVE%ld", Drive);
100 hDevice = CreateFile(Name,
101 GENERIC_READ,
102 FILE_SHARE_READ,
103 NULL,
104 OPEN_EXISTING,
105 0,
106 NULL);
107 if (hDevice == INVALID_HANDLE_VALUE)
108 {
109 if (Drive > 0)
110 {
111 VirtualFree(Buffer, 512 * 1024, MEM_RELEASE);
112 }
113 else
114 {
115 printf("Cannot open '%s'\n", Name);
116 }
117 break;
118 }
119 if (Drive == 0)
120 {
121 printf("Transfer Size (kB) 1 2 4 8 16 32 64 128 256\n");
122 printf("Transfer Rate (MB/s)\n");
123 printf("-------------------------------------------------------------------------------\n");
124
125 Buffer = VirtualAlloc(NULL, 512 * 1024, MEM_COMMIT, PAGE_READWRITE);
126 }
127 Result = GetInquiryData(hDevice, &InquiryData);
128 if (Result)
129 {
130 printf("%.24s ", InquiryData.VendorId);
131 }
132 else
133 {
134 printf("Disk %ld ", Drive + 1);
135 }
136 Size = 1024;
137 memset(&ov, 0, sizeof(OVERLAPPED));
138 while (Size <= 256 * 1024)
139 {
140 memset(Buffer, 0, Size);
141 dwReadTotal = 0;
142
143 Start = GetTickCount() + 2000;
144 while (Start > GetTickCount())
145 {
146 Result = ReadFile(hDevice, Buffer, Size, &dwReturned, &ov);
147 if (Result)
148 {
149 dwReadTotal += dwReturned;
150 ov.Offset += dwReturned;
151 }
152 }
153 dwReadTotal /= 2048;
154 printf("%3ld.%ld ", dwReadTotal / 1024, (dwReadTotal % 1024) * 10 / 1024);
155 Size *= 2;
156 }
157 printf("\n");
158 CloseHandle(hDevice);
159 Drive++;
160 }
161 printf("\n");
162
163
164 return 0;
165 }