Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

178 lines
4.3 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. blrange.h
  5. Abstract:
  6. This module declares ranges, rangelists and their methods. These
  7. can be used to keep track of cached ranges of a disk for instance.
  8. Author:
  9. Cenk Ergan (cenke) 11-Jan-2000
  10. Revision History:
  11. --*/
  12. #ifndef _BLRANGE_H
  13. #define _BLRANGE_H
  14. #include "bldr.h"
  15. //
  16. // Define range & range list data structures.
  17. //
  18. //
  19. // NOTE: BLCRANGE's Start is inclusive and End is exclusive. E.g.
  20. // 200-400 contains 200th but does not contain 400th byte, apple,
  21. // meter etc. This allows a single subtraction to determine the
  22. // number of elements in the range.
  23. //
  24. //
  25. // NOTE: BLCRANGE's Start should be less than or equal to its End.
  26. //
  27. //
  28. // Representing ranges with start and end instead of start and length
  29. // seems to simplify the code and remove a lot of addition and
  30. // subtractions. We could maybe use a ULONG Length, which would save 4
  31. // bytes per range, but lists make it hard to have thousands of ranges
  32. // and even if you had 10 thousand ranges, you'd save only 40KB, which
  33. // seemed to be insignificant to the cons above when I began changing
  34. // the code to have Length instead of End. With both Start and End
  35. // ULONGLONG more data can be represented by ranges, e.g. 64bit
  36. // offsets [memory or disk] where 4GB Length may not be enough.
  37. //
  38. typedef struct _BLCRANGE
  39. {
  40. ULONGLONG Start;
  41. ULONGLONG End;
  42. } BLCRANGE, *PBLCRANGE;
  43. typedef struct _BLCRANGE_ENTRY
  44. {
  45. LIST_ENTRY Link;
  46. BLCRANGE Range;
  47. PVOID UserData; // UserData field is not used by range functions.
  48. LIST_ENTRY UserLink; // UserLink field is not used by range functions.
  49. } BLCRANGE_ENTRY, *PBLCRANGE_ENTRY;
  50. //
  51. // Define range entry merging routine type. This routine should
  52. // perform the necessary operations to merge the user controlled /
  53. // maintained Data field of the pSrcEntry to pDestEntry's Data
  54. // field. It should not manipulate any other BLCRANGE_ENTRT fields. It
  55. // should return FALSE if there was an error and it could not merge
  56. // the two Data fields, TRUE otherwise. If it returns FALSE, it should
  57. // undo its modifications to pDestEntry and pSrcEntry.
  58. //
  59. typedef
  60. BOOLEAN
  61. (*PBLCRANGE_MERGE_ROUTINE) (
  62. PBLCRANGE_ENTRY pDestEntry,
  63. PBLCRANGE_ENTRY pSrcEntry
  64. );
  65. //
  66. // Define range entry free'ing routine type. This routine should free
  67. // all the resources & memory allocated for a range entry.
  68. //
  69. typedef
  70. VOID
  71. (*PBLCRANGE_FREE_ROUTINE) (
  72. PBLCRANGE_ENTRY pRangeEntry
  73. );
  74. //
  75. // BLCRANGE_LIST maintains a sorted list of non-overlapping range
  76. // entries off its Head field.
  77. //
  78. typedef struct _BLCRANGE_LIST
  79. {
  80. LIST_ENTRY Head;
  81. ULONG NumEntries;
  82. PBLCRANGE_MERGE_ROUTINE MergeRoutine;
  83. PBLCRANGE_FREE_ROUTINE FreeRoutine;
  84. } BLCRANGE_LIST, *PBLCRANGE_LIST;
  85. //
  86. // Useful macros. Be mindful of expression reevaluation as with
  87. // all macros.
  88. //
  89. #define BLRGMIN(a,b) (((a) <= (b)) ? (a) : (b))
  90. #define BLRGMAX(a,b) (((a) >= (b)) ? (a) : (b))
  91. //
  92. // Range function prototypes. See ntos\boot\lib\blrange.c for comments
  93. // and implementation.
  94. //
  95. VOID
  96. BlRangeListInitialize (
  97. PBLCRANGE_LIST pRangeList,
  98. OPTIONAL PBLCRANGE_MERGE_ROUTINE pMergeRoutine,
  99. OPTIONAL PBLCRANGE_FREE_ROUTINE pFreeRoutine
  100. );
  101. BOOLEAN
  102. BlRangeListAddRange (
  103. PBLCRANGE_LIST pRangeList,
  104. PBLCRANGE_ENTRY pRangeEntry
  105. );
  106. BOOLEAN
  107. BlRangeListFindOverlaps (
  108. PBLCRANGE_LIST pRangeList,
  109. PBLCRANGE pRange,
  110. PBLCRANGE_ENTRY *pOverlapsBuffer,
  111. ULONG OverlapsBufferSize,
  112. OUT ULONG *pNumOverlaps
  113. );
  114. BOOLEAN
  115. BlRangeListFindDistinctRanges (
  116. PBLCRANGE_LIST pRangeList,
  117. PBLCRANGE pRange,
  118. PBLCRANGE pDistinctRanges,
  119. ULONG BufferSize,
  120. OUT ULONG *pNumRanges
  121. );
  122. VOID
  123. BlRangeListRemoveRange (
  124. PBLCRANGE_LIST pRangeList,
  125. PBLCRANGE pRange
  126. );
  127. VOID
  128. BlRangeListRemoveAllRanges (
  129. PBLCRANGE_LIST pRangeList
  130. );
  131. BOOLEAN
  132. BlRangeListMergeRangeEntries (
  133. PBLCRANGE_LIST pRangeList,
  134. PBLCRANGE_ENTRY pDestEntry,
  135. PBLCRANGE_ENTRY pSrcEntry
  136. );
  137. BOOLEAN
  138. BlRangeEntryMerge (
  139. PBLCRANGE_ENTRY pDestEntry,
  140. PBLCRANGE_ENTRY pSrcEntry,
  141. OPTIONAL PBLCRANGE_MERGE_ROUTINE pMergeRoutine
  142. );
  143. #endif // _BLRANGE_H