Win2000 directly read and write disk sectors

xiaoxiao2021-03-06  50

Under NT and 2000, the drive, readfile, writefile you need to read and write via CREATEFILE, to perform disk read and write.

The following code demonstrates how to read and write A drive

/ * ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----- Read Floppy Disk Sector for WIN NT / 2000Reads [Numsec] Sectors from [Head] [TRACK] [Sector] ---------------------------------------------------------------------------------------------------------------- --------------------------------- * / char * readsectors (int head, int sync, int track, int number ) {// Getting Logical Sector from Absolute Head / TRACK / SECTOR ... / / Calculation Sector Position INT Logicalsector = (Sector-1) (TRACK * SECTORSPERTRACK * NUMOFHEADS); char * buffer; Handle Hdevice; CHAR * BUFFER = (char *) Malloc (512 * Numsec); strset (buffer, ''); dword BytesRead; // getting a handle to the drive a: using // createfile () function. ... // Open the drive //./a: HDevice = CreateFile (".// A:", generic_read, file_share_read | file_share_write, null, open_existing, 0, null; if (hdevice == null) {MessageBox "Failed!"); Return null;} // setting the file pointer to the start of the // sector we want to read. // Mobile file pointer to the need to read location setfilepointer (HDevice, (Logicalsector * 512), NULL , File_begin); // Reading Sector (s) ... // Read Data I f (! Readfile (HDEvice, BYTESREAD, NULL) {/ * int err; char error [10]; err = getLastError (); ITOA (Err, Error, 10); MessageBox (Error, " Reading sectors ... failed "); return null; * /} // Close CloseHandle (HDEvice); Return Buffer;}

转载请注明原文地址:https://www.9cbs.com/read-83282.html

New Post(0)