partmap.c
上传用户:xiaoan1112
上传日期:2013-04-11
资源大小:19621k
文件大小:3k
源码类别:

操作系统开发

开发平台:

Visual C++

  1. /***************************************************************************/
  2. /* */
  3. /* PARTMAP.C */
  4. /* */
  5. /* Copyright (c) 1991 - Microsoft Corp. */
  6. /* All rights reserved. */
  7. /* Microsoft Confidential */
  8. /*                                                                         */
  9. /* Builds a map of the entire partition layout of a hard disk. The map is */
  10. /* sorted by physical starting disk sectors and contains all free and */
  11. /* allocated areas of the disk. */
  12. /*  */
  13. /* BuildPartMap( struct Part *Part, struct PartMap *Map, */
  14. /*  struct HdParms *Parms ) */
  15. /*  */
  16. /* ARGUMENTS: Part - Ptr to partition entry table to build the map from */
  17. /*  Map - Ptr to array of at least 9 partition map structures */
  18. /*  Parms - Ptr to hard disk parameter structure  */
  19. /* RETURNS: void */
  20. /*  */
  21. /* Created 02-07-90 johnhe */
  22. /***************************************************************************/
  23. #include <stdio.h>
  24. #include <alias.h>
  25. #include  <hdisk.h>
  26. UL BuildPartMap( struct Part *Part, struct PartMap *Map,
  27.   struct HdParms *Parms )
  28. {
  29. register  i;  /* Loop indice  */
  30. UL  ulNext; /* Start of next possible partition */
  31. UL  ulMaxSec; /* Max physical sector on the disk */
  32. UL  ulTmpStart;  /* Tmp holds partition start sector */
  33. UL  ulTmpEnd; /* Tmp hold last partition sector */
  34. UL  ulMaxFree; /* Largest free disk area */
  35. ulMaxSec = GetTotalHdSectors( Parms );
  36. ulNext = Parms->MaxSec; /* Sector 1 track 1 */
  37. ulMaxFree = 0L;
  38. for ( i = 0; i < MAX_PART_ENTRIES; i++ )
  39. if ( (Part+i)->SystemIndicator != 0 &&
  40.   (Part+i)->RelativeSector < ulNext ) /* Any partitions */
  41. ulNext = (Part+i)->RelativeSector; /* start lower? */
  42. do
  43. {
  44. ulTmpEnd = ulMaxSec;
  45. for ( i = 0; i < MAX_PART_ENTRIES; i++ )
  46. {
  47. ulTmpStart = (Part+i)->RelativeSector;
  48. if ( ulTmpStart == ulNext ) /* Does a part start here? */
  49. {
  50. CreateMapEntry( Map, Part + i );  /* Found match so save it */
  51. break;
  52. }
  53. else if ( ulTmpStart > ulNext && ulTmpStart < ulTmpEnd )
  54. ulTmpEnd = ulTmpStart - 1;  /* End of possible free area */
  55. }
  56. if ( i >= MAX_PART_ENTRIES )
  57. { /* No partition found so mark free area */
  58. Map->PartType = 0;
  59. Map->StartSec = ulNext;
  60. Map->EndSec  = ulTmpEnd;
  61. Map->TotalSecs = (Map->EndSec - Map->StartSec) + 1;
  62. if ( ulMaxFree < Map->TotalSecs ) /* See if biggest free area */
  63. ulMaxFree = Map->TotalSecs;
  64. }
  65. ulNext = Map->EndSec + 1;
  66. Map++;
  67. }
  68. while( ulNext < ulMaxSec );
  69. return( ulMaxFree );
  70. }