54 { |
55 { |
55 } |
56 } |
56 |
57 |
57 void CCmdDrvinfo::ArgumentErrorL() |
58 void CCmdDrvinfo::ArgumentErrorL() |
58 { |
59 { |
59 Stderr().Write(_L("Invalid drive specification - use \'<drive_letter>:\', e.g. \'drvinfo c:\'\r\n")); |
60 Stderr().Write(_L("Invalid drive specification - use '<drive_letter>:', e.g. 'drvinfo c:'\r\n")); |
60 User::Leave(KErrArgument); |
61 User::Leave(KErrArgument); |
61 } |
62 } |
62 |
63 |
63 void FormatLineEndL(IoUtils::CTextBuffer& aPrintBuf) |
64 void FormatLineEndL(IoUtils::CTextBuffer& aPrintBuf) |
64 { |
65 { |
153 { |
154 { |
154 aPrintBuf.AppendFormatL(_L("%ld\r\n"), volInfo.iFree); |
155 aPrintBuf.AppendFormatL(_L("%ld\r\n"), volInfo.iFree); |
155 } |
156 } |
156 if (iVerbose) |
157 if (iVerbose) |
157 { |
158 { |
158 aPrintBuf.AppendFormatL(_L("VolName:\t\'%S\'"), &volInfo.iName); |
159 aPrintBuf.AppendFormatL(_L("VolName:\t\'%S\'\r\n"), &volInfo.iName); |
159 } |
160 } |
160 aPrintBuf.AppendL(_L("\r\n")); |
|
161 } |
161 } |
162 |
162 |
163 void CCmdDrvinfo::PrintDriveInfoL(TInt aDriveNum) |
163 void CCmdDrvinfo::PrintDriveInfoL(TInt aDriveNum) |
164 { |
164 { |
|
165 TDriveInfo driveInfo; |
|
166 User::LeaveIfError(FsL().Drive(driveInfo, aDriveNum)); |
|
167 |
|
168 TVolumeInfo volInfo; |
|
169 TInt volErr = Fs().Volume(volInfo, aDriveNum); |
|
170 |
|
171 if (iLong) |
|
172 { |
|
173 TText readonly = '-'; |
|
174 TText removable = '-'; |
|
175 TText ram = '-'; |
|
176 if (driveInfo.iMediaAtt & KMediaAttWriteProtected) readonly = 'r'; |
|
177 if (driveInfo.iDriveAtt & KDriveAttRemovable) removable = 'e'; |
|
178 if (driveInfo.iType == EMediaRam) ram = 'm'; |
|
179 |
|
180 Printf(_L("%c%c%c %c: "), readonly, removable, ram, 'a' + aDriveNum); |
|
181 TInt64 free = 0; |
|
182 TInt64 size = 0; |
|
183 if (volErr == KErrNone) |
|
184 { |
|
185 free = volInfo.iFree; |
|
186 size = volInfo.iSize; |
|
187 } |
|
188 Printf(_L("%Ld %Ld %S"), free, size, &volInfo.iName); |
|
189 return; |
|
190 } |
|
191 |
|
192 User::LeaveIfError(volErr); // Long listing handles volErr itself so didn't want to leave |
|
193 |
165 IoUtils::CTextBuffer* buf = IoUtils::CTextBuffer::NewLC(0x100); |
194 IoUtils::CTextBuffer* buf = IoUtils::CTextBuffer::NewLC(0x100); |
166 |
|
167 TDriveInfo driveInfo; |
|
168 User::LeaveIfError(FsL().Drive(driveInfo, aDriveNum)); |
|
169 |
|
170 TVolumeInfo volInfo; |
|
171 User::LeaveIfError(Fs().Volume(volInfo, aDriveNum)); |
|
172 |
195 |
173 if (iVerbose || (iDriveLetter == NULL)) |
196 if (iVerbose || (iDriveLetter == NULL)) |
174 { |
197 { |
175 buf->AppendFormatL(_L("Drive:\t%c:\r\n"), 'A'+ aDriveNum); |
198 buf->AppendFormatL(_L("Drive:\t%c:\r\n"), 'A'+ aDriveNum); |
176 } |
199 } |
189 buf->AppendFormatL(_L("BatteryState:\t%d\r\n"),driveInfo.iBattery); |
212 buf->AppendFormatL(_L("BatteryState:\t%d\r\n"),driveInfo.iBattery); |
190 FormatDriveAttInfoL(driveInfo, *buf); |
213 FormatDriveAttInfoL(driveInfo, *buf); |
191 FormatMediaAttInfoL(driveInfo, *buf); |
214 FormatMediaAttInfoL(driveInfo, *buf); |
192 } |
215 } |
193 |
216 |
194 FormatVolInfoL(volInfo, *buf); |
217 if (volErr == KErrNone) FormatVolInfoL(volInfo, *buf); |
195 |
218 |
196 CTextFormatter* formatter = CTextFormatter::NewLC(Stdout()); |
219 CTextFormatter* formatter = CTextFormatter::NewLC(Stdout()); |
197 formatter->TabulateL(0, 2, buf->Descriptor()); |
220 formatter->TabulateL(0, 2, buf->Descriptor()); |
198 Write(formatter->Descriptor()); |
221 Write(formatter->Descriptor()); |
199 |
222 |
270 |
296 |
271 void CCmdDrvinfo::OptionsL(RCommandOptionList& aOptions) |
297 void CCmdDrvinfo::OptionsL(RCommandOptionList& aOptions) |
272 { |
298 { |
273 _LIT(KOptVerbose, "verbose"); |
299 _LIT(KOptVerbose, "verbose"); |
274 _LIT(KOptHuman, "human"); |
300 _LIT(KOptHuman, "human"); |
|
301 _LIT(KOptLong, "long"); |
275 |
302 |
276 aOptions.AppendBoolL(iVerbose, KOptVerbose); |
303 aOptions.AppendBoolL(iVerbose, KOptVerbose); |
277 aOptions.AppendBoolL(iHuman, KOptHuman); |
304 aOptions.AppendBoolL(iHuman, KOptHuman); |
|
305 aOptions.AppendBoolL(iLong, KOptLong); |
278 } |
306 } |
279 |
307 |
280 |
308 |
281 EXE_BOILER_PLATE(CCmdDrvinfo) |
309 EXE_BOILER_PLATE(CCmdDrvinfo) |
282 |
310 |