Source code of Windows XP (NT5)
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.

78 lines
1.8 KiB

  1. /***
  2. *drivfree.c - Get the size of a disk
  3. *
  4. * Copyright (c) 1991-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * This file has _getdiskfree()
  8. *
  9. *Revision History:
  10. * 08-21-91 PHG Module created for Win32
  11. * 10-24-91 GJF Added LPDWORD casts to make MIPS compiler happy.
  12. * ASSUMES THAT sizeof(unsigned) == sizeof(DWORD).
  13. * 04-06-93 SKS Replace _CRTAPI* with _cdecl
  14. * 01-27-95 GJF Removed explicit handling for case where the default
  15. * drive is specified and the current directory is a
  16. * UNC path Also, cleaned up a bit.
  17. * 01-31-95 GJF Further cleanup, as suggested by Richard Shupak.
  18. *
  19. *******************************************************************************/
  20. #include <cruntime.h>
  21. #include <direct.h>
  22. #include <oscalls.h>
  23. /***
  24. *int _getdiskfree(drivenum, diskfree) - get size of a specified disk
  25. *
  26. *Purpose:
  27. * Gets the size of the current or specified disk drive
  28. *
  29. *Entry:
  30. * int drivenum - 0 for current drive, or drive 1-26
  31. *
  32. *Exit:
  33. * returns 0 if succeeds
  34. * returns system error code on error.
  35. *
  36. *Exceptions:
  37. *
  38. *******************************************************************************/
  39. #ifndef _WIN32
  40. #error ERROR - ONLY WIN32 TARGET SUPPORTED!
  41. #endif
  42. unsigned __cdecl _getdiskfree (
  43. unsigned uDrive,
  44. struct _diskfree_t * pdf
  45. )
  46. {
  47. char Root[4];
  48. char * pRoot;
  49. if ( uDrive == 0 ) {
  50. pRoot = NULL;
  51. }
  52. else if ( uDrive > 26 ) {
  53. return ( ERROR_INVALID_PARAMETER );
  54. }
  55. else {
  56. pRoot = &Root[0];
  57. Root[0] = (char)uDrive + (char)('A' - 1);
  58. Root[1] = ':';
  59. Root[2] = '\\';
  60. Root[3] = '\0';
  61. }
  62. if ( !GetDiskFreeSpace( pRoot,
  63. (LPDWORD)&(pdf->sectors_per_cluster),
  64. (LPDWORD)&(pdf->bytes_per_sector),
  65. (LPDWORD)&(pdf->avail_clusters),
  66. (LPDWORD)&(pdf->total_clusters)) )
  67. {
  68. return ( (unsigned)GetLastError() );
  69. }
  70. return ( 0 );
  71. }