Symbian3/SDK/Source/GUID-D91DC379-947A-52CB-A154-7922AF334527.dita
author Dominic Pinkman <dominic.pinkman@nokia.com>
Tue, 20 Jul 2010 12:00:49 +0100
changeset 13 48780e181b38
parent 7 51a74ef9ed63
permissions -rw-r--r--
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
<!-- This component and the accompanying materials are made available under the terms of the License 
"Eclipse Public License v1.0" which accompanies this distribution, 
and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
<!-- Initial Contributors:
    Nokia Corporation - initial contribution.
Contributors: 
-->
<!DOCTYPE concept
  PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
<concept id="GUID-D91DC379-947A-52CB-A154-7922AF334527" xml:lang="en"><title>How
to retrieve drive and volume information</title><shortdesc>This topic describes how to retrieve drive and volume information.</shortdesc><prolog><metadata><keywords/></metadata></prolog><conbody>
<p>The class <xref href="GUID-E263C747-946F-35AA-9F1D-41833BD350FC.dita"><apiname>RFs</apiname></xref> provides a number of functions that extract
drive and volume information. </p>
<p>The <xref href="GUID-D91DC379-947A-52CB-A154-7922AF334527.dita#GUID-D91DC379-947A-52CB-A154-7922AF334527/GUID-23B14094-0526-5BB2-8CCB-E25558F452F4">FileSystemSubType()</xref> 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. </p>
<p>The volume information supplied by <xref href="GUID-D91DC379-947A-52CB-A154-7922AF334527.dita#GUID-D91DC379-947A-52CB-A154-7922AF334527/GUID-35712294-BF6D-5ADF-A717-67B949F02EC3">VolumeIOParam()</xref> 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: </p>
<ul>
<li id="GUID-519C820E-DDF3-574C-9FF0-C16E805C38E4"><p>Applications that download
from a local or network connection to transfer files, for example, bluetooth
beaming, HTTP, FTP, may be able to improve their performance by knowing the
recommended block and cluster sizes. </p> </li>
<li id="GUID-555B3946-64CA-52BC-96AC-12034ACC0483"><p>For Multimedia source
data, reading in optimal sized blocks may help to achieve a consistent read
speed. </p> </li>
</ul>
<ul>
<li id="GUID-F9366D6D-E5CA-58EC-B28F-7219AB43F61A"><p> <xref href="GUID-D91DC379-947A-52CB-A154-7922AF334527.dita#GUID-D91DC379-947A-52CB-A154-7922AF334527/GUID-83B63D4E-65E5-5DC6-8C4B-CD3A26165B6D">Drive information</xref>  </p> <ul>
<li id="GUID-3E51BA09-FB64-54C7-9FD6-F05E43FC9DB5"><p> <xref href="GUID-D91DC379-947A-52CB-A154-7922AF334527.dita#GUID-D91DC379-947A-52CB-A154-7922AF334527/GUID-BF5C8B94-7600-555F-B9F7-DFAE390B4EE3">DriveList()</xref> </p> </li>
<li id="GUID-58D7E17C-9D24-551C-AD21-BA234395C0E5"><p> <xref href="GUID-D91DC379-947A-52CB-A154-7922AF334527.dita#GUID-D91DC379-947A-52CB-A154-7922AF334527/GUID-57F650DF-4144-586F-81E5-B1386202A27B">Drive()</xref>  </p> </li>
<li id="GUID-241A56DC-B1B5-57A7-8A03-11CC9F11D523"><p> <xref href="GUID-D91DC379-947A-52CB-A154-7922AF334527.dita#GUID-D91DC379-947A-52CB-A154-7922AF334527/GUID-23B14094-0526-5BB2-8CCB-E25558F452F4">FileSystemSubType()</xref> </p> </li>
</ul> </li>
<li id="GUID-16335B02-EF2C-51C8-AC1E-8F596085D896"><p> <xref href="GUID-D91DC379-947A-52CB-A154-7922AF334527.dita#GUID-D91DC379-947A-52CB-A154-7922AF334527/GUID-43EFDCEC-A390-56F6-A4C0-A8150E188E05">Volume information</xref>  </p> <ul>
<li id="GUID-50F492F4-FBF5-50CA-A318-C7758C1999E1"><p> <xref href="GUID-D91DC379-947A-52CB-A154-7922AF334527.dita#GUID-D91DC379-947A-52CB-A154-7922AF334527/GUID-8F14799F-6F60-5C64-AC8D-4083CE06E6A2">Volume()</xref>  </p> </li>
<li id="GUID-746C70D5-F301-5F99-B8B6-31E1AB1D42EE"><p> <xref href="GUID-D91DC379-947A-52CB-A154-7922AF334527.dita#GUID-D91DC379-947A-52CB-A154-7922AF334527/GUID-35712294-BF6D-5ADF-A717-67B949F02EC3">VolumeIOParam()</xref> </p> </li>
</ul> </li>
</ul>
<section id="GUID-83B63D4E-65E5-5DC6-8C4B-CD3A26165B6D"><title>Drive information</title> <p id="GUID-BF5C8B94-7600-555F-B9F7-DFAE390B4EE3"><b> DriveList()</b> </p> <p> <xref href="GUID-E263C747-946F-35AA-9F1D-41833BD350FC.dita#GUID-E263C747-946F-35AA-9F1D-41833BD350FC/GUID-384A86BF-EB47-3525-9614-D474977AF991"><apiname>RFs::DriveList()</apiname></xref> 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 <xref href="GUID-E263C747-946F-35AA-9F1D-41833BD350FC.dita#GUID-E263C747-946F-35AA-9F1D-41833BD350FC/GUID-51CDDF8D-3F18-398D-A477-B81948C10872"><apiname>RFs::Drive</apiname></xref> to test
for its presence. </p> <p>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. </p> <codeblock id="GUID-78C60DB6-8AA1-598C-80F8-98163898ED7D" xml:space="preserve">TDriveList drivelist;
TChar driveLetter; 
TInt driveNumber; 
_LIT(KDrive,"%c: %02x ");

User::LeaveIfError(fsSession.DriveList(drivelist)); 
for(driveNumber=EDriveA;driveNumber&lt;=EDriveZ;driveNumber++) 
{ 
    if (drivelist[driveNumber]) 
    {
        User::LeaveIfError(fsSession.DriveToChar(driveNumber,driveLetter));
        console-&gt;Printf(KDrive, TUint(driveLetter), drivelist[driveNumber]); 
    }
}</codeblock> <p id="GUID-57F650DF-4144-586F-81E5-B1386202A27B"><b>Drive()</b> </p> <p> <xref href="GUID-E263C747-946F-35AA-9F1D-41833BD350FC.dita#GUID-E263C747-946F-35AA-9F1D-41833BD350FC/GUID-BAB41D5B-A8B2-31D0-8A45-931112D1F5D3"><apiname>RFs::Drive()</apiname></xref> retrieves
the attributes of the drive specified with <xref href="GUID-4D883FA4-115C-3425-8A34-B00D1D4BBCF9.dita"><apiname>TDriveInfo</apiname></xref>.
The following example loops through all possible drives, a-z, and prints a
message if a drive is flash-based. </p> <codeblock id="GUID-8711C4BC-225A-5824-A920-09696CD59E06" xml:space="preserve">TChar driveLetter; 
TDriveInfo driveInfo; 
TInt driveNumber;
_LIT(KFlash,"Drive %c is flash\n"); 

for (driveNumber=EDriveA; driveNumber&lt;=EDriveZ; driveNumber++) 
{
    fsSession.Drive(driveInfo, driveNumber); 
    if (driveInfo.iDriveAtt == KDriveAbsent) 
        continue; 
    if (driveInfo.iType == EMediaFlash) 
    {
        User::LeaveIfError(fsSession.DriveToChar(driveNumber, driveLetter));
        console-&gt;Printf(KFlash, driveLetter); 
    }
}</codeblock> <p id="GUID-23B14094-0526-5BB2-8CCB-E25558F452F4"><b>FileSystemSubType()</b> </p> <p>To
retrieve the sub type of the volume use <xref href="GUID-E263C747-946F-35AA-9F1D-41833BD350FC.dita#GUID-E263C747-946F-35AA-9F1D-41833BD350FC/GUID-00404432-7095-3461-A669-9009A91BD45C"><apiname>RFs::FileSystemSubType()</apiname></xref>.
Pass this function a drive number and a <xref href="GUID-F3E8BB64-554E-3A9A-A7FA-A5C935A644FD.dita"><apiname>TFSName</apiname></xref> for the
sub type. For example, the sub type can be 'FAT16' of the Fat file system. </p> <p> <b>Note</b>:
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'. </p> <codeblock id="GUID-7BB4BAAD-95C3-57D2-8BDB-C4698FEB4748" xml:space="preserve">TChar driveLetter;
TFSName name;
TInt driveNumber;
_LIT(KSubType,"Drive %c is Sub Type: %S\n"); 

for (driveNumber=EDriveA; driveNumber&lt;=EDriveZ; driveNumber++) 
{
    TInt err = fsSession.FileSystemSubType(driveNumber, name); 
    if (err != KErrNone)
        continue; 
    User::LeaveIfError(fsSession.DriveToChar(driveNumber, driveLetter));
    console-&gt;Printf(KSubType, driveLetter, &amp;name);
}</codeblock> </section>
<section id="GUID-43EFDCEC-A390-56F6-A4C0-A8150E188E05"><title>Volume information</title> <p id="GUID-8F14799F-6F60-5C64-AC8D-4083CE06E6A2"><b>Volume()</b> </p> <p>Use <xref href="GUID-E263C747-946F-35AA-9F1D-41833BD350FC.dita#GUID-E263C747-946F-35AA-9F1D-41833BD350FC/GUID-52EFB8B0-E175-328F-AB1B-EACD03104A15"><apiname>RFs::Volume()</apiname></xref> to
get the volume information, with a <xref href="GUID-F7AECD65-6C3C-3056-847A-FD49BB2E927F.dita"><apiname>TVolumeInfo</apiname></xref> object.
The information returned includes a <xref href="GUID-4D883FA4-115C-3425-8A34-B00D1D4BBCF9.dita"><apiname>TDriveInfo</apiname></xref> object with
the volume name, its unique ID, size and the amount of free space. </p> <p>The
following example prints out the names of volumes: </p> <codeblock id="GUID-2C806466-0FC6-5AB3-A1C1-1655323DCEB3" xml:space="preserve">TChar driveLetter;
TVolumeInfo volumeInfo; 
TInt driveNumber;
_LIT(KVolName,"Volume name: %S\n"); 

for (driveNumber=EDriveA; driveNumber&lt;=EDriveZ; driveNumber++) 
{
    TInt err = fsSession.Volume(volumeInfo, driveNumber); 
    if (err != KErrNone)
        continue; 
    User::LeaveIfError(fsSession.DriveToChar(driveNumber, driveLetter));
    console-&gt;Printf(KVolName, &amp;volumeInfo.iName);
}</codeblock> <p>Note: Use the return value from <xref href="GUID-E263C747-946F-35AA-9F1D-41833BD350FC.dita#GUID-E263C747-946F-35AA-9F1D-41833BD350FC/GUID-52EFB8B0-E175-328F-AB1B-EACD03104A15"><apiname>RFs::Volume()</apiname></xref> to
test whether a volume is present in the drive, a value of <xref href="GUID-51298FCE-7857-39F8-BFAB-49AF5556D0CC.dita"><apiname>KErrNotReady</apiname></xref> indicates
that there is no volume present. </p> <p id="GUID-35712294-BF6D-5ADF-A717-67B949F02EC3"><b> VolumeIOParam()</b> </p> <p>Use <xref href="GUID-E263C747-946F-35AA-9F1D-41833BD350FC.dita#GUID-E263C747-946F-35AA-9F1D-41833BD350FC/GUID-DE5542A5-18ED-3F68-9012-DEE13619DCA2"><apiname>RFs::VolumeIOParam</apiname></xref> to
retrieve volume information, with a <xref href="GUID-FA2892FC-4554-3E1D-93AD-593DFA4FB6F7.dita"><apiname>TVolumeIOParamInfo</apiname></xref> object.
The object returns the recommended sizes for read and write operations on
memory and buffers. </p> <codeblock id="GUID-8618DED6-7771-5495-B109-3B629BFC006C" xml:space="preserve">TChar driveLetter;
TVolumeIOParamInfo volumeparamInfo; 
TInt driveNumber;

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

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