PC Review


Reply
Thread Tools Rate Thread

ZwCreateFie Problem Please Help

 
 
Shalini
Guest
Posts: n/a
 
      9th Mar 2004
Hi
I am using ZwCreateFile to open my PhysicalDrive0 from the Filter driver
that i have written.
For example i write that in the DriverEntry function as this

RtlInitUnicodeString( &fileNameUnicodeString, L"\\Device\\Harddisk0");
InitializeObjectAttributes( &objectAttributes, &fileNameUnicodeString,
OBJ_CASE_INSENSITIVE, NULL, NULL );
rc = ZwCreateFile( &hFileHandle, SYNCHRONIZE|FILE_ANY_ACCESS,
&objectAttributes,
&IoStatus,
NULL,
0,
FILE_SHARE_READ|FILE_SHARE_WRITE,
FILE_OPEN,
FILE_SYNCHRONOUS_IO_NONALERT|FILE_NON_DIRECTORY_FI
LE,
NULL,
0);

KdPrint((DRIVERNAME "Created the File %X\n",hFileHandle));
But always the hFileHandle is NULL.
and also the NTSTATUS returns -1073741788.
The Win32 error code for the NTSTATUS would be 6 saying invalid handle.

I also tried other ways namely "\\\\.\\PhysicalDrive0 or
\\Device\\PhysicalDrive0 but any time it was not successful

Apart from ZwCreateFile is it possible to access raw sectors from the Hard
disk,
If there is any other way also i can use that actually..
I thought i could use ZwCreateFile and then ZwReadFile to read some sectors
from the disk.
If there is any other way to read raw sectors i cud also use that


Any hints/Suggestions?

Thanks and Expecting ur replies
Regards
Shal



 
Reply With Quote
 
 
 
 
aphillips
Guest
Posts: n/a
 
      6th Apr 2005

I too am trying to access raw disk sectors (from user mode). I have
been able to using CreateFile but there are several annoyances with
that (see below). So I tried using NtOpenFile/NtCreateFile (which is
the user mode equivalent of ZwOpenFile/ZwCreateFile I believe).

Anyway I also found that you can't open "\device\harddisk0" using
NtCreateFile, while "\device\harddisk0\partition0", "\device\floppy0"
and "\device\cdrom0" all work fine. I assume that is because
"\device\harddisk0" is a "directory" and not a "file" - like trying to
open "\device".

I don't want to just access a partition but the whole device. I assume
there is something like "\device\harddisk0\wholedevice" but I haven't
been able to find any documentation if that is the case.

Using CreateFile

I have used CreateFile to open "\\.\PhysicalDrive0" and even
"\\.\CdRom0" OK, but I have had problems keeping the code consistent
between devices/OS versions and have found little annoying problems:

1. CreateFile cannot open "\\.\Floppy0". The only way I have found to
open a floppy is using "\\.\A:" but I want to be able to access all
devices even if not mounted on a volume letter.

2. Finding the size of the device is a problem. I can use
IOCTL_DISK_GET_LENGTH_INFO under XP but it does not work under Windows
2000/NT and does not work for floppies. I can calculate the size using
IOCTL_DISK_GET_DRIVE_GEOMETRY but this does not allow for reserved
sectors before the first cluster (boot sector etc). I could work it
out from value in the boot sector but I want this to work with any disk
not just one using NTFS or FAT.

What I ended up doing was using "\\.\PhysicalDrive0" for hard disks and
"\\.\A:" for floppies. I use IOCTL_DISK_GET_DRIVE_GEOMETRY to get the
approximate disk size then do a "binary search" out from the end to
find the very last sector that can be read.

(I haven't even mentioned the problems with 9X/ME.)

However, I would prefer to use NtOpenFile (or NtCreateFile) for
consistency and so I can just use NtQueryInformationFile (using
EndOfFile flag in FileStandardInfo) to get the size of the device.
However, the problem with "\device\harddisk0" has me stumped.



--
aphillips
------------------------------------------------------------------------
Posted via http://www.mcse.ms
------------------------------------------------------------------------
View this thread: http://www.mcse.ms/message463161.html

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
cant install vista im going crazy please help please please please =?Utf-8?B?TWFuTmVlZEhlbHA=?= Windows Vista Installation 2 31st Jul 2006 02:55 PM
cant install vista im going crazy please help please please please =?Utf-8?B?TWFuTmVlZEhlbHA=?= Windows Vista Installation 2 30th Jul 2006 09:31 PM
XP SP2 Please wait ... please wait ... please wait ... please wait ... PK Windows XP General 0 27th Aug 2004 12:02 AM
Help! Anyone! Please Please Please Please Please Please =?Utf-8?B?UmFuZHk=?= Microsoft Access Macros 2 17th May 2004 07:16 PM
Help! Help! Help! Help! Help! Help! Help! Help! Help! Help! Help! Help! Help! -$- Windows XP Internet Explorer 2 21st Dec 2003 11:45 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:47 AM.