ZwCreateFie Problem Please Help

Discussion in 'Windows XP Drivers' started by Shalini, Mar 9, 2004.

  1. Shalini

    Shalini Guest

    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
     
    Shalini, Mar 9, 2004
    #1
    1. Advertisements

  2. Shalini

    aphillips Guest

    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
     
    aphillips, Apr 6, 2005
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. rachelle

    cd rom problem please help me!!T_T

    rachelle, Nov 28, 2003, in forum: Windows XP Drivers
    Replies:
    0
    Views:
    250
    rachelle
    Nov 28, 2003
  2. Shalini

    Re: ZwCreateFile problem-Please Help.

    Shalini, Mar 9, 2004, in forum: Windows XP Drivers
    Replies:
    0
    Views:
    365
    Shalini
    Mar 9, 2004
  3. Shalini

    ZwOpenKey Problem-Please Help

    Shalini, Mar 23, 2004, in forum: Windows XP Drivers
    Replies:
    12
    Views:
    2,481
    Shalini
    Mar 26, 2004
  4. G-dub

    USB 2 Problem. Please help.

    G-dub, Jun 12, 2004, in forum: Windows XP Drivers
    Replies:
    1
    Views:
    300
    S Vijay [MSFT]
    Jun 14, 2004
  5. Guest

    windows xp problem help, please!!

    Guest, Sep 20, 2004, in forum: Windows XP Drivers
    Replies:
    0
    Views:
    273
    Guest
    Sep 20, 2004
Loading...

Share This Page