опубликован 11-02-2002 12:21 MSK
Было это написано в какой-то статье, не помню где (потому что было то ышо летом).#define VWIN32_DIOC_DOS_INT25 2
#define VWIN32_DIOC_DOS_INT26 3
#define VWIN32_DIOC_DOS_DRIVEINFO 6
#define CARRY_FLAG 1
#define LENGTH_STRING_DISKS 120
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, *PDIOC_REGISTERS;
#pragma pack(1)
typedef struct _DISKIO {
DWORD dwStartSector; // starting logical sector number
WORD wSectors; // number of sectors
DWORD dwBuffer; // address of read/write buffer
} DISKIO, * PDISKIO;
#pragma pack()
//******************************************************************************
/*--------------- ;---------------- ;---------------- ;---------------- ;---
NewReadSectors(hDev, bDrive, dwStartSector, wSectors, lpSectBuff)
Purpose:
Reads the specified number of sectors into a caller-supplied buffer. Uses Int 21h function 7305h
Parameters:
hDev - Handle of VWIN32
bDrive The MS-DOS logical drive number. 0 = default, 1 = A, 2 = B,3 = C, etc.
dwStartSector The first sector to read.
wSectors The number of sectors to read.
lpSectBuff The caller-supplied buffer to read into.
Return Value:
Returns TRUE if successful, or FALSE if failure.
Comments:
This function does not validate its parameters. It assumes that
lpSectBuff is allocated by the caller and is large enough to
hold all of the data from all of the sectors being read.
------------- 45;--------------- 45;--------------- 45;--------------- 45;----*/
char NewReadSectors (HANDLE hDev, BYTE bDrive,DWORD dwStartSector,WORD wSectors,LPBYTE lpSectBuff)
{ BOOL fResult;
DWORD cb;
DIOC_REGISTERS reg = {0};
DISKIO dio;
dio.dwStartSector = dwStartSector;
dio.wSectors = wSectors;
dio.dwBuffer=(DWORD)lpSectBuff;
reg.reg_EAX = 0x7305; // Ext_ABSDiskReadWrite
reg.reg_EBX = (DWORD)&dio; reg.reg_ECX = -1;
reg.reg_EDX = bDrive; // Int 21h, fn 7305h drive numbers are 1-based
fResult = DeviceIoControl(hDev, VWIN32_DIOC_DOS_DRIVEINFO,
®, sizeof(reg),
®, sizeof(reg), &cb, 0);
// Determine if the DeviceIoControl call and the read succeeded.
fResult=fResult&&!(reg.reg_Flags & CARRY_FLAG);
if(!fResult)return READ_ERROR;
return 0;
}
//******************************************************************************
/*-------------- ;---------------- ;---------------- ;---------------- ;----
NewWriteSectors(hDev, bDrive, dwStartSector, wSectors, lpSectBuff)
Purpose:
Writes the specified number of sectors from a caller-supplied
buffer. Uses Int 21h function 7305h
Parameters:
hDev Handle of VWIN32
bDrive The MS-DOS logical drive number. 0 = default, 1 = A, 2 = B,3 = C, etc.
dwStartSector The first sector to write.
wSectors The number of sectors to write.
lpSectBuff The caller-supplied buffer from which to write.
Return Value:
Returns TRUE if successful, or FALSE if failure.
Comments:
This function does not validate its parameters. It assumes that
lpSectBuff is allocated by the caller and is large enough to
hold all of the data to be written.
------------- ;---------------- ;---------------- ;---------------- ;-----*/
BOOL NewWriteSectors (HANDLE hDev, BYTE bDrive,DWORD dwStartSector,WORD wSectors,LPBYTE lpSectBuff)
{ BOOL fResult;
DWORD cb;
DIOC_REGISTERS reg = {0};
DISKIO dio;
dio.dwStartSector = dwStartSector;
dio.wSectors = wSectors;
dio.dwBuffer = (DWORD)lpSectBuff;
reg.reg_EAX = 0x7305; // Ext_ABSDiskReadWrite
reg.reg_EBX = (DWORD)&dio;
reg.reg_ECX = -1;
reg.reg_EDX = bDrive; // Int 21h, fn 7305h drive numbers are 1-based
reg.reg_ESI = 0x6001; // Normal file data (See function
// documentation for other values)
fResult = DeviceIoControl(hDev, VWIN32_DIOC_DOS_DRIVEINFO,
®, sizeof(reg),
®, sizeof(reg), &cb, 0);
// Determine if the DeviceIoControl call and the write succeeded.
fResult = fResult && !(reg.reg_Flags & CARRY_FLAG);
if(!fResult)return WRITE_ERROR;
return 0;
}
//******************************************************************************
WRITE_ERROR и READ_ERROR - по твоему усмотрению, как понимаешь. :))
Это для физического доступа, т.е. в обод логики диска. Там были ышо 2 функции (чтение/запись) и для логических дисков, но я их не юзал.