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
00036 #include <stdio.h>
00037 #include <f32file.h>
00038 #include <stdlib.h>
00039 #include <string.h>
00040
00046 char* DescToChar(const TDesC& aDes)
00047 {
00048
00049 TInt length = aDes.Length();
00050
00051
00052
00053
00054 char* ptr = (char*)malloc(sizeof(char)*(length + 1));
00055 if(ptr == NULL)
00056 {
00057
00058 return NULL;
00059 }
00060
00061 TInt ix = 0;
00062 for(; ix < length; ix++)
00063 {
00064
00065 ptr[ix] = aDes[ix];
00066 }
00067
00068 ptr[ix] = '\0';
00069
00070
00071 return ptr;
00072 }
00073
00079 void PrintDriveInfoL(const RFs& aFs, const TInt aDriveNumber)
00080 {
00081
00082 TDriveInfo driveInfo;
00083 TInt errDrive = aFs.Drive(driveInfo,aDriveNumber);
00084 if(errDrive != KErrNone)
00085 return;
00086
00087
00088 TBuf<KMaxFileName> driveName;
00089 TInt errName = aFs.GetDriveName(aDriveNumber,driveName);
00090 if(errName != KErrNone)
00091 return;
00092
00093
00094 char* cptr = DescToChar(driveName);
00095 CleanupStack::PushL(cptr);
00096
00097 if(strlen(cptr))
00098 {
00099
00100 printf("Drive Name :%s\n",cptr);
00101 }
00102
00103
00104
00105 if((driveInfo.iMediaAtt & KMediaAttFormattable))
00106 {
00107 TChar driveLetter;
00108
00109 TInt errDLetter = aFs.DriveToChar(aDriveNumber,driveLetter);
00110 if(errDLetter != KErrNone)
00111 return;
00112
00113
00114 printf("Drive Letter: %c\n",TUint(driveLetter));
00115
00116
00117 TVolumeInfo volumeInfo;
00118 TInt errVol = aFs.Volume(volumeInfo,aDriveNumber);
00119 if(errVol != KErrNone)
00120 return;
00121
00122
00123 TInt64 driveTotalSize = volumeInfo.iSize;
00124 TInt64 driveFreeSize = volumeInfo.iFree;
00125
00126 printf("Total size of the drive: %d\n", driveTotalSize);
00127 printf("Free space: %d\n", driveFreeSize);
00128
00129 printf(" [press the enter key to continue]\n");
00130
00131 getchar();
00132 }
00133
00134 CleanupStack::PopAndDestroy(cptr);
00135 }
00136
00137 LOCAL_C void MainL()
00138 {
00139
00140 RFs fs;
00141
00142 User::LeaveIfError(fs.Connect());
00143 CleanupClosePushL(fs);
00144 printf("\nValid drives as characters (and as numbers) are:\n");
00145
00146
00147 TInt driveNumber=EDriveA;
00148 TChar driveLetter;
00149
00150 for (; driveNumber<=EDriveZ; driveNumber++)
00151 {
00152 if (fs.IsValidDrive(driveNumber))
00153 {
00154
00155 TInt errDrive = fs.DriveToChar(driveNumber,driveLetter);
00156 if(errDrive == KErrNone)
00157 {
00158
00159 printf("%c",TUint(driveLetter));
00160
00161 TInt errChar = fs.CharToDrive(driveLetter, driveNumber);
00162 if(errChar == KErrNone)
00163 {
00164
00165 printf("(%d) ",driveNumber);
00166 }
00167 }
00168 }
00169 }
00170
00171 printf("\n");
00172
00173
00174 TDriveList drivelist;
00175 User::LeaveIfError(fs.DriveList(drivelist));
00176
00177
00178
00179
00180
00181 printf("\nUsing DriveList(), available drives are: \n");
00182 for (driveNumber=EDriveA; driveNumber<=EDriveZ;driveNumber++)
00183 {
00184 if (drivelist[driveNumber])
00185 {
00186
00187 TInt errDrive = fs.DriveToChar(driveNumber,driveLetter);
00188 if(errDrive == KErrNone)
00189 {
00190
00191
00192 printf("Drive Letter: %c\n",TUint(driveLetter));
00193 printf(" [press the enter key to continue]\n");
00194
00195 getchar();
00196 }
00197 }
00198 }
00199
00200 printf("Memory information for formattable drives:\n");
00201 printf(" [press the enter key to continue]\n");
00202
00203 getchar();
00204 for (driveNumber=EDriveA; driveNumber<=EDriveZ;driveNumber++)
00205 {
00206 if (drivelist[driveNumber])
00207 {
00208 PrintDriveInfoL(fs,driveNumber);
00209 }
00210 }
00211
00212 CleanupStack::PopAndDestroy(&fs);
00213 }
00214
00215
00216 GLDEF_C TInt E32Main()
00217 {
00218
00219 __UHEAP_MARK;
00220 CTrapCleanup* cleanup = CTrapCleanup::New();
00221
00222
00223 TRAPD(mainError, MainL());
00224 if (mainError)
00225 {
00226 printf(" failed, leave code = %d", mainError);
00227 }
00228
00229 printf(" [press the enter key to exit]\n");
00230 getchar();
00231
00232 delete cleanup;
00233 __UHEAP_MARKEND;
00234 return KErrNone;
00235 }
00236