Hi,
I am very new to writing filter drivers. I have a problem while trying
to rename a file from within my filter driver.
I have taken this sample code from the OSR notes on FSD’s, with slight
modifications. The sample was for running in user mode using NT native
API calls and I have modified it to take ZwXxxxx calls.
The sample works if the file is CREATED using the ZwCreateFile() but if
the file is already present and I try to give the FILE_OPEN in the
CreateDisposition field, then it gives me error STATUS_ACCESS_DENIED.
I am trying to do this on fat system, secondly I dont have access to the
IFS kit. The files that I have tried this on are of size 32KB to 1MB.
Do I have to use IRP_MJ_SET_INFORMATION? if yes, then what are the
fields I need to set.
The sample below does relative renaming, what should I do to acheive
fully qualified renaming, the the file will cahnge from c:\temp\abc.txt
to c:\temp\subdir\123.txt.
Can someone please help me out with this?
thanks a lot in advance,
Almas
I declared the structure as
typedef struct _FILE_RENAME_INFORMATION
{
BOOLEAN ReplaceIfExists;
HANDLE RootDirectory;
ULONG FileNameLength;
WCHAR FileName[1];
} FILE_RENAME_INFORMATION, *PFILE_RENAME_INFORMATION;
//the filenames were intialised
RtlInitUnicodeString(&MainDir, L"\DosDevices\d:\temp");
RtlInitUnicodeString(&subdir1, L"\DosDevices\d:\temp\test1");
RtlInitUnicodeString(&subdir2, L"\DosDevices\d:\temp\test2");
RtlInitUnicodeString(&filename, L"abc.txt");
// the MainDir was opened with attributes
//GENERIC_READ | GENERIC_WRITE and
//share as FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE
// the subdir1 was opened with attributes
//GENERIC_READ | GENERIC_WRITE | FILE_DELETE_CHILD and
//share as FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE
// the subdir2 was opened with attributes
//GENERIC_READ | GENERIC_WRITE and
//share as FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE
// the file the opened like this
ntStatus = ZwCreateFile( &filehandle,
FILE_ALL_ACCESS,
&fileAttrib,
&IoStatus,
NULL, // alloc size = none
FILE_ATTRIBUTE_NORMAL,
0,
FILE_CREATE, <<<<<<<<--------- Does not work with
FILE_OPEN, with the file already existing.
FILE_NON_DIRECTORY_FILE,
NULL, // eabuffer
0 ); // ealength
<<<<<<< Gives the error here, ACCESS_DENIED
//allocation for the renameinfo is done
renameInfo->ReplaceIfExists = FALSE;
renameInfo->RootDirectory = subdirHandle2;
renameInfo->FileNameLength = filename.Length;
RtlCopyMemory(&renameInfo->FileName[0], filename.Buffer,
filename.Length);
ntStatus = ZwSetInformationFile(filehandle, &IoStatus, renameInfo,
sizeof(buffer), FileRenameInformation);