🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.os.ms-windows.programmer.nt.kernel-mode
4 messages
4 total messages Started by Irina Koulinitch Fri, 24 Apr 1998 00:00
Renaming a file
#2
Author: Irina Koulinitch
Date: Fri, 24 Apr 1998 00:00
9 lines
901 bytes
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.

Thanks,
Irina.
Re: Renaming a file
#3
Author: Maxim Tseitlin
Date: Fri, 24 Apr 1998 00:00
23 lines
1210 bytes
I can't recall now about how it to do. But I remember, that this
information was in mail list ntfsd@atria.com. You can seek it in them
archive: ftp://ftp.atria.com/archives/ntfsd

It is very right step to subscribe for this mail-list. For it need
send mail to ntfsd-request@atria.com.

Maxim Tseitlin

On Fri, 24 Apr 1998 10:07:28 +1000, Irina Koulinitch
<irina@vet.com.au> 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.
>
>Thanks,
>Irina.
>
>
Re: Renaming a file
#4
Author: Slava Monich
Date: Sat, 25 Apr 1998 00:00
58 lines
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;
Re: Renaming a file
#6
Author: jjaimon
Date: Tue, 28 Apr 1998 00:00
78 lines
3424 bytes

> > 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;
>

Hi,
  using an IRP would be a difficult process.  Instead you can use
NtSetInformationFile(..) routine.  The prototype for the function is
NTSYSAPI
NTSTATUS
NTAPI
NtSetInformationFile(
    IN HANDLE FileHandle,
    OUT PIO_STATUS_BLOCK IoStatusBlock,
    IN PVOID FileInformation,
    IN ULONG Length,
    IN FILE_INFORMATION_CLASS FileInformationClass
    );

FileInformation field will have the structure type FILE_RENAME_INFORMATION and
FileInformationClass will have enumerated type FileRenameInformation (ntddk.h)

Jaimon

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads