1 | /* $Id: VSCSISense.cpp 38530 2011-08-25 14:26:49Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Virtual SCSI driver: Sense handling
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2010 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 | #define LOG_GROUP LOG_GROUP_VSCSI
|
---|
18 | #include <VBox/log.h>
|
---|
19 | #include <iprt/assert.h>
|
---|
20 | #include <iprt/string.h>
|
---|
21 |
|
---|
22 | #include "VSCSIInternal.h"
|
---|
23 |
|
---|
24 | void vscsiSenseInit(PVSCSISENSE pVScsiSense)
|
---|
25 | {
|
---|
26 | memset(pVScsiSense->abSenseBuf, 0, sizeof(pVScsiSense->abSenseBuf));
|
---|
27 | }
|
---|
28 |
|
---|
29 | int vscsiReqSenseOkSet(PVSCSISENSE pVScsiSense, PVSCSIREQINT pVScsiReq)
|
---|
30 | {
|
---|
31 | memset(pVScsiSense->abSenseBuf, 0, sizeof(pVScsiSense->abSenseBuf));
|
---|
32 |
|
---|
33 | pVScsiSense->abSenseBuf[0] = (1 << 7) | SCSI_SENSE_RESPONSE_CODE_CURR_FIXED; /* Fixed format */
|
---|
34 | pVScsiSense->abSenseBuf[2] = SCSI_SENSE_NONE;
|
---|
35 | pVScsiSense->abSenseBuf[7] = 10;
|
---|
36 | pVScsiSense->abSenseBuf[12] = SCSI_ASC_NONE;
|
---|
37 | pVScsiSense->abSenseBuf[13] = SCSI_ASC_NONE; /* Should be ASCQ but it has the same value for success. */
|
---|
38 |
|
---|
39 | if (pVScsiReq->pbSense && pVScsiReq->cbSense)
|
---|
40 | memcpy(pVScsiReq->pbSense, pVScsiSense->abSenseBuf, RT_MIN(sizeof(pVScsiSense->abSenseBuf), pVScsiReq->cbSense));
|
---|
41 |
|
---|
42 | return SCSI_STATUS_OK;
|
---|
43 | }
|
---|
44 |
|
---|
45 | int vscsiReqSenseErrorSet(PVSCSISENSE pVScsiSense, PVSCSIREQINT pVScsiReq, uint8_t uSCSISenseKey, uint8_t uSCSIASC)
|
---|
46 | {
|
---|
47 | memset(pVScsiSense->abSenseBuf, 0, sizeof(pVScsiSense->abSenseBuf));
|
---|
48 | pVScsiSense->abSenseBuf[0] = (1 << 7) | SCSI_SENSE_RESPONSE_CODE_CURR_FIXED; /* Fixed format */
|
---|
49 | pVScsiSense->abSenseBuf[2] = uSCSISenseKey;
|
---|
50 | pVScsiSense->abSenseBuf[7] = 10;
|
---|
51 | pVScsiSense->abSenseBuf[12] = uSCSIASC;
|
---|
52 | pVScsiSense->abSenseBuf[13] = 0x00; /** @todo: Provide more info. */
|
---|
53 |
|
---|
54 | if (pVScsiReq->pbSense && pVScsiReq->cbSense)
|
---|
55 | memcpy(pVScsiReq->pbSense, pVScsiSense->abSenseBuf, RT_MIN(sizeof(pVScsiSense->abSenseBuf), pVScsiReq->cbSense));
|
---|
56 |
|
---|
57 | return SCSI_STATUS_CHECK_CONDITION;
|
---|
58 | }
|
---|
59 |
|
---|
60 | int vscsiReqSenseCmd(PVSCSISENSE pVScsiSense, PVSCSIREQINT pVScsiReq)
|
---|
61 | {
|
---|
62 | /* Copy the current sense data to the buffer. */
|
---|
63 | vscsiCopyToIoMemCtx(&pVScsiReq->IoMemCtx, pVScsiSense->abSenseBuf, sizeof(pVScsiSense->abSenseBuf));
|
---|
64 | return vscsiReqSenseOkSet(pVScsiSense, pVScsiReq);
|
---|
65 | }
|
---|
66 |
|
---|