00001 00002 /* 00003 * THIS FILE IS UNDER RCS - DO NOT MODIFY UNLESS YOU HAVE 00004 * CHECKED IT OUT USING THE COMMAND CHECKOUT. 00005 * 00006 * $Id: getavail_8c-source.html 2161 2006-05-19 16:55:03Z paulf $ 00007 * 00008 * Revision history: 00009 * $Log$ 00009 * Revision 1.1 2006/05/19 16:55:02 paulf 00009 * first inclusion 00009 * 00010 * Revision 1.1 2000/02/14 18:53:30 lucky 00011 * Initial revision 00012 * 00013 * 00014 */ 00015 00016 /****************************************************** 00017 * GetDiskAvail * 00018 * Windows NT version. * 00019 * * 00020 * DiskAvail = Available disk space on the default * 00021 * disk, in kilobytes. * 00022 * * 00023 * This function returns -1 if error, * 00024 * 0 if no error. * 00025 ******************************************************/ 00026 00027 #include <windows.h> 00028 #include <stdio.h> 00029 00030 00031 int GetDiskAvail( unsigned *DiskAvail ) 00032 { 00033 BOOL success; 00034 const char device[] = "\\"; 00035 unsigned long sectorsPerCluster; 00036 unsigned long bytesPerSector; 00037 unsigned long freeClusters; 00038 unsigned long clusters; 00039 00040 success = GetDiskFreeSpace( device, 00041 §orsPerCluster, 00042 &bytesPerSector, 00043 &freeClusters, 00044 &clusters ); 00045 if ( !success ) 00046 { 00047 printf( "GetDiskAvail() error: %d\n", GetLastError() ); 00048 return -1; 00049 } 00050 00051 /* printf( "sectorsPerCluster: %u\n", sectorsPerCluster ); 00052 printf( "bytesPerSector: %u\n", bytesPerSector ); 00053 printf( "freeClusters: %u\n", freeClusters ); 00054 printf( "clusters: %u\n", clusters ); */ 00055 00056 00057 *DiskAvail = (unsigned)((double)freeClusters * 00058 (double)bytesPerSector * 00059 (double)sectorsPerCluster / 1024.); 00060 return 0; 00061 }