CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Feb 2005
    Posts
    331

    Directly reading/writing a HDD

    Hi,

    I'm writing a console program to directly read from and write to an external USB HDD in sector level, and I'm wondering how to get started. I've only done file level I/O before on directly connected drives so I'm not sure how to identify the USB drive(USB VID/PID/serial number maybe?) and also how to address it directly. Are there any primers for this to help me get started?

    Thanks!

  2. #2
    Join Date
    Jun 2005
    Posts
    1,255

    Smile Re: Directly reading/writing a HDD

    See:
    http://www.lvr.com/usb.htm (Information, tools, and links by Jan Axelson)
    http://www.usb.org/developers (USB-IF Developers Area)

  3. #3
    Join Date
    Feb 2005
    Posts
    331

    Re: Directly reading/writing a HDD

    Hi,
    I've visited the USB-IF website before. It seems to be more geared towards developers of USB devices. However, I'm simply trying to access the drive with C programming.

  4. #4

    Re: Directly reading/writing a HDD

    A USB HDD gets asssigned as a PhysicalDriveX right?
    Try using CreateFile and WriteFile for opening and writing directly on to sectors. I have done it and its pretty simple.

    Try looking at CreateFile in MSDN.
    C++ is divine.

  5. #5
    Join Date
    Feb 2005
    Posts
    331

    Re: Directly reading/writing a HDD

    Thanks. I'll check that out. Is there any way of identifying which drive I'm writing to(other than drive/volume letter) to make sure I'm writing to the right drive?

  6. #6
    Join Date
    Feb 2005
    Posts
    331

    Re: Directly reading/writing a HDD

    OK so I tried CreateFile using the following syntax:
    Code:
    hUserPort = CreateFile("G:\"", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
    but hUserPort keeps getting set to INVALID_HANDLE_VALUE.

    I also tried GetLogicalDrives() and GetLogicalDriveStrings(), and while they work, they only give me the logical drive letter, so there's no way of physically identifying which drive I'm accessing...how do I do that?

  7. #7
    Join Date
    Aug 1999
    Location
    <Classified>
    Posts
    6,882

    Re: Directly reading/writing a HDD

    Have you never searched on internet ?? There are thousands of links on this topic.

    Here,

    INFO: Direct Drive Access Under Win32

    Editing A Remote Hard Disk

    Forensic Inspection of Hard Disks

    Undeleting in Windows 95/98/Me/NT/2000/XP
    Regards,
    Ramkrishna Pawar

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured