Symbian
Symbian Developer Library

SYMBIAN OS V9.4

Feedback

[Index] [Previous] [Next]


How to retrieve drive and volume information

The class RFs provides a number of functions that extract drive and volume information.

The FileSystemSubType() function returns the sub type of a drive. This information can be used to warn a user if they try to use a volume that is not of the correct format.

The volume information supplied by VolumeIOParam() is particularly useful as it allows you to get specific properties for a volume. This includes the block size of the underlying media for read/write operations, allowing your application to access data on the underlying media in the most efficient way. For example:

[Top]


Drive information


DriveList()

RFs::DriveList() retrieves an array of drives. The drive list consists of an array of 26 bytes. Array index zero corresponds to drive A, one equals B and so on. If the value of an array member is 1 the corresponding drive exists. If this drive is able to contain removable media then use RFs::Drive to test for its presence.

The following code prints each drive in the drive list as a letter, followed by the hex value of the integer indicating the drive's attributes.

TDriveList drivelist;
TChar driveLetter; 
TInt driveNumber; 
_LIT(KDrive,"%c: %02x ");

User::LeaveIfError(fsSession.DriveList(drivelist)); 
for(driveNumber=EDriveA;driveNumber<=EDriveZ;driveNumber++) 

    if (drivelist[driveNumber]) 
    {
        User::LeaveIfError(fsSession.DriveToChar(driveNumber,driveLetter));
        console->Printf(KDrive, TUint(driveLetter), drivelist[driveNumber]); 
    }
}

Drive()

RFs::Drive() retrieves the attributes of the drive specified with TDriveInfo. The following example loops through all possible drives, a-z, and prints a message if a drive is flash-based.

TChar driveLetter; 
TDriveInfo driveInfo; 
TInt driveNumber;
_LIT(KFlash,"Drive %c is flash\n"); 

for (driveNumber=EDriveA; driveNumber<=EDriveZ; driveNumber++) 
{
    fsSession.Drive(driveInfo, driveNumber); 
    if (driveInfo.iDriveAtt == KDriveAbsent) 
        continue; 
    if (driveInfo.iType == EMediaFlash) 
    {
        User::LeaveIfError(fsSession.DriveToChar(driveNumber, driveLetter));
        console->Printf(KFlash, driveLetter); 
    }
}

FileSystemSubType()

To retrieve the sub type of the volume use RFs::FileSystemSubType(). Pass this function a drive number and a TFSName for the sub type. For example, the sub type can be 'FAT16' of the Fat file system.

Note: For file systems that do not have a sub type, for example a ROM file system, the name of the file system is returned, in this case 'ROM'.

TChar driveLetter;
TFSName name;
TInt driveNumber;
_LIT(KSubType,"Drive %c is Sub Type: %S\n"); 

for (driveNumber=EDriveA; driveNumber<=EDriveZ; driveNumber++) 
{
    TInt err = fsSession.FileSystemSubType(driveNumber, name); 
    if (err != KErrNone)
        continue; 
    User::LeaveIfError(fsSession.DriveToChar(driveNumber, driveLetter));
    console->Printf(KSubType, driveLetter, &name);
}

[Top]


Volume information


Volume()

Use RFs::Volume() to get the volume information, with a TVolumeInfo object. The information returned includes a TDriveInfo object with the volume name, its unique ID, size and the amount of free space.

The following example prints out the names of volumes:

TChar driveLetter;
TVolumeInfo volumeInfo; 
TInt driveNumber;
_LIT(KVolName,"Volume name: %S\n"); 

for (driveNumber=EDriveA; driveNumber<=EDriveZ; driveNumber++) 
{
    TInt err = fsSession.Volume(volumeInfo, driveNumber); 
    if (err != KErrNone)
        continue; 
    User::LeaveIfError(fsSession.DriveToChar(driveNumber, driveLetter));
    console->Printf(KVolName, &volumeInfo.iName);
}

Note: Use the return value from RFs::Volume() to test whether a volume is present in the drive, a value of KErrNotReady indicates that there is no volume present.


VolumeIOParam()

Use RFs::VolumeIOParam to retrieve volume information, with a TVolumeIOParamInfo object. The object returns the recommended sizes for read and write operations on memory and buffers.

TChar driveLetter;
TVolumeIOParamInfo volumeparamInfo; 
TInt driveNumber;

_LIT(KRecWriteSize,"Drive %c's recommended write size: %d\n"); 

for (driveNumber=EDriveA; driveNumber<=EDriveZ; driveNumber++) 
{
    TInt err = fsSession.VolumeIOParam(driveNumber, volumeparamInfo); 
    if (err != KErrNone)
        continue; 
    
    User::LeaveIfError(fsSession.DriveToChar(driveNumber, driveLetter));
    console->Printf(KRecWriteSize, driveLetter, &volumeparamInfo.iRecWriteBufSize);
}