This commit was generated by cvs2svn to compensate for changes in r21,
[reactos.git] / reactos / ntoskrnl / io / mdl.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: ntoskrnl/io/mdl.c
5 * PURPOSE: Io manager mdl functions
6 * PROGRAMMER: David Welch (welch@mcmail.com)
7 * UPDATE HISTORY:
8 * Created 22/05/98
9 */
10
11 /* INCLUDES *****************************************************************/
12
13 #include <internal/kernel.h>
14 #include <internal/linkage.h>
15 #include <internal/hal/page.h>
16 #include <ddk/ntddk.h>
17
18 #include <internal/debug.h>
19
20 /* FUNCTIONS *****************************************************************/
21
22 PMDL IoAllocateMdl(PVOID VirtualAddress,
23 ULONG Length,
24 BOOLEAN SecondaryBuffer,
25 BOOLEAN ChargeQuota,
26 PIRP Irp)
27 {
28 PMDL Mdl;
29
30 if (ChargeQuota)
31 {
32 Mdl = ExAllocatePoolWithQuota(NonPagedPool,
33 MmSizeOfMdl(VirtualAddress,Length));
34 }
35 else
36 {
37 Mdl = ExAllocatePool(NonPagedPool,MmSizeOfMdl(VirtualAddress,Length));
38 }
39 MmInitializeMdl(Mdl,VirtualAddress,Length);
40 if (Irp!=NULL && !SecondaryBuffer)
41 {
42 Irp->MdlAddress = Mdl;
43 }
44 return(Mdl);
45 }
46
47 VOID IoBuildPartialMdl(PMDL SourceMdl,
48 PMDL TargetMdl,
49 PVOID VirtualAddress,
50 ULONG Length)
51 {
52 PULONG TargetPages = (PULONG)(TargetMdl + 1);
53 PULONG SourcePages = (PULONG)(SourceMdl + 1);
54 ULONG Va;
55 ULONG Delta = (PAGE_ROUND_DOWN(VirtualAddress) - (ULONG)SourceMdl->StartVa)/
56 PAGESIZE;
57
58 for (Va = 0; Va < (PAGE_ROUND_UP(Length)/PAGESIZE); Va++)
59 {
60 TargetPages[Va] = SourcePages[Va+Delta];
61 }
62 }
63
64 VOID IoFreeMdl(PMDL Mdl)
65 {
66 MmUnmapLockedPages(MmGetSystemAddressForMdl(Mdl),Mdl);
67 MmUnlockPages(Mdl);
68 ExFreePool(Mdl);
69 }