Re: ZwCreateFie Problem Please Help

Posted: 04-06-2005, 06:31 AM

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

Responses to "Re: ZwCreateFie Problem Please Help"

 
LinkBack Thread Tools Display Modes
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may 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 On
Forum Jump


Similar Threads
Thread Thread Starter Forum Replies Last Post
Vista Sleep Problem / Network Problem WWJD Windows Vista Networking & Sharing 0 10-11-2006 09:17 AM
audio problem with my sony vaio laptop and x64 problem alex Windows Vista Hardware & Devices 1 07-14-2006 03:32 PM
Vista Upgrade Problem - Windows Explorer Loop problem Steve S Windows Vista Install & Setup 0 06-27-2006 04:15 PM
I've got a problem w/ windows xp and drivers. Blue screen type problem... Person with a device problem Windows XP Device Drivers 3 11-12-2003 11:08 PM
time problem || software or hardware problem? michael Windows XP Help & Support 1 09-19-2003 04:30 AM