-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
586 lines (536 loc) · 21.5 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
//#include <iostream>
//
//int main() {
// std::cout << "Hello, World!" << std::endl;
// return 0;
//}
// DiskInfo.cpp : Defines the entry point for the console application.
//
#include <tchar.h>
#include <cstdio>
#include <cstdlib>
#include <windows.h>
#include <winioctl.h>
#include <cstddef>
#include <memory.h>
#define IOCTL_STORAGE_QUERY_PROPERTY CTL_CODE(IOCTL_STORAGE_BASE, 0x0500, METHOD_BUFFERED, FILE_ANY_ACCESS)
typedef struct _IDENTIFY_DEVICE {
WORD GeneralConfiguration; //0
WORD LogicalCylinders; //1 Obsolete
WORD SpecificConfiguration; //2
WORD LogicalHeads; //3 Obsolete
WORD Retired1[2]; //4-5
WORD LogicalSectors; //6 Obsolete
DWORD ReservedForCompactFlash; //7-8
WORD Retired2; //9
CHAR SerialNumber[20]; //10-19
WORD Retired3; //20
WORD BufferSize; //21 Obsolete
// WORD Obsolute4; //22
CHAR FirmwareRev[8]; //23-26
CHAR Model[40]; //27-46
WORD MaxNumPerInterupt; //47
WORD Reserved1; //48
WORD Capabilities1; //49
WORD Capabilities2; //50
DWORD Obsolute5; //51-52
WORD Field88and7064; //53
WORD Obsolute6[5]; //54-58
WORD MultSectorStuff; //59
DWORD TotalAddressableSectors; //60-61
WORD Obsolute7; //62
WORD MultiWordDma; //63
WORD PioMode; //64
WORD MinMultiwordDmaCycleTime; //65
WORD RecommendedMultiwordDmaCycleTime; //66
WORD MinPioCycleTimewoFlowCtrl; //67
WORD MinPioCycleTimeWithFlowCtrl; //68
WORD Reserved2[6]; //69-74
WORD QueueDepth; //75
WORD SerialAtaCapabilities; //76
WORD SerialAtaAdditionalCapabilities; //77
WORD SerialAtaFeaturesSupported; //78
WORD SerialAtaFeaturesEnabled; //79
WORD MajorVersion; //80
WORD MinorVersion; //81
WORD CommandSetSupported1; //82
WORD CommandSetSupported2; //83
WORD CommandSetSupported3; //84
WORD CommandSetEnabled1; //85
WORD CommandSetEnabled2; //86
WORD CommandSetDefault; //87
WORD UltraDmaMode; //88
WORD TimeReqForSecurityErase; //89
WORD TimeReqForEnhancedSecure; //90
WORD CurrentPowerManagement; //91
WORD MasterPasswordRevision; //92
WORD HardwareResetResult; //93
WORD AcoustricManagement; //94
WORD StreamMinRequestSize; //95
WORD StreamingTimeDma; //96
WORD StreamingAccessLatency; //97
DWORD StreamingPerformance; //98-99
ULONGLONG MaxUserLba; //100-103
WORD StremingTimePio; //104
WORD Reserved3; //105
WORD SectorSize; //106
WORD InterSeekDelay; //107
WORD IeeeOui; //108
WORD UniqueId3; //109
WORD UniqueId2; //110
WORD UniqueId1; //111
WORD Reserved4[4]; //112-115
WORD Reserved5; //116
DWORD WordsPerLogicalSector; //117-118
WORD Reserved6[8]; //119-126
WORD RemovableMediaStatus; //127
WORD SecurityStatus; //128
WORD VendorSpecific[31]; //129-159
WORD CfaPowerMode1; //160
WORD ReservedForCompactFlashAssociation[7]; //161-167
WORD DeviceNominalFormFactor; //168
WORD DataSetManagement; //169
WORD AdditionalProductIdentifier[4]; //170-173
WORD Reserved7[2]; //174-175
CHAR CurrentMediaSerialNo[60]; //176-205
WORD SctCommandTransport; //206
WORD ReservedForCeAta1[2]; //207-208
WORD AlignmentOfLogicalBlocks; //209
DWORD WriteReadVerifySectorCountMode3; //210-211
DWORD WriteReadVerifySectorCountMode2; //212-213
WORD NvCacheCapabilities; //214
DWORD NvCacheSizeLogicalBlocks; //215-216
WORD NominalMediaRotationRate; //217
WORD Reserved8; //218
WORD NvCacheOptions1; //219
WORD NvCacheOptions2; //220
WORD Reserved9; //221
WORD TransportMajorVersionNumber; //222
WORD TransportMinorVersionNumber; //223
WORD ReservedForCeAta2[10]; //224-233
WORD MinimumBlocksPerDownloadMicrocode; //234
WORD MaximumBlocksPerDownloadMicrocode; //235
WORD Reserved10[19]; //236-254
WORD IntegrityWord; //255
} IDENTIFY_DEVICE;
typedef enum _COMMAND_TYPE {
CMD_TYPE_PHYSICAL_DRIVE = 0,
CMD_TYPE_SCSI_MINIPORT,
CMD_TYPE_SILICON_IMAGE,
CMD_TYPE_SAT, // SAT = SCSI_ATA_TRANSLATION
CMD_TYPE_SUNPLUS,
CMD_TYPE_IO_DATA,
CMD_TYPE_LOGITEC,
CMD_TYPE_JMICRON,
CMD_TYPE_CYPRESS,
CMD_TYPE_PROLIFIC, // Not imprement
CMD_TYPE_CSMI, // CSMI = Common Storage Management Interface
CMD_TYPE_CSMI_PHYSICAL_DRIVE, // CSMI = Common Storage Management Interface
CMD_TYPE_WMI,
CMD_TYPE_DEBUG
} COMMAND_TYPE;
// retrieve the properties of a storage device or adapter.
/*
typedef enum _STORAGE_QUERY_TYPE {
PropertyStandardQuery = 0,
PropertyExistsQuery,
PropertyMaskQuery,
PropertyQueryMaxDefined
} STORAGE_QUERY_TYPE, *PSTORAGE_QUERY_TYPE;
// retrieve the properties of a storage device or adapter.
typedef struct _STORAGE_PROPERTY_QUERY {
STORAGE_PROPERTY_ID PropertyId;
STORAGE_QUERY_TYPE QueryType;
UCHAR AdditionalParameters[1];
} STORAGE_PROPERTY_QUERY, *PSTORAGE_PROPERTY_QUERY;
*/
#define FILE_DEVICE_SCSI 0x0000001b
#define IOCTL_SCSI_MINIPORT_IDENTIFY ((FILE_DEVICE_SCSI << 16) + 0x0501)
#define IOCTL_SCSI_MINIPORT_READ_SMART_ATTRIBS ((FILE_DEVICE_SCSI << 16) + 0x0502)
#define IOCTL_SCSI_MINIPORT_READ_SMART_THRESHOLDS ((FILE_DEVICE_SCSI << 16) + 0x0503)
#define IOCTL_SCSI_MINIPORT_ENABLE_SMART ((FILE_DEVICE_SCSI << 16) + 0x0504)
#define IOCTL_SCSI_MINIPORT_DISABLE_SMART ((FILE_DEVICE_SCSI << 16) + 0x0505)
#define IOCTL_SCSI_BASE FILE_DEVICE_CONTROLLER
#define IOCTL_SCSI_PASS_THROUGH CTL_CODE(IOCTL_SCSI_BASE, 0x0401, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
//
// Define values for pass-through DataIn field.
//
#define SCSI_IOCTL_DATA_OUT 0
#define SCSI_IOCTL_DATA_IN 1
#define SCSI_IOCTL_DATA_UNSPECIFIED 2
//
// Define the SCSI pass through structure.
//
typedef struct _SCSI_PASS_THROUGH {
USHORT Length;
UCHAR ScsiStatus;
UCHAR PathId;
UCHAR TargetId;
UCHAR Lun;
UCHAR CdbLength;
UCHAR SenseInfoLength;
UCHAR DataIn;
ULONG DataTransferLength;
ULONG TimeOutValue;
ULONG_PTR DataBufferOffset;
ULONG SenseInfoOffset;
UCHAR Cdb[16];
} SCSI_PASS_THROUGH, *PSCSI_PASS_THROUGH;
typedef struct _SCSI_PASS_THROUGH_WITH_BUFFERS {
SCSI_PASS_THROUGH Spt;
ULONG Filler; // realign buffers to double word boundary
UCHAR SenseBuf[32];
UCHAR DataBuf[512];
} SCSI_PASS_THROUGH_WITH_BUFFERS, *PSCSI_PASS_THROUGH_WITH_BUFFERS;
static void dump_buffer(const char *title, const unsigned char *buffer, int len) {
int i = 0;
int j;
printf("\n-- %s --\n", title);
if (len > 0) {
printf("%8.8s ", " ");
for (j = 0; j < 16; ++j) {
printf(" %2X", j);
}
printf(" ");
for (j = 0; j < 16; ++j) {
printf("%1X", j);
}
printf("\n");
}
while (i < len) {
printf("%08x ", i);
for (j = 0; j < 16; ++j) {
if ((i + j) < len)
printf(" %02x", (int) buffer[i + j]);
else
printf(" ");
}
printf(" ");
for (j = 0; j < 16; ++j) {
if ((i + j) < len)
printf("%c", isprint(buffer[i + j]) ? buffer[i + j] : '.');
else
printf(" ");
}
printf("\n");
i += 16;
}
printf("-- DONE --\n");
}
void ChangeByteOrder(PCHAR szString, USHORT uscStrSize) {
USHORT i;
CHAR temp;
for (i = 0; i < uscStrSize; i += 2) {
temp = szString[i];
szString[i] = szString[i + 1];
szString[i + 1] = temp;
}
}
BOOL DoIdentifyDeviceSat(HANDLE physicalDriveId, BYTE target, IDENTIFY_DEVICE *data, COMMAND_TYPE type) {
BOOL bRet;
HANDLE hIoCtrl;
DWORD dwReturned;
DWORD length;
SCSI_PASS_THROUGH_WITH_BUFFERS sptwb;
if (data == NULL) {
printf("Data\n");
return FALSE;
}
ZeroMemory(data, sizeof(IDENTIFY_DEVICE));
hIoCtrl = physicalDriveId;
if (hIoCtrl == INVALID_HANDLE_VALUE) {
printf("Handle\n");
return FALSE;
}
ZeroMemory(&sptwb, sizeof(SCSI_PASS_THROUGH_WITH_BUFFERS));
sptwb.Spt.Length = sizeof(SCSI_PASS_THROUGH);
sptwb.Spt.PathId = 0;
sptwb.Spt.TargetId = 0;
sptwb.Spt.Lun = 0;
sptwb.Spt.SenseInfoLength = 24;
sptwb.Spt.DataIn = SCSI_IOCTL_DATA_IN;
sptwb.Spt.DataTransferLength = IDENTIFY_BUFFER_SIZE;
sptwb.Spt.TimeOutValue = 2;
sptwb.Spt.DataBufferOffset = offsetof(SCSI_PASS_THROUGH_WITH_BUFFERS, DataBuf);
sptwb.Spt.SenseInfoOffset = offsetof(SCSI_PASS_THROUGH_WITH_BUFFERS, SenseBuf);
if (type == CMD_TYPE_SAT) {
sptwb.Spt.CdbLength = 12;
sptwb.Spt.Cdb[0] = 0xA1;//ATA PASS THROUGH(12) OPERATION CODE(A1h)
sptwb.Spt.Cdb[1] = (4 << 1) | 0; //MULTIPLE_COUNT=0,PROTOCOL=4(PIO Data-In),Reserved
sptwb.Spt.Cdb[2] =
(1 << 3) | (1 << 2) | 2;//OFF_LINE=0,CK_COND=0,Reserved=0,T_DIR=1(ToDevice),BYTE_BLOCK=1,T_LENGTH=2
sptwb.Spt.Cdb[3] = 0;//FEATURES (7:0)
sptwb.Spt.Cdb[4] = 1;//SECTOR_COUNT (7:0)
sptwb.Spt.Cdb[5] = 0;//LBA_LOW (7:0)
sptwb.Spt.Cdb[6] = 0;//LBA_MID (7:0)
sptwb.Spt.Cdb[7] = 0;//LBA_HIGH (7:0)
sptwb.Spt.Cdb[8] = target;
sptwb.Spt.Cdb[9] = 0xEC;//COMMAND
} else if (type == CMD_TYPE_SUNPLUS) {
sptwb.Spt.CdbLength = 12;
sptwb.Spt.Cdb[0] = 0xF8;
sptwb.Spt.Cdb[1] = 0x00;
sptwb.Spt.Cdb[2] = 0x22;
sptwb.Spt.Cdb[3] = 0x10;
sptwb.Spt.Cdb[4] = 0x01;
sptwb.Spt.Cdb[5] = 0x00;
sptwb.Spt.Cdb[6] = 0x01;
sptwb.Spt.Cdb[7] = 0x00;
sptwb.Spt.Cdb[8] = 0x00;
sptwb.Spt.Cdb[9] = 0x00;
sptwb.Spt.Cdb[10] = target;
sptwb.Spt.Cdb[11] = 0xEC; // ID_CMD
} else if (type == CMD_TYPE_IO_DATA) {
sptwb.Spt.CdbLength = 12;
sptwb.Spt.Cdb[0] = 0xE3;
sptwb.Spt.Cdb[1] = 0x00;
sptwb.Spt.Cdb[2] = 0x00;
sptwb.Spt.Cdb[3] = 0x01;
sptwb.Spt.Cdb[4] = 0x01;
sptwb.Spt.Cdb[5] = 0x00;
sptwb.Spt.Cdb[6] = 0x00;
sptwb.Spt.Cdb[7] = target;
sptwb.Spt.Cdb[8] = 0xEC; // ID_CMD
sptwb.Spt.Cdb[9] = 0x00;
sptwb.Spt.Cdb[10] = 0x00;
sptwb.Spt.Cdb[11] = 0x00;
} else if (type == CMD_TYPE_LOGITEC) {
sptwb.Spt.CdbLength = 10;
sptwb.Spt.Cdb[0] = 0xE0;
sptwb.Spt.Cdb[1] = 0x00;
sptwb.Spt.Cdb[2] = 0x00;
sptwb.Spt.Cdb[3] = 0x00;
sptwb.Spt.Cdb[4] = 0x00;
sptwb.Spt.Cdb[5] = 0x00;
sptwb.Spt.Cdb[6] = 0x00;
sptwb.Spt.Cdb[7] = target;
sptwb.Spt.Cdb[8] = 0xEC; // ID_CMD
sptwb.Spt.Cdb[9] = 0x4C;
} else if (type == CMD_TYPE_JMICRON) {
sptwb.Spt.CdbLength = 12;
sptwb.Spt.Cdb[0] = 0xDF;
sptwb.Spt.Cdb[1] = 0x10;
sptwb.Spt.Cdb[2] = 0x00;
sptwb.Spt.Cdb[3] = 0x02;
sptwb.Spt.Cdb[4] = 0x00;
sptwb.Spt.Cdb[5] = 0x00;
sptwb.Spt.Cdb[6] = 0x01;
sptwb.Spt.Cdb[7] = 0x00;
sptwb.Spt.Cdb[8] = 0x00;
sptwb.Spt.Cdb[9] = 0x00;
sptwb.Spt.Cdb[10] = target;
sptwb.Spt.Cdb[11] = 0xEC; // ID_CMD
} else if (type == CMD_TYPE_CYPRESS) {
sptwb.Spt.CdbLength = 16;
sptwb.Spt.Cdb[0] = 0x24;
sptwb.Spt.Cdb[1] = 0x24;
sptwb.Spt.Cdb[2] = 0x00;
sptwb.Spt.Cdb[3] = 0xBE;
sptwb.Spt.Cdb[4] = 0x01;
sptwb.Spt.Cdb[5] = 0x00;
sptwb.Spt.Cdb[6] = 0x00;
sptwb.Spt.Cdb[7] = 0x01;
sptwb.Spt.Cdb[8] = 0x00;
sptwb.Spt.Cdb[9] = 0x00;
sptwb.Spt.Cdb[10] = 0x00;
sptwb.Spt.Cdb[11] = target;
sptwb.Spt.Cdb[12] = 0xEC; // ID_CMD
sptwb.Spt.Cdb[13] = 0x00;
sptwb.Spt.Cdb[14] = 0x00;
sptwb.Spt.Cdb[15] = 0x00;
} else {
return FALSE;
}
length = offsetof(SCSI_PASS_THROUGH_WITH_BUFFERS, DataBuf) + sptwb.Spt.DataTransferLength;
bRet = DeviceIoControl(hIoCtrl, IOCTL_SCSI_PASS_THROUGH,
&sptwb, sizeof(SCSI_PASS_THROUGH),
&sptwb, length, &dwReturned, NULL);
CloseHandle(hIoCtrl);
if (bRet == FALSE || dwReturned != length) {
return FALSE;
}
memcpy(data, sptwb.DataBuf, sizeof(IDENTIFY_DEVICE));
return TRUE;
}
/******************************************************************************
* Function: get disk's physical number from its drive letter
* e.g. C-->0 (C: is on disk0)
* input: letter, drive letter
* output: N/A
* return: Succeed, disk number
* Fail, -1
******************************************************************************/
DWORD GetPhysicalDriveFromPartitionLetter(CHAR letter)
{
HANDLE hDevice; // handle to the drive to be examined
BOOL result; // results flag
DWORD readed; // discard results
STORAGE_DEVICE_NUMBER number; //use this to get disk numbers
CHAR path[4096];
sprintf(path, "\\\\.\\%c:", letter);
hDevice = CreateFile(path, // drive to open
GENERIC_READ | GENERIC_WRITE, // access to the drive
FILE_SHARE_READ | FILE_SHARE_WRITE, //share mode
NULL, // default security attributes
OPEN_EXISTING, // disposition
0, // file attributes
NULL); // do not copy file attribute
if (hDevice == INVALID_HANDLE_VALUE) // cannot open the drive
{
fprintf(stderr, "CreateFile() Error: %ld\n", GetLastError());
return DWORD(-1);
}
result = DeviceIoControl(
hDevice, // handle to device
IOCTL_STORAGE_GET_DEVICE_NUMBER, // dwIoControlCode
NULL, // lpInBuffer
0, // nInBufferSize
&number, // output buffer
sizeof(number), // size of output buffer
&readed, // number of bytes returned
NULL // OVERLAPPED structure
);
if (!result) // fail
{
fprintf(stderr, "IOCTL_STORAGE_GET_DEVICE_NUMBER Error: %ld\n", GetLastError());
(void)CloseHandle(hDevice);
return (DWORD)-1;
}
//printf("%d %d %d\n\n", number.DeviceType, number.DeviceNumber, number.PartitionNumber);
(void)CloseHandle(hDevice);
return number.DeviceNumber;
}
/*DWORD GetSystemDiskPhysicalNumber(void)
{
CHAR sysPath[DISK_PATH_LEN];
CHAR diskLetter;
DWORD diskNumber;
DWORD ret = GetSystemDirectory(sysPath, sizeof(sysPath));
if (ret == 0)
{
fprintf(stderr, "GetSystemDirectory() Error: %ld\n", GetLastError());
return (DWORD)-1;
}
diskLetter = sysPath[0];
diskNumber = GetPhysicalDriveFromPartitionLetter(diskLetter);
return diskNumber;
}*/
int main(int argc, char *argv[]) {
HANDLE hDevice = NULL;
STORAGE_PROPERTY_QUERY sQuery;
STORAGE_DEVICE_DESCRIPTOR *pDescriptor;
char *model, *firmware, *serialnumber;
char usb_hdd_model[41], usb_hdd_firmware[9], usb_hdd_Serialnumber[21];
IDENTIFY_DEVICE identify = {0};
char pcbData[4096];
int dwLen = 4096;
DWORD dwRet;
BOOL bRet;
char diskLetter[1];
char deviceNumber[1];
char deviceName[19] = "\\\\.\\PhysicalDrive3";
// 空判
if (argv[1] == NULL) {
return -1;
};
// copy 到变量
strcpy(diskLetter, argv[1]);
DWORD diskNumber ;
diskNumber = GetPhysicalDriveFromPartitionLetter(diskLetter[0]);
if (diskNumber == NULL && diskNumber!=0) {
printf("Number Not Found");
return -1;
};
deviceNumber[0] = CHAR(UINT(diskNumber+48));
printf(deviceNumber);
// deviceNumber[0] = LOBYTE(diskNumber);
// 连接string
deviceName[17]= CHAR(UINT(diskNumber+48));// deviceNumber[0];
// deviceName[17]= CHAR(diskNumber);// deviceNumber[0];
printf( diskLetter);
printf("\r\n");
printf( deviceNumber);
printf("\r\n");
printf(deviceName);
printf("\r\n");
// hDevice = CreateFileA(deviceName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
hDevice = CreateFileA(deviceName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
OPEN_EXISTING, 0, NULL);
// 如果没有管理员权限会抱错 2020.1
if (hDevice == INVALID_HANDLE_VALUE) {
printf("NEED SUPER ADMIN");
// fprintf(stderr, "CreateFile()\n");
exit(1);
}
memset(pcbData, 0, 4096);
sQuery.PropertyId = StorageDeviceProperty;
sQuery.QueryType = PropertyStandardQuery;
bRet = DeviceIoControl(hDevice, IOCTL_STORAGE_QUERY_PROPERTY, &sQuery, sizeof(STORAGE_PROPERTY_QUERY), pcbData,
dwLen, &dwRet, NULL);
if (bRet) {
pDescriptor = (STORAGE_DEVICE_DESCRIPTOR *) pcbData;
if (pDescriptor->BusType == BusTypeUsb) {
printf("USB-Type\n");
}
if (pDescriptor->ProductIdOffset) {
model = (char *) pDescriptor + pDescriptor->ProductIdOffset;
printf("Model: %s\n", model);
}
if (pDescriptor->ProductRevisionOffset) {
firmware = (char *) pDescriptor + pDescriptor->ProductRevisionOffset;
printf("Firmware: %s\n", firmware);
}
if (pDescriptor->SerialNumberOffset) {
serialnumber = (char *) pDescriptor + pDescriptor->SerialNumberOffset;
printf("Serial number: %s\n", serialnumber);
}
}
/*
CMD_TYPE_SAT, // SAT = SCSI_ATA_TRANSLATION
CMD_TYPE_SUNPLUS,
CMD_TYPE_IO_DATA,
CMD_TYPE_LOGITEC,
CMD_TYPE_JMICRON,
CMD_TYPE_CYPRESS,
*/
if (DoIdentifyDeviceSat(hDevice, 0xa0, &identify, CMD_TYPE_SAT)) {
printf("0xA0-CMD_TYPE_SAT-Return ok");
} else if (DoIdentifyDeviceSat(hDevice, 0xa0, &identify, CMD_TYPE_SUNPLUS)) {
printf("0xA0-CMD_TYPE_SUNPLUS-Return ok");
} else if (DoIdentifyDeviceSat(hDevice, 0xa0, &identify, CMD_TYPE_IO_DATA)) {
printf("0xA0-CMD_TYPE_IO_DATA-Return ok");
} else if (DoIdentifyDeviceSat(hDevice, 0xa0, &identify, CMD_TYPE_LOGITEC)) {
printf("0xA0-CMD_TYPE_LOGITEC-Return ok");
} else if (DoIdentifyDeviceSat(hDevice, 0xa0, &identify, CMD_TYPE_JMICRON)) {
printf("0xA0-CMD_TYPE_JMICRON-Return ok");
} else if (DoIdentifyDeviceSat(hDevice, 0xb0, &identify, CMD_TYPE_SAT)) {
printf("0xB0-CMD_TYPE_SAT-Return ok");
} else if (DoIdentifyDeviceSat(hDevice, 0xb0, &identify, CMD_TYPE_SUNPLUS)) {
printf("0xB0-CMD_TYPE_SUNPLUS-Return ok");
} else if (DoIdentifyDeviceSat(hDevice, 0xb0, &identify, CMD_TYPE_IO_DATA)) {
printf("0xB0-CMD_TYPE_IO_DATA-Return ok");
} else if (DoIdentifyDeviceSat(hDevice, 0xb0, &identify, CMD_TYPE_LOGITEC)) {
printf("0xB0-CMD_TYPE_LOGITEC-Return ok");
} else if (DoIdentifyDeviceSat(hDevice, 0xb0, &identify, CMD_TYPE_JMICRON)) {
printf("0xB0-CMD_TYPE_JMICRON-Return ok");
} else {
printf("Return ng\n");
}
#define debug 0
#if debug
dump_buffer("data", (const unsigned char *)&identify, sizeof(IDENTIFY_DEVICE));
#endif
memcpy(usb_hdd_model, identify.Model, 40);
ChangeByteOrder(usb_hdd_model, 40);
usb_hdd_model[40] = '\0';
memcpy(usb_hdd_firmware, identify.FirmwareRev, 8);
ChangeByteOrder(usb_hdd_firmware, 8);
usb_hdd_firmware[8] = '\0';
memcpy(usb_hdd_Serialnumber, identify.SerialNumber, 20);
ChangeByteOrder(usb_hdd_Serialnumber, 20);
usb_hdd_Serialnumber[20] = '\0';
printf("\nUSB-HDD Model name: %s", usb_hdd_model);
printf("\nUSB-HDD Firmware Rev: %s", usb_hdd_firmware);
printf("\nUSB-HDD Serial number: %s", usb_hdd_Serialnumber);
return 0;
}