Continue of MSVC-compiling changes....
[reactos.git] / reactos / ntoskrnl / io / mdl.c
1 /* $Id: mdl.c,v 1.13 2003/12/30 18:52:04 fireball Exp $
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/io/mdl.c
6 * PURPOSE: Io manager mdl functions
7 * PROGRAMMER: David Welch (welch@mcmail.com)
8 * UPDATE HISTORY:
9 * Created 22/05/98
10 */
11
12 /* INCLUDES *****************************************************************/
13
14 #include <ddk/ntddk.h>
15 #include <internal/pool.h>
16
17 #include <internal/debug.h>
18
19 /* GLOBALS *******************************************************************/
20
21 #define TAG_MDL TAG('M', 'D', 'L', ' ')
22
23 /* FUNCTIONS *****************************************************************/
24
25 /*
26 * @implemented
27 */
28 PMDL
29 STDCALL
30 IoAllocateMdl(PVOID VirtualAddress,
31 ULONG Length,
32 BOOLEAN SecondaryBuffer,
33 BOOLEAN ChargeQuota,
34 PIRP Irp)
35 {
36 PMDL Mdl;
37
38 if (ChargeQuota)
39 {
40 // Mdl = ExAllocatePoolWithQuota(NonPagedPool,
41 // MmSizeOfMdl(VirtualAddress,Length));
42 Mdl = ExAllocatePoolWithTag(NonPagedPool,
43 MmSizeOfMdl(VirtualAddress,Length),
44 TAG_MDL);
45 }
46 else
47 {
48 Mdl = ExAllocatePoolWithTag(NonPagedPool,
49 MmSizeOfMdl(VirtualAddress,Length),
50 TAG_MDL);
51 }
52 MmInitializeMdl(Mdl, (char*)VirtualAddress, Length);
53 if (Irp!=NULL && !SecondaryBuffer)
54 {
55 Irp->MdlAddress = Mdl;
56 }
57 return(Mdl);
58 }
59
60 /*
61 * @implemented
62 */
63 VOID
64 STDCALL
65 IoBuildPartialMdl(PMDL SourceMdl,
66 PMDL TargetMdl,
67 PVOID VirtualAddress,
68 ULONG Length)
69 {
70 PULONG TargetPages = (PULONG)(TargetMdl + 1);
71 PULONG SourcePages = (PULONG)(SourceMdl + 1);
72 ULONG Va;
73 ULONG Delta = (PAGE_ROUND_DOWN(VirtualAddress) - (ULONG)SourceMdl->StartVa)/
74 PAGE_SIZE;
75
76 for (Va = 0; Va < (PAGE_ROUND_UP(Length)/PAGE_SIZE); Va++)
77 {
78 TargetPages[Va] = SourcePages[Va+Delta];
79 }
80 }
81
82 /*
83 * @implemented
84 */
85 VOID STDCALL
86 IoFreeMdl(PMDL Mdl)
87 {
88 MmUnmapLockedPages(MmGetSystemAddressForMdl(Mdl), Mdl);
89 MmUnlockPages(Mdl);
90 ExFreePool(Mdl);
91 }
92
93
94 /* EOF */