I am writing an NLM that needs to...
Articles and Tips: qna
01 Jul 2003
Q.
I am writing an NLM that needs to find out programmatically the available space on a certain volume. I need to do this on both traditional and NSS volumes and on NetWare versions 3.2 (sorry, I know it's no longer supported, but...) 4.2, 5.1 and 6.
Could you tell me what the proper way of calculating the space currently available on a particular volume (taking into consideration Low Space Warning Threshold, buffers, or whatever else is necessary)? Is there a method which would work properly on both types of volumes and all versions of NetWare, or should it be done in different ways each version?
A.
The following equations explain how to calculate available disk space in bytes:
Total usable blocks = availableBlocks + purgableBlocks.
Block size in bytes = sectorsPerBlock * 512.
TOTAL AVAILABLE DISK SPACE in bytes = total usable blocks * block size in bytes.
Here is some sample code that illustrates how this function can be used. I think it can be rewritten to avoid the 64-bit variables.
#include <nit/nwdir.h> #include <nwerrno.h> #include <stdio.h> #include <stdlib.h> static unsigned long GetFreeDiskSpaceInMBs(const char* volumeName) { unsigned long availableDiskSpaceInMBs = 0; int volumeNumber; if ( GetVolumeNumber( volumeName, &volumeNumber) == ESUCCESS) { VOLUME_INFO volumeStatistics; if ( GetVolumeStatistics( 0, ( BYTE) volumeNumber, sizeof(volumeStatistics), &volumeStatistics) == ESUCCESS) { unsigned __int64 totalUsableBlocks = (unsigned long long) volumeStatistics.availableBlocks + volumeStatistics.purgableBlocks; unsigned __int64 blockSizeInBytes = (unsigned long long) (volumeStatistics.sectorsPerBlock) * 512; unsigned __int64 availableDiskSpace = totalUsableBlocks * blockSizeInBytes; availableDiskSpaceInMBs = ( unsigned long) (availableDiskSpace / (1024 * 1024)); } } return availableDiskSpaceInMBs; } int main( int argc, char* argv[]) { if ( argc != 2) { printf( "Usage: %s <volume name>\n", argv[ 0]); return EXIT_FAILURE; } printf( "Available disk space in MBs: %u\n", GetFreeDiskSpaceInMBs(argv[ 1])); return EXIT_SUCCESS; }
* Originally published in Novell AppNotes
Disclaimer
The origin of this information may be internal or external to Novell. While Novell makes all reasonable efforts to verify this information, Novell does not make explicit or implied claims to its validity.