设为首页  
联系我们  
加入收藏  
网页制作 冲浪宝典 图形图像 操作系统 软件教学 编程开发 认证考试 安全技术 站长专区 文学驿站 娱乐天地 游戏天地 办公软件
文章搜索
您的位置: 首页 >> 文章首页 >> 编程开发 >> Visual C++ >> Reading/Writing Disk Sectors (Absolute Disk Read/Write)
精品推荐
Visual C++点击TOP10
·用WINSOCK实现聊天室的VC++程序设计
·利用mfc编写activex控件
·用vc实现生产者消费者问题
·DirectX8.0
·C/C++ 大量经典编程书籍下载
·VC快捷键大全
·CreateFileMapping的MSDN翻译和使用心得
·Windows环境下的麦克风录音系统
·挂钩Windows API
·如何开发OPC Server
编程开发点击TOP10
·数字小键盘指法练习
·用C语言编通讯录程序(初学者级别的)
·ASP.NET 程序中常用的三十三种代码
·我写的Java学生成绩管理系统源代码
·CHK文件恢复工具
·Modem 常用AT指令集
·java笔试题
·异常java.sql.SQLException: Io exception:The Network Adapter could not establish connection
·单片机模拟I2C总线及24C02(I2C EEPROM)读写实例(源代码)
·C++经典电子书下载
精选专题

Reading/Writing Disk Sectors (Absolute Disk Read/Write)

作者: 来源:网络文章 时间:2005-12-13 17:13:29

Windows 9x

Windows 9x provides a vxd called vwin32.vxd using which msdos functions including absolute disk read/write can be performed. A handle to vwin32.vxd must be first created using the CreateFile function. After creating the handle DeviceIoControl function must be used with the correct control code to read or write from the disk drives. The control code depends on the type of the function you want to perform.

The control codes for vwin32.vxd are ...

CodeDescription
VWIN32_DIOC_DOS_IOCTL (1)Interrupt 21h Function 4400h through 4411h
VWIN32_DIOC_DOS_INT25 (2)Performs the Absolute Disk Read command (Interrupt 25h)
VWIN32_DIOC_DOS_INT26 (3)Performs the Absolute Disk Write command (Interrupt 25h)
VWIN32_DIOC_DOS_INT13 (4)Performs Interrupt 13h commands
VWIN32_DIOC_DOS_DRIVEINFO (6)Interrupt 21h Function 730X commands

The lpvInBuffer & lpvOutBuffer params of DeviceIoControl function must point to addresses of DIOC_REGISTERS strUCtures . This structure contains the state of the processor registers before ioctl and after ioctl.

Windows NT/2K/XP

In Windows NT/2K/XP the CreateFile function can be used to open a disk drive or a partition on it. After getting a handle to the disk drive using CreateFile function the ReadFile function can be used to read sectors and the WriteFile function can be used to write to the drive.If you want to open a logical drive give the filename param of the CreateFile function as "\\\\.\\a:" or "\\\\.\\c:" ... etc. and if you want to open a physical drive for raw reading/writing give the filename param as "\\\\.\\PhysicalDrive0" or "\\\\.\\PhysicalDrive1" ... etc


Code to read disk sectors from win 9x/NT/2K/XP

Reads [numberofsectors] disk sectors from [drive {0=A, 1=B, 2=C, ...}] drive starting from [startinglogicalsector]

To read sectors from win 9x int 21h's 7305h extention is used (Extended Absolute Disk Read/Write). For more info about int 21h's 7305h extention refer Ralf Brown's interrupt list.


Word>char * ReadSectors(int drive, DWORD startinglogicalsector, int numberofsectors){// All msdos data structures must be packed on a 1 byte boundary#pragma pack (1)struct{DWORD StartingSector ;WORD NumberOfSectors ;DWORD pBuffer;}ControlBlock;#pragma pack ()#pragma pack (1)typedef struct _DIOC_REGISTERS{ DWORD reg_EBX; DWORD reg_EDX; DWORD reg_ECX; DWORD reg_EAX; DWORD reg_EDI; DWORD reg_ESI; DWORD reg_Flags;} DIOC_REGISTERS ;#pragma pack ()char* buffer = (char*)malloc (512*numberofsectors);HANDLE hDevice ;DIOC_REGISTERS reg ;BOOLfResult ;DWORD cb ;// Creating handle to vwin32.vxd (win 9x)hDevice = CreateFile ( "\\\\.\\vwin32", 0, 0, NULL, 0, FILE_FLAG_DELETE_ON_CLOSE, NULL );if ( hDevice == INVALID_HANDLE_VALUE ){// win NT/2K/XP code HANDLE hDevice;DWORD bytesread;char _devicename[] = "\\\\.\\A:";_devicename[4] += drive;// Creating a handle to disk drive using CreateFile () function ..hDevice = CreateFile(_devicename, GENERIC_READ, FILE_SHARE_READ  FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);if (hDevice == INVALID_HANDLE_VALUE)return NULL;// Setting the pointer to point to the start of the sector we want to read ..SetFilePointer (hDevice, (startinglogicalsector*512), NULL, FILE_BEGIN);if (!ReadFile (hDevice, buffer, 512*numberofsectors, &bytesread, NULL) )return NULL;}else{// code for win 95/98ControlBlock.StartingSector = (DWORD)startinglogicalsector;ControlBlock.NumberOfSectors = (DWORD)numberofsectors ;ControlBlock.pBuffer = (DWORD)buffer ;//-----------------------------------------------------------// SI contains read/write mode flags// SI=0h for read and SI=1h for write// CX must be equal to ffffh for// int 21h's 7305h extention// DS:BX -> base addr of the// control block structure// DL must contain the drive number// (01h=A:, 02h=B: etc)//-----------------------------------------------------------reg.reg_ESI = 0x00 ;reg.reg_ECX = -1 ;reg.reg_EBX = (DWORD)(&ControlBlock);reg.reg_EDX = drive+1;reg.reg_EAX = 0x7305 ;//6 == VWIN32_DIOC_DOS_DRIVEINFOfResult = DeviceIoControl ( hDevice,6, &(reg), sizeof (reg), &(reg), sizeof (reg), &cb,0);if (!fResult  (reg.reg_Flags & 0x0001)) return NULL; }CloseHandle(hDevice); return buffer;}

Reading/Writing Disk Sectors (Absolute Disk Read/Write) 相关文章:
Reading/Writing Disk Sectors (Absolute Disk Read/Write) 相关软件:
特别声明:本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系编辑人员,我们尽快予以更正。
转载请注明来源:http://www.xgdown.com