IoPageRead(): Fix 'StatusBlock' parameter to return correct value (FIXME)
[reactos.git] / ntoskrnl / io / page.c
1 /* $Id$
2  *
3  * COPYRIGHT:       See COPYING in the top level directory
4  * PROJECT:         ReactOS kernel
5  * FILE:            ntoskrnl/io/page.c
6  * PURPOSE:         
7  * PROGRAMMER:      
8  * UPDATE HISTORY:
9  *                  
10  */
11
12 /* INCLUDES *****************************************************************/
13
14 #include <ddk/ntddk.h>
15 #include <internal/io.h>
16
17 #define NDEBUG
18 #include <internal/debug.h>
19
20 /* FUNCTIONS *****************************************************************/
21
22 #ifndef LIBCAPTIVE
23
24 NTSTATUS STDCALL 
25 IoPageWrite(PFILE_OBJECT FileObject,
26             PMDL Mdl,
27             PLARGE_INTEGER Offset,
28             PKEVENT Event,
29             PIO_STATUS_BLOCK StatusBlock)
30 {
31    PIRP Irp;
32    PIO_STACK_LOCATION StackPtr;
33    NTSTATUS Status;
34    
35    DPRINT("IoPageWrite(FileObject %x, Mdl %x)\n",
36           FileObject, Mdl);
37    
38    Irp = IoBuildSynchronousFsdRequestWithMdl(IRP_MJ_WRITE,
39                                              FileObject->DeviceObject,
40                                              Mdl,
41                                              Offset,
42                                              Event,
43                                              StatusBlock,
44                                              TRUE);
45    if (Irp == NULL)
46    {
47       return (STATUS_INSUFFICIENT_RESOURCES);
48    }
49    Irp->Flags = IRP_NOCACHE|IRP_PAGING_IO;
50    StackPtr = IoGetNextIrpStackLocation(Irp);
51    StackPtr->FileObject = FileObject;
52    DPRINT("Before IoCallDriver\n");
53    Status = IofCallDriver(FileObject->DeviceObject,Irp);
54    DPRINT("Status %d STATUS_PENDING %d\n",Status,STATUS_PENDING);
55    return(Status);
56 }
57
58 #endif /* LIBCAPTIVE */
59
60 NTSTATUS STDCALL 
61 IoPageRead(PFILE_OBJECT FileObject,
62            PMDL Mdl,
63            PLARGE_INTEGER Offset,
64            PKEVENT Event,
65            PIO_STATUS_BLOCK StatusBlock)
66 {
67    PIRP Irp;
68    PIO_STACK_LOCATION StackPtr;
69    NTSTATUS Status;
70    
71    DPRINT("IoPageRead(FileObject %x, Mdl %x)\n",
72           FileObject, Mdl);
73    
74    Irp = IoBuildSynchronousFsdRequestWithMdl(IRP_MJ_READ,
75                                              FileObject->DeviceObject,
76                                              Mdl,
77                                              Offset,
78                                              Event,
79                                              StatusBlock,
80                                              TRUE);
81    if (Irp == NULL)
82    {
83       return (STATUS_INSUFFICIENT_RESOURCES);
84    }
85    Irp->Flags = IRP_NOCACHE
86 #ifndef LIBCAPTIVE
87          |IRP_PAGING_IO;
88 #else /* !LIBCAPTIVE */
89 /* IRP_SYNCHRONOUS_PAGING_IO: We need to prevent STATUS_PENDING
90  * IRP_PAGING_IO: We need to pass check in W32 filesystem as we are FO_CLEANUP_COMPLETE (why?)
91  */
92          |IRP_PAGING_IO|IRP_SYNCHRONOUS_PAGING_IO;
93 #endif /* !LIBCAPTIVE */
94    StackPtr = IoGetNextIrpStackLocation(Irp);
95    StackPtr->FileObject = FileObject;
96    DPRINT("Before IoCallDriver\n");
97    Status = IofCallDriver(FileObject->DeviceObject, Irp);
98    /* FIXME: IoBuildSynchronousFsdRequestWithMdl() will fill 'StatusBlock' to 'Irp->UserIoSb'
99     * but W32 filesystem takes care just of 'Irp->IoStatus'. Hack it back here.
100     */
101    *StatusBlock=Irp->IoStatus;
102    DPRINT("Status %d STATUS_PENDING %d\n",Status,STATUS_PENDING);
103
104    return(Status);
105 }
106
107 #ifndef LIBCAPTIVE
108
109 NTSTATUS STDCALL 
110 IoSynchronousPageWrite (PFILE_OBJECT FileObject,
111                         PMDL Mdl,
112                         PLARGE_INTEGER Offset,
113                         PKEVENT Event,
114                         PIO_STATUS_BLOCK StatusBlock)
115 {
116    PIRP Irp;
117    PIO_STACK_LOCATION StackPtr;
118    NTSTATUS Status;
119    
120    DPRINT("IoSynchronousPageWrite(FileObject %x, Mdl %x)\n",
121           FileObject, Mdl);
122    
123    Irp = IoBuildSynchronousFsdRequestWithMdl(IRP_MJ_WRITE,
124                                              FileObject->DeviceObject,
125                                              Mdl,
126                                              Offset,
127                                              Event,
128                                              StatusBlock,
129                                              TRUE);
130    if (Irp == NULL)
131    {
132       return (STATUS_INSUFFICIENT_RESOURCES);
133    }
134    Irp->Flags = IRP_NOCACHE|IRP_PAGING_IO|IRP_SYNCHRONOUS_PAGING_IO;
135    StackPtr = IoGetNextIrpStackLocation(Irp);
136    StackPtr->FileObject = FileObject;
137    DPRINT("Before IoCallDriver\n");
138    Status = IofCallDriver(FileObject->DeviceObject,Irp);
139    DPRINT("Status %d STATUS_PENDING %d\n",Status,STATUS_PENDING);
140    return(Status);
141 }
142
143 #endif /* LIBCAPTIVE */
144
145 /* EOF */