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



Hybrid Mode

