ReactOS  0.4.13-dev-656-g74bcf30
diskspeed.c
Go to the documentation of this file.
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:
9  */
10 
11 #include <stdio.h>
12 #include <stdlib.h>
13 #define WIN32_NO_STATUS
14 #include <windows.h>
15 #define NTOS_MODE_USER
16 #include <ndk/ntndk.h>
17 
18 #define _NTSCSI_USER_MODE_
19 #include <ntddscsi.h>
20 #include <scsi.h>
21 
22 BOOL GetInquiryData(HANDLE hDevice, PINQUIRYDATA InquiryData)
23 {
24  BOOL Result;
25  DWORD dwReturned;
26  SCSI_ADDRESS ScsiAddress;
27  PSCSI_ADAPTER_BUS_INFO AdapterInfo;
28  PSCSI_INQUIRY_DATA InquiryBuffer;
29  BYTE Buffer[4096];
30  int i;
31 
32  Result = DeviceIoControl(hDevice,
34  NULL,
35  0,
36  &ScsiAddress,
37  sizeof(ScsiAddress),
38  &dwReturned,
39  FALSE);
40  if (Result == FALSE)
41  {
42  return FALSE;
43  }
44  Result = DeviceIoControl(hDevice,
46  NULL,
47  0,
48  Buffer,
49  sizeof(Buffer),
50  &dwReturned,
51  FALSE);
52  if (Result)
53  {
54  AdapterInfo = (PSCSI_ADAPTER_BUS_INFO)Buffer;
55  for (i = 0; i < AdapterInfo->NumberOfBuses; i++)
56  {
57  InquiryBuffer = (PSCSI_INQUIRY_DATA) (Buffer + AdapterInfo->BusData[i].InquiryDataOffset);
58  if (AdapterInfo->BusData[i].InquiryDataOffset)
59  {
60  while (1)
61  {
62  if (InquiryBuffer->PathId == ScsiAddress.PathId &&
63  InquiryBuffer->TargetId == ScsiAddress.TargetId &&
64  InquiryBuffer->Lun == ScsiAddress.Lun)
65  {
66  memcpy(InquiryData, InquiryBuffer->InquiryData, sizeof(INQUIRYDATA));
67  return TRUE;
68  }
69  if (InquiryBuffer->NextInquiryDataOffset == 0)
70  {
71  break;
72  }
73  InquiryBuffer = (PSCSI_INQUIRY_DATA) (Buffer + InquiryBuffer->NextInquiryDataOffset);
74  }
75  }
76  }
77  }
78  return FALSE;
79 }
80 
81 
82 
83 int main(void)
84 {
85  HANDLE hDevice;
86  OVERLAPPED ov;
87 
88  PBYTE Buffer = NULL ;
89  DWORD Start;
90  DWORD dwReturned;
91  DWORD dwReadTotal;
92  DWORD Size;
93  BOOL Result;
94  ULONG Drive;
95  CHAR Name[20];
96 
97  INQUIRYDATA InquiryData;
98 
99 
100  Drive = 0;
101  while (1)
102  {
103  sprintf(Name, "\\\\.\\PHYSICALDRIVE%ld", Drive);
104  hDevice = CreateFile(Name,
105  GENERIC_READ,
107  NULL,
109  0,
110  NULL);
111  if (hDevice == INVALID_HANDLE_VALUE)
112  {
113  if (Drive > 0)
114  {
115  VirtualFree(Buffer, 512 * 1024, MEM_RELEASE);
116  }
117  else
118  {
119  printf("Cannot open '%s'\n", Name);
120  }
121  break;
122  }
123  if (Drive == 0)
124  {
125  printf("Transfer Size (kB) 1 2 4 8 16 32 64 128 256\n");
126  printf("Transfer Rate (MB/s)\n");
127  printf("-------------------------------------------------------------------------------\n");
128 
130  }
131  Result = GetInquiryData(hDevice, &InquiryData);
132  if (Result)
133  {
134  printf("%.24s ", InquiryData.VendorId);
135  }
136  else
137  {
138  printf("Disk %ld ", Drive + 1);
139  }
140  Size = 1024;
141  memset(&ov, 0, sizeof(OVERLAPPED));
142  while (Size <= 256 * 1024)
143  {
144  memset(Buffer, 0, Size);
145  dwReadTotal = 0;
146 
147  Start = GetTickCount() + 2000;
148  while (Start > GetTickCount())
149  {
150  Result = ReadFile(hDevice, Buffer, Size, &dwReturned, &ov);
151  if (Result)
152  {
153  dwReadTotal += dwReturned;
154  ov.Offset += dwReturned;
155  }
156  }
157  dwReadTotal /= 2048;
158  printf("%3ld.%ld ", dwReadTotal / 1024, (dwReadTotal % 1024) * 10 / 1024);
159  Size *= 2;
160  }
161  printf("\n");
162  CloseHandle(hDevice);
163  Drive++;
164  }
165  printf("\n");
166 
167 
168  return 0;
169 }
UCHAR PathId
Definition: scsi_port.h:149
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
#define IOCTL_SCSI_GET_ADDRESS
Definition: scsi_port.h:52
char CHAR
Definition: xmlstorage.h:175
DWORD WINAPI GetTickCount(VOID)
Definition: time.c:445
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
ULONG NextInquiryDataOffset
Definition: scsi_port.h:118
UCHAR VendorId[8]
Definition: cdrw_hw.h:1132
DWORD Offset
Definition: winbase.h:787
#define MEM_COMMIT
Definition: nt_native.h:1313
UCHAR TargetId
Definition: scsi_port.h:150
#define FILE_SHARE_READ
Definition: compat.h:125
SCSI_BUS_DATA BusData[1]
Definition: scsi_port.h:106
#define sprintf(buf, format,...)
Definition: sprintf.c:55
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
LPVOID NTAPI VirtualAlloc(IN LPVOID lpAddress, IN SIZE_T dwSize, IN DWORD flAllocationType, IN DWORD flProtect)
Definition: virtmem.c:74
unsigned int BOOL
Definition: ntddk_ex.h:94
PWCHAR Drive
Definition: chkdsk.c:73
struct _SCSI_INQUIRY_DATA * PSCSI_INQUIRY_DATA
smooth NULL
Definition: ftsmooth.c:416
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
Definition: bufpool.h:45
ULONG InquiryDataOffset
Definition: scsi_port.h:98
#define OPEN_EXISTING
Definition: compat.h:426
int main(void)
Definition: diskspeed.c:83
unsigned long DWORD
Definition: ntddk_ex.h:95
Definition: partlist.h:33
BOOL GetInquiryData(HANDLE hDevice, PINQUIRYDATA InquiryData)
Definition: diskspeed.c:22
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
unsigned char BYTE
Definition: mem.h:68
#define GENERIC_READ
Definition: compat.h:124
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
UCHAR InquiryData[1]
Definition: scsi_port.h:119
#define IOCTL_SCSI_GET_INQUIRY_DATA
Definition: scsi_port.h:49
BOOL WINAPI DeviceIoControl(IN HANDLE hDevice, IN DWORD dwIoControlCode, IN LPVOID lpInBuffer OPTIONAL, IN DWORD nInBufferSize OPTIONAL, OUT LPVOID lpOutBuffer OPTIONAL, IN DWORD nOutBufferSize OPTIONAL, OUT LPDWORD lpBytesReturned OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: deviceio.c:136
IN OUT PVCB OUT PDIRENT OUT PBCB IN BOOLEAN CreateFile
Definition: fatprocs.h:904
#define MEM_RELEASE
Definition: nt_native.h:1316
unsigned int ULONG
Definition: retypes.h:1
BOOL NTAPI VirtualFree(IN LPVOID lpAddress, IN SIZE_T dwSize, IN DWORD dwFreeType)
Definition: virtmem.c:128
struct _SCSI_ADAPTER_BUS_INFO * PSCSI_ADAPTER_BUS_INFO
BOOL WINAPI ReadFile(IN HANDLE hFile, IN LPVOID lpBuffer, IN DWORD nNumberOfBytesToRead, OUT LPDWORD lpNumberOfBytesRead OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:123
#define memset(x, y, z)
Definition: compat.h:39
BYTE * PBYTE
Definition: pedump.c:66
#define printf
Definition: config.h:203
#define PAGE_READWRITE
Definition: nt_native.h:1304