Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
3.1 KiB

  1. #include <windows.h>
  2. //=--------------------------------------------------------------------------=
  3. // Function name here
  4. //=--------------------------------------------------------------------------=
  5. // Function description
  6. //
  7. // Parameters:
  8. //
  9. // Returns:
  10. //
  11. // Notes:
  12. //
  13. // Checks the install destination dir free disk space
  14. //
  15. DWORD GetSpace( LPSTR szPath )
  16. {
  17. DWORD dwSecsPerCluster = 0;
  18. DWORD dwBytesPerSector = 0;
  19. DWORD dwFreeClusters = 0;
  20. DWORD dwTotalClusters = 0;
  21. DWORD dwClusterSize = 0;
  22. DWORD dwFreeBytes = 0;
  23. DWORD dwVolFlags = 0;
  24. if( szPath[0] == 0)
  25. return 0;
  26. if ( ! GetDiskFreeSpace( szPath, &dwSecsPerCluster, &dwBytesPerSector,
  27. &dwFreeClusters, &dwTotalClusters ) )
  28. {
  29. return( 0 );
  30. }
  31. dwClusterSize = dwBytesPerSector * dwSecsPerCluster;
  32. dwFreeBytes = MulDiv(dwClusterSize, dwFreeClusters, 1024);
  33. return dwFreeBytes;
  34. }
  35. //=--------------------------------------------------------------------------=
  36. // Function name here
  37. //=--------------------------------------------------------------------------=
  38. // Function description
  39. //
  40. // Parameters:
  41. //
  42. // Returns:
  43. //
  44. // Notes:
  45. //
  46. // Checks the install destination dir free disk space
  47. //
  48. DWORD GetDriveSize( LPSTR szPath )
  49. {
  50. DWORD dwSecsPerCluster = 0;
  51. DWORD dwBytesPerSector = 0;
  52. DWORD dwFreeClusters = 0;
  53. DWORD dwTotalClusters = 0;
  54. DWORD dwClusterSize = 0;
  55. DWORD dwFreeBytes = 0;
  56. DWORD dwVolFlags = 0;
  57. if( szPath[0] == 0)
  58. return 0;
  59. if ( ! GetDiskFreeSpace( szPath, &dwSecsPerCluster, &dwBytesPerSector,
  60. &dwFreeClusters, &dwTotalClusters ) )
  61. {
  62. return( 0 );
  63. }
  64. dwClusterSize = dwBytesPerSector * dwSecsPerCluster;
  65. dwFreeBytes = MulDiv(dwClusterSize, dwTotalClusters, 1024);
  66. return dwFreeBytes;
  67. }
  68. //=--------------------------------------------------------------------------=
  69. // Function name here
  70. //=--------------------------------------------------------------------------=
  71. // Function description
  72. //
  73. // Parameters:
  74. //
  75. // Returns:
  76. //
  77. // Notes:
  78. //
  79. // Checks the given path drive free space and the current cluster size
  80. //
  81. DWORD GetDrvFreeSpaceAndClusterSize( LPSTR szPath, LPDWORD lpdwClustSize )
  82. {
  83. DWORD dwSecsPerCluster = 0;
  84. DWORD dwBytesPerSector = 0;
  85. DWORD dwFreeClusters = 0;
  86. DWORD dwTotalClusters = 0;
  87. DWORD dwClusterSize = 0;
  88. DWORD dwFreeBytes = 0;
  89. DWORD dwVolFlags = 0;
  90. // if szPath is NULL, the current directory root will be used by the API
  91. if ( ! GetDiskFreeSpace( szPath, &dwSecsPerCluster, &dwBytesPerSector,
  92. &dwFreeClusters, &dwTotalClusters ) )
  93. {
  94. return( 0 );
  95. }
  96. dwClusterSize = dwBytesPerSector * dwSecsPerCluster;
  97. dwFreeBytes = MulDiv(dwClusterSize, dwFreeClusters, 1024);
  98. if (lpdwClustSize)
  99. *lpdwClustSize = dwClusterSize;
  100. return dwFreeBytes;
  101. }