Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Writing to a file from a device driver!

Writing to a file from a device driver!

Scheduled Pinned Locked Moved C / C++ / MFC
helpcsharphtmlcomquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nish Nishant
    wrote on last edited by
    #1

    Hey fellas, Right now I am pretty much stuck at a point :-( I am modifying a device driver and well I don't really have much prior experience doing such stuff. For debugging reasons I need to write some data to a disk file. For this purpose I am using the following code :-

    /*nish-start*/
    NTSTATUS Status;
    LARGE_INTEGER ByteOffset;
    IO_STATUS_BLOCK IoStatusBlock;
    OBJECT_ATTRIBUTES InitializedAttributes;
    UNICODE_STRING ustr;
    HANDLE handle;
    WCHAR fname[] = L"\\??\\D:\\Output.txt";

    RtlInitUnicodeString(&ustr,fname);
    InitializeObjectAttributes(&InitializedAttributes,&ustr,0, 0, NULL);
    Status = ZwCreateFile(
    &handle,GENERIC_WRITE|SYNCHRONIZE,
    &InitializedAttributes,
    &IoStatusBlock,
    0,FILE_ATTRIBUTE_NORMAL,
    0, FILE_OVERWRITE_IF, FILE_NON_DIRECTORY_FILE|
    FILE_WRITE_THROUGH|
    FILE_SYNCHRONOUS_IO_ALERT,
    NULL,0);
    ByteOffset.QuadPart = 0;
    ZwWriteFile(handle,NULL,NULL,NULL,&IoStatusBlock,
    data,512,NULL,NULL);
    ZwClose(handle);
    /*nish-end*/

    My problem is that the file is not getting created at all! Can anyone tell me what I doing wrong here? Regards, Nish


    Author of the romantic comedy Summer Love and Some more Cricket [New Win] Review by Shog9 Click here for review[NW]

    S 1 Reply Last reply
    0
    • N Nish Nishant

      Hey fellas, Right now I am pretty much stuck at a point :-( I am modifying a device driver and well I don't really have much prior experience doing such stuff. For debugging reasons I need to write some data to a disk file. For this purpose I am using the following code :-

      /*nish-start*/
      NTSTATUS Status;
      LARGE_INTEGER ByteOffset;
      IO_STATUS_BLOCK IoStatusBlock;
      OBJECT_ATTRIBUTES InitializedAttributes;
      UNICODE_STRING ustr;
      HANDLE handle;
      WCHAR fname[] = L"\\??\\D:\\Output.txt";

      RtlInitUnicodeString(&ustr,fname);
      InitializeObjectAttributes(&InitializedAttributes,&ustr,0, 0, NULL);
      Status = ZwCreateFile(
      &handle,GENERIC_WRITE|SYNCHRONIZE,
      &InitializedAttributes,
      &IoStatusBlock,
      0,FILE_ATTRIBUTE_NORMAL,
      0, FILE_OVERWRITE_IF, FILE_NON_DIRECTORY_FILE|
      FILE_WRITE_THROUGH|
      FILE_SYNCHRONOUS_IO_ALERT,
      NULL,0);
      ByteOffset.QuadPart = 0;
      ZwWriteFile(handle,NULL,NULL,NULL,&IoStatusBlock,
      data,512,NULL,NULL);
      ZwClose(handle);
      /*nish-end*/

      My problem is that the file is not getting created at all! Can anyone tell me what I doing wrong here? Regards, Nish


      Author of the romantic comedy Summer Love and Some more Cricket [New Win] Review by Shog9 Click here for review[NW]

      S Offline
      S Offline
      Shiva Prasad T S
      wrote on last edited by
      #2

      Hi Nish, if u have win2k ddk(ntddk) ,there u can find a sample at the following directory. root\ntddk\src\kernel\parclass\debug.c this file debug.c has a sample on how to create a file from the kernel device driver..u can compare u r program with this and check out where u r going out of wrong.. regards, shiv:)

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups