阅读:1151回复:0
楚狂人说:一个文件系统驱动只有一个CDO,所以下面的我就看不懂了,请赐教!
请看下面有中文的地方(这是sfilter里的一段):
NTSTATUS SfEnumerateFileSystemVolumes ( IN PDEVICE_OBJECT FSDeviceObject, IN PUNICODE_STRING Name ) { PDEVICE_OBJECT newDeviceObject; PSFILTER_DEVICE_EXTENSION newDevExt; PDEVICE_OBJECT *devList; PDEVICE_OBJECT diskDeviceObject; NTSTATUS status; ULONG numDevices; ULONG i; PAGED_CODE(); // // Find out how big of an array we need to allocate for the // mounted device list. // status = IoEnumerateDeviceObjectList( FSDeviceObject->DriverObject, NULL, 0, &numDevices); // // We only need to get this list of there are devices. If we // don't get an error there are no devices so go on. // if (!NT_SUCCESS( status )) { ASSERT(STATUS_BUFFER_TOO_SMALL == status); // // Allocate memory for the list of known devices // numDevices += 8; //grab a few extra slots devList = ExAllocatePoolWithTag( NonPagedPool, (numDevices * sizeof(PDEVICE_OBJECT)), SFLT_POOL_TAG ); if (NULL == devList) { return STATUS_INSUFFICIENT_RESOURCES; } // // Now get the list of devices. If we get an error again // something is wrong, so just fail. // status = IoEnumerateDeviceObjectList( FSDeviceObject->DriverObject, devList, (numDevices * sizeof(PDEVICE_OBJECT)), &numDevices); if (!NT_SUCCESS( status )) { ExFreePool( devList ); return status; } // // Walk the given list of devices and attach to them if we should. // for (i=0; i < numDevices; i++) { // // Do not attach if: // - This is the control device object (the one passed in) // - We are already attached to it // if ((devList != FSDeviceObject) && !SfIsAttachedToDevice( devList, NULL )) { //*********************就是这个了FSDeviceObjetc不就是这个文件系统驱动的CDO吗,怎么下面还要判断是不是CDO??********************* // See if this device has a name. If so, then it must // be a control device so don't attach to it. This handles // drivers with more then one control device. // SfGetBaseDeviceObjectName( devList, Name ); if (Name->Length <= 0) { // // Get the real (disk) device object associated with this // file system device object. Only try to attach if we // have a disk device object. // status = IoGetDiskDeviceObject( devList, &diskDeviceObject ); if (NT_SUCCESS( status )) { // // Allocate a new device object to attach with // status = IoCreateDevice( gSFilterDriverObject, sizeof( SFILTER_DEVICE_EXTENSION ), NULL, devList->DeviceType, 0, FALSE, &newDeviceObject ); if (NT_SUCCESS( status )) { // // Set disk device object // newDevExt = newDeviceObject->DeviceExtension; newDevExt->DiskDeviceObject = diskDeviceObject; // // Set Device Name // RtlInitEmptyUnicodeString( &newDevExt->DeviceName, newDevExt->DeviceNameBuffer, sizeof(newDevExt->DeviceNameBuffer) ); SfGetObjectName( diskDeviceObject, &newDevExt->DeviceName ); // // Attach to volume. // status = SfAttachToMountedDevice( devList, newDeviceObject ); if (!NT_SUCCESS( status )) { // // The attachment failed, cleanup. Note that // we continue processing so we will cleanup // the reference counts and try to attach to // the rest of the volumes. // SfCleanupMountedDevice( newDeviceObject ); IoDeleteDevice( newDeviceObject ); } } // // Remove reference added by IoGetDiskDeviceObject. // We only need to hold this reference until we are // successfully attached to the current volume. Once // we are successfully attached to devList, the // IO Manager will make sure that the underlying // diskDeviceObject will not go away until the file // system stack is torn down. // ObDereferenceObject( diskDeviceObject ); } } } // // Dereference the object (reference added by // IoEnumerateDeviceObjectList) // ObDereferenceObject( devList ); } // // We are going to ignore any errors received while mounting. We // simply won't be attached to those volumes if we get an error // status = STATUS_SUCCESS; // // Free the memory we allocated for the list // ExFreePool( devList ); } return status; } |
|