[CMAKE]
[reactos.git] / ntoskrnl / config / cmvalche.c
1 /*
2 * PROJECT: ReactOS Kernel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: ntoskrnl/config/cmvalche.c
5 * PURPOSE: Configuration Manager - Value Cell Cache
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
7 */
8
9 /* INCLUDES ******************************************************************/
10
11 #include "ntoskrnl.h"
12 #define NDEBUG
13 #include "debug.h"
14
15 FORCEINLINE
16 BOOLEAN
17 CmpIsValueCached(IN HCELL_INDEX CellIndex)
18 {
19 /* Make sure that the cell is valid in the first place */
20 if (CellIndex == HCELL_NIL) return FALSE;
21
22 /*Is this cell actually a pointer to the cached value data? */
23 if (CellIndex & 1) return TRUE;
24
25 /* This is a regular cell */
26 return FALSE;
27 }
28
29 FORCEINLINE
30 VOID
31 CmpSetValueCached(IN PHCELL_INDEX CellIndex)
32 {
33 /* Set the cached bit */
34 *CellIndex |= 1;
35 }
36
37 #define ASSERT_VALUE_CACHE() \
38 ASSERTMSG("Cached Values Not Yet Supported!", FALSE);
39
40 /* FUNCTIONS *****************************************************************/
41
42 VALUE_SEARCH_RETURN_TYPE
43 NTAPI
44 CmpGetValueListFromCache(IN PCM_KEY_CONTROL_BLOCK Kcb,
45 OUT PCELL_DATA *CellData,
46 OUT BOOLEAN *IndexIsCached,
47 OUT PHCELL_INDEX ValueListToRelease)
48 {
49 PHHIVE Hive;
50 PCACHED_CHILD_LIST ChildList;
51 HCELL_INDEX CellToRelease;
52 PCM_KEY_NODE KeyNode;
53
54 /* Set defaults */
55 *ValueListToRelease = HCELL_NIL;
56 *IndexIsCached = FALSE;
57
58 /* Get the hive and value cache */
59 Hive = Kcb->KeyHive;
60 ChildList = &Kcb->ValueCache;
61 KeyNode = (PCM_KEY_NODE)HvGetCell(Hive, Kcb->KeyCell);
62 ChildList = (PCACHED_CHILD_LIST)&KeyNode->ValueList;
63
64 /* Check if the value is cached */
65 if (CmpIsValueCached(ChildList->ValueList))
66 {
67 /* It is: we don't expect this yet! */
68 ASSERT_VALUE_CACHE();
69 *IndexIsCached = TRUE;
70 *CellData = NULL;
71 }
72 else
73 {
74 /* Make sure the KCB is locked exclusive */
75 if (!(CmpIsKcbLockedExclusive(Kcb)) &&
76 !(CmpTryToConvertKcbSharedToExclusive(Kcb)))
77 {
78 /* We need the exclusive lock */
79 return SearchNeedExclusiveLock;
80 }
81
82 /* Select the value list as our cell, and get the actual list array */
83 CellToRelease = ChildList->ValueList;
84 *CellData = (PCELL_DATA)HvGetCell(Hive, CellToRelease);
85 if (!(*CellData)) return SearchFail;
86
87 /* FIXME: Here we would cache the value */
88
89 /* Return the cell to be released */
90 *ValueListToRelease = CellToRelease;
91 }
92
93 /* If we got here, then the value list was found */
94 return SearchSuccess;
95 }
96
97 VALUE_SEARCH_RETURN_TYPE
98 NTAPI
99 CmpGetValueKeyFromCache(IN PCM_KEY_CONTROL_BLOCK Kcb,
100 IN PCELL_DATA CellData,
101 IN ULONG Index,
102 OUT PCM_CACHED_VALUE **CachedValue,
103 OUT PCM_KEY_VALUE *Value,
104 IN BOOLEAN IndexIsCached,
105 OUT BOOLEAN *ValueIsCached,
106 OUT PHCELL_INDEX CellToRelease)
107 {
108 PHHIVE Hive;
109 PCM_KEY_VALUE KeyValue;
110 HCELL_INDEX Cell;
111
112 /* Set defaults */
113 *CellToRelease = HCELL_NIL;
114 *Value = NULL;
115 *ValueIsCached = FALSE;
116
117 /* Get the hive */
118 Hive = Kcb->KeyHive;
119
120 /* Check if the index was cached */
121 if (IndexIsCached)
122 {
123 /* Not expected yet! */
124 ASSERT_VALUE_CACHE();
125 *ValueIsCached = TRUE;
126 }
127 else
128 {
129 /* Get the cell index and the key value associated to it */
130 Cell = CellData->u.KeyList[Index];
131 KeyValue = (PCM_KEY_VALUE)HvGetCell(Hive, Cell);
132 if (!KeyValue) return SearchFail;
133
134 /* Return the cell and the actual key value */
135 *CellToRelease = Cell;
136 *Value = KeyValue;
137 }
138
139 /* If we got here, then we found the key value */
140 return SearchSuccess;
141 }
142
143 VALUE_SEARCH_RETURN_TYPE
144 NTAPI
145 CmpGetValueDataFromCache(IN PCM_KEY_CONTROL_BLOCK Kcb,
146 IN PCM_CACHED_VALUE *CachedValue,
147 IN PCELL_DATA ValueKey,
148 IN BOOLEAN ValueIsCached,
149 OUT PVOID *DataPointer,
150 OUT PBOOLEAN Allocated,
151 OUT PHCELL_INDEX CellToRelease)
152 {
153 PHHIVE Hive;
154 ULONG Length;
155
156 /* Sanity checks */
157 ASSERT(MAXIMUM_CACHED_DATA < CM_KEY_VALUE_BIG);
158 ASSERT((ValueKey->u.KeyValue.DataLength & CM_KEY_VALUE_SPECIAL_SIZE) == 0);
159
160 /* Set defaults */
161 *DataPointer = NULL;
162 *Allocated = FALSE;
163 *CellToRelease = HCELL_NIL;
164
165 /* Get the hive */
166 Hive = Kcb->KeyHive;
167
168 /* Check it the value is cached */
169 if (ValueIsCached)
170 {
171 /* This isn't expected! */
172 ASSERT_VALUE_CACHE();
173 }
174 else
175 {
176 /* It's not, get the value data using the typical routine */
177 if (!CmpGetValueData(Hive,
178 &ValueKey->u.KeyValue,
179 &Length,
180 DataPointer,
181 Allocated,
182 CellToRelease))
183 {
184 /* Nothing found: make sure no data was allocated */
185 ASSERT(*Allocated == FALSE);
186 ASSERT(*DataPointer == NULL);
187 return SearchFail;
188 }
189 }
190
191 /* We found the actual data, return success */
192 return SearchSuccess;
193 }
194
195 VALUE_SEARCH_RETURN_TYPE
196 NTAPI
197 CmpFindValueByNameFromCache(IN PCM_KEY_CONTROL_BLOCK Kcb,
198 IN PCUNICODE_STRING Name,
199 OUT PCM_CACHED_VALUE **CachedValue,
200 OUT ULONG *Index,
201 OUT PCM_KEY_VALUE *Value,
202 OUT BOOLEAN *ValueIsCached,
203 OUT PHCELL_INDEX CellToRelease)
204 {
205 PHHIVE Hive;
206 VALUE_SEARCH_RETURN_TYPE SearchResult = SearchFail;
207 LONG Result;
208 UNICODE_STRING SearchName;
209 PCELL_DATA CellData;
210 PCACHED_CHILD_LIST ChildList;
211 PCM_KEY_VALUE KeyValue;
212 BOOLEAN IndexIsCached;
213 ULONG i = 0;
214 HCELL_INDEX Cell = HCELL_NIL;
215 PCM_KEY_NODE KeyNode;
216
217 /* Set defaults */
218 *CellToRelease = HCELL_NIL;
219 *Value = NULL;
220
221 /* Get the hive and child list */
222 Hive = Kcb->KeyHive;
223 ChildList = &Kcb->ValueCache;
224 KeyNode = (PCM_KEY_NODE)HvGetCell(Hive, Kcb->KeyCell);
225 ChildList = (PCACHED_CHILD_LIST)&KeyNode->ValueList;
226
227 /* Check if the child list has any entries */
228 if (ChildList->Count != 0)
229 {
230 /* Get the value list associated to this child list */
231 SearchResult = CmpGetValueListFromCache(Kcb,
232 &CellData,
233 &IndexIsCached,
234 &Cell);
235 if (SearchResult != SearchSuccess)
236 {
237 /* We either failed or need the exclusive lock */
238 ASSERT((SearchResult == SearchFail) || !(CmpIsKcbLockedExclusive(Kcb)));
239 ASSERT(Cell == HCELL_NIL);
240 return SearchResult;
241 }
242
243 /* The index shouldn't be cached right now */
244 if (IndexIsCached) ASSERT_VALUE_CACHE();
245
246 /* Loop every value */
247 while (TRUE)
248 {
249 /* Check if there's any cell to release */
250 if (*CellToRelease != HCELL_NIL)
251 {
252 /* Release it now */
253 HvReleaseCell(Hive, *CellToRelease);
254 *CellToRelease = HCELL_NIL;
255 }
256
257 /* Get the key value for this index */
258 SearchResult = CmpGetValueKeyFromCache(Kcb,
259 CellData,
260 i,
261 CachedValue,
262 Value,
263 IndexIsCached,
264 ValueIsCached,
265 CellToRelease);
266 if (SearchResult != SearchSuccess)
267 {
268 /* We either failed or need the exclusive lock */
269 ASSERT((SearchResult == SearchFail) || !(CmpIsKcbLockedExclusive(Kcb)));
270 ASSERT(Cell == HCELL_NIL);
271 return SearchResult;
272 }
273
274 /* Check if the both the index and the value are cached */
275 if ((IndexIsCached) && (*ValueIsCached))
276 {
277 /* We don't expect this yet */
278 ASSERT_VALUE_CACHE();
279 Result = -1;
280 }
281 else
282 {
283 /* No cache, so try to compare the name. Is it compressed? */
284 KeyValue = *Value;
285 if (KeyValue->Flags & VALUE_COMP_NAME)
286 {
287 /* It is, do a compressed name comparison */
288 Result = CmpCompareCompressedName(Name,
289 KeyValue->Name,
290 KeyValue->NameLength);
291 }
292 else
293 {
294 /* It's not compressed, so do a standard comparison */
295 SearchName.Length = KeyValue->NameLength;
296 SearchName.MaximumLength = SearchName.Length;
297 SearchName.Buffer = KeyValue->Name;
298 Result = RtlCompareUnicodeString(Name, &SearchName, TRUE);
299 }
300 }
301
302 /* Check if we found the value data */
303 if (!Result)
304 {
305 /* We have, return the index of the value and success */
306 *Index = i;
307 SearchResult = SearchSuccess;
308 goto Quickie;
309 }
310
311 /* We didn't find it, try the next entry */
312 if (++i == ChildList->Count)
313 {
314 /* The entire list was parsed, fail */
315 *Value = NULL;
316 SearchResult = SearchFail;
317 goto Quickie;
318 }
319 }
320 }
321
322 /* We should only get here if the child list is empty */
323 ASSERT(ChildList->Count == 0);
324
325 Quickie:
326 /* Release the value list cell if required, and return search result */
327 if (Cell != HCELL_NIL) HvReleaseCell(Hive, Cell);
328 return SearchResult;
329 }
330
331 VALUE_SEARCH_RETURN_TYPE
332 NTAPI
333 CmpQueryKeyValueData(IN PCM_KEY_CONTROL_BLOCK Kcb,
334 IN PCM_CACHED_VALUE *CachedValue,
335 IN PCM_KEY_VALUE ValueKey,
336 IN BOOLEAN ValueIsCached,
337 IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass,
338 IN PVOID KeyValueInformation,
339 IN ULONG Length,
340 OUT PULONG ResultLength,
341 OUT PNTSTATUS Status)
342 {
343 PKEY_VALUE_INFORMATION Info = (PKEY_VALUE_INFORMATION)KeyValueInformation;
344 PCELL_DATA CellData;
345 USHORT NameSize;
346 ULONG Size, MinimumSize, SizeLeft, KeySize, AlignedData = 0, DataOffset;
347 PVOID Buffer;
348 BOOLEAN IsSmall, BufferAllocated = FALSE;
349 HCELL_INDEX CellToRelease = HCELL_NIL;
350 VALUE_SEARCH_RETURN_TYPE Result = SearchSuccess;
351
352 /* Get the value data */
353 CellData = (PCELL_DATA)ValueKey;
354
355 /* Check if the value is compressed */
356 if (CellData->u.KeyValue.Flags & VALUE_COMP_NAME)
357 {
358 /* Get the compressed name size */
359 NameSize = CmpCompressedNameSize(CellData->u.KeyValue.Name,
360 CellData->u.KeyValue.NameLength);
361 }
362 else
363 {
364 /* Get the real size */
365 NameSize = CellData->u.KeyValue.NameLength;
366 }
367
368 /* Check what kind of information the caller is requesting */
369 switch (KeyValueInformationClass)
370 {
371 /* Basic information */
372 case KeyValueBasicInformation:
373
374 /* This is how much size we'll need */
375 Size = FIELD_OFFSET(KEY_VALUE_BASIC_INFORMATION, Name) + NameSize;
376
377 /* This is the minimum we can work with */
378 MinimumSize = FIELD_OFFSET(KEY_VALUE_BASIC_INFORMATION, Name);
379
380 /* Return the size we'd like, and assume success */
381 *ResultLength = Size;
382 *Status = STATUS_SUCCESS;
383
384 /* Check if the caller gave us below our minimum */
385 if (Length < MinimumSize)
386 {
387 /* Then we must fail */
388 *Status = STATUS_BUFFER_TOO_SMALL;
389 break;
390 }
391
392 /* Fill out the basic information */
393 Info->KeyValueBasicInformation.TitleIndex = 0;
394 Info->KeyValueBasicInformation.Type = CellData->u.KeyValue.Type;
395 Info->KeyValueBasicInformation.NameLength = NameSize;
396
397 /* Now only the name is left */
398 SizeLeft = Length - MinimumSize;
399 Size = NameSize;
400
401 /* Check if the remaining buffer is too small for the name */
402 if (SizeLeft < Size)
403 {
404 /* Copy only as much as can fit, and tell the caller */
405 Size = SizeLeft;
406 *Status = STATUS_BUFFER_OVERFLOW;
407 }
408
409 /* Check if this is a compressed name */
410 if (CellData->u.KeyValue.Flags & VALUE_COMP_NAME)
411 {
412 /* Copy as much as we can of the compressed name */
413 CmpCopyCompressedName(Info->KeyValueBasicInformation.Name,
414 Size,
415 CellData->u.KeyValue.Name,
416 CellData->u.KeyValue.NameLength);
417 }
418 else
419 {
420 /* Copy as much as we can of the raw name */
421 RtlCopyMemory(Info->KeyValueBasicInformation.Name,
422 CellData->u.KeyValue.Name,
423 Size);
424 }
425
426 /* We're all done */
427 break;
428
429 /* Full key information */
430 case KeyValueFullInformation:
431
432 /* Check if this is a small key and compute key size */
433 IsSmall = CmpIsKeyValueSmall(&KeySize,
434 CellData->u.KeyValue.DataLength);
435
436 /* Calculate the total size required */
437 Size = FIELD_OFFSET(KEY_VALUE_FULL_INFORMATION, Name) +
438 NameSize +
439 KeySize;
440
441 /* And this is the least we can work with */
442 MinimumSize = FIELD_OFFSET(KEY_VALUE_FULL_INFORMATION, Name);
443
444 /* Check if there's any key data */
445 if (KeySize > 0)
446 {
447 /* Calculate the data offset */
448 DataOffset = Size - KeySize;
449
450 /* Align the offset to 4 bytes */
451 AlignedData = ALIGN_UP(DataOffset, ULONG);
452
453 /* If alignment was required, we'll need more space */
454 if (AlignedData > DataOffset) Size += (AlignedData-DataOffset);
455 }
456
457 /* Tell the caller the size we'll finally need, and set success */
458 *ResultLength = Size;
459 *Status = STATUS_SUCCESS;
460
461 /* Check if the caller is giving us too little */
462 if (Length < MinimumSize)
463 {
464 /* Then fail right now */
465 *Status = STATUS_BUFFER_TOO_SMALL;
466 break;
467 }
468
469 /* Fill out the basic information */
470 Info->KeyValueFullInformation.TitleIndex = 0;
471 Info->KeyValueFullInformation.Type = CellData->u.KeyValue.Type;
472 Info->KeyValueFullInformation.DataLength = KeySize;
473 Info->KeyValueFullInformation.NameLength = NameSize;
474
475 /* Only the name is left now */
476 SizeLeft = Length - MinimumSize;
477 Size = NameSize;
478
479 /* Check if the name fits */
480 if (SizeLeft < Size)
481 {
482 /* It doesn't, truncate what we'll copy, and tell the caller */
483 Size = SizeLeft;
484 *Status = STATUS_BUFFER_OVERFLOW;
485 }
486
487 /* Check if this key value is compressed */
488 if (CellData->u.KeyValue.Flags & VALUE_COMP_NAME)
489 {
490 /* It is, copy the compressed name */
491 CmpCopyCompressedName(Info->KeyValueFullInformation.Name,
492 Size,
493 CellData->u.KeyValue.Name,
494 CellData->u.KeyValue.NameLength);
495 }
496 else
497 {
498 /* It's not, copy the raw name */
499 RtlCopyMemory(Info->KeyValueFullInformation.Name,
500 CellData->u.KeyValue.Name,
501 Size);
502 }
503
504 /* Now check if the key had any data */
505 if (KeySize > 0)
506 {
507 /* Was it a small key? */
508 if (IsSmall)
509 {
510 /* Then the data is directly into the cell */
511 Buffer = &CellData->u.KeyValue.Data;
512 }
513 else
514 {
515 /* Otherwise, we must retrieve it from the value cache */
516 Result = CmpGetValueDataFromCache(Kcb,
517 CachedValue,
518 CellData,
519 ValueIsCached,
520 &Buffer,
521 &BufferAllocated,
522 &CellToRelease);
523 if (Result != SearchSuccess)
524 {
525 /* We failed, nothing should be allocated */
526 ASSERT(Buffer == NULL);
527 ASSERT(BufferAllocated == FALSE);
528 *Status = STATUS_INSUFFICIENT_RESOURCES;
529 }
530 }
531
532 /* Now that we know we truly have data, set its offset */
533 Info->KeyValueFullInformation.DataOffset = AlignedData;
534
535 /* Only the data remains to be copied */
536 SizeLeft = (((LONG)Length - (LONG)AlignedData) < 0) ?
537 0 : (Length - AlignedData);
538 Size = KeySize;
539
540 /* Check if the caller has no space for it */
541 if (SizeLeft < Size)
542 {
543 /* Truncate what we'll copy, and tell the caller */
544 Size = SizeLeft;
545 *Status = STATUS_BUFFER_OVERFLOW;
546 }
547
548 /* Sanity check */
549 ASSERT((IsSmall ? (Size <= CM_KEY_VALUE_SMALL) : TRUE));
550
551 /* Make sure we have a valid buffer */
552 if (Buffer)
553 {
554 /* Copy the data into the aligned offset */
555 RtlCopyMemory((PVOID)((ULONG_PTR)Info + AlignedData),
556 Buffer,
557 Size);
558 }
559 }
560 else
561 {
562 /* We don't have any data, set the offset to -1, not 0! */
563 Info->KeyValueFullInformation.DataOffset = 0xFFFFFFFF;
564 }
565
566 /* We're done! */
567 break;
568
569 /* Partial information requested (no name or alignment!) */
570 case KeyValuePartialInformation:
571
572 /* Check if this is a small key and compute key size */
573 IsSmall = CmpIsKeyValueSmall(&KeySize,
574 CellData->u.KeyValue.DataLength);
575
576 /* Calculate the total size required */
577 Size = FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data) + KeySize;
578
579 /* And this is the least we can work with */
580 MinimumSize = FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data);
581
582 /* Tell the caller the size we'll finally need, and set success */
583 *ResultLength = Size;
584 *Status = STATUS_SUCCESS;
585
586 /* Check if the caller is giving us too little */
587 if (Length < MinimumSize)
588 {
589 /* Then fail right now */
590 *Status = STATUS_BUFFER_TOO_SMALL;
591 break;
592 }
593
594 /* Fill out the basic information */
595 Info->KeyValuePartialInformation.TitleIndex = 0;
596 Info->KeyValuePartialInformation.Type = CellData->u.KeyValue.Type;
597 Info->KeyValuePartialInformation.DataLength = KeySize;
598
599 /* Now check if the key had any data */
600 if (KeySize > 0)
601 {
602 /* Was it a small key? */
603 if (IsSmall)
604 {
605 /* Then the data is directly into the cell */
606 Buffer = &CellData->u.KeyValue.Data;
607 }
608 else
609 {
610 /* Otherwise, we must retrieve it from the value cache */
611 Result = CmpGetValueDataFromCache(Kcb,
612 CachedValue,
613 CellData,
614 ValueIsCached,
615 &Buffer,
616 &BufferAllocated,
617 &CellToRelease);
618 if (Result != SearchSuccess)
619 {
620 /* We failed, nothing should be allocated */
621 ASSERT(Buffer == NULL);
622 ASSERT(BufferAllocated == FALSE);
623 *Status = STATUS_INSUFFICIENT_RESOURCES;
624 }
625 }
626
627 /* Only the data remains to be copied */
628 SizeLeft = Length - MinimumSize;
629 Size = KeySize;
630
631 /* Check if the caller has no space for it */
632 if (SizeLeft < Size)
633 {
634 /* Truncate what we'll copy, and tell the caller */
635 Size = SizeLeft;
636 *Status = STATUS_BUFFER_OVERFLOW;
637 }
638
639 /* Sanity check */
640 ASSERT((IsSmall ? (Size <= CM_KEY_VALUE_SMALL) : TRUE));
641
642 /* Make sure we have a valid buffer */
643 if (Buffer)
644 {
645 /* Copy the data into the aligned offset */
646 RtlCopyMemory(Info->KeyValuePartialInformation.Data,
647 Buffer,
648 Size);
649 }
650 }
651
652 /* We're done! */
653 break;
654
655 /* Other information class */
656 default:
657
658 /* We got some class that we don't support */
659 *Status = STATUS_INVALID_PARAMETER;
660 break;
661 }
662
663 /* Return the search result as well */
664 return Result;
665 }
666
667 VALUE_SEARCH_RETURN_TYPE
668 NTAPI
669 CmpCompareNewValueDataAgainstKCBCache(IN PCM_KEY_CONTROL_BLOCK Kcb,
670 IN PUNICODE_STRING ValueName,
671 IN ULONG Type,
672 IN PVOID Data,
673 IN ULONG DataSize)
674 {
675 VALUE_SEARCH_RETURN_TYPE SearchResult;
676 PCM_KEY_NODE KeyNode;
677 PCM_CACHED_VALUE *CachedValue;
678 ULONG Index;
679 PCM_KEY_VALUE Value;
680 BOOLEAN ValueCached, BufferAllocated = FALSE;
681 PVOID Buffer;
682 HCELL_INDEX ValueCellToRelease = HCELL_NIL, CellToRelease = HCELL_NIL;
683 BOOLEAN IsSmall;
684 ULONG CompareResult;
685 PAGED_CODE();
686
687 /* Check if this is a symlink */
688 if (Kcb->Flags & KEY_SYM_LINK)
689 {
690 /* We need the exclusive lock */
691 if (!(CmpIsKcbLockedExclusive(Kcb)) &&
692 !(CmpTryToConvertKcbSharedToExclusive(Kcb)))
693 {
694 /* We need the exclusive lock */
695 return SearchNeedExclusiveLock;
696 }
697
698 /* Otherwise, get the key node */
699 KeyNode = (PCM_KEY_NODE)HvGetCell(Kcb->KeyHive, Kcb->KeyCell);
700 if (!KeyNode) return SearchFail;
701
702 /* Cleanup the KCB cache */
703 CmpCleanUpKcbValueCache(Kcb);
704
705 /* Sanity checks */
706 ASSERT(!(CMP_IS_CELL_CACHED(Kcb->ValueCache.ValueList)));
707 ASSERT(!(Kcb->ExtFlags & CM_KCB_SYM_LINK_FOUND));
708
709 /* Set the value cache */
710 Kcb->ValueCache.Count = KeyNode->ValueList.Count;
711 Kcb->ValueCache.ValueList = KeyNode->ValueList.List;
712
713 /* Release the cell */
714 HvReleaseCell(Kcb->KeyHive, Kcb->KeyCell);
715 }
716
717 /* Do the search */
718 SearchResult = CmpFindValueByNameFromCache(Kcb,
719 ValueName,
720 &CachedValue,
721 &Index,
722 &Value,
723 &ValueCached,
724 &ValueCellToRelease);
725 if (SearchResult == SearchNeedExclusiveLock)
726 {
727 /* We need the exclusive lock */
728 ASSERT(!CmpIsKcbLockedExclusive(Kcb));
729 ASSERT(ValueCellToRelease == HCELL_NIL);
730 ASSERT(Value == NULL);
731 goto Quickie;
732 }
733 else if (SearchResult == SearchSuccess)
734 {
735 /* Sanity check */
736 ASSERT(Value);
737
738 /* First of all, check if the key size and type matches */
739 if ((Type == Value->Type) &&
740 (DataSize == (Value->DataLength & ~CM_KEY_VALUE_SPECIAL_SIZE)))
741 {
742 /* Check if this is a small key */
743 IsSmall = (DataSize <= CM_KEY_VALUE_SMALL) ? TRUE: FALSE;
744 if (IsSmall)
745 {
746 /* Compare against the data directly */
747 Buffer = &Value->Data;
748 }
749 else
750 {
751 /* Do a search */
752 SearchResult = CmpGetValueDataFromCache(Kcb,
753 CachedValue,
754 (PCELL_DATA)Value,
755 ValueCached,
756 &Buffer,
757 &BufferAllocated,
758 &CellToRelease);
759 if (SearchResult != SearchSuccess)
760 {
761 /* Sanity checks */
762 ASSERT(Buffer == NULL);
763 ASSERT(BufferAllocated == FALSE);
764 goto Quickie;
765 }
766 }
767
768 /* Now check the data size */
769 if (DataSize)
770 {
771 /* Do the compare */
772 CompareResult = RtlCompareMemory(Buffer,
773 Data,
774 DataSize &
775 ~CM_KEY_VALUE_SPECIAL_SIZE);
776 }
777 else
778 {
779 /* It's equal */
780 CompareResult = 0;
781 }
782
783 /* Now check if the compare wasn't equal */
784 if (CompareResult != DataSize) SearchResult = SearchFail;
785 }
786 else
787 {
788 /* The length or type isn't equal */
789 SearchResult = SearchFail;
790 }
791 }
792
793 Quickie:
794 /* Release the value cell */
795 if (ValueCellToRelease) HvReleaseCell(Kcb->KeyHive, ValueCellToRelease);
796
797 /* Free the buffer */
798 if (BufferAllocated) CmpFree(Buffer, 0);
799
800 /* Free the cell */
801 if (CellToRelease) HvReleaseCell(Kcb->KeyHive, CellToRelease);
802
803 /* Return the search result */
804 return SearchResult;
805 }