ReactOS  0.4.15-dev-1197-g8081ba9
history.c
Go to the documentation of this file.
1 /*++
2 
3 
4 Copyright (C) Microsoft Corporation, 1991 - 1999
5 
6 Module Name:
7 
8  history.c
9 
10 Abstract:
11 
12  Packet history routines for CLASSPNP
13 
14 Environment:
15 
16  kernel mode only
17 
18 Notes:
19 
20 
21 Revision 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 );
61  NT_ASSERT( fdoData->InterpretSenseInfo->Compress != 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 
__callback PCLASS_COMPRESS_RETRY_HISTORY_DATA Compress
Definition: classpnp.h:565
_In_ PTRANSFER_PACKET Pkt
Definition: classp.h:1754
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
struct _SRB_HISTORY_ITEM SRB_HISTORY_ITEM
#define TRUE
Definition: types.h:120
PSTORAGE_REQUEST_BLOCK_HEADER Srb
Definition: classp.h:580
struct _SRB_HISTORY SRB_HISTORY
#define IsDescriptorSenseDataFormat(SenseInfoBuffer)
Definition: scsi.h:3685
PDEVICE_OBJECT Fdo
Definition: classp.h:503
PVOID DeviceExtension
Definition: env_spec_w32.h:418
unsigned char BOOLEAN
VOID HistoryLogReturnedPacket(TRANSFER_PACKET *Pkt)
Definition: history.c:83
smooth NULL
Definition: ftsmooth.c:416
__inline PVOID ClasspTransferPacketGetSenseInfoBuffer(_In_ PTRANSFER_PACKET Pkt)
Definition: classp.h:2513
#define _Out_
Definition: no_sal2.h:323
void * PVOID
Definition: retypes.h:9
VOID NTAPI KeQueryTickCount(IN PLARGE_INTEGER TickCount)
Definition: clock.c:165
VOID History(INT dir, LPTSTR commandline)
Definition: history.c:326
PSRB_HISTORY RetryHistory
Definition: classp.h:598
PFIXED_SENSE_DATA senseInfoBuffer
Definition: scsi.h:3710
VOID HistoryLogSendPacket(TRANSFER_PACKET *Pkt)
Definition: history.c:45
PDEVICE_OBJECT DeviceObject
Definition: classpnp.h:871
unsigned char UCHAR
Definition: xmlstorage.h:181
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
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
__inline UCHAR ClasspTransferPacketGetSenseInfoBufferLength(_In_ PTRANSFER_PACKET Pkt)
Definition: classp.h:2521
PCLASS_INTERPRET_SENSE_INFO2 InterpretSenseInfo
Definition: classp.h:958
BOOLEAN validSense
Definition: scsi.h:4018
#define NT_ASSERT
Definition: rtlfuncs.h:3312