опубликован 25-10-2001 15:17 MSK
Я занимался этой проблемой недавно (месяца 2-3 назад). Как раз под вин9х. :)
Сначала искал по всяким мсдн-ам, почти нашел и разобрался, но потом наткнулся на уже готовые функции, которые и применил. Они приводятся внизу, комменатрии на аглицком, но там все понятно.
Вот как у меня работает:1)Дескриптор
HANDLE hVxD=CreateFile("\\\\.\\vwin32",0,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,NULL);
if(hVxD==(HANDLE)INVALID_HANDLE_VALUE)
{MessageBox(0,"Error","",MB_OK);
return;
}
2) Чтение/запись:
#define VWIN32_DIOC_DOS_DRIVEINFO 6
- Для чтения:
/*
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.
*/
BOOL 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);
return fResult;
}
- Для записи:
/*
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);
return fResult;
}
Вот.
3) В конце закрываешь свой дескриптор
CloseHandle(hVxD);
ЗЫ: ваще есть ышо 1 способ, но там используются логические диски. Но принцип почти такой же. Если хошь, могу кинуть. Или посмотри сам в МСДНе по ключевым словам VWIN32_DIOC_DOS_INT25 и VWIN32_DIOC_DOS_INT26