home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / BOOTDR.ZIP / BOOT.C next >
C/C++ Source or Header  |  1991-08-23  |  2KB  |  85 lines

  1. /* Demo program that illustrates how to determine the boot drive.  This is
  2. ** important in OS/2 2.0 because the Boot Manager allows drives other than
  3. ** C: to be the active boot drive for OS/2.  Any software that assumes the
  4. ** boot drive IS dirve C: may not function properly.
  5. **
  6. **  Three routines are included:
  7. **
  8. **        main                    The test driver
  9. **
  10. **        GetSysInfo            Routine allocates storage and calls DosQuerySysInfo
  11. **                                It returns a pointer to a results buffer.  In the
  12. **                                test case listed, the buffer contains a single ULONG
  13. **                                with the value 3.
  14. **
  15. **        QueryBootDrive        Routine calls GetSysInfo and returns the numeric
  16. **                                value of the boot drive (e.g., if the boot drive is
  17. **                                drive C: QueryBootDrive returns 3);
  18. **
  19. **
  20. **    NOTE: The driver routine ASSUMES English and single byte characters, etc.
  21. **       The conversion from drive number to letter may NOT be suitable for
  22. **            "internationalization"  The method used is not totally collating
  23. **       sequence independent.
  24. **
  25. ** Author: David Moskowitz
  26. ** Copyright (c) 1991, Productivity Solutions, Inc.  All Rights reserved.
  27. ** Permission is hereby granted for unrestricted use of this code.
  28. **
  29. */
  30.  
  31. #define INCL_DOSMISC
  32. #define INCL_NOPMAPI
  33. #include <os2.h>
  34.  
  35. #include <stdlib.h>
  36. #include <stdio.h>
  37.  
  38.  
  39. PUINT GetSysInfo(UINT, UINT);
  40. UINT QueryBootDrive(VOID);
  41.  
  42. int main (VOID)
  43. {
  44.     UINT result;
  45.     PUINT pResultBuf;
  46.  
  47.     pResultBuf = GetSysInfo(QSV_BOOT_DRIVE, QSV_BOOT_DRIVE);
  48.  
  49.     printf("\n\tGetSysInfo for QSV_BOOT_DRIVE reports number %u letter %c:\n"
  50.         , *(pResultBuf), *(pResultBuf) + ('A'-1));
  51.  
  52.     result = QueryBootDrive();
  53.     printf("\n\tQueryBootDrive reports %u letter %c:\n", result
  54.         , result + ('a'-1));
  55.  
  56. }
  57.  
  58.  
  59. UINT QueryBootDrive(VOID)
  60. {
  61.     return (*(GetSysInfo(QSV_BOOT_DRIVE, QSV_BOOT_DRIVE)));
  62. }
  63.  
  64.  
  65. PUINT GetSysInfo(UINT StartType, UINT EndType)
  66. {
  67.     PUINT pSysInfoBuf;
  68.  
  69.     UINT cItemsRequested;
  70.     UINT cbBuf;
  71.  
  72.     cItemsRequested = EndType - StartType + 1;
  73.     cbBuf           = cItemsRequested * 4;
  74.  
  75.     pSysInfoBuf = (PUINT) calloc(cItemsRequested, cbBuf);
  76.  
  77.     DosQuerySysInfo(StartType, EndType, (PVOID) pSysInfoBuf, cbBuf);
  78.  
  79.     return pSysInfoBuf;
  80.  
  81. //    free(pSysInfoBuf);
  82.  
  83. }
  84.  
  85.