- Implement RtlFindRange().

- Add documentation.

svn path=/trunk/; revision=9479
This commit is contained in:
Eric Kohl 2004-05-23 11:56:16 +00:00
parent 27119bd65c
commit fc9d0d4b4d

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
/* $Id: rangelist.c,v 1.5 2004/05/17 13:21:52 ekohl Exp $ /* $Id: rangelist.c,v 1.6 2004/05/23 11:56:16 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries * PROJECT: ReactOS system libraries
@ -31,6 +31,7 @@
#define NDEBUG #define NDEBUG
#include <ntdll/ntdll.h> #include <ntdll/ntdll.h>
#define ROUND_DOWN(N, S) ((N) - ((N) % (S)))
typedef struct _RTL_RANGE_ENTRY typedef struct _RTL_RANGE_ENTRY
{ {
@ -41,7 +42,25 @@ typedef struct _RTL_RANGE_ENTRY
/* FUNCTIONS ***************************************************************/ /* FUNCTIONS ***************************************************************/
/* /**********************************************************************
* NAME EXPORTED
* RtlAddRange
*
* DESCRIPTION
* Adds a range to a range list.
*
* ARGUMENTS
* RangeList Range list.
* Start
* End
* Attributes
* Flags
* UserData
* Owner
*
* RETURN VALUE
* Status
*
* TODO: * TODO:
* - Check for overlapping ranges. * - Check for overlapping ranges.
* *
@ -122,6 +141,10 @@ RtlAddRange (IN OUT PRTL_RANGE_LIST RangeList,
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
RtlFreeHeap (RtlGetProcessHeap(),
0,
RangeEntry);
return STATUS_UNSUCCESSFUL; return STATUS_UNSUCCESSFUL;
} }
@ -280,8 +303,32 @@ RtlDeleteRange (IN OUT PRTL_RANGE_LIST RangeList,
} }
/* /**********************************************************************
* @unimplemented * NAME EXPORTED
* RtlFindRange
*
* DESCRIPTION
* Searches for an unused range.
*
* ARGUMENTS
* RangeList Pointer to the range list.
* Minimum
* Maximum
* Length
* Alignment
* Flags
* AttributeAvailableMask
* Context
* Callback
* Start
*
* RETURN VALUE
* Status
*
* TODO
* Support shared ranges and callback.
*
* @implemented
*/ */
NTSTATUS STDCALL NTSTATUS STDCALL
RtlFindRange (IN PRTL_RANGE_LIST RangeList, RtlFindRange (IN PRTL_RANGE_LIST RangeList,
@ -295,34 +342,74 @@ RtlFindRange (IN PRTL_RANGE_LIST RangeList,
IN PRTL_CONFLICT_RANGE_CALLBACK Callback OPTIONAL, IN PRTL_CONFLICT_RANGE_CALLBACK Callback OPTIONAL,
OUT PULONGLONG Start) OUT PULONGLONG Start)
{ {
#if 0 PRTL_RANGE_ENTRY CurrentEntry;
PRTL_RANGE_ENTRY Current; PRTL_RANGE_ENTRY NextEntry;
PLIST_ENTRY Entry; PLIST_ENTRY Entry;
ULONGLONG RangeMin;
ULONGLONG RangeMax;
Entry = RangeList->ListHead.Flink; if (Alignment == 0 || Length == 0)
{
return STATUS_INVALID_PARAMETER;
}
if (IsListEmpty(&RangeList->ListHead))
{
*Start = ROUND_DOWN (Maximum - (Length - 1), Alignment);
return STATUS_SUCCESS;
}
NextEntry = NULL;
Entry = RangeList->ListHead.Blink;
while (Entry != &RangeList->ListHead) while (Entry != &RangeList->ListHead)
{ {
Current = CONTAINING_RECORD (Entry, RTL_RANGE_ENTRY, Entry); CurrentEntry = CONTAINING_RECORD (Entry, RTL_RANGE_ENTRY, Entry);
if (Current->Range.Start >= Minimum &&
Current->Range.End <= Maximum) RangeMax = NextEntry ? (NextEntry->Range.Start - 1) : Maximum;
if (RangeMax + (Length - 1) < Minimum)
{ {
if (Callback != NULL) return STATUS_RANGE_NOT_FOUND;
{ }
Callback (Context,
&Current->Range);
}
*Start = Current->Range.Start; RangeMin = ROUND_DOWN (RangeMax - (Length - 1), Alignment);
if (RangeMin < Minimum ||
(RangeMax - RangeMin) < (Length - 1))
{
return STATUS_RANGE_NOT_FOUND;
}
DPRINT("RangeMax: %I64x\n", RangeMax);
DPRINT("RangeMin: %I64x\n", RangeMin);
if (RangeMin > CurrentEntry->Range.End)
{
*Start = RangeMin;
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
Entry = Entry->Flink; NextEntry = CurrentEntry;
Entry = Entry->Blink;
} }
return STATUS_RANGE_NOT_FOUND; RangeMax = NextEntry ? (NextEntry->Range.Start - 1) : Maximum;
#endif if (RangeMax + (Length - 1) < Minimum)
return STATUS_NOT_IMPLEMENTED; {
return STATUS_RANGE_NOT_FOUND;
}
RangeMin = ROUND_DOWN (RangeMax - (Length - 1), Alignment);
if (RangeMin < Minimum ||
(RangeMax - RangeMin) < (Length - 1))
{
return STATUS_RANGE_NOT_FOUND;
}
DPRINT("RangeMax: %I64x\n", RangeMax);
DPRINT("RangeMin: %I64x\n", RangeMin);
*Start = RangeMin;
return STATUS_SUCCESS;
} }
@ -331,7 +418,7 @@ RtlFindRange (IN PRTL_RANGE_LIST RangeList,
* RtlFreeRangeList * RtlFreeRangeList
* *
* DESCRIPTION * DESCRIPTION
* Deletes all ranges of a range list. * Deletes all ranges in a range list.
* *
* ARGUMENTS * ARGUMENTS
* RangeList Pointer to the range list. * RangeList Pointer to the range list.
@ -478,7 +565,20 @@ RtlInitializeRangeList (IN OUT PRTL_RANGE_LIST RangeList)
} }
/* /**********************************************************************
* NAME EXPORTED
* RtlInvertRangeList
*
* DESCRIPTION
* Inverts a range list.
*
* ARGUMENTS
* InvertedRangeList Inverted range list.
* RangeList Range list.
*
* RETURN VALUE
* Status
*
* @unimplemented * @unimplemented
*/ */
NTSTATUS STDCALL NTSTATUS STDCALL
@ -489,7 +589,26 @@ RtlInvertRangeList (OUT PRTL_RANGE_LIST InvertedRangeList,
} }
/* /**********************************************************************
* NAME EXPORTED
* RtlIsRangeAvailable
*
* DESCRIPTION
* Checks whether a range is available or not.
*
* ARGUMENTS
* RangeList Pointer to the range list.
* Start
* End
* Flags
* AttributeAvailableMask
* Context
* Callback
* Available
*
* RETURN VALUE
* Status
*
* TODO: * TODO:
* - honor Flags and AttributeAvailableMask. * - honor Flags and AttributeAvailableMask.
* *
@ -535,7 +654,22 @@ RtlIsRangeAvailable (IN PRTL_RANGE_LIST RangeList,
} }
/* /**********************************************************************
* NAME EXPORTED
* RtlMergeRangeList
*
* DESCRIPTION
* Merges two range lists.
*
* ARGUMENTS
* MergedRangeList Resulting range list.
* RangeList1 First range list.
* RangeList2 Second range list
* Flags
*
* RETURN VALUE
* Status
*
* @unimplemented * @unimplemented
*/ */
NTSTATUS STDCALL NTSTATUS STDCALL