오전 12:21 2001-11-08
드라이버에서 파일명 바꾸기
=============================================================
Search Result 15
From: Slava Monich (monich@ftp.com)
Subject: Re: Renaming a file
Newsgroups: comp.os.ms-windows.programmer.nt.kernel-mode, cis.winnt.drivers, comp.os.ms-windows.programmer.win32
View: Complete Thread (4 articles) | Original Format
Date: 1998/04/25
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;
드라이버에서 파일명 바꾸기
=============================================================
Search Result 15
From: Slava Monich (monich@ftp.com)
Subject: Re: Renaming a file
Newsgroups: comp.os.ms-windows.programmer.nt.kernel-mode, cis.winnt.drivers, comp.os.ms-windows.programmer.win32
View: Complete Thread (4 articles) | Original Format
Date: 1998/04/25
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;
'KB > MFC/Win32' 카테고리의 다른 글
NT 커널 드라이버 Visual C++에서 컴파일하기 (0) | 2004.03.19 |
---|---|
[ddk] NT Kernel Driver (0) | 2004.03.19 |
Essential COM #2 Interface (0) | 2004.03.19 |
COM 디버그 (0) | 2004.03.19 |
원하는 인터페이스 가져다 쓰기 (0) | 2004.03.19 |