
/*--------------------------------------------------------------------*/
/*                                                                    */
/*                                                                    */
/*                                                                    */
/*                                                                    */
/*                                                                    */
/*                                                                    */
/*                                                                    */
/*                                                                    */
/*--------------------------------------------------------------------*/

#define INCL_DOSFILEMGR
#define INCL_DOSMISC
#include <os2.h>

#include "cons.h"
#include "types.h"
#include "apipro.h"

#define NO_API 1
#include "api.h"

extern char bootDrive[];

FATDIRENT Dir[] =
{
   {{0x49,0x42,0x4d,0x42,0x49,0x4f,0x20,0x20,0x43,0x4f,0x4d}, 0x27},
   {{0x49,0x42,0x4d,0x44,0x4f,0x53,0x20,0x20,0x43,0x4f,0x4d}, 0x27}
};
UCHAR BootBPB[SECTOR_SIZE];
UCHAR BioFile[SECTOR_SIZE * 3];

#define BOOT_PATH_LEN 14
UCHAR BootPath[] = "c:\\os2\\system\\          ";
UCHAR dosBootPath[] = "c:\\os2\\system\\boot.dos";

ULONG GetDosInfo ( VOID )
{
  ULONG bytecnt, rc = 0;
  PFATINFO pFSI;
  HFILE hFile;
  PFILE pFile;
  ULONG BootDrive;

  /*
   * Open IBMBIO.COM
   */
  strcpy( (PSZ)(&BootPath[BOOT_PATH_LEN]), "IBMBIO.COM" );
  if ( rc = MFSOpen( BootPath, &hFile ) )
     return(rc);

  /*
   * Build it's directory entry
   */
  pFile = (PFILE)hFile;
  pFSI = (PFATINFO)pFile->FSInfo;
  Dir[0].FileStartCluster = pFSI->FatCLMap.StartCluster;
  Dir[0].FileSize = pFile->FileEOFByte;

  /*
   * Read in the BPB of the boot drive
   */
  MFSRead( pFile->pVol, 0, (PBYTE)&BootBPB, SECTOR_SIZE );

  /*
   * Read in the first 3 sectors of IBMBIO.COM
   */
  MFSReadFileAt( hFile, 0, (PBYTE)&BioFile, SECTOR_SIZE * 3, &bytecnt);

  /*
   * Close the file
   */
  MFSClose( hFile );

  /*
   * Open IBMDOS.COM
   */
  strcpy( (PSZ)(&BootPath[BOOT_PATH_LEN]), "IBMDOS.COM" );
  if ( (rc = MFSOpen( BootPath, &hFile )) )
     return(rc);

  /*
   * Build it's directory entry
   */
  pFile = (PFILE)hFile;
  pFSI = (PFATINFO)pFile->FSInfo;
  Dir[1].FileStartCluster = pFSI->FatCLMap.StartCluster;
  Dir[1].FileSize = pFile->FileEOFByte;

  /*
   * Close the file
   */
  MFSClose( hFile );

  return( rc );
}
