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