From: Dan Partelly [dan_partelly@rdsor.ro] Sent: Saturday, June 01, 2002 8:31 PM To: NT Developers Interest List Subject: [ntdev] RE: ZwFlushBuffersFile from kernel Max, thank you for giving source code. I suggested handocded IRP from my first post . The only thing you forgot here is aquiring the file object lock, if required, for this code to be a perfect replacemnt of the original syscall. However, the whole discution wanst whithout a scope. Ppl shoul understand then they try to use "exotic" techniques, they have to be aware of OS mechanics, CPU architectures, and carefully double check the design. My reagrds, Dan ----- Original Message ----- From: "Maxim S. Shatskih" To: "NT Developers Interest List" Sent: Sunday, June 02, 2002 1:19 AM Subject: [ntdev] RE: ZwFlushBuffersFile from kernel > > youll call into the instance of ntdll.dll mapped into the current > process > > In fact, the discussion started from calling the flush function of the > FSD from the kernel. > No need to call ntdll for this. I'm publishing a snippet of the > debugged code which does this: > > // Flushes the volume > static NTSTATUS FlushVolume(PDEVICE_OBJECT DeviceObject, PFILE_OBJECT > FileObject) > { > PIRP Irp; > PIO_STACK_LOCATION NextLoc; > NTSTATUS Status; > // Allocate the IRP > Irp = IoAllocateIrp((CCHAR)(DeviceObject->StackSize + 1), FALSE); > if( Irp == NULL ) > // Failed > return STATUS_INSUFFICIENT_RESOURCES; > // Fill the IRP > NextLoc = IoGetNextIrpStackLocation(Irp); > NextLoc->MajorFunction = IRP_MJ_FLUSH_BUFFERS; > NextLoc->FileObject = FileObject; > // Pass down > Status = CallDriverSync(DeviceObject, Irp); > // Free the IRP > IoFreeIrp(Irp); > // Done > return Status; > } > > // CallDriverSync > // Calls the lower driver and wait for the operation to be completed > by the lower driver > static NTSTATUS CallDriverSync(PDEVICE_OBJECT DeviceObject, PIRP Irp) > { > NTSTATUS ntStatus; > KEVENT event; > // Initialize the completion event. > KeInitializeEvent(&event, NotificationEvent, FALSE); > // Set completion routine for this request. > IoSetCompletionRoutine(Irp, SyncComplete, &event, TRUE, TRUE, > TRUE); > // Call the target driver. > if ((ntStatus = IoCallDriver(DeviceObject, Irp)) == > STATUS_PENDING) > { > // Wait for the request to complete. > KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, > NULL); > // Update the local status. > ntStatus = Irp->IoStatus.Status; > } > return ntStatus; > } > > // Generic completion routine to synchronize a request. > static NTSTATUS SyncComplete(PDEVICE_OBJECT DeviceObject, PIRP Irp, > PVOID Context) > { > // Check for a Context pointer. > if (ARGUMENT_PRESENT(Context)) > // Signal the IRP originator that this operation is complete. > KeSetEvent((PKEVENT)Context, IO_NO_INCREMENT, FALSE); > // Halt completing the IRP and return. > return STATUS_MORE_PROCESSING_REQUIRED; > UNREFERENCED_PARAMETER(DeviceObject); > UNREFERENCED_PARAMETER(Irp); > } > > Max > > > > --- > You are currently subscribed to ntdev as: dan_partelly@rdsor.ro > To unsubscribe send a blank email to %%email.unsub%% > --- You are currently subscribed to ntdev as: GlennEverhart@FirstUSA.com To unsubscribe send a blank email to leave-ntdev-247T@lists.osr.com