ReactOS 0.4.15-dev-8131-g4988de4
history.c
Go to the documentation of this file.
1/*++
2
3
4Copyright (C) Microsoft Corporation, 1991 - 1999
5
6Module Name:
7
8 history.c
9
10Abstract:
11
12 Packet history routines for CLASSPNP
13
14Environment:
15
16 kernel mode only
17
18Notes:
19
20
21Revision History:
22
23--*/
24
25#include "classp.h"
26#include "debug.h"
27
28#ifdef DEBUG_USE_WPP
29#include "history.tmh"
30#endif
31
32//#ifdef ALLOC_PRAGMA
33// #pragma alloc_text(PAGE, InitializeTransferPackets)
34//#endif
35
37 ULONG tmpSize = HistoryCount * sizeof(SRB_HISTORY_ITEM);
38 tmpSize += sizeof(SRB_HISTORY) - sizeof(SRB_HISTORY_ITEM);
39 RtlZeroMemory(History, tmpSize);
40 History->TotalHistoryCount = HistoryCount;
41 return;
42}
43
44
46
47 PSRB_HISTORY history;
49
51 history = Pkt->RetryHistory;
52 // sending a packet implies a new history unit is to be used.
53 NT_ASSERT( history->UsedHistoryCount <= history->TotalHistoryCount );
54
55 // if already all used up, request class driver to remove at least one history unit
56 if (history->UsedHistoryCount == history->TotalHistoryCount )
57 {
59 PCLASS_PRIVATE_FDO_DATA fdoData = fdoExtension->PrivateFdoData;
60 NT_ASSERT( fdoData->InterpretSenseInfo != NULL );
62 fdoData->InterpretSenseInfo->Compress( fdoExtension->DeviceObject, history );
63 NT_ASSERT( history->UsedHistoryCount < history->TotalHistoryCount );
64 }
65
66 // thus, since we are about to increment the count, it must now be less...
67 NT_ASSERT( history->UsedHistoryCount < history->TotalHistoryCount );
68
69 // increment the number of history units in use
70 history->UsedHistoryCount++;
71
72 // determine index to use
73 item = &( history->History[ history->UsedHistoryCount-1 ] );
74
75 // zero out the history item
77
78 // Query the tick count and store in the history
79 KeQueryTickCount(&item->TickCountSent);
80 return;
81}
82
84
85 PSRB_HISTORY history;
87 UCHAR senseSize;
89 UCHAR senseInfoBufferLength;
90 SENSE_DATA convertedSenseBuffer = {0};
92
94 history = Pkt->RetryHistory;
95 NT_ASSERT( history->UsedHistoryCount <= history->TotalHistoryCount );
96 item = &( history->History[ history->UsedHistoryCount-1 ] );
97
98 // Query the tick count and store in the history
99 KeQueryTickCount(&item->TickCountCompleted);
100
101 // Copy the SRB Status...
102 item->SrbStatus = Pkt->Srb->SrbStatus;
103
104 //
105 // Process sense data
106 //
107
109 senseInfoBufferLength = ClasspTransferPacketGetSenseInfoBufferLength(Pkt);
110
112
113 validSense = ScsiConvertToFixedSenseFormat(senseInfoBuffer,
114 senseInfoBufferLength,
115 (PVOID)&convertedSenseBuffer,
116 sizeof(convertedSenseBuffer));
117
118 if (validSense) {
119 senseInfoBuffer = (PVOID)&convertedSenseBuffer;
120 senseInfoBufferLength = sizeof(convertedSenseBuffer);
121 }
122 }
123
124 RtlZeroMemory(&(item->NormalizedSenseData), sizeof(item->NormalizedSenseData));
125
126 if (validSense) {
127
128 // Determine the amount of valid sense data
129
130 if (!ScsiGetTotalSenseByteCountIndicated(senseInfoBuffer,
131 senseInfoBufferLength,
132 &senseSize)) {
133 senseSize = senseInfoBufferLength;
134 }
135
136 // Normalize the sense data copy in the history
137 senseSize = min(senseSize, sizeof(item->NormalizedSenseData));
138 RtlCopyMemory(&(item->NormalizedSenseData),
140 senseSize
141 );
142 }
143
144 return;
145}
146
unsigned char BOOLEAN
VOID History(INT dir, LPTSTR commandline)
Definition: history.c:326
struct _SRB_HISTORY SRB_HISTORY
struct _SRB_HISTORY_ITEM SRB_HISTORY_ITEM
_In_ PTRANSFER_PACKET Pkt
Definition: classp.h:1754
FORCEINLINE PVOID ClasspTransferPacketGetSenseInfoBuffer(_In_ PTRANSFER_PACKET Pkt)
Definition: classp.h:2513
FORCEINLINE UCHAR ClasspTransferPacketGetSenseInfoBufferLength(_In_ PTRANSFER_PACKET Pkt)
Definition: classp.h:2521
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
VOID HistoryLogSendPacket(TRANSFER_PACKET *Pkt)
Definition: history.c:45
VOID HistoryLogReturnedPacket(TRANSFER_PACKET *Pkt)
Definition: history.c:83
VOID HistoryInitializeRetryLogs(_Out_ PSRB_HISTORY History, ULONG HistoryCount)
Definition: history.c:36
static ATOM item
Definition: dde.c:856
#define min(a, b)
Definition: monoChain.cc:55
#define _Out_
Definition: ms_sal.h:345
PFIXED_SENSE_DATA senseInfoBuffer
Definition: scsi.h:3710
BOOLEAN validSense
Definition: scsi.h:4018
#define IsDescriptorSenseDataFormat(SenseInfoBuffer)
Definition: scsi.h:3685
#define KeQueryTickCount(CurrentCount)
Definition: ke.h:43
__callback PCLASS_COMPRESS_RETRY_HISTORY_DATA Compress
Definition: classpnp.h:565
PCLASS_INTERPRET_SENSE_INFO2 InterpretSenseInfo
Definition: classp.h:958
PVOID DeviceExtension
Definition: env_spec_w32.h:418
PDEVICE_OBJECT DeviceObject
Definition: classpnp.h:871
PSTORAGE_REQUEST_BLOCK_HEADER Srb
Definition: classp.h:580
PSRB_HISTORY RetryHistory
Definition: classp.h:598
PDEVICE_OBJECT Fdo
Definition: classp.h:503
void * PVOID
Definition: typedefs.h:50
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG
Definition: typedefs.h:59
#define NT_ASSERT
Definition: rtlfuncs.h:3310
unsigned char UCHAR
Definition: xmlstorage.h:181