author | William Roberts <williamr@symbian.org> |
Fri, 28 May 2010 17:11:06 +0100 | |
branch | RCL_3 |
changeset 138 | 23c4ec5a1df9 |
parent 33 | 0173bcd7697c |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
2 |
// All rights reserved. |
|
3 |
// This component and the accompanying materials are made available |
|
4 |
// under the terms of the License "Eclipse Public License v1.0" |
|
5 |
// which accompanies this distribution, and is available |
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 |
// |
|
8 |
// Initial Contributors: |
|
9 |
// Nokia Corporation - initial contribution. |
|
10 |
// |
|
11 |
// Contributors: |
|
12 |
// |
|
13 |
// Description: |
|
14 |
// |
|
15 |
||
16 |
||
17 |
#include <e32def.h> |
|
18 |
#include <e32cmn.h> |
|
19 |
#include <f32file.h> |
|
20 |
#include <e32test.h> |
|
21 |
||
22 |
#include "tmsprintdrive.h" |
|
23 |
||
24 |
extern RTest test; |
|
25 |
extern RFs fsSession; |
|
26 |
||
27 |
void TMsPrintDrive::FormatDriveInfo(TDes& aBuffer, const TDriveInfo& aDriveInfo) |
|
28 |
{ |
|
29 |
// Append battery, media and drive information to aBuffer |
|
30 |
// Define descriptor constants using the _LIT macro |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
31 |
_LIT(KFormatString,"Type=0x%02x,Connection Bus=0x%02x,DriveAtt=0x%02x,MediaAtt=0x%02x\r\n"); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
32 |
_LIT(KConnectionBusInternal,"Connection Bus is Internal\r\n"); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
33 |
_LIT(KConnectionBusUsb,"Connection Bus is USB\r\n"); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
34 |
_LIT(KConnectionBusUnknown,"Connection Bus is Unknown\r\n"); |
0 | 35 |
_LIT(KNotPresent,"No media present\r\n"); |
36 |
_LIT(KFloppy,"Media is floppy disk\r\n"); |
|
37 |
_LIT(KHard,"Media is hard disk\r\n"); |
|
38 |
_LIT(KCDROM,"Media is CD-ROM\r\n"); |
|
39 |
_LIT(KRam,"Media is RAM\r\n"); |
|
40 |
_LIT(KFlash,"Media is flash\r\n"); |
|
41 |
_LIT(KRom,"Media is ROM\r\n"); |
|
42 |
_LIT(KRemote,"Media is remote\r\n"); |
|
43 |
_LIT(KNANDFlash,"Media is NAND flash\r\n"); |
|
44 |
_LIT(KUnknown,"Media unknown\r\n"); |
|
45 |
_LIT(KDriveAtts,"Drive attributes:"); |
|
46 |
_LIT(KLocal," local"); |
|
47 |
_LIT(KROMDrive," ROM"); |
|
48 |
_LIT(KRedirected," redirected"); |
|
49 |
_LIT(KSubstituted," substituted"); |
|
50 |
_LIT(KInternal," internal"); |
|
51 |
_LIT(KRemovable," removable"); |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
52 |
_LIT(KExternal," external"); |
0 | 53 |
_LIT(KMediaAtts,"\r\nMedia attributes:"); |
54 |
_LIT(KDynamic," dynamic"); |
|
55 |
_LIT(KDual," dual-density"); |
|
56 |
_LIT(KFormattable," formattable"); |
|
57 |
_LIT(KLockable," lockable"); |
|
58 |
_LIT(KLocked," locked"); |
|
59 |
_LIT(KHasPassword," has password"); |
|
60 |
_LIT(KWriteProtected," write-protected"); |
|
61 |
_LIT(KNewLine,"\r\n"); |
|
62 |
||
63 |
aBuffer.AppendFormat(KFormatString, TInt(aDriveInfo.iType), |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
64 |
TInt(aDriveInfo.iConnectionBusType), |
0 | 65 |
TInt(aDriveInfo.iDriveAtt), |
66 |
TInt(aDriveInfo.iMediaAtt)); |
|
67 |
||
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
68 |
switch (aDriveInfo.iConnectionBusType) |
0 | 69 |
{ |
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
70 |
case EConnectionBusInternal: |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
71 |
aBuffer.Append(KConnectionBusInternal); |
0 | 72 |
break; |
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
73 |
case EConnectionBusUsb: |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
74 |
aBuffer.Append(KConnectionBusUsb); |
0 | 75 |
break; |
76 |
default: |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
77 |
aBuffer.Append(KConnectionBusUnknown); |
0 | 78 |
} |
79 |
||
80 |
switch (aDriveInfo.iType) |
|
81 |
{ |
|
82 |
case EMediaNotPresent: |
|
83 |
aBuffer.Append(KNotPresent); |
|
84 |
break; |
|
85 |
case EMediaFloppy: |
|
86 |
aBuffer.Append(KFloppy); |
|
87 |
break; |
|
88 |
case EMediaHardDisk: |
|
89 |
aBuffer.Append(KHard); |
|
90 |
break; |
|
91 |
case EMediaCdRom: |
|
92 |
aBuffer.Append(KCDROM); |
|
93 |
break; |
|
94 |
case EMediaRam: |
|
95 |
aBuffer.Append(KRam); |
|
96 |
break; |
|
97 |
case EMediaFlash: |
|
98 |
aBuffer.Append(KFlash); |
|
99 |
break; |
|
100 |
case EMediaRom: |
|
101 |
aBuffer.Append(KRom); |
|
102 |
break; |
|
103 |
case EMediaRemote: |
|
104 |
aBuffer.Append(KRemote); |
|
105 |
break; |
|
106 |
case EMediaNANDFlash: |
|
107 |
aBuffer.Append(KNANDFlash); |
|
108 |
break; |
|
109 |
default: |
|
110 |
aBuffer.Append(KUnknown); |
|
111 |
||
112 |
} |
|
113 |
aBuffer.Append(KDriveAtts); |
|
114 |
if (aDriveInfo.iDriveAtt & KDriveAttLocal) |
|
115 |
aBuffer.Append(KLocal); |
|
116 |
if (aDriveInfo.iDriveAtt & KDriveAttRom) |
|
117 |
aBuffer.Append(KROMDrive); |
|
118 |
if (aDriveInfo.iDriveAtt & KDriveAttRedirected) |
|
119 |
aBuffer.Append(KRedirected); |
|
120 |
if (aDriveInfo.iDriveAtt & KDriveAttSubsted) |
|
121 |
aBuffer.Append(KSubstituted); |
|
122 |
if (aDriveInfo.iDriveAtt & KDriveAttInternal) |
|
123 |
aBuffer.Append(KInternal); |
|
124 |
if (aDriveInfo.iDriveAtt & KDriveAttRemovable) |
|
125 |
aBuffer.Append(KRemovable); |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
126 |
if (aDriveInfo.iDriveAtt & KDriveAttExternal) |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
127 |
aBuffer.Append(KExternal); |
0 | 128 |
aBuffer.Append(KMediaAtts); |
129 |
if (aDriveInfo.iMediaAtt & KMediaAttVariableSize) |
|
130 |
aBuffer.Append(KDynamic); |
|
131 |
if (aDriveInfo.iMediaAtt & KMediaAttDualDensity) |
|
132 |
aBuffer.Append(KDual); |
|
133 |
if (aDriveInfo.iMediaAtt & KMediaAttFormattable) |
|
134 |
aBuffer.Append(KFormattable); |
|
135 |
if (aDriveInfo.iMediaAtt & KMediaAttWriteProtected) |
|
136 |
aBuffer.Append(KWriteProtected); |
|
137 |
if (aDriveInfo.iMediaAtt & KMediaAttLockable) |
|
138 |
aBuffer.Append(KLockable); |
|
139 |
if (aDriveInfo.iMediaAtt & KMediaAttLocked) |
|
140 |
aBuffer.Append(KLocked); |
|
141 |
if (aDriveInfo.iMediaAtt & KMediaAttHasPassword) |
|
142 |
aBuffer.Append(KHasPassword); |
|
143 |
aBuffer.Append(KNewLine); |
|
144 |
} |
|
145 |
||
146 |
||
147 |
void TMsPrintDrive::FormatVolumeInfo(TDes& aBuffer, const TVolumeInfo& aVolumeInfo) |
|
148 |
{ |
|
149 |
// Append volume information to aBuffer |
|
150 |
_LIT(KUID,"Unique ID: %08x\r\n"); |
|
151 |
_LIT(KSize,"Size: 0x%Lx bytes\r\n"); |
|
152 |
_LIT(KFree,"Free space: 0x%Lx bytes\r\n"); |
|
153 |
_LIT(KVolName,"Volume name: %S\r\n"); |
|
154 |
aBuffer.AppendFormat(KUID, aVolumeInfo.iUniqueID); |
|
155 |
aBuffer.AppendFormat(KSize, aVolumeInfo.iSize); |
|
156 |
aBuffer.AppendFormat(KFree, aVolumeInfo.iFree); |
|
157 |
aBuffer.AppendFormat(KVolName, &aVolumeInfo.iName); |
|
158 |
} |
|
159 |
||
160 |
||
161 |
void TMsPrintDrive::VolInfoL(TInt aDriveNumber) |
|
162 |
{ |
|
163 |
_LIT(KMessage,"Drive Info\r\n"); |
|
164 |
_LIT(KValidDriveMsg,"Valid drives as characters (and as numbers) are:"); |
|
165 |
_LIT(KDriveChar,"%c"); |
|
166 |
_LIT(KDriveNum,"(%d) "); |
|
167 |
_LIT(KNewLine,"\r\n"); |
|
168 |
_LIT(KAvailDriveMsg,"Using DriveList(), available drives are: "); |
|
169 |
_LIT(KDriveAtts,"%c: %02x "); |
|
170 |
_LIT(KDriveInfo,"Drive information for %c: drive is:\r\n%S\r\n"); |
|
171 |
_LIT(KVolInfo,"Volume information for %c: is:\r\n%S\r\n"); |
|
172 |
||
173 |
test.Printf(KMessage); |
|
174 |
test.Printf(KValidDriveMsg); |
|
175 |
||
176 |
TChar driveLetter; |
|
177 |
||
178 |
if (fsSession.IsValidDrive(aDriveNumber)) |
|
179 |
{ |
|
180 |
fsSession.DriveToChar(aDriveNumber,driveLetter); |
|
181 |
test.Printf(KDriveChar,TUint(driveLetter)); |
|
182 |
fsSession.CharToDrive(driveLetter, aDriveNumber); |
|
183 |
test.Printf(KDriveNum, aDriveNumber); |
|
184 |
} |
|
185 |
||
186 |
test.Printf(KNewLine); |
|
187 |
||
188 |
TDriveList drivelist; |
|
189 |
User::LeaveIfError(fsSession.DriveList(drivelist)); |
|
190 |
// A TDriveList (the list of available drives), is an array of |
|
191 |
// 26 bytes. Each byte with a non zero value signifies that the |
|
192 |
// corresponding drive is available. |
|
193 |
||
194 |
test.Printf(KAvailDriveMsg); |
|
195 |
||
196 |
if (drivelist[aDriveNumber]) // if drive-list entry non-zero, drive is available |
|
197 |
{ |
|
198 |
User::LeaveIfError(fsSession.DriveToChar(aDriveNumber,driveLetter)); |
|
199 |
// The following line prints the drive letter followed by the hex value |
|
200 |
// of the integer indicating that drive's attributes |
|
201 |
test.Printf(KDriveAtts,TUint(driveLetter), drivelist[aDriveNumber]); |
|
202 |
} |
|
203 |
||
204 |
test.Printf(KNewLine); |
|
205 |
||
206 |
// Print information about available drives |
|
207 |
TBuf<200> buffer; |
|
208 |
TDriveInfo driveInfo; |
|
209 |
||
210 |
fsSession.Drive(driveInfo, aDriveNumber); |
|
211 |
if (driveInfo.iDriveAtt == KDriveAbsent) |
|
212 |
{ |
|
213 |
} |
|
214 |
else |
|
215 |
{ |
|
216 |
FormatDriveInfo(buffer, driveInfo); |
|
217 |
User::LeaveIfError(fsSession.DriveToChar(aDriveNumber, driveLetter)); |
|
218 |
test.Printf(KDriveInfo, TUint(driveLetter), &buffer); |
|
219 |
buffer.Zero(); |
|
220 |
} |
|
221 |
||
222 |
// Print volume information for all available drives. TVolumeInfo |
|
223 |
// provides drive information, and additional information about |
|
224 |
// the volume. Just print out the volume information. |
|
225 |
||
226 |
TVolumeInfo volumeInfo; |
|
227 |
||
228 |
TInt err=fsSession.Volume(volumeInfo, aDriveNumber); |
|
229 |
if (err!=KErrNotReady) |
|
230 |
// Volume() returns KErrNotReady if no volume present. |
|
231 |
// In this case, check next drive number |
|
232 |
{ |
|
233 |
buffer.Zero(); |
|
234 |
FormatVolumeInfo(buffer, volumeInfo); |
|
235 |
User::LeaveIfError(fsSession.DriveToChar(aDriveNumber,driveLetter)); |
|
236 |
test.Printf(KVolInfo, (TUint)driveLetter, &buffer); |
|
237 |
} |
|
238 |
} |
|
239 |