2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: ntoskrnl/fs/util.c
5 * PURPOSE: Misc Utility Functions for File System Drivers
7 * PROGRAMMERS: Alex Ionescu (alex@relsoft.net)
10 /* INCLUDES *****************************************************************/
13 #include <internal/debug.h>
15 #define FSRTL_MAX_RESOURCES 16
17 #define FTTYPE ((ULONG)'f')
18 #define FT_BALANCED_READ_MODE \
19 CTL_CODE(FTTYPE, 6, METHOD_NEITHER, FILE_ANY_ACCESS)
21 /* GLOBALS *******************************************************************/
23 BOOLEAN STDCALL
MmIsFileAPagingFile(PFILE_OBJECT FileObject
);
24 VOID STDCALL INIT_FUNCTION
RtlpInitializeResources(VOID
);
25 static ULONG FsRtlpAllocatedResources
= 0;
26 static PERESOURCE FsRtlpResources
;
28 #if defined (ALLOC_PRAGMA)
29 #pragma alloc_text(INIT, RtlpInitializeResources)
32 /* PRIVATE FUNCTIONS**********************************************************/
37 RtlpInitializeResources(VOID
)
41 /* Allocate the Resource Buffer */
42 FsRtlpResources
= FsRtlAllocatePool(NonPagedPool
,
43 FSRTL_MAX_RESOURCES
*sizeof(ERESOURCE
));
45 /* Initialize the Resources */
46 for (i
= 0; i
< FSRTL_MAX_RESOURCES
; i
++)
48 ExInitializeResource(&FsRtlpResources
[i
]);
52 /* FUNCTIONS *****************************************************************/
55 * @name FsRtlIsTotalDeviceFailure
58 * The FsRtlIsTotalDeviceFailure routine checks if an NTSTATUS error code
59 * represents a disk hardware failure.
62 * The NTSTATUS Code to Test
64 * @return TRUE in case of Hardware Failure, FALSE otherwise.
71 FsRtlIsTotalDeviceFailure(IN NTSTATUS NtStatus
)
73 return((NT_SUCCESS(NtStatus
)) ||
74 (STATUS_CRC_ERROR
== NtStatus
) ||
75 (STATUS_DEVICE_DATA_ERROR
== NtStatus
) ? FALSE
: TRUE
);
79 * @name FsRtlIsNtstatusExpected
82 * The FsRtlIsNtstatusExpected routine checks if an NTSTATUS error code
83 * is expected by the File System Support Library.
86 * The NTSTATUS Code to Test
88 * @return TRUE if the Value is Expected, FALSE otherwise.
95 FsRtlIsNtstatusExpected(IN NTSTATUS NtStatus
)
97 return((STATUS_DATATYPE_MISALIGNMENT
== NtStatus
) ||
98 (STATUS_ACCESS_VIOLATION
== NtStatus
) ||
99 (STATUS_ILLEGAL_INSTRUCTION
== NtStatus
) ||
100 (STATUS_INSTRUCTION_MISALIGNMENT
== NtStatus
)) ? FALSE
: TRUE
;
104 * @name FsRtlIsPagingFile
105 * @implemented NT 4.0
107 * The FsRtlIsPagingFile routine checks if the FileObject is a Paging File.
110 * A pointer to the File Object to be tested.
112 * @return TRUE if the File is a Paging File, FALSE otherwise.
119 FsRtlIsPagingFile(IN PFILE_OBJECT FileObject
)
121 return MmIsFileAPagingFile(FileObject
);
125 * @name FsRtlNormalizeNtstatus
126 * @implemented NT 4.0
128 * The FsRtlNormalizeNtstatus routine normalizes an NTSTATUS error code.
130 * @param NtStatusToNormalize
131 * The NTSTATUS error code to Normalize.
133 * @param NormalizedNtStatus
134 * The NTSTATUS error code to return if the NtStatusToNormalize is not
135 * a proper expected error code by the File System Library.
137 * @return NtStatusToNormalize if it is an expected value, otherwise
138 * NormalizedNtStatus.
145 FsRtlNormalizeNtstatus(IN NTSTATUS NtStatusToNormalize
,
146 IN NTSTATUS NormalizedNtStatus
)
148 return(TRUE
== FsRtlIsNtstatusExpected(NtStatusToNormalize
)) ?
149 NtStatusToNormalize
: NormalizedNtStatus
;
153 * @name FsRtlAllocateResource
154 * @implemented NT 4.0
156 * The FsRtlAllocateResource routine returns a pre-initialized ERESOURCE
157 * for use by a File System Driver.
159 * @return A Pointer to a pre-initialized ERESOURCE.
161 * @remarks The File System Library only provides up to 16 Resources.
166 FsRtlAllocateResource(VOID
)
168 /* Return a pre-allocated ERESOURCE */
169 return &FsRtlpResources
[FsRtlpAllocatedResources
++ & FSRTL_MAX_RESOURCES
];
173 * @name FsRtlBalanceReads
174 * @implemented NT 4.0
176 * The FsRtlBalanceReads routine sends an IRP to an FTDISK Driver
177 * requesting the driver to balance read requests across a mirror set.
179 * @param TargetDevice
180 * A pointer to an FTDISK Device Object.
182 * @return The NTSTATUS error code returned by the FTDISK Driver.
184 * @remarks FTDISK is a Software RAID Implementation.
189 FsRtlBalanceReads(PDEVICE_OBJECT TargetDevice
)
193 IO_STATUS_BLOCK IoStatusBlock
;
196 /* Initialize the Local Event */
197 KeInitializeEvent(&Event
, NotificationEvent
, FALSE
);
199 /* Build the special IOCTL */
200 Irp
= IoBuildDeviceIoControlRequest(FT_BALANCED_READ_MODE
,
211 Status
= IoCallDriver(TargetDevice
, Irp
);
214 if (Status
== STATUS_PENDING
)
216 Status
= KeWaitForSingleObject(&Event
,
222 Status
= IoStatusBlock
.Status
;
229 * @name FsRtlPostPagingFileStackOverflow
230 * @unimplemented NT 4.0
232 * The FsRtlPostPagingFileStackOverflow routine
238 * @param StackOverflowRoutine
247 FsRtlPostPagingFileStackOverflow(IN PVOID Context
,
249 IN PFSRTL_STACK_OVERFLOW_ROUTINE StackOverflowRoutine
)
255 * @name FsRtlPostStackOverflow
256 * @unimplemented NT 4.0
258 * The FsRtlPostStackOverflow routine
264 * @param StackOverflowRoutine
273 FsRtlPostStackOverflow(IN PVOID Context
,
275 IN PFSRTL_STACK_OVERFLOW_ROUTINE StackOverflowRoutine
)
281 * @name FsRtlSyncVolumes
282 * @implemented NT 4.0
284 * The FsRtlSyncVolumes routine is deprecated.
286 * @return Always returns STATUS_SUCCESS.
288 * @remarks Deprecated.
293 FsRtlSyncVolumes(DWORD Unknown0
,
297 return STATUS_SUCCESS
;