⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bootsec.c

📁 WINDOWS下磁盘根区数据的显示
💻 C
📖 第 1 页 / 共 2 页
字号:

}                                                                            

/****************************************************************************

    FUNCTION: ReadBootSector(int iDrive, PSTR pTemp)

    PURPOSE: reads the boot sector of iDrive into the pTemp buffer.
    
    pTemp should be at least 512 bytes 
    
    we use the #pragma to turn optimization off so that the compiler won't
    complain about the inline assembly
    

****************************************************************************/
#pragma optimize("",off)
BOOL ReadBootSector(int iDrive, PSTR pTemp)
{
  
    DISKIO dio;          
    NPDISKIO npDIO;    
    dio.diStartSector = 0;
    dio.diSectors = 1;
    dio.diBuffer = pTemp;
    npDIO = &dio;
  
  _asm 
   {
        mov ax, iDrive    /* Drive number (0 based) */
        mov bx, npDIO     /* Establish buffer for read */        
        mov cx, 0FFFFh    /* use the DISKIO structure */
        xor dx, dx        /* ignored */
        int 25h           /* Absolute Disk Read */        
        jc error
        popf        // pop registers
    }     
      return TRUE;  
error:
    
    return FALSE;
}                
#pragma optimize("",on)
        
/****************************************************************************

    FUNCTION: ShowDriveInfo(HWND hDlg, BOOTSECTOR *bs)

    PURPOSE: 
             given a pointer to a BOOTSECTOR structure, display its
             contents in the dialog.  Its assumed that the id's of the
             static controls start at ID_FIRST and are sequential to 
             ID_LAST, and are in the same order as the structure.

****************************************************************************/
        
void ShowDriveInfo(HWND hDlg, BOOTSECTOR *bs)
{
    int iParameter,nCount;    
    char szBuf[64];          
    iParameter = ID_FIRST;    
    wsprintf((LPSTR)szBuf, "%#x",(WORD)bs -> bsJump);                           
    SetDlgItemText(hDlg,iParameter++,szBuf);                                      
    wsprintf((LPSTR)szBuf, "%s",(LPSTR)bs -> bsOemName);                           
    SetDlgItemText(hDlg,iParameter++,szBuf);            
    wsprintf((LPSTR)szBuf, "%d",(WORD)bs -> bsBytePerSec);
    SetDlgItemText(hDlg,iParameter++,szBuf);
    wsprintf((LPSTR)szBuf, "%d",(BYTE)bs -> bsSecPerCluster);
    SetDlgItemText(hDlg,iParameter++,szBuf);
    wsprintf((LPSTR)szBuf, "%d",(WORD)bs -> bsResSectores);
    SetDlgItemText(hDlg,iParameter++,szBuf);
    wsprintf((LPSTR)szBuf, "%d",(BYTE)bs -> bsFAT);
    SetDlgItemText(hDlg,iParameter++,szBuf);
    wsprintf((LPSTR)szBuf, "%d",(WORD)bs -> bsRootDirEnts);
    SetDlgItemText(hDlg,iParameter++,szBuf);
    wsprintf((LPSTR)szBuf, "%d",(WORD)bs -> bsSectors);
    SetDlgItemText(hDlg,iParameter++,szBuf);
    wsprintf((LPSTR)szBuf, "%#x",(BYTE)bs -> bsMedia);
    SetDlgItemText(hDlg,iParameter++,szBuf);
    wsprintf((LPSTR)szBuf, "%d",(WORD)bs -> bsFATsecs);
    SetDlgItemText(hDlg,iParameter++,szBuf);
    wsprintf((LPSTR)szBuf, "%d",(WORD)bs -> bsSecPerTrack);
    SetDlgItemText(hDlg,iParameter++,szBuf);
    wsprintf((LPSTR)szBuf, "%d",(WORD)bs -> bsHeads);
    SetDlgItemText(hDlg,iParameter++,szBuf);     
// if we have a RAM drive (only one FAT), then
// all the following information is invalid
    if (MyGetDriveType(bs) != DRIVE_RAM)    
    {
        wsprintf((LPSTR)szBuf, "%ld",(DWORD)bs -> bsHiddenSecs);
        SetDlgItemText(hDlg,iParameter++,szBuf);
        wsprintf((LPSTR)szBuf, "%ld",(DWORD)bs -> bsHugeSectoes);
        SetDlgItemText(hDlg,iParameter++,szBuf);
        wsprintf((LPSTR)szBuf, "%#x",(BYTE)bs -> bsDriveNumber);
        SetDlgItemText(hDlg,iParameter++,szBuf);
        wsprintf((LPSTR)szBuf, "%d",(BYTE)bs -> bsReserved);
        SetDlgItemText(hDlg,iParameter++,szBuf);
        wsprintf((LPSTR)szBuf, "%#x",(BYTE)bs -> bsBootSig);
        SetDlgItemText(hDlg,iParameter++,szBuf);
        wsprintf((LPSTR)szBuf, "%lX",(DWORD)bs -> bsVolumeID); // serial number
        SetDlgItemText(hDlg,iParameter++,szBuf);
         
        // there are no NULL terminated strings
        // so put the whole thing in a terminated
        // string
        memset(szBuf, NULL,64); 
        for (nCount=0; nCount < 11; nCount++)
            szBuf[nCount] =  bs -> bsVolumeLabel[nCount];                  
            
        SetDlgItemText(hDlg,iParameter++,szBuf);   
            
        memset(szBuf, NULL,12);
        for (nCount=0; nCount < 8 ; nCount++)
            szBuf[nCount]=bs -> bsFileSysType[nCount];
                
        SetDlgItemText(hDlg,iParameter++,szBuf);
      }
     else // its a RAMDRIVE
     {        
        while (iParameter < ID_LAST)
            SetDlgItemText(hDlg, iParameter++, "N/A");
     }
   
   
}                         

 
 
/****************************************************************************

    FUNCTION: 
              IsCDROM(int iDrive)                                                  

    PURPOSE:
              Determines if iDrive is a CD-ROM drive

****************************************************************************/

#pragma optimize("",off)
BOOL IsCDRomDrive(int iDrive)
{
   BOOL bRet;
   _asm 
   {
        mov     ax,1500h            ; first test for presence of MSCDEX
        xor     bx,bx
        int     2fh
        mov     ax,bx               ; MSCDEX is not there if BX is still zero
        or      ax,ax               ; ...so return FALSE from this function
        jz      no_mscdex

        mov     ax, 150bh           ; MSCDEX driver check API
        mov     cx, iDrive          ; ...cx is drive index
        int     2fh                 ; will return AX=0 iff drive is not CDROM
        mov     bRet, ax
   
   } 
  
   return bRet;
  no_mscdex:
    return FALSE;
}                      
#pragma optimize("",on)

/****************************************************************************

    FUNCTION: GetPictRect(HWND hWnd, LPRECT lpRect) 

    PURPOSE: gets the rectangle to display the drive icon

****************************************************************************/
void GetPictRect(HWND hWnd, LPRECT lpRect) 
{ 
    
    GetWindowRect(GetDlgItem(hWnd,IDC_DRIVE), lpRect);    
    ScreenToClient(hWnd, (LPPOINT)lpRect);
    ScreenToClient(hWnd, ((LPPOINT)lpRect)+1);    
    lpRect -> left = lpRect -> right + 5;
    lpRect -> right += BM_WIDTH;

}
/****************************************************************************

    FUNCTION: IsNetDrive(int iDrive)

    PURPOSE: Determines if iDrive is a network drive

****************************************************************************/
WORD IsNetDrive(int iDrive)
{
    int err;
    char szDrive[3];
    char szConn[64];    
    int nSize = 64;
    szDrive[0] = (char)(iDrive+'A');
    szDrive[1] = ':';
    szDrive[2] = (char)0;

    if (IsCDRomDrive(iDrive)) 
        return 0;

    err = WNetGetConnection(szDrive, szConn, &nSize);

    if (err == WN_SUCCESS)
        return 1;

    if (err == WN_CONNECTION_CLOSED || err == WN_DEVICE_ERROR)
        return 2;

    return 0;
}
/****************************************************************************

    FUNCTION: SetAllLabels(HWND hDlg, LPSTR szText)

    PURPOSE: Sets all labels in hDlg to szText

****************************************************************************/
void SetAllLabels(HWND hDlg, LPSTR szText)
{
    int i;
    for (i=ID_FIRST; i < ID_LAST; i++)    
        SetDlgItemText(hDlg, i, szText);
}

                                              
/****************************************************************************

    FUNCTION: 
             NewEditProc(HWND hEdit, UINT message, WPARAM wParam , LPARAM lParam)

    PURPOSE: 
             The subclassed edit procedure.  Restricts input of theedit control
             to capital letters, the TAB key, and the backspace key.

****************************************************************************/                                              
long FAR PASCAL __export NewEditProc(HWND hEdit, UINT message, WPARAM wParam , LPARAM lParam)
{
    if (message == WM_CHAR)
    {
        // if it is a lower case letter, convert it to 
        // uppercase - NOTE: This is NOT portable!
        if (wParam <= 'z' && wParam >= 'a')
            wParam -= 'a' - 'A';                  
        
        // allow only letters, TAB, or backspance keys
        if ((wParam <= 'Z' && wParam >= 'A') || (wParam == VK_TAB) || (wParam == VK_BACK))
        {
            
            
            CallWindowProc(lpfnOldEditProc, hEdit, message, wParam, lParam);                                                      
            //we never want more than one character in the
            //control, so after we put the char in there,
            // highlight it
            SendMessage(hEdit, EM_SETSEL,0,MAKELPARAM(0,-1));
            return 0;
        } 
        else
        {  
            MessageBeep(0);                                                     
            return 0L;
        }
        
    
    }
    CallWindowProc(lpfnOldEditProc, hEdit, message, wParam, lParam);

}
 
/****************************************************************************

    FUNCTION: AboutDlgProc(HWND, unsigned, WORD, LONG)

    PURPOSE:  Processes messages for "About" dialog box

    MESSAGES:

    WM_INITDIALOG - initialize dialog box
    WM_COMMAND    - Input received

****************************************************************************/
 
BOOL FAR PASCAL __export AboutDlgProc (HWND hDlg, UINT message,  WPARAM wParam, LPARAM lParam)
{

    switch (message)
    {
        case WM_INITDIALOG:
            return (TRUE);
        case WM_COMMAND:
            if (wParam == IDOK)
            {
                EndDialog(hDlg, TRUE);
                return (TRUE);
            }
            break;
    }
    return (FALSE);

}
/****************************************************************************

    FUNCTION: MyGetDriveType(BOOTSECTOR *bs)

    PURPOSE:  Given a pointer to a bootsector, determine what kind of drive
              it is.
              
              Drive         Test
              -----         ----
              RAM           TRUE if only 1 FAT
              FIXED         TRUE if media descriptor is 0xF8h
              FLOPPY        Default 

    
    call IsCDRom() and IsNetDrive() before calling this function!
    (or integrate them into it...)

****************************************************************************/
int MyGetDriveType(BOOTSECTOR *bs)
{
    
    
    if (bs -> bsFAT == 1)
        return  DRIVE_RAM;
    if (bs -> bsMedia == 0xF8)
        return DRIVE_FIXED;
        
    return DRIVE_REMOVABLE; 

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -