Hi,
I am trying to rename the file when it is getting deleted. So in my dispatch routine for IRP_MJ_SET_INFORMATION when i receive FileDisposition information i create my own IRP with major function IRP_MJ_SET_INFORMATION for FileRenameInformation and pass it to the next driver. But i am always getting C0000033 error.
Here is the code for the funtions,
DWORD HoldFileBack( PDEVICE_OBJECT next_device, PFILE_OBJECT file_obj )
{
PFILE_RENAME_INFORMATION link_info = NULL;
NTSTATUS status;
//allocate memory for link_info
link_info = ExAllocatePool( NonPagedPool, sizeof( FILE_RENAME_INFORMATION )
- MAX_FILENAME_LENGTH );
if( NULL == link_info )
{
DbgPrint( “No memory for Link_info\n” );
return 1;
}
memset( link_info, 0, sizeof( FILE_RENAME_INFORMATION ) + MAX_FILENAME_LENGTH );
//create link filename
wcscpy( link_info->FileName, L"\??\C:\hlink\0.tmp" );
link_info->FileNameLength = wcslen( link_info->FileName ) * 2;
//now pass the rename irp down
status = SetFileInfo( next_device, file_obj, NULL, link_info,
sizeof( FILE_RENAME_INFORMATION ) + link_info->FileNameLength,
FileRenameInformation, NULL );
if( status != STATUS_SUCCESS )
{
DbgPrint( “rename Failed\n” );
ExFreePool( link_info );
return 1;
}
ExFreePool( link_info );
return 0;
}
//----------------------------------------------------------------------
//
// SetFileInfoComplete
//
// This routine is used to handle I/O completion for our self-generated
// IRP that is used to set file information.
//
//----------------------------------------------------------------------
NTSTATUS SetFileInfoComplete(IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp,
IN PKEVENT SynchronizingEvent
)
{
DeviceObject;
// Copy the status information back into the “user” IOSB.
ASSERT( NULL != Irp->UserIosb );
*Irp->UserIosb = Irp->IoStatus;
// Set the user event - wakes up the mainline code doing this.
KeSetEvent(SynchronizingEvent, IO_NO_INCREMENT, FALSE);
// Free the IRP now that we are done with it.
IoFreeIrp(Irp);
// We return STATUS_MORE_PROCESSING_REQUIRED because this “magic” return value
// tells the I/O Manager that additional processing will be done by this driver
// to the IRP - in fact, it might (as it is in this case) already BE done - and
// the IRP cannot be completed.
return STATUS_MORE_PROCESSING_REQUIRED;
}
//----------------------------------------------------------------------
//
// SetFileInfo
//
// This function sets file information.
//
//----------------------------------------------------------------------
NTSTATUS SetFileInfo(IN PDEVICE_OBJECT next_device_object,
IN PFILE_OBJECT file_object,
PFILE_OBJECT trg_file_object,
OUT PVOID file_information,
IN ULONG length,
IN FILE_INFORMATION_CLASS file_information_class,
OUT PULONG length_returned OPTIONAL
)
{
PIRP irp;
KEVENT event;
IO_STATUS_BLOCK io_status_block;
PIO_STACK_LOCATION io_stack_location;
NTSTATUS status;
length_returned;
//Initialize the event
KeInitializeEvent(&event, SynchronizationEvent, FALSE);
io_status_block.Status = STATUS_SUCCESS;
io_status_block.Information = 0;
//Allocate an irp for this request.
irp = IoAllocateIrp(next_device_object->StackSize, FALSE);
if(!irp)
{
DbgPrint(“Unable to allocate irp %d\n”,LINE);
return FALSE;
}
//Build the irp’s main body
irp->Tail.Overlay.Thread = PsGetCurrentThread();
irp->RequestorMode = KernelMode;
irp->UserIosb = &io_status_block;
irp->UserEvent = NULL;
irp->Flags = IRP_SYNCHRONOUS_API;
//Set up the I/O stack location.
io_stack_location = IoGetNextIrpStackLocation(irp);
io_stack_location->MajorFunction = IRP_MJ_SET_INFORMATION;
io_stack_location->FileObject = file_object;
irp->AssociatedIrp.SystemBuffer = file_information;
io_stack_location->Parameters.SetFile.Length = length;
io_stack_location->Parameters.SetFile.FileInformationClass = file_information_class; //FileInternalInformation;
io_stack_location->Parameters.SetFile.FileObject = trg_file_object;
// Set the completion routine.
IoSetCompletionRoutine(irp, SetFileInfoComplete,
&event, TRUE, TRUE, TRUE);
//Send it to the FSD
status = IoCallDriver(next_device_object, irp);
if (STATUS_PENDING == status)
{
//Wait for the I/O
KeWaitForSingleObject(&event, Executive, KernelMode, TRUE, 0);
}
return io_status_block.Status;
}
Can anybody please point out what i am doing wrong with filename?
Thanks,
Rahul