diff -r 89d6a7a84779 -r 25a17d01db0c Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/_drive_info_8cpp-source.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/_drive_info_8cpp-source.html Fri Jan 22 18:26:19 2010 +0000 @@ -0,0 +1,295 @@ + + +TB10.1 Example Applications: examples/Base/FileServer/DriveInfo/DriveInfo.cpp Source File + + + + +

examples/Base/FileServer/DriveInfo/DriveInfo.cpp

00001 // Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
+00002 // All rights reserved.
+00003 // This component and the accompanying materials are made available
+00004 // under the terms of "Eclipse Public License v1.0"
+00005 // which accompanies this distribution, and is available
+00006 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
+00007 //
+00008 // Initial Contributors:
+00009 // Nokia Corporation - initial contribution.
+00010 //
+00011 // Contributors:
+00012 //
+00013 // Description:
+00014 //
+00015 
+00016 
+00017 #include <f32file.h>
+00018 #include "CommonFramework.h"
+00019         
+00020 
+00021 LOCAL_D RFs fsSession;
+00022 
+00023 // example functions
+00024 void PrintDriveVolInfoL();
+00025 
+00026 // utility functions
+00027 void FormatDriveInfo(TDes& aBuffer, const TDriveInfo aDriveInfo);
+00028 void FormatVolumeInfo(TDes& aBuffer, const TVolumeInfo aVolumeInfo);
+00029 
+00030 void WaitForKey()
+00031         {
+00032         _LIT(KMessage,"Press any key to continue\n\n");
+00033         console->Printf(KMessage);
+00034         console->Getch();
+00035         }
+00036 
+00037 // do the example
+00038 LOCAL_C void doExampleL()
+00039     {
+00040         // Connect to file server
+00041         User::LeaveIfError(fsSession.Connect()); // Start session
+00042         PrintDriveVolInfoL();
+00043         fsSession.Close(); // close file server session
+00044         }
+00045 
+00046 void PrintDriveVolInfoL()
+00047         {
+00048         _LIT(KMessage,"PrintDriveVolInfoL()\n");
+00049         _LIT(KValidDriveMsg,"\nValid drives as characters (and as numbers) are:\n");
+00050         _LIT(KDriveChar,"%c");
+00051         _LIT(KDriveNum,"(%d) ");
+00052         _LIT(KNewLine,"\n");
+00053         _LIT(KAvailDriveMsg,"\nUsing DriveList(), available drives are: ");
+00054         _LIT(KDriveAtts,"%c: %02x ");
+00055         _LIT(KDriveInfo,"\nDrive information for %c: drive is:\n%S");
+00056         _LIT(KVolInfo,"\nVolume information for %c: is:\n%S");
+00057 
+00058         console->Printf(KMessage);
+00059 
+00060         // Print the valid drives as characters and as numbers. 
+00061         // Then print the drive list (list of available drives), and
+00062         // information about each drive in the list using Drive(). 
+00063         // Finally, print volume information.
+00064 
+00065         console->Printf(KValidDriveMsg);
+00066 
+00067         TInt driveNumber=EDriveA; 
+00068         TChar driveLetter; 
+00069         for (; driveNumber<=EDriveZ; driveNumber++)
+00070                 {
+00071                 if (fsSession.IsValidDrive(driveNumber))
+00072                         {
+00073                         fsSession.DriveToChar(driveNumber,driveLetter);
+00074                         console->Printf(KDriveChar,TUint(driveLetter));
+00075                         fsSession.CharToDrive(driveLetter, driveNumber);
+00076                         console->Printf(KDriveNum,driveNumber);
+00077                         }
+00078                 }
+00079         console->Printf(KNewLine);
+00080 
+00081         TDriveList drivelist; 
+00082         User::LeaveIfError(fsSession.DriveList(drivelist));
+00083         // A TDriveList (the list of available drives), is an array of 
+00084         // 26 bytes. Each byte with a non zero value signifies that the 
+00085         // corresponding drive is available.
+00086 
+00087         console->Printf(KAvailDriveMsg);
+00088         for (driveNumber=EDriveA; driveNumber<=EDriveZ;driveNumber++)
+00089                 {
+00090                 if (drivelist[driveNumber]) // if drive-list entry non-zero, drive is available
+00091                         {
+00092                         TInt err = fsSession.DriveToChar(driveNumber,driveLetter);
+00093                         if(err == KErrNone)
+00094                                 {
+00095                                 // The following line prints the drive letter followed by the hex value 
+00096                                 // of the integer indicating that drive's attributes 
+00097                                 console->Printf(KDriveAtts,TUint(driveLetter), drivelist[driveNumber]);
+00098                                 }
+00099                         else if(err == KErrArgument)
+00100                                 {
+00101                                 _LIT(KTextInvalidDriveNumber, "Drive Number %d is invalid\n");
+00102                                 console->Printf(KTextInvalidDriveNumber, driveNumber);
+00103                                 }
+00104                         else
+00105                                 {
+00106                                 _LIT(KTextErrCode, "DriveToChar() returned %d error code");
+00107                                 console->Printf(KTextErrCode, err);
+00108                                 }
+00109                         }
+00110                 }
+00111         console->Printf(KNewLine);
+00112 
+00113         // Print information about available drives 
+00114 
+00115         TBuf<200> buffer;
+00116         TDriveInfo driveInfo; 
+00117         for (driveNumber=EDriveA; driveNumber<=EDriveZ; driveNumber++)
+00118                 {
+00119                 fsSession.Drive(driveInfo,driveNumber);
+00120                 if (TInt(driveInfo.iDriveAtt)==KDriveAbsent)
+00121                         // test whether drive is available. If not, skip to next drive
+00122                         continue;
+00123                 FormatDriveInfo(buffer,driveInfo);
+00124                 TInt errNum = fsSession.DriveToChar(driveNumber,driveLetter);
+00125                 if(errNum == KErrNone)
+00126                         {
+00127                         console->Printf(KDriveInfo,TUint(driveLetter),&buffer);
+00128                         buffer.Zero();
+00129                         WaitForKey();
+00130                         }
+00131                 }
+00132 
+00133         // Print volume information for all available drives. TVolumeInfo
+00134         // provides drive information, and additional information about
+00135         // the volume. Just print out the volume information.
+00136  
+00137         TVolumeInfo volumeInfo;
+00138         for (driveNumber=EDriveA; driveNumber<=EDriveZ; driveNumber++)
+00139                 {
+00140                 TInt err=fsSession.Volume(volumeInfo,driveNumber);
+00141                 if (err!=KErrNotReady) 
+00142                         // Volume() returns KErrNotReady if no volume present.
+00143                         // In this case, check next drive number
+00144                         {
+00145                         buffer.Zero();
+00146                         FormatVolumeInfo(buffer,volumeInfo);
+00147                         TInt errNum = fsSession.DriveToChar(driveNumber,driveLetter);
+00148                         if(errNum == KErrNone)
+00149                                 {
+00150                                 console->Printf(KVolInfo,
+00151                                 (TUint)driveLetter,&buffer);
+00152                                 WaitForKey();
+00153                                 }                       
+00154                         }
+00155                 }
+00156         }
+00157 
+00158 void FormatDriveInfo(TDes& aBuffer, const TDriveInfo aDriveInfo)
+00159         {
+00160         // Append battery, media and drive information to aBuffer
+00161         // Define descriptor constants using the _LIT macro 
+00162         _LIT(KFormatString,"iType=%02x,iBattery=%02x,iDriveAtt=%02x,iMediaAtt=%02x\n");
+00163         _LIT(KBatLow,"Battery low\n");
+00164         _LIT(KBatGood,"Battery good\n");
+00165         _LIT(KBatNotSupported,"Battery not supported\n");
+00166         _LIT(KNotPresent,"No media present\n");
+00167         _LIT(KFloppy,"Media is floppy disk\n");
+00168         _LIT(KHard,"Media is hard disk\n");
+00169         _LIT(KCDROM,"Media is CD-ROM\n");
+00170         _LIT(KRam,"Media is RAM\n");
+00171         _LIT(KFlash,"Media is flash\n");
+00172         _LIT(KRom,"Media is ROM\n");
+00173         _LIT(KRemote,"Media is remote\n");
+00174         _LIT(KNANDFlash,"Media is NAND flash\n");
+00175         _LIT(KUnknown,"Media unknown\n");
+00176         _LIT(KDriveAtts,"Drive attributes:");
+00177         _LIT(KLocal," local");
+00178         _LIT(KROMDrive," ROM");
+00179         _LIT(KRedirected," redirected");
+00180         _LIT(KSubstituted," substituted");
+00181         _LIT(KInternal," internal");
+00182         _LIT(KRemovable," removable");
+00183         _LIT(KMediaAtts,"\nMedia attributes:");
+00184         _LIT(KDynamic," dynamic");
+00185         _LIT(KDual," dual-density");
+00186         _LIT(KFormattable," formattable");
+00187         _LIT(KLockable," lockable");
+00188         _LIT(KLocked," locked");
+00189         _LIT(KHasPassword," has password");
+00190         _LIT(KWriteProtected," write-protected");
+00191         _LIT(KNewLine,"\n");
+00192 
+00193         aBuffer.AppendFormat(KFormatString, TInt(aDriveInfo.iType), 
+00194                 TInt(aDriveInfo.iBattery), TInt(aDriveInfo.iDriveAtt), TInt(aDriveInfo.iMediaAtt));
+00195 
+00196         switch (aDriveInfo.iBattery)
+00197                 {
+00198                 case EBatLow:
+00199                         aBuffer.Append(KBatLow);
+00200                         break;
+00201                 case EBatGood:
+00202                         aBuffer.Append(KBatGood);
+00203                         break;
+00204                 default:
+00205                         aBuffer.Append(KBatNotSupported);
+00206                 }
+00207 
+00208         switch (aDriveInfo.iType)
+00209                         {
+00210                 case EMediaNotPresent:
+00211                         aBuffer.Append(KNotPresent);                    
+00212                         break;
+00213                 case EMediaFloppy:
+00214                         aBuffer.Append(KFloppy);
+00215                         break;
+00216                 case EMediaHardDisk:    
+00217                         aBuffer.Append(KHard);
+00218                         break;
+00219                 case EMediaCdRom:
+00220                         aBuffer.Append(KCDROM);
+00221                         break;
+00222                 case EMediaRam:
+00223                         aBuffer.Append(KRam);
+00224                         break;
+00225                 case EMediaFlash:
+00226                         aBuffer.Append(KFlash);
+00227                         break;
+00228                 case EMediaRom:
+00229                         aBuffer.Append(KRom);
+00230                         break;
+00231                 case EMediaRemote:
+00232                         aBuffer.Append(KRemote);
+00233                         break;
+00234                 case EMediaNANDFlash:
+00235             aBuffer.Append(KNANDFlash);
+00236                         break;
+00237                 default: 
+00238                         aBuffer.Append(KUnknown);
+00239 
+00240                 }
+00241                 aBuffer.Append(KDriveAtts);
+00242                 if (aDriveInfo.iDriveAtt & KDriveAttLocal)
+00243                         aBuffer.Append(KLocal);
+00244                 if (aDriveInfo.iDriveAtt & KDriveAttRom)
+00245                         aBuffer.Append(KROMDrive);
+00246                 if (aDriveInfo.iDriveAtt & KDriveAttRedirected)
+00247                         aBuffer.Append(KRedirected);
+00248                 if (aDriveInfo.iDriveAtt & KDriveAttSubsted)
+00249                         aBuffer.Append(KSubstituted);
+00250                 if (aDriveInfo.iDriveAtt & KDriveAttInternal)
+00251                         aBuffer.Append(KInternal);
+00252                 if (aDriveInfo.iDriveAtt & KDriveAttRemovable)
+00253                         aBuffer.Append(KRemovable);
+00254                 aBuffer.Append(KMediaAtts);
+00255                 if (aDriveInfo.iMediaAtt & KMediaAttVariableSize)
+00256                         aBuffer.Append(KDynamic);
+00257                 if (aDriveInfo.iMediaAtt & KMediaAttDualDensity)
+00258                         aBuffer.Append(KDual);
+00259                 if (aDriveInfo.iMediaAtt & KMediaAttFormattable)
+00260                         aBuffer.Append(KFormattable);
+00261                 if (aDriveInfo.iMediaAtt & KMediaAttWriteProtected)
+00262                         aBuffer.Append(KWriteProtected);
+00263                 if (aDriveInfo.iMediaAtt & KMediaAttLockable)
+00264                         aBuffer.Append(KLockable);
+00265                 if (aDriveInfo.iMediaAtt & KMediaAttLocked)
+00266                         aBuffer.Append(KLocked);
+00267                 if (aDriveInfo.iMediaAtt & KMediaAttHasPassword)
+00268                         aBuffer.Append(KHasPassword);
+00269                 aBuffer.Append(KNewLine);
+00270         }
+00271 
+00272 void FormatVolumeInfo(TDes& aBuffer, const TVolumeInfo aVolumeInfo)
+00273         {
+00274         // Append volume information to aBuffer
+00275         _LIT(KUID,"Unique ID: %08x\n");
+00276         _LIT(KSize,"Size: %Ld bytes\n");
+00277         _LIT(KFree,"Free space: %Ld bytes\n");
+00278         _LIT(KVolName,"Volume name: %S\n");
+00279         aBuffer.AppendFormat(KUID,aVolumeInfo.iUniqueID);
+00280         aBuffer.AppendFormat(KSize,aVolumeInfo.iSize);
+00281         aBuffer.AppendFormat(KFree,aVolumeInfo.iFree);
+00282         aBuffer.AppendFormat(KVolName,&aVolumeInfo.iName);
+00283         }
+

Generated on Thu Jan 21 10:32:56 2010 for TB10.1 Example Applications by  + +doxygen 1.5.3
+ +