Article ID: 104790
Article Last Modified on 6/30/2004
40h - Set Device Parameters 41h - Write Track on Logical Drive 42h - Format Track on Logical Drive 60h - Get Device Parameters 61h - Read Track on Logical Drive 62h - Verify Track on Logical Drive 68h - Sense Media TypeThe following are not automatically translated by the DOSMGR VxD:
46h - Set Media ID 66h - Get Media IDTo use the Get Media ID or Set Media ID functions from a protected mode application in the Windows operating environment, the DPMI function Simulate Real Mode Interrupt must be used to manually translate the buffer pointer from protected mode to real mode.
// This is a standard MS-DOS structure.
typedef struct tagMEDIAID
{
WORD wInfoLevel;
DWORD dwSerialNum; // Serial number
char VolLabel[11]; // ASCII volume label
char FileSysType[8]; // File system type
} MEDIAID, far *LPMEDIAID;
// This is a standard DPMI structure.
typedef struct tagREALMODEREG {
DWORD rmEDI, rmESI, rmEBP, Reserved, rmEBX, rmEDX, rmECX, rmEAX;
WORD rmCPUFlags, rmES, rmDS, rmFS, rmGS, rmIP, rmCS, rmSP, rmSS;
} REALMODEREG, FAR *LPREALMODEREG;
//********************************************************************
// RealInt()
//
// Simulate an interrupt in real mode using DPMI function 0300h
// When the interrupt is simulated in real mode, the registers will
// contain the values in lpRealModeReg. When the interrupt returns,
// lpRealModeReg will contain the values from real mode.
//
//********************************************************************
BOOL RealInt (BYTE intnum, LPREALMODEREG lpRealModeReg)
{
BOOL bRetVal = TRUE;
_asm
{
mov ax, 0300h // Simulate real mode interrupt
mov bl, intnum // Interrupt number to simulate
mov bh, 0 // Flags
mov cx, 0 // Number of words to copy on stack
les di, lpRealModeReg
int 31h
jnc Done
mov bRetVal, FALSE
Done:
}
return bRetVal;
}
//********************************************************************
// GetMediaID()
//
// Get Media ID by simulating an Interrupt 21h, AX=440Dh, CX=0866h in
// real mode. Set up RealModeReg to contain a real mode pointer to a
// MediaID structure.
//********************************************************************
BOOL GetMediaID (WORD Drive,
LPMEDIAID lpMediaID)
{
REALMODEREG RealModeReg;
DWORD dwGlobalDosBuffer;
LPMEDIAID lpRMMediaID;
BOOL bRetVal;
// (1) Get a real mode addressable buffer for the MediaID structure.
//
dwGlobalDosBuffer = GlobalDosAlloc(sizeof(MEDIAID));
if (dwGlobalDosBuffer == NULL)
{
return FALSE;
}
// (2) Initialize the real mode register structure.
//
memset(&RealModeReg, 0, sizeof(RealModeReg));
(WORD)RealModeReg.rmEAX = 0x440D; // IOCTL for Block Device
(WORD)RealModeReg.rmEBX = Drive; // 0 = default, 1 = A, 2 = B
(WORD)RealModeReg.rmECX = 0x0866; // Get Media ID
// Set the real mode DS:DX to a real mode pointer to the buffer.
// The offset in DX is zero from the memset().
RealModeReg.rmDS = HIWORD(dwGlobalDosBuffer);
// (3) Simulate the real mode interrupt.
//
if (RealInt(0x21, &RealModeReg) && // Int simulation ok?
(RealModeReg.rmCPUFlags & 0x0001)==0) // Carry clear?
{
// (4) Copy the content of the real mode addressable buffer
// to the protected mode destination buffer.
//
lpRMMediaID = (LPMEDIAID) MAKELP(LOWORD(dwGlobalDosBuffer), 0);
*lpMediaID = *lpRMMediaID; // Structure copy
bRetVal = TRUE;
}
else
{
bRetVal = FALSE;
}
// (5) Free the real mode addressable buffer.
//
GlobalDosFree(LOWORD(dwGlobalDosBuffer));
return bRetVal;
}
For more information on the DOS Protected Mode Interface (DPMI), see
the DPMI version 0.9 specification, which is available on the
Microsoft Developer Network CD Disk Four.
Additional query words: serial number volume label
Keywords: kbhowto kb16bitonly KB104790