How to get drive size
Article Metadata
Header:
#include <f32file.h>Link against:
LIBRARY efsrv.lib
Capabilities:
CAPABILITY NONE
#include <e32base.h>
class ClassName
{
public:
static TInt GetDriveSizeInfoL(TChar aDriveChar, TInt64& aDriveTotalSize, TInt64& aDriveFreeSize);
};
#include <f32file.h>
TInt ClassName :: GetDriveSizeInfoL(TChar aDriveChar, TInt64& aDriveTotalSize, TInt64& aDriveFreeSize)
{
TInt err = KErrNone;
aDriveTotalSize = 0;
aDriveFreeSize = 0;
RFs fs;
User::LeaveIfError( fs.Connect() );
TInt driveIndex;
err = RFs :: CharToDrive( aDriveChar, driveIndex );
if(err == KErrNone)
{
TDriveInfo driveInfo;
err = fs.Drive( driveInfo, driveIndex );
if(err == KErrNone)
{
if(driveInfo.iMediaAtt & KMediaAttFormattable) // size defined only for formattable drives
{
TVolumeInfo volumeInfo;
err = fs.Volume(volumeInfo, driveIndex);
if(err == KErrNone)
{
// now we can get drive size info
aDriveTotalSize = volumeInfo.iSize;
aDriveFreeSize = volumeInfo.iFree;
}
}
else
err = KErrArgument;
}
else
err = KErrArgument;
}
fs.Close();
return err;
}
How to use:
TInt64 size, freeSize;
if(ClassName::GetDriveSizeInfoL('C', size, freeSize)==KErrNone)
{
....
}


13 Sep
2009
This is a useful code snippet. It illustrates how to obtain information about size of a particular drive. This function could help you to make decision where to save important information. Also it could help you to realize necessary functionality in own file manager.
It works fine on my Nokia 5800.