ReactOS  0.4.13-dev-259-g5ca9c9c
id_badblock.cpp File Reference
#include "stdafx.h"
Include dependency graph for id_badblock.cpp:

Go to the source code of this file.

Functions

static NTSTATUS __stdcall BadBlockQueryRoutine (IN PWSTR ValueName, IN ULONG ValueType, IN PVOID ValueData, IN ULONG ValueLength, IN PVOID Context, IN PVOID EntryContext)
 
void NTAPI InitBadBlocks (IN PHW_LU_EXTENSION LunExt)
 
void NTAPI ForgetBadBlocks (IN PHW_LU_EXTENSION LunExt)
 
bool NTAPI CheckIfBadBlock (IN PHW_LU_EXTENSION LunExt, IN ULONGLONG lba, IN ULONG count)
 

Variables

LIST_ENTRY BBList
 
BOOLEAN BBListInited = FALSE
 

Function Documentation

◆ BadBlockQueryRoutine()

static NTSTATUS __stdcall BadBlockQueryRoutine ( IN PWSTR  ValueName,
IN ULONG  ValueType,
IN PVOID  ValueData,
IN ULONG  ValueLength,
IN PVOID  Context,
IN PVOID  EntryContext 
)
static

Definition at line 52 of file id_badblock.cpp.

60 {
63  ULONG i;
64  // The ValueType should be REG_SZ
65  // The ValueData is UNICODE string of the following format:
66  // "badblocks_start_from_lba badblocks_end_at_lba"
67 
68  KdPrint(( "BadBlockQueryRoutine: S/N:%S\n type %#x, len %#x\n", ValueName, ValueType, ValueLength));
69 
70  if(!BBListInited)
71  return STATUS_SUCCESS;
72 
73  if((ValueType == REG_BINARY) && // STRING
74  ValueLength && // At least "0 0 0"
75  !(ValueLength % sizeof(SBadBlockRange))) // There is free space for the record
76  {
77  cur = NULL;
78  link = BBList.Flink;
79  while(link != &BBList) {
81  link = link->Flink;
82  if(!wcscmp(cur->SerNumStr, ValueName)) {
83  KdPrint(( "already loaded\n"));
84  if(cur->LunExt) {
85  cur->LunExt->nBadBlocks = 0;
86  cur->LunExt->arrBadBlocks = NULL;
87  cur->LunExt->bbListDescr = NULL;
88  cur->LunExt = NULL;
89  }
90  break;
91  }
92  }
93 
94  if(!cur) {
96  if(!cur)
97  return STATUS_SUCCESS;
98  } else {
99  if(cur->arrBadBlocks) {
100  ExFreePool(cur->arrBadBlocks);
101  cur->arrBadBlocks = NULL;
102  }
103  }
105  if(!cur->arrBadBlocks) {
106  ExFreePool(cur);
107  return STATUS_SUCCESS;
108  }
110  wcsncpy(cur->SerNumStr, ValueName, 127);
111  cur->SerNumStr[127] = 0;
112  cur->nBadBlocks = ValueLength/sizeof(SBadBlockRange);
113  cur->LunExt = NULL;
114  InitializeListHead(&cur->List);
115  InsertTailList(&BBList, &(cur->List));
116  for(i=0; i<cur->nBadBlocks; i++) {
117  KdPrint(( "BB: %I64x - %I64x\n", cur->arrBadBlocks[i].m_lbaStart, cur->arrBadBlocks[i].m_lbaEnd-1));
118  }
119  }
120  return STATUS_SUCCESS;
121 } // end BadBlockQueryRoutine()
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define REG_BINARY
Definition: nt_native.h:1496
_In_ PCWSTR _In_z_ PCWSTR _In_ ULONG ValueType
Definition: rtlfuncs.h:4000
#define InsertTailList(ListHead, Entry)
struct _SBadBlockListItem * bbListDescr
Definition: bsmaster.h:1200
_In_ PUNICODE_STRING ValueName
Definition: cmfuncs.h:264
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
smooth NULL
Definition: ftsmooth.c:416
LIST_ENTRY BBList
Definition: id_badblock.cpp:47
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
WCHAR SerNumStr[128]
Definition: badblock.h:53
struct _SBadBlockRange SBadBlockRange
LIST_ENTRY List
Definition: psmgr.c:57
PHW_LU_EXTENSION LunExt
Definition: badblock.h:52
BOOLEAN BBListInited
Definition: id_badblock.cpp:48
_In_ GUID _In_ PVOID ValueData
Definition: hubbusif.h:311
ULONGLONG m_lbaStart
Definition: badblock.h:46
struct _SBadBlockListItem * PSBadBlockListItem
_In_ GUID _In_ PVOID _In_ ULONG ValueLength
Definition: hubbusif.h:311
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
ULONGLONG m_lbaEnd
Definition: badblock.h:47
Definition: typedefs.h:117
struct _SBadBlockRange * arrBadBlocks
Definition: bsmaster.h:1201
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
_CRTIMP wchar_t *__cdecl wcsncpy(wchar_t *_Dest, const wchar_t *_Source, size_t _Count)
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
unsigned int ULONG
Definition: retypes.h:1
const WCHAR * link
Definition: db.cpp:985
return STATUS_SUCCESS
Definition: btrfs.c:2745
#define KdPrint(x)
Definition: env_spec_w32.h:288
LIST_ENTRY List
Definition: badblock.h:51
SBadBlockRange * arrBadBlocks
Definition: badblock.h:54
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by InitBadBlocks().

◆ CheckIfBadBlock()

bool NTAPI CheckIfBadBlock ( IN PHW_LU_EXTENSION  LunExt,
IN ULONGLONG  lba,
IN ULONG  count 
)

Definition at line 251 of file id_badblock.cpp.

257 {
258  if (LunExt->nBadBlocks == 0)
259  return false;
260 /*
261  // this is checked by caller
262  if(!(AtaCommandFlags[command] & ATA_CMD_FLAG_LBAsupp)) {
263  return false;
264 */
265  ULONG nBadBlocks = LunExt->nBadBlocks;
266  SBadBlockRange* arrBadBlocks = LunExt->arrBadBlocks;
267 
268  // back transform for possibly CHS'ed LBA
270 
271  for (ULONG i = 0; i < nBadBlocks; i++)
272  {
273  if (lba + count > arrBadBlocks->m_lbaStart &&
274  lba < arrBadBlocks->m_lbaEnd) {
275  KdPrint(( "listed BB @ %I64x\n", lba));
276  return true;
277  }
278  arrBadBlocks++;
279  }
280 
281  return false;
282 
283 } // end CheckIfBadBlock()
GLuint GLuint GLsizei count
Definition: gl.h:1545
ULONGLONG NTAPI UniAtaCalculateLBARegsBack(struct _HW_LU_EXTENSION *LunExt, ULONGLONG lba)
#define lba
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
ULONGLONG m_lbaStart
Definition: badblock.h:46
unsigned int ULONG
Definition: retypes.h:1
#define KdPrint(x)
Definition: env_spec_w32.h:288

Referenced by AtaCommand48(), and UniataAhciSetupFIS_H2D().

◆ ForgetBadBlocks()

void NTAPI ForgetBadBlocks ( IN PHW_LU_EXTENSION  LunExt)

Definition at line 237 of file id_badblock.cpp.

240 {
241  if(LunExt->bbListDescr) {
242  LunExt->bbListDescr->LunExt = NULL;
243  LunExt->nBadBlocks = 0;
244  LunExt->arrBadBlocks = NULL;
245  LunExt->bbListDescr = NULL;
246  }
247 } // end ForgetBadBlocks()
smooth NULL
Definition: ftsmooth.c:416

Referenced by AtapiStartIo__().

◆ InitBadBlocks()

void NTAPI InitBadBlocks ( IN PHW_LU_EXTENSION  LunExt)

Definition at line 126 of file id_badblock.cpp.

129 {
130  RTL_QUERY_REGISTRY_TABLE QueryTable[2]; // Main record and zero filled end of array marker
131  WCHAR DevSerial[128];
132 #ifdef _DEBUG
133  UCHAR cDevSerial[128];
134  ULONG i;
135 #endif
136  ULONG Length;
138  PSBadBlockListItem cur;
139  // Read from the registry necessary badblock pairs and fill in arrBadBlocks array
140  // HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\UniATA\Parameters\BadBlocks
141 
142  if(!LunExt) {
143  // init
144  KdPrint(( "InitBadBlocks general\n"));
145  if(!BBListInited) {
147  BBListInited = TRUE;
148  }
149 
152  QueryTable[0].Name = NULL; // If Name is NULL, the QueryRoutine function
153  // specified for this table entry is called
154  // for all values associated with the current
155  // registry key.
158  QueryTable[0].DefaultData = 0;
159  QueryTable[0].DefaultLength = 0;
160 
162 
164  L"UniATA\\Parameters\\BadBlocks",
165  QueryTable, 0, 0);
166 
167 #ifdef _DEBUG
168  KdPrint(( "InitBadBlocks returned: %#x\n", status));
169 #else
171 #endif
172  } else {
173 
174  KdPrint(( "InitBadBlocks local\n"));
175  Length = EncodeVendorStr(DevSerial, (PUCHAR)LunExt->IdentifyData.ModelNumber, sizeof(LunExt->IdentifyData.ModelNumber));
176  DevSerial[Length] = '-';
177  Length++;
178  Length += EncodeVendorStr(DevSerial+Length, LunExt->IdentifyData.SerialNumber, sizeof(LunExt->IdentifyData.SerialNumber));
179 
180 #ifdef _DEBUG
181  KdPrint(( "LunExt %#x\n", LunExt));
182  for(i=0; i<Length; i++) {
183  cDevSerial[i] = (UCHAR)(DevSerial[i]);
184  }
185  cDevSerial[i] = 0;
186  KdPrint(( "S/N:%s\n", cDevSerial));
187 #endif
188 
189  LunExt->nBadBlocks = 0;
190  LunExt->arrBadBlocks = NULL;
191 
192  link = BBList.Flink;
193  while(link != &BBList) {
195  link = link->Flink;
196  if(cur->LunExt == LunExt) {
197  KdPrint(( " deassociate BB list (by LunExt)\n"));
198  cur->LunExt->nBadBlocks = 0;
199  cur->LunExt->arrBadBlocks = NULL;
200  cur->LunExt->bbListDescr = NULL;
201  cur->LunExt = NULL;
202  } else
203  if(!wcscmp(cur->SerNumStr, DevSerial)) {
204  KdPrint(( " deassociate BB list (by Serial)\n"));
205  if(cur->LunExt) {
206  cur->LunExt->nBadBlocks = 0;
207  cur->LunExt->arrBadBlocks = NULL;
208  cur->LunExt->bbListDescr = NULL;
209  cur->LunExt = NULL;
210  }
211  }
212  }
213 
214  if(!(LunExt->DeviceFlags & DFLAGS_ATAPI_DEVICE)) {
215 
216  link = BBList.Flink;
217  while(link != &BBList) {
219  link = link->Flink;
220  if(!wcscmp(cur->SerNumStr, DevSerial)) {
221  KdPrint(( "found BB:List\n"));
222  cur->LunExt = LunExt;
223  LunExt->arrBadBlocks = cur->arrBadBlocks;
224  LunExt->nBadBlocks = cur->nBadBlocks;
225  LunExt->bbListDescr = cur;
226  return;
227  }
228  }
229  }
230  }
231  return;
232 } // end InitBadBlocks()
_In_ PCWSTR _Inout_ _At_ QueryTable _Pre_unknown_ PRTL_QUERY_REGISTRY_TABLE QueryTable
Definition: rtlfuncs.h:3988
#define TRUE
Definition: types.h:120
ULONG EncodeVendorStr(OUT char *Buffer, IN PUCHAR Str, IN ULONG Length, IN ULONG Xorer)
Definition: atactl.cpp:524
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
#define DFLAGS_ATAPI_DEVICE
Definition: atapi.h:41
#define RTL_REGISTRY_SERVICES
Definition: nt_native.h:162
struct _SBadBlockListItem * bbListDescr
Definition: bsmaster.h:1200
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
PRTL_QUERY_REGISTRY_ROUTINE QueryRoutine
Definition: nt_native.h:109
smooth NULL
Definition: ftsmooth.c:416
LIST_ENTRY BBList
Definition: id_badblock.cpp:47
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
WCHAR SerNumStr[128]
Definition: badblock.h:53
LIST_ENTRY List
Definition: psmgr.c:57
PHW_LU_EXTENSION LunExt
Definition: badblock.h:52
__wchar_t WCHAR
Definition: xmlstorage.h:180
BOOLEAN BBListInited
Definition: id_badblock.cpp:48
NTSYSAPI NTSTATUS WINAPI RtlQueryRegistryValues(ULONG, PCWSTR, PRTL_QUERY_REGISTRY_TABLE, PVOID, PVOID)
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
unsigned char UCHAR
Definition: xmlstorage.h:181
static const WCHAR L[]
Definition: oid.c:1250
Definition: typedefs.h:117
struct _SBadBlockRange * arrBadBlocks
Definition: bsmaster.h:1201
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
static NTSTATUS __stdcall BadBlockQueryRoutine(IN PWSTR ValueName, IN ULONG ValueType, IN PVOID ValueData, IN ULONG ValueLength, IN PVOID Context, IN PVOID EntryContext)
Definition: id_badblock.cpp:52
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
const WCHAR * link
Definition: db.cpp:985
#define REG_NONE
Definition: nt_native.h:1492
#define RTL_QUERY_REGISTRY_REQUIRED
Definition: nt_native.h:132
#define KdPrint(x)
Definition: env_spec_w32.h:288
SBadBlockRange * arrBadBlocks
Definition: badblock.h:54
Definition: ps.c:97

Referenced by DriverEntry(), and IssueIdentify().

Variable Documentation

◆ BBList

LIST_ENTRY BBList

Definition at line 47 of file id_badblock.cpp.

Referenced by BadBlockQueryRoutine(), and InitBadBlocks().

◆ BBListInited

BOOLEAN BBListInited = FALSE

Definition at line 48 of file id_badblock.cpp.

Referenced by BadBlockQueryRoutine(), and InitBadBlocks().