1# SCSI Peripheral DDK 2 3 4## Overview 5 6The SCSI Peripheral DDK is a suite dedicated to SCSI device driver development at the application layer. It provides APIs for initializing the DDK, releasing the DDK, enabling and disabling devices, and reading data from and writing data to devices. It also declares the macros, enum variables, and data structures required by the SCSI Peripheral DDK APIs. 7 8**System capability**: SystemCapability.Driver.SCSI.Extension 9 10**Since**: 18 11 12 13## Summary 14 15 16### File 17 18| Name| Description| 19| -------- | -------- | 20| [scsi_peripheral_api.h](scsi__peripheral__api_8h.md) | Declares the SCSI Peripheral DDK APIs used by the host to access the SCSI device.| 21| [scsi_peripheral_types.h](scsi__peripheral__types_8h.md) | Provides the enum variables, structures, and macros used in the SCSI Peripheral DDK APIs.| 22 23 24### Structs 25 26| Name| Description| 27| -------- | -------- | 28| struct [ScsiPeripheral_DeviceMemMap](_scsi_peripheral___device_mem_map.md) | Device memory mapping created by calling **OH_ScsiPeripheral_CreateDeviceMemMap**. The buffer that uses the device memory mapping can provide better performance.| 29| struct [ScsiPeripheral_IORequest](_scsi_peripheral___i_o_request.md) | Read/write operation request.| 30| struct [ScsiPeripheral_Request](_scsi_peripheral___request.md) | Request structure.| 31| struct [ScsiPeripheral_Response](_scsi_peripheral___response.md) | Response structure.| 32| struct [ScsiPeripheral_TestUnitReadyRequest](_scsi_peripheral___test_unit_ready_request.md) | Request structure of the **test unit ready** command.| 33| struct [ScsiPeripheral_InquiryRequest](_scsi_peripheral___inquiry_request.md) | Request structure of the **inquiry** command.| 34| struct [ScsiPeripheral_InquiryInfo](_scsi_peripheral___inquiry_info.md) | SCSI inquiry data.| 35| struct [ScsiPeripheral_ReadCapacityRequest](_scsi_peripheral___read_capacity_request.md) | Request structure of the **read capacity** command.| 36| struct [ScsiPeripheral_CapacityInfo](_scsi_peripheral___capacity_info.md) | SCSI read capacity.| 37| struct [ScsiPeripheral_RequestSenseRequest](_scsi_peripheral___request_sense_request.md) | Request structure of the **request sense** command.| 38| struct [ScsiPeripheral_BasicSenseInfo](_scsi_peripheral___basic_sense_info.md) | Basic information about the sense data.| 39| struct [ScsiPeripheral_VerifyRequest](_scsi_peripheral___verify_request.md) | Request structure of the **verify** command.| 40 41 42### Macros 43 44| Name| Description| 45| -------- | -------- | 46| [SCSIPERIPHERAL_MIN_DESCRIPTOR_FORMAT_SENSE](#scsiperipheral_min_descriptor_format_sense) 8 | Minimum length of the sense data descriptor format.| 47| [SCSIPERIPHERAL_MIN_FIXED_FORMAT_SENSE](#scsiperipheral_min_fixed_format_sense) 18 | Minimum length of the fixed format of sense data.| 48| [SCSIPERIPHERAL_MAX_CMD_DESC_BLOCK_LEN](#scsiperipheral_max_cmd_desc_block_len) 16 | Maximum length of a command descriptor block (CDB).| 49| [SCSIPERIPHERAL_MAX_SENSE_DATA_LEN](#scsiperipheral_max_sense_data_len) 252 | Maximum length of sense data. In the SCSI protocol, the maximum length of sense data is usually 252 bytes.| 50| [SCSIPERIPHERAL_VENDOR_ID_LEN](#scsiperipheral_vendor_id_len) 8 | Maximum length of the vendor ID.| 51| [SCSIPERIPHERAL_PRODUCT_ID_LEN](#scsiperipheral_product_id_len) 16 | Maximum length of the product ID.| 52| [SCSIPERIPHERAL_PRODUCT_REV_LEN](#scsiperipheral_product_rev_len) 4 | Maximum length of the product version.| 53 54 55### Types 56 57| Name| Description| 58| -------- | -------- | 59| typedef struct [ScsiPeripheral_Device](#scsiperipheral_device) [ScsiPeripheral_Device](#scsiperipheral_device) | Opaque SCSI device structure.| 60| typedef struct [ScsiPeripheral_DeviceMemMap](_scsi_peripheral___device_mem_map.md) [ScsiPeripheral_DeviceMemMap](#scsiperipheral_devicememmap) | Device memory mapping created by calling **OH_ScsiPeripheral_CreateDeviceMemMap**. The buffer that uses the device memory mapping can provide better performance.| 61| typedef struct [ScsiPeripheral_IORequest](_scsi_peripheral___i_o_request.md) [ScsiPeripheral_IORequest](#scsiperipheral_iorequest) | Read/write operation request.| 62| typedef struct [ScsiPeripheral_Request](_scsi_peripheral___request.md) [ScsiPeripheral_Request](#scsiperipheral_request) | Request structure.| 63| typedef struct [ScsiPeripheral_Response](_scsi_peripheral___response.md) [ScsiPeripheral_Response](#scsiperipheral_response) | Response structure.| 64| typedef struct [ScsiPeripheral_TestUnitReadyRequest](_scsi_peripheral___test_unit_ready_request.md) [ScsiPeripheral_TestUnitReadyRequest](#scsiperipheral_testunitreadyrequest) | Request structure of the **test unit ready** command.| 65| typedef struct [ScsiPeripheral_InquiryRequest](_scsi_peripheral___inquiry_request.md) [ScsiPeripheral_InquiryRequest](#scsiperipheral_inquiryrequest) | Request structure of the **inquiry** command.| 66| typedef struct [ScsiPeripheral_InquiryInfo](_scsi_peripheral___inquiry_info.md) [ScsiPeripheral_InquiryInfo](#scsiperipheral_inquiryinfo) | SCSI inquiry data.| 67| typedef struct [ScsiPeripheral_ReadCapacityRequest](_scsi_peripheral___read_capacity_request.md) [ScsiPeripheral_ReadCapacityRequest](#scsiperipheral_readcapacityrequest) | Request structure of the **read capacity** command.| 68| typedef struct [ScsiPeripheral_CapacityInfo](_scsi_peripheral___capacity_info.md) [ScsiPeripheral_CapacityInfo](#scsiperipheral_capacityinfo) | SCSI read capacity.| 69| typedef struct [ScsiPeripheral_RequestSenseRequest](_scsi_peripheral___request_sense_request.md) [ScsiPeripheral_RequestSenseRequest](#scsiperipheral_requestsenserequest) | Request structure of the **request sense** command.| 70| typedef struct [ScsiPeripheral_BasicSenseInfo](_scsi_peripheral___basic_sense_info.md) [ScsiPeripheral_BasicSenseInfo](#scsiperipheral_basicsenseinfo) | Basic information about the sense data.| 71| typedef struct [ScsiPeripheral_VerifyRequest](_scsi_peripheral___verify_request.md) [ScsiPeripheral_VerifyRequest](#scsiperipheral_verifyrequest) | Request structure of the **verify** command.| 72 73 74### Enums 75 76| Name| Description| 77| -------- | -------- | 78| [ScsiPeripheral_DdkErrCode](#scsiperipheral_ddkerrcode) {<br>SCSIPERIPHERAL_DDK_NO_PERM = 201, SCSIPERIPHERAL_DDK_INVALID_PARAMETER = 401, SCSIPERIPHERAL_DDK_SUCCESS = 31700000, SCSIPERIPHERAL_DDK_MEMORY_ERROR = 31700001, SCSIPERIPHERAL_DDK_INVALID_OPERATION = 31700002, SCSIPERIPHERAL_DDK_IO_ERROR = 31700003, SCSIPERIPHERAL_DDK_TIMEOUT = 31700004, SCSIPERIPHERAL_DDK_INIT_ERROR = 31700005, SCSIPERIPHERAL_DDK_SERVICE_ERROR = 31700006, SCSIPERIPHERAL_DDK_DEVICE_NOT_FOUND = 31700007<br>} | SCSI Peripheral DDK error codes.| 79| [ScsiPeripheral_Status](#scsiperipheral_status) {<br>SCSIPERIPHERAL_STATUS_GOOD = 0x00, SCSIPERIPHERAL_STATUS_CHECK_CONDITION_NEEDED = 0x02, SCSIPERIPHERAL_STATUS_CONDITION_MET = 0x04, SCSIPERIPHERAL_STATUS_BUSY = 0x08, SCSIPERIPHERAL_STATUS_RESERVATION_CONFLICT = 0x18, SCSIPERIPHERAL_STATUS_TASK_SET_FULL = 0x28, SCSIPERIPHERAL_STATUS_ACA_ACTIVE = 0x30, SCSIPERIPHERAL_STATUS_TASK_ABORTED = 0x40<br>} | SCSI status used for the response.| 80 81 82### Function 83 84| Name| Description| 85| -------- | -------- | 86| int32_t [OH_ScsiPeripheral_Init](#oh_scsiperipheral_init) (void) | Initializes the SCSI Peripheral DDK.| 87| int32_t [OH_ScsiPeripheral_Release](#oh_scsiperipheral_release) (void) | Releases the SCSI Peripheral DDK.| 88| int32_t [OH_ScsiPeripheral_Open](#oh_scsiperipheral_open) (uint64_t deviceId, uint8_t interfaceIndex, [ScsiPeripheral_Device](#scsiperipheral_device) \*\*dev) | Opens the SCSI device specified by **deviceId** and **interfaceIndex**.| 89| int32_t [OH_ScsiPeripheral_Close](#oh_scsiperipheral_close) ([ScsiPeripheral_Device](#scsiperipheral_device) \*\*dev) | Disables the SCSI device.| 90| int32_t [OH_ScsiPeripheral_TestUnitReady](#oh_scsiperipheral_testunitready) ([ScsiPeripheral_Device](#scsiperipheral_device) \*dev, [ScsiPeripheral_TestUnitReadyRequest](_scsi_peripheral___test_unit_ready_request.md) \*request, [ScsiPeripheral_Response](_scsi_peripheral___response.md) \*response) | Checks whether the logical units are ready.| 91| int32_t [OH_ScsiPeripheral_Inquiry](#oh_scsiperipheral_inquiry) ([ScsiPeripheral_Device](#scsiperipheral_device) \*dev, [ScsiPeripheral_InquiryRequest](_scsi_peripheral___inquiry_request.md) \*request, [ScsiPeripheral_InquiryInfo](_scsi_peripheral___inquiry_info.md) \*inquiryInfo, [ScsiPeripheral_Response](_scsi_peripheral___response.md) \*response) | Queries basic information about the SCSI device.| 92| int32_t [OH_ScsiPeripheral_ReadCapacity10](#oh_scsiperipheral_readcapacity10) ([ScsiPeripheral_Device](#scsiperipheral_device) \*dev, [ScsiPeripheral_ReadCapacityRequest](_scsi_peripheral___read_capacity_request.md) \*request, [ScsiPeripheral_CapacityInfo](_scsi_peripheral___capacity_info.md) \*capacityInfo, [ScsiPeripheral_Response](_scsi_peripheral___response.md) \*response) | Obtains the capacity information about the SCSI device.| 93| int32_t [OH_ScsiPeripheral_RequestSense](#oh_scsiperipheral_requestsense) ([ScsiPeripheral_Device](#scsiperipheral_device) \*dev, [ScsiPeripheral_RequestSenseRequest](_scsi_peripheral___request_sense_request.md) \*request, [ScsiPeripheral_Response](_scsi_peripheral___response.md) \*response) | Obtains sense data, that is, information returned by the SCSI device to the host to report the device status, error information, and diagnosis information.| 94| int32_t [OH_ScsiPeripheral_Read10](#oh_scsiperipheral_read10) ([ScsiPeripheral_Device](#scsiperipheral_device) \*dev, [ScsiPeripheral_IORequest](_scsi_peripheral___i_o_request.md) \*request, [ScsiPeripheral_Response](_scsi_peripheral___response.md) \*response) | Reads data from a specified logical block.| 95| int32_t [OH_ScsiPeripheral_Write10](#oh_scsiperipheral_write10) ([ScsiPeripheral_Device](#scsiperipheral_device) \*dev, [ScsiPeripheral_IORequest](_scsi_peripheral___i_o_request.md) \*request, [ScsiPeripheral_Response](_scsi_peripheral___response.md) \*response) | Writes data to a specified logical block of a device.| 96| int32_t [OH_ScsiPeripheral_Verify10](#oh_scsiperipheral_verify10) ([ScsiPeripheral_Device](#scsiperipheral_device) \*dev, [ScsiPeripheral_VerifyRequest](_scsi_peripheral___verify_request.md) \*request, [ScsiPeripheral_Response](_scsi_peripheral___response.md) \*response) | Verifies a specified logical block.| 97| int32_t [OH_ScsiPeripheral_SendRequestByCdb](#oh_scsiperipheral_sendrequestbycdb) ([ScsiPeripheral_Device](#scsiperipheral_device) \*dev, [ScsiPeripheral_Request](_scsi_peripheral___request.md) \*request, [ScsiPeripheral_Response](_scsi_peripheral___response.md) \*response) | Sends SCSI commands in CDB mode.| 98| int32_t [OH_ScsiPeripheral_CreateDeviceMemMap](#oh_scsiperipheral_createdevicememmap) ([ScsiPeripheral_Device](#scsiperipheral_device) \*dev, size_t size, [ScsiPeripheral_DeviceMemMap](_scsi_peripheral___device_mem_map.md) \*\*devMmap) | Creates a buffer. To avoid memory leakage, use [OH_ScsiPeripheral_DestroyDeviceMemMap](#oh_scsiperipheral_destroydevicememmap) to destroy a buffer after use.| 99| int32_t [OH_ScsiPeripheral_DestroyDeviceMemMap](#oh_scsiperipheral_destroydevicememmap) ([ScsiPeripheral_DeviceMemMap](_scsi_peripheral___device_mem_map.md) \*devMmap) | Destroys a buffer. To avoid resource leakage, destroy a buffer in time after use.| 100| int32_t [OH_ScsiPeripheral_ParseBasicSenseInfo](#oh_scsiperipheral_parsebasicsenseinfo) (uint8_t \*senseData, uint8_t senseDataLen, [ScsiPeripheral_BasicSenseInfo](_scsi_peripheral___basic_sense_info.md) \*senseInfo) | Parses basic sense data, including the **Information**, **Command specific information**, and **Sense key specific** fields.| 101 102 103## Macro Description 104 105 106### SCSIPERIPHERAL_MAX_CMD_DESC_BLOCK_LEN 107 108``` 109#define SCSIPERIPHERAL_MAX_CMD_DESC_BLOCK_LEN 16 110``` 111 112**Description** 113 114Maximum length of a CDB. 115 116**Since**: 18 117 118 119### SCSIPERIPHERAL_MAX_SENSE_DATA_LEN 120 121``` 122#define SCSIPERIPHERAL_MAX_SENSE_DATA_LEN 252 123``` 124 125**Description** 126 127Maximum length of sense data. In the SCSI protocol, the maximum length of sense data is usually 252 bytes. 128 129**Since**: 18 130 131 132### SCSIPERIPHERAL_MIN_DESCRIPTOR_FORMAT_SENSE 133 134``` 135#define SCSIPERIPHERAL_MIN_DESCRIPTOR_FORMAT_SENSE 8 136``` 137 138**Description** 139 140Minimum length of the sense data descriptor format. 141 142**Since**: 18 143 144 145### SCSIPERIPHERAL_MIN_FIXED_FORMAT_SENSE 146 147``` 148#define SCSIPERIPHERAL_MIN_FIXED_FORMAT_SENSE 18 149``` 150 151**Description** 152 153Minimum length of the fixed format of sense data. 154 155**Since**: 18 156 157 158### SCSIPERIPHERAL_PRODUCT_ID_LEN 159 160``` 161#define SCSIPERIPHERAL_PRODUCT_ID_LEN 16 162``` 163 164**Description** 165 166Maximum length of the product ID. 167 168**Since**: 18 169 170 171### SCSIPERIPHERAL_PRODUCT_REV_LEN 172 173``` 174#define SCSIPERIPHERAL_PRODUCT_REV_LEN 4 175``` 176 177**Description** 178 179Maximum length of the product version. 180 181**Since**: 18 182 183 184### SCSIPERIPHERAL_VENDOR_ID_LEN 185 186``` 187#define SCSIPERIPHERAL_VENDOR_ID_LEN 8 188``` 189 190**Description** 191 192Maximum length of the vendor ID. 193 194**Since**: 18 195 196 197## Type Description 198 199 200### ScsiPeripheral_BasicSenseInfo 201 202``` 203typedef struct ScsiPeripheral_BasicSenseInfo ScsiPeripheral_BasicSenseInfo 204``` 205 206**Description** 207 208Basic information about the sense data. 209 210**Since**: 18 211 212 213### ScsiPeripheral_CapacityInfo 214 215``` 216typedef struct ScsiPeripheral_CapacityInfo ScsiPeripheral_CapacityInfo 217``` 218 219**Description** 220 221SCSI read capacity. 222 223**Since**: 18 224 225 226### ScsiPeripheral_Device 227 228``` 229typedef struct ScsiPeripheral_Device ScsiPeripheral_Device 230``` 231 232**Description** 233 234Opaque SCSI device structure. 235 236**Since**: 18 237 238 239### ScsiPeripheral_DeviceMemMap 240 241``` 242typedef struct ScsiPeripheral_DeviceMemMap ScsiPeripheral_DeviceMemMap 243``` 244 245**Description** 246 247Device memory mapping created by calling **OH_ScsiPeripheral_CreateDeviceMemMap**. The buffer that uses the device memory mapping can provide better performance. 248 249**Since**: 18 250 251 252### ScsiPeripheral_InquiryInfo 253 254``` 255typedef struct ScsiPeripheral_InquiryInfo ScsiPeripheral_InquiryInfo 256``` 257 258**Description** 259 260SCSI inquiry data. 261 262**Since**: 18 263 264 265### ScsiPeripheral_InquiryRequest 266 267``` 268typedef struct ScsiPeripheral_InquiryRequest ScsiPeripheral_InquiryRequest 269``` 270 271**Description** 272 273Request structure of the **inquiry** command. 274 275**Since**: 18 276 277 278### ScsiPeripheral_IORequest 279 280``` 281typedef struct ScsiPeripheral_IORequest ScsiPeripheral_IORequest 282``` 283 284**Description** 285 286Read/write operation request. 287 288**Since**: 18 289 290 291### ScsiPeripheral_ReadCapacityRequest 292 293``` 294typedef struct ScsiPeripheral_ReadCapacityRequest ScsiPeripheral_ReadCapacityRequest 295``` 296 297**Description** 298 299Request structure of the **read capacity** command. 300 301**Since**: 18 302 303 304### ScsiPeripheral_Request 305 306``` 307typedef struct ScsiPeripheral_Request ScsiPeripheral_Request 308``` 309 310**Description** 311 312Request structure. 313 314**Since**: 18 315 316 317### ScsiPeripheral_RequestSenseRequest 318 319``` 320typedef struct ScsiPeripheral_RequestSenseRequest ScsiPeripheral_RequestSenseRequest 321``` 322 323**Description** 324 325Request structure of the **request sense** command. 326 327**Since**: 18 328 329 330### ScsiPeripheral_Response 331 332``` 333typedef struct ScsiPeripheral_Response ScsiPeripheral_Response 334``` 335 336**Description** 337 338Response structure. 339 340**Since**: 18 341 342 343### ScsiPeripheral_TestUnitReadyRequest 344 345``` 346typedef struct ScsiPeripheral_TestUnitReadyRequest ScsiPeripheral_TestUnitReadyRequest 347``` 348 349**Description** 350 351Request structure of the **test unit ready** command. 352 353**Since**: 18 354 355 356### ScsiPeripheral_VerifyRequest 357 358``` 359typedef struct ScsiPeripheral_VerifyRequest ScsiPeripheral_VerifyRequest 360``` 361 362**Description** 363 364Request structure of the **verify** command. 365 366**Since**: 18 367 368 369## Enum Description 370 371 372### ScsiPeripheral_DdkErrCode 373 374``` 375enum ScsiPeripheral_DdkErrCode 376``` 377 378**Description** 379 380SCSI Peripheral DDK error codes. 381 382**Since**: 18 383 384| Value| Description| 385| -------- | -------- | 386| SCSIPERIPHERAL_DDK_NO_PERM | Permission denied.| 387| SCSIPERIPHERAL_DDK_INVALID_PARAMETER | Invalid parameter.| 388| SCSIPERIPHERAL_DDK_SUCCESS | Operation succeeded.| 389| SCSIPERIPHERAL_DDK_MEMORY_ERROR | Memory-related errors, such as insufficient memory, memory data replication failure, or memory request failure.| 390| SCSIPERIPHERAL_DDK_INVALID_OPERATION | Invalid operation.| 391| SCSIPERIPHERAL_DDK_IO_ERROR | Device input/output operation failure.| 392| SCSIPERIPHERAL_DDK_TIMEOUT | Transfer timeout.| 393| SCSIPERIPHERAL_DDK_INIT_ERROR | DDK initialization error, or DDK uninitialized.| 394| SCSIPERIPHERAL_DDK_SERVICE_ERROR | Failed to communicate with the SCSI Peripheral DDK.| 395| SCSIPERIPHERAL_DDK_DEVICE_NOT_FOUND | Device not found.| 396 397 398### ScsiPeripheral_Status 399 400``` 401enum ScsiPeripheral_Status 402``` 403 404**Description** 405 406SCSI status used for the response. 407 408**Since**: 18 409 410| Value| Description| 411| -------- | -------- | 412| SCSIPERIPHERAL_STATUS_GOOD | Normal state.| 413| SCSIPERIPHERAL_STATUS_CHECK_CONDITION_NEEDED | Status check required.| 414| SCSIPERIPHERAL_STATUS_CONDITION_MET | Conditions met.| 415| SCSIPERIPHERAL_STATUS_BUSY | Occupying.| 416| SCSIPERIPHERAL_STATUS_RESERVATION_CONFLICT | Resource reservation conflict.| 417| SCSIPERIPHERAL_STATUS_TASK_SET_FULL | Task set already full.| 418| SCSIPERIPHERAL_STATUS_ACA_ACTIVE | ACA activity status.| 419| SCSIPERIPHERAL_STATUS_TASK_ABORTED | Task aborted.| 420 421 422## Function Description 423 424 425### OH_ScsiPeripheral_Close() 426 427``` 428int32_t OH_ScsiPeripheral_Close (ScsiPeripheral_Device ** dev) 429``` 430 431**Description** 432 433Disables the SCSI device. 434 435**Since**: 18 436 437**Parameters** 438 439| Name| Description| 440| -------- | -------- | 441| dev | Device handle. For details, see [ScsiPeripheral_Device](#scsiperipheral_device).| 442 443**Required Permissions** 444 445ohos.permission.ACCESS_DDK_SCSI_PERIPHERAL 446 447**Returns** 448 449- SCSIPERIPHERAL_DDK_SUCCESS: Operation succeeded. 450 451- SCSIPERIPHERAL_DDK_NO_PERM: Permission verification failed. 452 453- SCSIPERIPHERAL_DDK_INIT_ERROR: DDK not initialized. 454 455- SCSIPERIPHERAL_DDK_INVALID_PARAMETER: empty dev. 456 457- SCSIPERIPHERAL_DDK_SERVICE_ERROR: DDK service communication error. 458 459- SCSIPERIPHERAL_DDK_IO_ERROR: DDK I/O error. 460 461 462### OH_ScsiPeripheral_CreateDeviceMemMap() 463 464``` 465int32_t OH_ScsiPeripheral_CreateDeviceMemMap (ScsiPeripheral_Device * dev, size_t size, ScsiPeripheral_DeviceMemMap ** devMmap ) 466``` 467 468**Description** 469 470Creates a buffer. To avoid memory leakage, use [OH_ScsiPeripheral_DestroyDeviceMemMap](#oh_scsiperipheral_destroydevicememmap) to destroy a buffer after use. 471 472**Since**: 18 473 474**Parameters** 475 476| Name| Description| 477| -------- | -------- | 478| dev | Device handle. For details, see [ScsiPeripheral_Device](#scsiperipheral_device).| 479| size | Buffer size.| 480| devMmap | Device memory mapping used to return the created buffer to the caller. For details, see [ScsiPeripheral_DeviceMemMap](_scsi_peripheral___device_mem_map.md).| 481 482**Required Permissions** 483 484ohos.permission.ACCESS_DDK_SCSI_PERIPHERAL 485 486**Returns** 487 488- SCSIPERIPHERAL_DDK_SUCCESS: Operation succeeded. 489 490- SCSIPERIPHERAL_DDK_INVALID_PARAMETER: Empty dev or devMmap. 491 492- SCSIPERIPHERAL_DDK_MEMORY_ERROR: Memory operation error. 493 494 495### OH_ScsiPeripheral_DestroyDeviceMemMap() 496 497``` 498int32_t OH_ScsiPeripheral_DestroyDeviceMemMap (ScsiPeripheral_DeviceMemMap * devMmap) 499``` 500 501**Description** 502 503Destroys a buffer. To avoid resource leakage, destroy a buffer in time after use. 504 505**Since**: 18 506 507**Parameters** 508 509| Name| Description| 510| -------- | -------- | 511| devMmap | Buffer to be destroyed, which is created by calling **OH_ScsiPeripheral_CreateDeviceMemMa**. For details, see [ScsiPeripheral_DeviceMemMap](_scsi_peripheral___device_mem_map.md).| 512 513**Required Permissions** 514 515ohos.permission.ACCESS_DDK_SCSI_PERIPHERAL 516 517**Returns** 518 519- SCSIPERIPHERAL_DDK_SUCCESS: Operation succeeded. 520 521- SCSIPERIPHERAL_DDK_INVALID_PARAMETER: Empty devMmap. 522 523- SCSIPERIPHERAL_DDK_MEMORY_ERROR: Memory operation error. 524 525 526### OH_ScsiPeripheral_Init() 527 528``` 529int32_t OH_ScsiPeripheral_Init (void ) 530``` 531 532**Description** 533 534Initializes the SCSI Peripheral DDK. 535 536**Since**: 18 537 538**Required Permissions** 539 540ohos.permission.ACCESS_DDK_SCSI_PERIPHERAL 541 542**Returns** 543 544- SCSIPERIPHERAL_DDK_SUCCESS: Operation succeeded. 545 546- SCSIPERIPHERAL_DDK_NO_PERM: Permission verification failed. 547 548- SCSIPERIPHERAL_DDK_INIT_ERROR: DDK initialization error. 549 550- SCSIPERIPHERAL_DDK_SERVICE_ERROR: DDK service communication error. 551 552 553### OH_ScsiPeripheral_Inquiry() 554 555``` 556int32_t OH_ScsiPeripheral_Inquiry (ScsiPeripheral_Device * dev, ScsiPeripheral_InquiryRequest * request, ScsiPeripheral_InquiryInfo * inquiryInfo, ScsiPeripheral_Response * response ) 557``` 558 559**Description** 560 561Queries basic information about the SCSI device. 562 563**Since**: 18 564 565**Parameters** 566 567| Name| Description| 568| -------- | -------- | 569| dev | Device handle. For details, see [ScsiPeripheral_Device](#scsiperipheral_device).| 570| request | Request of the **inquiry** command. For details, see [ScsiPeripheral_InquiryRequest](_scsi_peripheral___inquiry_request.md).| 571| inquiryInfo | Query result returned by the **inquiry** command. For details, see [ScsiPeripheral_InquiryInfo](_scsi_peripheral___inquiry_info.md).| 572| response | Original response returned by the **inquiry** command. For details, see [ScsiPeripheral_Response](_scsi_peripheral___response.md).| 573 574**Required Permissions** 575 576ohos.permission.ACCESS_DDK_SCSI_PERIPHERAL 577 578**Returns** 579 580- SCSIPERIPHERAL_DDK_SUCCESS: Operation succeeded. 581 582- SCSIPERIPHERAL_DDK_NO_PERM: Permission verification failed. 583 584- SCSIPERIPHERAL_DDK_INIT_ERROR: DDK not initialized. 585 586- SCSIPERIPHERAL_DDK_INVALID_PARAMETER: Empty dev, request, inquiryInfo, inquiryInfo->data, or response. 587 588- SCSIPERIPHERAL_DDK_SERVICE_ERROR: DDK service communication error. 589 590- SCSIPERIPHERAL_DDK_MEMORY_ERROR: Memory operation error. 591 592- SCSIPERIPHERAL_DDK_IO_ERROR: DDK I/O error. 593 594- SCSIPERIPHERAL_DDK_TIMEOUT: Transfer timeout. 595 596- SCSIPERIPHERAL_DDK_INVALID_OPERATION: Operation not supported. 597 598 599### OH_ScsiPeripheral_Open() 600 601``` 602int32_t OH_ScsiPeripheral_Open (uint64_t deviceId, uint8_t interfaceIndex, ScsiPeripheral_Device ** dev ) 603``` 604 605**Description** 606 607Opens the SCSI device specified by **deviceId** and **interfaceIndex**. 608 609**Since**: 18 610 611**Parameters** 612 613| Name| Description| 614| -------- | -------- | 615| deviceId | Device ID.| 616| interfaceIndex | Interface index for the API of the SCSI device.| 617| dev | Device handle. For details, see [ScsiPeripheral_Device](#scsiperipheral_device).| 618 619**Required Permissions** 620 621ohos.permission.ACCESS_DDK_SCSI_PERIPHERAL 622 623**Returns** 624 625- SCSIPERIPHERAL_DDK_SUCCESS: Operation succeeded. 626 627- SCSIPERIPHERAL_DDK_NO_PERM: Permission verification failed. 628 629- SCSIPERIPHERAL_DDK_INIT_ERROR: DDK not initialized. 630 631- SCSIPERIPHERAL_DDK_INVALID_PARAMETER: empty dev. 632 633- SCSIPERIPHERAL_DDK_SERVICE_ERROR: DDK service communication error. 634 635- SCSIPERIPHERAL_DDK_MEMORY_ERROR: Memory operation error. 636 637- SCSIPERIPHERAL_DDK_IO_ERROR: DDK I/O operation error. 638 639- SCSIPERIPHERAL_DDK_DEVICE_NOT_FOUND: Device not found based on deviceId and interfaceIndex. 640 641- SCSIPERIPHERAL_DDK_INVALID_OPERATION: Operation not supported. 642 643 644### OH_ScsiPeripheral_ParseBasicSenseInfo() 645 646``` 647int32_t OH_ScsiPeripheral_ParseBasicSenseInfo (uint8_t * senseData, uint8_t senseDataLen, ScsiPeripheral_BasicSenseInfo * senseInfo ) 648``` 649 650**Description** 651 652Parses basic sense data, including the **Information**, **Command specific information**, and **Sense key specific** fields. 653 654**Since**: 18 655 656**Parameters** 657 658| Name| Description| 659| -------- | -------- | 660| senseData | Sense data to be parsed.| 661| senseDataLen | Length of sense data.| 662| senseInfo | Stores parsed basic information. For details, see [ScsiPeripheral_BasicSenseInfo](_scsi_peripheral___basic_sense_info.md).| 663 664**Required Permissions** 665 666ohos.permission.ACCESS_DDK_SCSI_PERIPHERAL 667 668**Returns** 669 670- SCSIPERIPHERAL_DDK_SUCCESS: Operation succeeded. 671 672- SCSIPERIPHERAL_DDK_INVALID_PARAMETER: senseData or senseDataLen error. (senseData is not a descriptor or is not of the fixed format, or senseDataLen is smaller than SCSIPERIPHERAL_MIN_DESCRIPTOR_FORMAT_SENSE or SCSIPERIPHERAL_MIN_FIXED_FORMAT_SENSE.) 673 674 675### OH_ScsiPeripheral_Read10() 676 677``` 678int32_t OH_ScsiPeripheral_Read10 (ScsiPeripheral_Device * dev, ScsiPeripheral_IORequest * request, ScsiPeripheral_Response * response ) 679``` 680 681**Description** 682 683Reads data from a specified logical block. 684 685**Since**: 18 686 687**Parameters** 688 689| Name| Description| 690| -------- | -------- | 691| dev | Device handle. For details, see [ScsiPeripheral_Device](#scsiperipheral_device).| 692| request | Request of the **read** command. For details, see [ScsiPeripheral_IORequest](_scsi_peripheral___i_o_request.md).| 693| response | Response returned by the **read** command. For details, see [ScsiPeripheral_Response](_scsi_peripheral___response.md).| 694 695**Required Permissions** 696 697ohos.permission.ACCESS_DDK_SCSI_PERIPHERAL 698 699**Returns** 700 701- SCSIPERIPHERAL_DDK_SUCCESS: Operation succeeded. 702 703- SCSIPERIPHERAL_DDK_NO_PERM: Permission verification failed. 704 705- SCSIPERIPHERAL_DDK_INIT_ERROR: DDK not initialized. 706 707- SCSIPERIPHERAL_DDK_INVALID_PARAMETER: Empty dev, request, request->data, or response. 708 709- SCSIPERIPHERAL_DDK_SERVICE_ERROR: DDK service communication error. 710 711- SCSIPERIPHERAL_DDK_MEMORY_ERROR: Memory operation error. 712 713- SCSIPERIPHERAL_DDK_IO_ERROR: DDK I/O error. 714 715- SCSIPERIPHERAL_DDK_TIMEOUT: Transfer timeout. 716 717- SCSIPERIPHERAL_DDK_INVALID_OPERATION: Operation not supported. 718 719 720### OH_ScsiPeripheral_ReadCapacity10() 721 722``` 723int32_t OH_ScsiPeripheral_ReadCapacity10 (ScsiPeripheral_Device * dev, ScsiPeripheral_ReadCapacityRequest * request, ScsiPeripheral_CapacityInfo * capacityInfo, ScsiPeripheral_Response * response ) 724``` 725 726**Description** 727 728Obtains the capacity information about the SCSI device. 729 730**Since**: 18 731 732**Parameters** 733 734| Name| Description| 735| -------- | -------- | 736| dev | Device handle. For details, see [ScsiPeripheral_Device](#scsiperipheral_device).| 737| request | Request of the **read capacity** command. For details, see [ScsiPeripheral_ReadCapacityRequest](_scsi_peripheral___read_capacity_request.md).| 738| capacityInfo | Capacity information returned by the **read capacity** command. For details, see [ScsiPeripheral_CapacityInfo](_scsi_peripheral___capacity_info.md).| 739| response | Original response returned by the **read capacity** command. For details, see [ScsiPeripheral_Response](_scsi_peripheral___response.md).| 740 741**Required Permissions** 742 743ohos.permission.ACCESS_DDK_SCSI_PERIPHERAL 744 745**Returns** 746 747- SCSIPERIPHERAL_DDK_SUCCESS: Operation succeeded. 748 749- SCSIPERIPHERAL_DDK_NO_PERM: Permission verification failed. 750 751- SCSIPERIPHERAL_DDK_INIT_ERROR: DDK not initialized. 752 753- SCSIPERIPHERAL_DDK_INVALID_PARAMETER: Empty dev, request, capacityInfo, or response. 754 755- SCSIPERIPHERAL_DDK_SERVICE_ERROR: DDK service communication error. 756 757- SCSIPERIPHERAL_DDK_MEMORY_ERROR: Memory operation error. 758 759- SCSIPERIPHERAL_DDK_IO_ERROR: DDK I/O error. 760 761- SCSIPERIPHERAL_DDK_TIMEOUT: Transfer timeout. 762 763- SCSIPERIPHERAL_DDK_INVALID_OPERATION: Operation not supported. 764 765 766### OH_ScsiPeripheral_Release() 767 768``` 769int32_t OH_ScsiPeripheral_Release (void ) 770``` 771 772**Description** 773 774Releases the SCSI Peripheral DDK. 775 776**Since**: 18 777 778**Required Permissions** 779 780ohos.permission.ACCESS_DDK_SCSI_PERIPHERAL 781 782**Returns** 783 784- SCSIPERIPHERAL_DDK_SUCCESS: Operation succeeded. 785 786- SCSIPERIPHERAL_DDK_NO_PERM: Permission verification failed. 787 788- SCSIPERIPHERAL_DDK_INIT_ERROR: DDK not initialized. 789 790- SCSIPERIPHERAL_DDK_SERVICE_ERROR: DDK service communication error. 791 792 793### OH_ScsiPeripheral_RequestSense() 794 795``` 796int32_t OH_ScsiPeripheral_RequestSense (ScsiPeripheral_Device * dev, ScsiPeripheral_RequestSenseRequest * request, ScsiPeripheral_Response * response ) 797``` 798 799**Description** 800 801Obtains sense data, that is, information returned by the SCSI device to the host to report the device status, error information, and diagnosis information. 802 803**Since**: 18 804 805**Parameters** 806 807| Name| Description| 808| -------- | -------- | 809| dev | Device handle. For details, see [ScsiPeripheral_Device](#scsiperipheral_device).| 810| request | Request of the **request sense** command. For details, see [ScsiPeripheral_RequestSenseRequest](_scsi_peripheral___request_sense_request.md).| 811| response | Response returned by the **request sense** command. For details, see [ScsiPeripheral_Response](_scsi_peripheral___response.md).| 812 813**Required Permissions** 814 815ohos.permission.ACCESS_DDK_SCSI_PERIPHERAL 816 817**Returns** 818 819- SCSIPERIPHERAL_DDK_SUCCESS: Operation succeeded. 820 821- SCSIPERIPHERAL_DDK_NO_PERM: Permission verification failed. 822 823- SCSIPERIPHERAL_DDK_INIT_ERROR: DDK not initialized. 824 825- SCSIPERIPHERAL_DDK_INVALID_PARAMETER: Empty dev, request, or response. 826 827- SCSIPERIPHERAL_DDK_SERVICE_ERROR: DDK service communication error. 828 829- SCSIPERIPHERAL_DDK_MEMORY_ERROR: Memory operation error. 830 831- SCSIPERIPHERAL_DDK_IO_ERROR: DDK I/O error. 832 833- SCSIPERIPHERAL_DDK_TIMEOUT: Transfer timeout. 834 835- SCSIPERIPHERAL_DDK_INVALID_OPERATION: Operation not supported. 836 837 838### OH_ScsiPeripheral_SendRequestByCdb() 839 840``` 841int32_t OH_ScsiPeripheral_SendRequestByCdb (ScsiPeripheral_Device * dev, ScsiPeripheral_Request * request, ScsiPeripheral_Response * response ) 842``` 843 844**Description** 845 846Sends SCSI commands in command descriptor block (CDB) mode. 847 848**Since**: 18 849 850**Parameters** 851 852| Name| Description| 853| -------- | -------- | 854| dev | Device handle. For details, see [ScsiPeripheral_Device] (#scsiperipheral_device).| 855| request | Request. For details, see [ScsiPeripheral_Request](_scsi_peripheral___request.md).| 856| response | Response. For details, see [ScsiPeripheral_Response](_scsi_peripheral___response.md).| 857 858**Required Permissions** 859 860ohos.permission.ACCESS_DDK_SCSI_PERIPHERAL 861 862**Returns** 863 864- SCSIPERIPHERAL_DDK_SUCCESS: Operation succeeded. 865 866- SCSIPERIPHERAL_DDK_NO_PERM: Permission verification failed. 867 868- SCSIPERIPHERAL_DDK_INIT_ERROR: DDK not initialized. 869 870- SCSIPERIPHERAL_DDK_INVALID_PARAMETER: Empty dev, request, request->data, or response, or invalid request->cdbLength value (0). 871 872- SCSIPERIPHERAL_DDK_SERVICE_ERROR: DDK service communication error. 873 874- SCSIPERIPHERAL_DDK_MEMORY_ERROR: Memory operation error. 875 876- SCSIPERIPHERAL_DDK_IO_ERROR: DDK I/O error. 877 878- SCSIPERIPHERAL_DDK_TIMEOUT: Transfer timeout. 879 880- SCSIPERIPHERAL_DDK_INVALID_OPERATION: Operation not supported. 881 882 883### OH_ScsiPeripheral_TestUnitReady() 884 885``` 886int32_t OH_ScsiPeripheral_TestUnitReady (ScsiPeripheral_Device * dev, ScsiPeripheral_TestUnitReadyRequest * request, ScsiPeripheral_Response * response ) 887``` 888 889**Description** 890 891Checks whether the logical units are ready. 892 893**Since**: 18 894 895**Parameters** 896 897| Name| Description| 898| -------- | -------- | 899| dev | Device handle. For details, see [ScsiPeripheral_Device](#scsiperipheral_device).| 900| request | Request of the **test unit ready** command. For details, see [ScsiPeripheral_TestUnitReadyRequest](_scsi_peripheral___test_unit_ready_request.md).| 901| response | Response returned by the **test unit ready** command. For details, see [ScsiPeripheral_Response](_scsi_peripheral___response.md).| 902 903**Required Permissions** 904 905ohos.permission.ACCESS_DDK_SCSI_PERIPHERAL 906 907**Returns** 908 909- SCSIPERIPHERAL_DDK_SUCCESS: Operation succeeded. 910 911- SCSIPERIPHERAL_DDK_NO_PERM: Permission verification failed. 912 913- SCSIPERIPHERAL_DDK_INIT_ERROR: DDK not initialized. 914 915- SCSIPERIPHERAL_DDK_INVALID_PARAMETER: Empty dev, request, or response. 916 917- SCSIPERIPHERAL_DDK_SERVICE_ERROR: DDK service communication error. 918 919- SCSIPERIPHERAL_DDK_MEMORY_ERROR: Memory operation error. 920 921- SCSIPERIPHERAL_DDK_IO_ERROR: DDK I/O error. 922 923- SCSIPERIPHERAL_DDK_TIMEOUT: Transfer timeout. 924 925- SCSIPERIPHERAL_DDK_INVALID_OPERATION: Operation not supported. 926 927 928### OH_ScsiPeripheral_Verify10() 929 930``` 931int32_t OH_ScsiPeripheral_Verify10 (ScsiPeripheral_Device * dev, ScsiPeripheral_VerifyRequest * request, ScsiPeripheral_Response * response ) 932``` 933 934**Description** 935 936Verifies a specified logical block. 937 938**Since**: 18 939 940**Parameters** 941 942| Name| Description| 943| -------- | -------- | 944| dev | Device handle. For details, see [ScsiPeripheral_Device](#scsiperipheral_device).| 945| request | Request of the **verify** command. For details, see [ScsiPeripheral_VerifyRequest](_scsi_peripheral___verify_request.md).| 946| response | Response returned by the **verify** command. For details, see [ScsiPeripheral_Response](_scsi_peripheral___response.md).| 947 948**Required Permissions** 949 950ohos.permission.ACCESS_DDK_SCSI_PERIPHERAL 951 952**Returns** 953 954- SCSIPERIPHERAL_DDK_SUCCESS: Operation succeeded. 955 956- SCSIPERIPHERAL_DDK_NO_PERM: Permission verification failed. 957 958- SCSIPERIPHERAL_DDK_INIT_ERROR: DDK not initialized. 959 960- SCSIPERIPHERAL_DDK_INVALID_PARAMETER: Empty dev, request, or response. 961 962- SCSIPERIPHERAL_DDK_SERVICE_ERROR: DDK service communication error. 963 964- SCSIPERIPHERAL_DDK_MEMORY_ERROR: Memory operation error. 965 966- SCSIPERIPHERAL_DDK_IO_ERROR: DDK I/O error. 967 968- SCSIPERIPHERAL_DDK_TIMEOUT: Transfer timeout. 969 970- SCSIPERIPHERAL_DDK_INVALID_OPERATION: Operation not supported. 971 972 973### OH_ScsiPeripheral_Write10() 974 975``` 976int32_t OH_ScsiPeripheral_Write10 (ScsiPeripheral_Device * dev, ScsiPeripheral_IORequest * request, ScsiPeripheral_Response * response ) 977``` 978 979**Description** 980 981Writes data to a specified logical block of a device. 982 983**Since**: 18 984 985**Parameters** 986 987| Name| Description| 988| -------- | -------- | 989| dev | Device handle. For details, see [ScsiPeripheral_Device](#scsiperipheral_device).| 990| request | Request of the **write** command. For details, see [ScsiPeripheral_IORequest](_scsi_peripheral___i_o_request.md).| 991| response | Response returned by the **write** command. For details, see [ScsiPeripheral_Response](_scsi_peripheral___response.md).| 992 993**Required Permissions** 994 995ohos.permission.ACCESS_DDK_SCSI_PERIPHERAL 996 997**Returns** 998 999- SCSIPERIPHERAL_DDK_SUCCESS: Operation succeeded. 1000 1001- SCSIPERIPHERAL_DDK_NO_PERM: Permission verification failed. 1002 1003- SCSIPERIPHERAL_DDK_INIT_ERROR: DDK not initialized. 1004 1005- SCSIPERIPHERAL_DDK_INVALID_PARAMETER: Empty dev, request, request->data, or response. 1006 1007- SCSIPERIPHERAL_DDK_SERVICE_ERROR: DDK service communication error. 1008 1009- SCSIPERIPHERAL_DDK_MEMORY_ERROR: Memory operation error. 1010 1011- SCSIPERIPHERAL_DDK_IO_ERROR: DDK I/O error. 1012 1013- SCSIPERIPHERAL_DDK_TIMEOUT: Transfer timeout. 1014 1015- SCSIPERIPHERAL_DDK_INVALID_OPERATION: Operation not supported. 1016 1017<!--no_check-->