reactos操作系统实现(123)

前端之家收集整理的这篇文章主要介绍了reactos操作系统实现(123)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

目前,Reactos主要使用FAT文件系统,因此下面就先来分析这个文件系统,以便了解这个文件系统的功能。这个文件系统的实现是在驱动程序FASTFAT.SYS里实现的,所以来分析这个驱动程序的源码,就可以了解FAT文件系统了。

6.2.1 FAT文件系统驱动程序入口函数

FAT文件系统是当作一个驱动程序来加载到系统里,因此它也有驱动程序的形式了,也就是它的入口点函数,还是DriverEntry函数,它的实现代码如下:

#001 NTSTATUS NTAPI

#002 DriverEntry(PDRIVER_OBJECT DriverObject,

#003 PUNICODE_STRING RegistryPath)

#004 /*

#005 * FUNCTION: Called by the system to initialize the driver

#006 * ARGUMENTS:

#007 * DriverObject = object describing this driver

#008 * RegistryPath = path to our configuration entries

#009 * RETURNS: Success or failure

#010 */

#011 {

#012 PDEVICE_OBJECT DeviceObject;

FAT作为设备名称

#013 UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(L"//Fat");

#014 NTSTATUS Status;

#015

创建文件系统设备对象。

#016 Status = IoCreateDevice(DriverObject,

#017 sizeof(VFAT_GLOBAL_DATA),

#018 &DeviceName,

#019 FILE_DEVICE_DISK_FILE_SYSTEM,

#020 0,

#021 FALSE,

#022 &DeviceObject);

#023

如果创建这个设备名称已经存在,就使用RosFat名称来创建设备。

#024 if (Status == STATUS_OBJECT_NAME_EXISTS ||

#025 Status == STATUS_OBJECT_NAME_COLLISION)

#026 {

#027 /* Try an other name,if 'Fat' is already in use. 'Fat' is also used by fastfat.sys on W2K */

#028 RtlInitUnicodeString(&DeviceName,L"//RosFat");

#029 Status = IoCreateDevice(DriverObject,

#030 sizeof(VFAT_GLOBAL_DATA),

#031 &DeviceName,

#032 FILE_DEVICE_DISK_FILE_SYSTEM,

#033 0,

#034 FALSE,

#035 &DeviceObject);

#036 }

#037

#038

#039

#040 if (!NT_SUCCESS(Status))

#041 {

#042 return (Status);

#043 }

#044

获取FAT全局数据区的指针。

#045 VfatGlobalData = DeviceObject->DeviceExtension;

清空FAT全局数据区。

#046 RtlZeroMemory (VfatGlobalData,sizeof(VFAT_GLOBAL_DATA));

#047 VfatGlobalData->DriverObject = DriverObject;

#048 VfatGlobalData->DeviceObject = DeviceObject;

#049

设置设备是直接访问IO的方式。

#050 DeviceObject->Flags |= DO_DIRECT_IO;

设置驱动程序的IRP消息处理函数

#051 DriverObject->MajorFunction[IRP_MJ_CLOSE] = VfatBuildRequest;

#052 DriverObject->MajorFunction[IRP_MJ_CREATE] = VfatBuildRequest;

#053 DriverObject->MajorFunction[IRP_MJ_READ] = VfatBuildRequest;

#054 DriverObject->MajorFunction[IRP_MJ_WRITE] = VfatBuildRequest;

#055 DriverObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL] = VfatBuildRequest;

#056 DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] = VfatBuildRequest;

#057 DriverObject->MajorFunction[IRP_MJ_SET_INFORMATION] = VfatBuildRequest;

#058 DriverObject->MajorFunction[IRP_MJ_DIRECTORY_CONTROL] = VfatBuildRequest;

#059 DriverObject->MajorFunction[IRP_MJ_QUERY_VOLUME_INFORMATION] =

#060 VfatBuildRequest;

#061 DriverObject->MajorFunction[IRP_MJ_SET_VOLUME_INFORMATION] =

#062 VfatBuildRequest;

#063 DriverObject->MajorFunction[IRP_MJ_SHUTDOWN] = VfatShutdown;

#064 DriverObject->MajorFunction[IRP_MJ_LOCK_CONTROL] = VfatBuildRequest;

#065 DriverObject->MajorFunction[IRP_MJ_CLEANUP] = VfatBuildRequest;

#066 DriverObject->MajorFunction[IRP_MJ_FLUSH_BUFFERS] = VfatBuildRequest;

#067

#068 DriverObject->DriverUnload = NULL;

#069

缓存管理函数

#070 /* Cache manager */

#071 VfatGlobalData->CacheMgrCallbacks.AcquireForLazyWrite = VfatAcquireForLazyWrite;

#072 VfatGlobalData->CacheMgrCallbacks.ReleaseFromLazyWrite = VfatReleaseFromLazyWrite;

#073 VfatGlobalData->CacheMgrCallbacks.AcquireForReadAhead = VfatAcquireForReadAhead;

#074 VfatGlobalData->CacheMgrCallbacks.ReleaseFromReadAhead = VfatReleaseFromReadAhead;

#075

快速I/O操作函数

#076 /* Fast I/O */

#077 VfatInitFastIoRoutines(&VfatGlobalData->FastIoDispatch);

#078 DriverObject->FastIoDispatch = &VfatGlobalData->FastIoDispatch;

#079

后备列表,以便提高速度。

#080 /* Private lists */

#081 ExInitializeNPagedLookasideList(&VfatGlobalData->FcbLookasideList,

#082 NULL,NULL,sizeof(VFATFCB),TAG_FCB,0);

#083 ExInitializeNPagedLookasideList(&VfatGlobalData->CcbLookasideList,

#084 NULL,sizeof(VFATCCB),TAG_CCB,0);

#085 ExInitializeNPagedLookasideList(&VfatGlobalData->IrpContextLookasideList,

#086 NULL,sizeof(VFAT_IRP_CONTEXT),TAG_IRP,0);

#087

初始化资源列表。

#088 ExInitializeResourceLite(&VfatGlobalData->VolumeListLock);

#089 InitializeListHead(&VfatGlobalData->VolumeListHead);

注册文件系统到系统列表里。

#090 IoRegisterFileSystem(DeviceObject);

#091 return(STATUS_SUCCESS);

#092}

原文链接:https://www.f2er.com/react/308403.html

猜你在找的React相关文章