[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[tyndur-devel] [PATCH v2 11/24] ata: Temporary buffer for ATAPI commands



! ATAPI commands need to be of size 12. However, general SCSI packets
  may have any length and thus the SCSI command to be sent has to be
  copied to a temporary buffer before it can be passed to the ATAPI
  device.

Signed-off-by: Max Reitz <max@xxxxxxxxxx>
Acked-by: Kevin Wolf <kevin@xxxxxxxxxx>
---
 src/modules/cdi/ata/atapi.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/modules/cdi/ata/atapi.c b/src/modules/cdi/ata/atapi.c
index 31c7263..78f7f29 100644
--- a/src/modules/cdi/ata/atapi.c
+++ b/src/modules/cdi/ata/atapi.c
@@ -28,6 +28,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
 #include "cdi.h"
 #include "cdi/storage.h"
@@ -92,6 +93,12 @@ void atapi_remove_device(struct cdi_device* device)
 
 int atapi_request(struct cdi_scsi_device* scsi,struct cdi_scsi_packet* packet)
 {
+    uint8_t atapi_request[12];
+    if (packet->cmdsize > 12) {
+        return -1;
+    }
+    memcpy(atapi_request, packet->command, sizeof(atapi_request));
+
     struct ata_device *dev = (struct ata_device*)scsi;
     struct ata_request request = {
         .dev = dev,
@@ -111,9 +118,9 @@ int atapi_request(struct cdi_scsi_device* scsi,struct cdi_scsi_packet* packet)
             }
         },
         .block_count = 1,
-        .block_size = packet->cmdsize,
+        .block_size = sizeof(atapi_request),
         .blocks_done = 0,
-        .buffer = packet->command,
+        .buffer = atapi_request,
         .error = 0
     };
 
-- 
2.6.3