Forum: PC-Programmierung Sektor von IDE-Gerät lesen?


von Carsten P. (papa_of_t)


Lesenswert?

Hallo allerseits,

hat jemand ein einfaches Kochrezept parat, um unter Windows 2000 /XP 
einen Sektor (idR. 512 Byte) von einer Festplatte zu lesen? Möglichst 
ohne kostenpflichtige DLLs und Gigabyte-große Entwicklungsumgebungen..

von Jens B. (sio2)


Lesenswert?

Mit cygwin und dd sollte es gehen. Vielleicht gibts auch nen dd unter 
win.
Du kannst mal nach rawrite.exe suchen, vielleicht kanns das auch, wird 
benutzt um images auf floppy zu schreiben. findet sich auf jeder 
linux-install-cd oder auf nem ftp, wo man linux findet

von Xenu (Gast)


Lesenswert?


von Rufus Τ. F. (rufus) Benutzerseite


Lesenswert?

Das können die üblichen Hexeditoren (Winhex, Hex Workshop etc.) auch, 
und selbst programmieren lässt sich das auch mit üblichen 
Win32-API-Funktionen.

von Carsten P. (papa_of_t)


Lesenswert?

Ja, WinHex kenne ich. genau so meine ich es, also ektoren, nicht 
zwangsläufig eine Datei lesen.

Hast Du denn ein Beispiel, wie man das prinzipiell mit API macht?

kann denn rawrite auch lesen? Ich möchte schon selbst programmieren, 
suche also kein fertiges Programm, sondern das Prinzip.. Habe gehört, 
INT13 geht nicht mehr wegen Schutz vom Betriebssystem?

von Rufus Τ. F. (rufus) Benutzerseite


Lesenswert?

Int13 gibt es nicht mehr. Das war DOS und das ist tot.

Der Zugriff erfolgt mit den üblichen Datei-Lesefunktionen, das dafür zu 
verwendende Handle wird mit CreateFile erzeugt.

1
HANDLE hFile;
2
3
hFile = CreateFile("\\\\.\\c:", ...);
Bei folgenden Zugriffen muss in ganzen Sektoren (also in 
512-Byte-Häppchen) gelesen werden.

Mehr und Details hier:

(Auszug aus der Dokumentation von CreateFile)


Disk Devices
Volume handles may be opened as noncached at the discretion of the file 
system, even when the noncached option is not specified with CreateFile. 
You should assume that all Microsoft file systems open volume handles as 
noncached. The restrictions on noncached I/O for files apply to volumes 
as well.

A file system may or may not require buffer alignment even though the 
data is noncached. However, if the noncached option is specified when 
opening a volume, buffer alignment is enforced regardless of the file 
system on the volume. It is recommended on all file systems that you 
open volume handles as noncached and follow the noncached I/O 
restrictions.

Windows NT/2000/XP: You can use the CreateFile function to open a disk 
drive or a partition on a disk drive. The function returns a handle to 
the disk device; that handle can be used with the DeviceIOControl 
function. The following requirements must be met in order for such a 
call to succeed:

The caller must have administrative privileges for the operation to 
succeed on a hard disk drive.
The lpFileName string should be of the form \\.\PHYSICALDRIVEx to open 
the hard disk x. Hard disk numbers start at zero. For example:
String Meaning
\\.\PHYSICALDRIVE2 Obtains a handle to the third physical drive on the 
user's computer.


For an example showing how to open a physical drive, see Calling 
DeviceIoControl on Windows NT/2000.

The lpFileName string should be \\.\x: to open a floppy drive x or a 
partition x on a hard disk. For example:
String Meaning
\\.\A: Obtains a handle to drive A on the user's computer.
\\.\C: Obtains a handle to drive C on the user's computer.


There is no trailing backslash in a drive name. The string "\\.\c:\" 
refers to the root directory of drive C.

On Windows 2000 or later, you can also open a volume by referring to its 
unique volume name. In this case also, there should be no trailing 
backslash on the unique volume name.

Note that all I/O buffers should be sector aligned (aligned on addresses 
in memory that are integer multiples of the volume's sector size), even 
if the disk device is opened without the FILE_FLAG_NO_BUFFERING flag. 
Depending the disk, this requirement may not be enforced.

Windows 95/98/Me: This technique does not work for opening a logical 
drive. Specifying a string in this form causes CreateFile to return an 
error.

The dwCreationDisposition parameter must have the OPEN_EXISTING value.
When opening a floppy disk or a partition on a hard disk, you must set 
the FILE_SHARE_WRITE flag in the dwShareMode parameter.

von Carsten P. (papa_of_t)


Lesenswert?

Danke Rufus, das sieht brauchbar aus. Mir war nicht klar, daß CreateFile 
ein Disc-Volume öffnen kann (etwas seltsamer Name dafür.. :-)

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.