Article View: comp.os.ms-windows.programmer.nt.kernel-mode
Article #4Re: Renaming a file
From: Slava Monich
Date: Sat, 25 Apr 1998 00:00
Date: Sat, 25 Apr 1998 00:00
58 lines
2655 bytes
2655 bytes
Irina Koulinitch wrote:
>
> Hello,
>
> Does anyone know how to rename a file from NT Driver?
> I can't find any functions to do that in NT DDK help.
> Please give me some hints.
>
The function is IoCallDriver()
The rename code may look like this:
==============================================================
PFILE_RENAME_INFORMATION Rename = ... ;
(initialize FILE_RENAME_INFORMATION with target file name)
Irp = IoAllocateIrp( DeviceObject->StackSize, FALSE );
if ( ! Irp ) return STATUS_INSUFFICIENT_RESOURCES;
Irp->Flags |= IRP_BUFFERED_IO;
Irp->RequestorMode = KernelMode;
Irp->UserIosb = &IoStatus;
Irp->UserEvent = &Event;
Irp->Tail.Overlay.OriginalFileObject = FileObject;
Irp->Tail.Overlay.Thread = PsGetCurrentThread();
Irp->AssociatedIrp.SystemBuffer = (PVOID)&Rename;
IrpSp = IoGetNextIrpStackLocation( Irp );
IrpSp->MajorFunction = IRP_MJ_SET_INFORMATION;
IrpSp->FileObject = FileObject;
IrpSp->DeviceObject = DeviceObject;
IrpSp->Parameters.SetFile.Length = Length; // length of Rename
IrpSp->Parameters.SetFile.FileInformationClass = FileRenameInformation;
IrpSp->Parameters.SetFile.FileObject = FileObject;
IrpSp->Parameters.SetFile.ReplaceIfExists = Rename->ReplaceIfExists;
Status = IoCallDriver( DeviceObject, Irp );
if (Status == STATUS_PENDING)
KeWaitForSingleObject( &Event, Executive, KernelMode,
FALSE, (PLARGE_INTEGER)NULL);
if (!NT_SUCCESS(Status)) IoStatus.Status = Status;
return IoStatus.Status;
==============================================================
Good luck,
-Slava
P.S FILE_RENAME_INFORMATION defined in one of Microsoft header
files as follows:
typedef struct _FILE_RENAME_INFORMATION {
BOOLEAN ReplaceIfExists;
HANDLE RootDirectory;
ULONG FileNameLength;
WCHAR FileName[1];
} FILE_RENAME_INFORMATION, *PFILE_RENAME_INFORMATION;
Technical Details
Message-ID:
<3542A43B.D77B4C4@ftp.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<353FD7C0.28FE2EA0@vet.com.au>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 113dfb,839b322f296bb490 X-Google-Attributes: gid113dfb,public X-Google-Thread: 10e551,839b322f296bb490 X-Google-Attributes: gid10e551,public X-Google-Thread: 10c4a9,839b322f296bb490 X-Google-Attributes: gid10c4a9,public From: Slava Monich <monich@ftp.com> Subject: Re: Renaming a file Date: 1998/04/25 Message-ID: <3542A43B.D77B4C4@ftp.com> X-Deja-AN: 347719410 Content-Transfer-Encoding: 7bit References: <353FD7C0.28FE2EA0@vet.com.au> Mime-Version: 1.0 To: Irina Koulinitch <irina@vet.com.au> Content-Type: text/plain; charset=us-ascii Organization: FTP Software, Inc. Newsgroups: comp.os.ms-windows.programmer.nt.kernel-mode,cis.winnt.drivers,comp.os.ms-windows.programmer.win32