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!
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)
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.
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.
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?
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?
Re: Directly reading/writing a HDD