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