⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fastio.cpp

📁 一个过滤层文件系统驱动的完整代码,实现了文件的加密,操作截获等
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/*
Copyright (c) 2004 By LiGen, All right reserved
Module Name:
	FastIO.cpp

Abstract:
	FAST I/O 处理函数
	
Environment:
	Windows XP, Compiler Ver > 13.00

Notes:
   	注意,本文件不光包括了FastIO的函数的声明还包括实体

Revision History:
	created: 18:7:2004 

Author:
	李根	13574849558@hnmcc.com

--*/

#include "FsTPM.h"

//
//  Macro to test if this is my device extension
//

#define IS_MY_DEVICE_EXTENSION(_devExt) \
	( ((_devExt) != NULL) && \
	(((PHOOK_EXTENSION)(_devExt))->thisDriver == FsTPMDriverObject) )


#define VALID_FAST_IO_DISPATCH_HANDLER(_FastIoDispatchPtr, _FieldName) \
	(((_FastIoDispatchPtr) != NULL) && \
	(((_FastIoDispatchPtr)->SizeOfFastIoDispatch) >= \
	(FIELD_OFFSET(FAST_IO_DISPATCH, _FieldName) + sizeof(void *))) && \
	((_FastIoDispatchPtr)->_FieldName != NULL))




/////////////////////////////////////////////////////////////////////////////
//
//                  FastIO Handling routines
//
/////////////////////////////////////////////////////////////////////////////


BOOLEAN
FsTPMFastIoCheckIfPossible (
							  IN PFILE_OBJECT FileObject,
							  IN PLARGE_INTEGER FileOffset,
							  IN ULONG Length,
							  IN BOOLEAN Wait,
							  IN ULONG LockKey,
							  IN BOOLEAN CheckForReadOperation,
							  OUT PIO_STATUS_BLOCK IoStatus,
							  IN PDEVICE_OBJECT DeviceObject
							  )

							  /*++

							  Routine Description:

							  This routine is the fast I/O "pass through" routine for checking to see
							  whether fast I/O is possible for this file.

							  This function simply invokes the file system's cooresponding routine, or
							  returns FALSE if the file system does not implement the function.

							  Arguments:

							  FileObject - Pointer to the file object to be operated on.

							  FileOffset - Byte offset in the file for the operation.

							  Length - Length of the operation to be performed.

							  Wait - Indicates whether or not the caller is willing to wait if the
							  appropriate locks, etc. cannot be acquired

							  LockKey - Provides the caller's key for file locks.

							  CheckForReadOperation - Indicates whether the caller is checking for a
							  read (TRUE) or a write operation.

							  IoStatus - Pointer to a variable to receive the I/O status of the
							  operation.

							  DeviceObject - Pointer to this driver's device object, the device on
							  which the operation is to occur.

							  Return Value:

							  The function value is TRUE or FALSE based on whether or not fast I/O
							  is possible for this file.

							  --*/

{
	// 暂不予支持
	return FALSE;

	FsTPM_DbgPrint(("->FsTPMFastIoCheckIfPossible \n"));

	PDEVICE_OBJECT deviceObject;
	PFAST_IO_DISPATCH fastIoDispatch;

	PAGED_CODE();
	//
	//  Pass through logic for this type of Fast I/O
	//

	deviceObject = ((PHOOK_EXTENSION) (DeviceObject->DeviceExtension))->Vcb.NextLowerDevice;

	if (deviceObject) {

		fastIoDispatch = deviceObject->DriverObject->FastIoDispatch;

		if (VALID_FAST_IO_DISPATCH_HANDLER( fastIoDispatch, FastIoCheckIfPossible )) {

			return (fastIoDispatch->FastIoCheckIfPossible)(
				FileObject,
				FileOffset,
				Length,
				Wait,
				LockKey,
				CheckForReadOperation,
				IoStatus,
				deviceObject );
		}
	}
	return FALSE;
}


BOOLEAN
FsTPMFastIoRead (
				   IN PFILE_OBJECT FileObject,
				   IN PLARGE_INTEGER FileOffset,
				   IN ULONG Length,
				   IN BOOLEAN Wait,
				   IN ULONG LockKey,
				   OUT PVOID Buffer,
				   OUT PIO_STATUS_BLOCK IoStatus,
				   IN PDEVICE_OBJECT DeviceObject
				   )

				   /*++

				   Routine Description:

				   This routine is the fast I/O "pass through" routine for reading from a
				   file.

				   This function simply invokes the file system's cooresponding routine, or
				   returns FALSE if the file system does not implement the function.

				   Arguments:

				   FileObject - Pointer to the file object to be read.

				   FileOffset - Byte offset in the file of the read.

				   Length - Length of the read operation to be performed.

				   Wait - Indicates whether or not the caller is willing to wait if the
				   appropriate locks, etc. cannot be acquired

				   LockKey - Provides the caller's key for file locks.

				   Buffer - Pointer to the caller's buffer to receive the data read.

				   IoStatus - Pointer to a variable to receive the I/O status of the
				   operation.

				   DeviceObject - Pointer to this driver's device object, the device on
				   which the operation is to occur.

				   Return Value:

				   The function value is TRUE or FALSE based on whether or not fast I/O
				   is possible for this file.

				   --*/

{
	// 暂不予支持
	return FALSE;

	FsTPM_DbgPrint(("->FsTPMFastIoRead \n"));

	PDEVICE_OBJECT deviceObject;
	PFAST_IO_DISPATCH fastIoDispatch;

	PAGED_CODE();
	ASSERT(IS_MY_DEVICE_EXTENSION( DeviceObject->DeviceExtension ));

	//
	//  Pass through logic for this type of Fast I/O
	//

	deviceObject = ((PHOOK_EXTENSION) (DeviceObject->DeviceExtension))->Vcb.NextLowerDevice;

	if (deviceObject) {

		fastIoDispatch = deviceObject->DriverObject->FastIoDispatch;

		if (VALID_FAST_IO_DISPATCH_HANDLER( fastIoDispatch, FastIoRead )) {

			return (fastIoDispatch->FastIoRead)(
				FileObject,
				FileOffset,
				Length,
				Wait,
				LockKey,
				Buffer,
				IoStatus,
				deviceObject );
		}
	}
	return FALSE;
}


BOOLEAN
FsTPMFastIoWrite (
					IN PFILE_OBJECT FileObject,
					IN PLARGE_INTEGER FileOffset,
					IN ULONG Length,
					IN BOOLEAN Wait,
					IN ULONG LockKey,
					IN PVOID Buffer,
					OUT PIO_STATUS_BLOCK IoStatus,
					IN PDEVICE_OBJECT DeviceObject
					)

					/*++

					Routine Description:

					This routine is the fast I/O "pass through" routine for writing to a
					file.

					This function simply invokes the file system's cooresponding routine, or
					returns FALSE if the file system does not implement the function.

					Arguments:

					FileObject - Pointer to the file object to be written.

					FileOffset - Byte offset in the file of the write operation.

					Length - Length of the write operation to be performed.

					Wait - Indicates whether or not the caller is willing to wait if the
					appropriate locks, etc. cannot be acquired

					LockKey - Provides the caller's key for file locks.

					Buffer - Pointer to the caller's buffer that contains the data to be
					written.

					IoStatus - Pointer to a variable to receive the I/O status of the
					operation.

					DeviceObject - Pointer to this driver's device object, the device on
					which the operation is to occur.

					Return Value:

					The function value is TRUE or FALSE based on whether or not fast I/O
					is possible for this file.

					--*/

{
	// 暂不予支持
	return FALSE;

	FsTPM_DbgPrint(("->FsTPMFastIoWrite \n"));

	PDEVICE_OBJECT deviceObject;
	PFAST_IO_DISPATCH fastIoDispatch;

	PAGED_CODE();
	ASSERT(IS_MY_DEVICE_EXTENSION( DeviceObject->DeviceExtension ));

	//
	//  Pass through logic for this type of Fast I/O
	//

	deviceObject = ((PHOOK_EXTENSION) (DeviceObject->DeviceExtension))->Vcb.NextLowerDevice;
	if (deviceObject) {

		fastIoDispatch = deviceObject->DriverObject->FastIoDispatch;

		if (VALID_FAST_IO_DISPATCH_HANDLER( fastIoDispatch, FastIoWrite )) {

			return (fastIoDispatch->FastIoWrite)(
				FileObject,
				FileOffset,
				Length,
				Wait,
				LockKey,
				Buffer,
				IoStatus,
				deviceObject );
		}
	}
	return FALSE;
}


BOOLEAN
FsTPMFastIoQueryBasicInfo (
							 IN PFILE_OBJECT FileObject,
							 IN BOOLEAN Wait,
							 OUT PFILE_BASIC_INFORMATION Buffer,
							 OUT PIO_STATUS_BLOCK IoStatus,
							 IN PDEVICE_OBJECT DeviceObject
							 )

							 /*++

							 Routine Description:

							 This routine is the fast I/O "pass through" routine for querying basic
							 information about the file.

							 This function simply invokes the file system's cooresponding routine, or
							 returns FALSE if the file system does not implement the function.

							 Arguments:

							 FileObject - Pointer to the file object to be queried.

							 Wait - Indicates whether or not the caller is willing to wait if the
							 appropriate locks, etc. cannot be acquired

							 Buffer - Pointer to the caller's buffer to receive the information about
							 the file.

							 IoStatus - Pointer to a variable to receive the I/O status of the
							 operation.

							 DeviceObject - Pointer to this driver's device object, the device on
							 which the operation is to occur.

							 Return Value:

							 The function value is TRUE or FALSE based on whether or not fast I/O
							 is possible for this file.

							 --*/

{
	// 暂不予支持
	return FALSE;

	FsTPM_DbgPrint(("->FsTPMFastIoQueryBasicInfo \n"));

	PDEVICE_OBJECT deviceObject;
	PFAST_IO_DISPATCH fastIoDispatch;

	PAGED_CODE();
	ASSERT(IS_MY_DEVICE_EXTENSION( DeviceObject->DeviceExtension ));

	//
	//  Pass through logic for this type of Fast I/O
	//

	deviceObject = ((PHOOK_EXTENSION) (DeviceObject->DeviceExtension))->Vcb.NextLowerDevice;
	if (deviceObject) {

		fastIoDispatch = deviceObject->DriverObject->FastIoDispatch;

		if (VALID_FAST_IO_DISPATCH_HANDLER( fastIoDispatch, FastIoQueryBasicInfo )) {

			return (fastIoDispatch->FastIoQueryBasicInfo)(
				FileObject,
				Wait,
				Buffer,
				IoStatus,
				deviceObject );
		}
	}
	return FALSE;
}


BOOLEAN
FsTPMFastIoQueryStandardInfo (
								IN PFILE_OBJECT FileObject,
								IN BOOLEAN Wait,
								OUT PFILE_STANDARD_INFORMATION Buffer,
								OUT PIO_STATUS_BLOCK IoStatus,
								IN PDEVICE_OBJECT DeviceObject
								)

								/*++

								Routine Description:

								This routine is the fast I/O "pass through" routine for querying standard
								information about the file.

								This function simply invokes the file system's cooresponding routine, or
								returns FALSE if the file system does not implement the function.

								Arguments:

								FileObject - Pointer to the file object to be queried.

								Wait - Indicates whether or not the caller is willing to wait if the
								appropriate locks, etc. cannot be acquired

								Buffer - Pointer to the caller's buffer to receive the information about
								the file.

								IoStatus - Pointer to a variable to receive the I/O status of the
								operation.

								DeviceObject - Pointer to this driver's device object, the device on
								which the operation is to occur.

								Return Value:

								The function value is TRUE or FALSE based on whether or not fast I/O
								is possible for this file.

								--*/

{
	// 暂不予支持
	return FALSE;

	FsTPM_DbgPrint(("->FsTPMFastIoQueryStandardInfo \n"));

	PDEVICE_OBJECT deviceObject;
	PFAST_IO_DISPATCH fastIoDispatch;

	PAGED_CODE();
	ASSERT(IS_MY_DEVICE_EXTENSION( DeviceObject->DeviceExtension ));

	//
	//  Pass through logic for this type of Fast I/O
	//

	deviceObject = ((PHOOK_EXTENSION) (DeviceObject->DeviceExtension))->Vcb.NextLowerDevice;
	if (deviceObject) {

		fastIoDispatch = deviceObject->DriverObject->FastIoDispatch;

		if (VALID_FAST_IO_DISPATCH_HANDLER( fastIoDispatch, FastIoQueryStandardInfo )) {

			return (fastIoDispatch->FastIoQueryStandardInfo)(
				FileObject,
				Wait,
				Buffer,
				IoStatus,
				deviceObject );
		}
	}
	return FALSE;
}


BOOLEAN

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -