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
|
|
31 |
_LIT(KFormatString,"Type=0x%02x,Battery=0x%02x,DriveAtt=0x%02x,MediaAtt=0x%02x\r\n");
|
|
32 |
_LIT(KBatLow,"Battery low\r\n");
|
|
33 |
_LIT(KBatGood,"Battery good\r\n");
|
|
34 |
_LIT(KBatNotSupported,"Battery not supported\r\n");
|
|
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");
|
|
52 |
_LIT(KMediaAtts,"\r\nMedia attributes:");
|
|
53 |
_LIT(KDynamic," dynamic");
|
|
54 |
_LIT(KDual," dual-density");
|
|
55 |
_LIT(KFormattable," formattable");
|
|
56 |
_LIT(KLockable," lockable");
|
|
57 |
_LIT(KLocked," locked");
|
|
58 |
_LIT(KHasPassword," has password");
|
|
59 |
_LIT(KWriteProtected," write-protected");
|
|
60 |
_LIT(KNewLine,"\r\n");
|
|
61 |
|
|
62 |
aBuffer.AppendFormat(KFormatString, TInt(aDriveInfo.iType),
|
|
63 |
TInt(aDriveInfo.iBattery),
|
|
64 |
TInt(aDriveInfo.iDriveAtt),
|
|
65 |
TInt(aDriveInfo.iMediaAtt));
|
|
66 |
|
|
67 |
switch (aDriveInfo.iBattery)
|
|
68 |
{
|
|
69 |
case EBatLow:
|
|
70 |
aBuffer.Append(KBatLow);
|
|
71 |
break;
|
|
72 |
case EBatGood:
|
|
73 |
aBuffer.Append(KBatGood);
|
|
74 |
break;
|
|
75 |
default:
|
|
76 |
aBuffer.Append(KBatNotSupported);
|
|
77 |
}
|
|
78 |
|
|
79 |
switch (aDriveInfo.iType)
|
|
80 |
{
|
|
81 |
case EMediaNotPresent:
|
|
82 |
aBuffer.Append(KNotPresent);
|
|
83 |
break;
|
|
84 |
case EMediaFloppy:
|
|
85 |
aBuffer.Append(KFloppy);
|
|
86 |
break;
|
|
87 |
case EMediaHardDisk:
|
|
88 |
aBuffer.Append(KHard);
|
|
89 |
break;
|
|
90 |
case EMediaCdRom:
|
|
91 |
aBuffer.Append(KCDROM);
|
|
92 |
break;
|
|
93 |
case EMediaRam:
|
|
94 |
aBuffer.Append(KRam);
|
|
95 |
break;
|
|
96 |
case EMediaFlash:
|
|
97 |
aBuffer.Append(KFlash);
|
|
98 |
break;
|
|
99 |
case EMediaRom:
|
|
100 |
aBuffer.Append(KRom);
|
|
101 |
break;
|
|
102 |
case EMediaRemote:
|
|
103 |
aBuffer.Append(KRemote);
|
|
104 |
break;
|
|
105 |
case EMediaNANDFlash:
|
|
106 |
aBuffer.Append(KNANDFlash);
|
|
107 |
break;
|
|
108 |
default:
|
|
109 |
aBuffer.Append(KUnknown);
|
|
110 |
|
|
111 |
}
|
|
112 |
aBuffer.Append(KDriveAtts);
|
|
113 |
if (aDriveInfo.iDriveAtt & KDriveAttLocal)
|
|
114 |
aBuffer.Append(KLocal);
|
|
115 |
if (aDriveInfo.iDriveAtt & KDriveAttRom)
|
|
116 |
aBuffer.Append(KROMDrive);
|
|
117 |
if (aDriveInfo.iDriveAtt & KDriveAttRedirected)
|
|
118 |
aBuffer.Append(KRedirected);
|
|
119 |
if (aDriveInfo.iDriveAtt & KDriveAttSubsted)
|
|
120 |
aBuffer.Append(KSubstituted);
|
|
121 |
if (aDriveInfo.iDriveAtt & KDriveAttInternal)
|
|
122 |
aBuffer.Append(KInternal);
|
|
123 |
if (aDriveInfo.iDriveAtt & KDriveAttRemovable)
|
|
124 |
aBuffer.Append(KRemovable);
|
|
125 |
aBuffer.Append(KMediaAtts);
|
|
126 |
if (aDriveInfo.iMediaAtt & KMediaAttVariableSize)
|
|
127 |
aBuffer.Append(KDynamic);
|
|
128 |
if (aDriveInfo.iMediaAtt & KMediaAttDualDensity)
|
|
129 |
aBuffer.Append(KDual);
|
|
130 |
if (aDriveInfo.iMediaAtt & KMediaAttFormattable)
|
|
131 |
aBuffer.Append(KFormattable);
|
|
132 |
if (aDriveInfo.iMediaAtt & KMediaAttWriteProtected)
|
|
133 |
aBuffer.Append(KWriteProtected);
|
|
134 |
if (aDriveInfo.iMediaAtt & KMediaAttLockable)
|
|
135 |
aBuffer.Append(KLockable);
|
|
136 |
if (aDriveInfo.iMediaAtt & KMediaAttLocked)
|
|
137 |
aBuffer.Append(KLocked);
|
|
138 |
if (aDriveInfo.iMediaAtt & KMediaAttHasPassword)
|
|
139 |
aBuffer.Append(KHasPassword);
|
|
140 |
aBuffer.Append(KNewLine);
|
|
141 |
}
|
|
142 |
|
|
143 |
|
|
144 |
void TMsPrintDrive::FormatVolumeInfo(TDes& aBuffer, const TVolumeInfo& aVolumeInfo)
|
|
145 |
{
|
|
146 |
// Append volume information to aBuffer
|
|
147 |
_LIT(KUID,"Unique ID: %08x\r\n");
|
|
148 |
_LIT(KSize,"Size: 0x%Lx bytes\r\n");
|
|
149 |
_LIT(KFree,"Free space: 0x%Lx bytes\r\n");
|
|
150 |
_LIT(KVolName,"Volume name: %S\r\n");
|
|
151 |
aBuffer.AppendFormat(KUID, aVolumeInfo.iUniqueID);
|
|
152 |
aBuffer.AppendFormat(KSize, aVolumeInfo.iSize);
|
|
153 |
aBuffer.AppendFormat(KFree, aVolumeInfo.iFree);
|
|
154 |
aBuffer.AppendFormat(KVolName, &aVolumeInfo.iName);
|
|
155 |
}
|
|
156 |
|
|
157 |
|
|
158 |
void TMsPrintDrive::VolInfoL(TInt aDriveNumber)
|
|
159 |
{
|
|
160 |
_LIT(KMessage,"Drive Info\r\n");
|
|
161 |
_LIT(KValidDriveMsg,"Valid drives as characters (and as numbers) are:");
|
|
162 |
_LIT(KDriveChar,"%c");
|
|
163 |
_LIT(KDriveNum,"(%d) ");
|
|
164 |
_LIT(KNewLine,"\r\n");
|
|
165 |
_LIT(KAvailDriveMsg,"Using DriveList(), available drives are: ");
|
|
166 |
_LIT(KDriveAtts,"%c: %02x ");
|
|
167 |
_LIT(KDriveInfo,"Drive information for %c: drive is:\r\n%S\r\n");
|
|
168 |
_LIT(KVolInfo,"Volume information for %c: is:\r\n%S\r\n");
|
|
169 |
|
|
170 |
test.Printf(KMessage);
|
|
171 |
test.Printf(KValidDriveMsg);
|
|
172 |
|
|
173 |
TChar driveLetter;
|
|
174 |
|
|
175 |
if (fsSession.IsValidDrive(aDriveNumber))
|
|
176 |
{
|
|
177 |
fsSession.DriveToChar(aDriveNumber,driveLetter);
|
|
178 |
test.Printf(KDriveChar,TUint(driveLetter));
|
|
179 |
fsSession.CharToDrive(driveLetter, aDriveNumber);
|
|
180 |
test.Printf(KDriveNum, aDriveNumber);
|
|
181 |
}
|
|
182 |
|
|
183 |
test.Printf(KNewLine);
|
|
184 |
|
|
185 |
TDriveList drivelist;
|
|
186 |
User::LeaveIfError(fsSession.DriveList(drivelist));
|
|
187 |
// A TDriveList (the list of available drives), is an array of
|
|
188 |
// 26 bytes. Each byte with a non zero value signifies that the
|
|
189 |
// corresponding drive is available.
|
|
190 |
|
|
191 |
test.Printf(KAvailDriveMsg);
|
|
192 |
|
|
193 |
if (drivelist[aDriveNumber]) // if drive-list entry non-zero, drive is available
|
|
194 |
{
|
|
195 |
User::LeaveIfError(fsSession.DriveToChar(aDriveNumber,driveLetter));
|
|
196 |
// The following line prints the drive letter followed by the hex value
|
|
197 |
// of the integer indicating that drive's attributes
|
|
198 |
test.Printf(KDriveAtts,TUint(driveLetter), drivelist[aDriveNumber]);
|
|
199 |
}
|
|
200 |
|
|
201 |
test.Printf(KNewLine);
|
|
202 |
|
|
203 |
// Print information about available drives
|
|
204 |
TBuf<200> buffer;
|
|
205 |
TDriveInfo driveInfo;
|
|
206 |
|
|
207 |
fsSession.Drive(driveInfo, aDriveNumber);
|
|
208 |
if (driveInfo.iDriveAtt == KDriveAbsent)
|
|
209 |
{
|
|
210 |
}
|
|
211 |
else
|
|
212 |
{
|
|
213 |
FormatDriveInfo(buffer, driveInfo);
|
|
214 |
User::LeaveIfError(fsSession.DriveToChar(aDriveNumber, driveLetter));
|
|
215 |
test.Printf(KDriveInfo, TUint(driveLetter), &buffer);
|
|
216 |
buffer.Zero();
|
|
217 |
}
|
|
218 |
|
|
219 |
// Print volume information for all available drives. TVolumeInfo
|
|
220 |
// provides drive information, and additional information about
|
|
221 |
// the volume. Just print out the volume information.
|
|
222 |
|
|
223 |
TVolumeInfo volumeInfo;
|
|
224 |
|
|
225 |
TInt err=fsSession.Volume(volumeInfo, aDriveNumber);
|
|
226 |
if (err!=KErrNotReady)
|
|
227 |
// Volume() returns KErrNotReady if no volume present.
|
|
228 |
// In this case, check next drive number
|
|
229 |
{
|
|
230 |
buffer.Zero();
|
|
231 |
FormatVolumeInfo(buffer, volumeInfo);
|
|
232 |
User::LeaveIfError(fsSession.DriveToChar(aDriveNumber,driveLetter));
|
|
233 |
test.Printf(KVolInfo, (TUint)driveLetter, &buffer);
|
|
234 |
}
|
|
235 |
}
|
|
236 |
|