sl@0
|
1 |
// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#include "sl_std.h"
|
sl@0
|
17 |
|
sl@0
|
18 |
//-----------------------------------------------------------------------------
|
sl@0
|
19 |
|
sl@0
|
20 |
TTime DosTimeToTTime(TInt aDosTime,TInt aDosDate)
|
sl@0
|
21 |
//
|
sl@0
|
22 |
// Deciphers the dos time/date entry information and converts to TTime
|
sl@0
|
23 |
//
|
sl@0
|
24 |
{
|
sl@0
|
25 |
TInt secMask=0x1F;
|
sl@0
|
26 |
TInt minMask=0x07E0;
|
sl@0
|
27 |
TInt hrMask=0xF800;
|
sl@0
|
28 |
TInt dayMask=0x1F;
|
sl@0
|
29 |
TInt monthMask=0x01E0;
|
sl@0
|
30 |
TInt yearMask=0xFE00;
|
sl@0
|
31 |
|
sl@0
|
32 |
TInt secs=(aDosTime&secMask)*2;
|
sl@0
|
33 |
TInt mins=(aDosTime&minMask)>>5;
|
sl@0
|
34 |
TInt hrs=(aDosTime&hrMask)>>11;
|
sl@0
|
35 |
TInt days=(aDosDate&dayMask)-1;
|
sl@0
|
36 |
TMonth months=(TMonth)(((aDosDate&monthMask)>>5)-1);
|
sl@0
|
37 |
TInt years=((aDosDate&yearMask)>>9)+1980;
|
sl@0
|
38 |
|
sl@0
|
39 |
TDateTime datetime;
|
sl@0
|
40 |
TInt ret=datetime.Set(years,months,days,hrs,mins,secs,0);
|
sl@0
|
41 |
if (ret==KErrNone)
|
sl@0
|
42 |
return(TTime(datetime));
|
sl@0
|
43 |
return(TTime(0));
|
sl@0
|
44 |
}
|
sl@0
|
45 |
|
sl@0
|
46 |
TInt DosTimeFromTTime(const TTime& aTime)
|
sl@0
|
47 |
//
|
sl@0
|
48 |
// Converts a TTime to a dos time
|
sl@0
|
49 |
//
|
sl@0
|
50 |
{
|
sl@0
|
51 |
TDateTime dateTime=aTime.DateTime();
|
sl@0
|
52 |
TInt dosSecs=dateTime.Second()/2;
|
sl@0
|
53 |
TInt dosMins=dateTime.Minute()<<5;
|
sl@0
|
54 |
TInt dosHrs=dateTime.Hour()<<11;
|
sl@0
|
55 |
return dosSecs|dosMins|dosHrs;
|
sl@0
|
56 |
}
|
sl@0
|
57 |
|
sl@0
|
58 |
TInt DosDateFromTTime(const TTime& aTime)
|
sl@0
|
59 |
//
|
sl@0
|
60 |
// Converts a TTime to a dos date
|
sl@0
|
61 |
//
|
sl@0
|
62 |
{
|
sl@0
|
63 |
|
sl@0
|
64 |
TDateTime dateTime=aTime.DateTime();
|
sl@0
|
65 |
TInt dosDays=dateTime.Day()+1;
|
sl@0
|
66 |
TInt dosMonths=(dateTime.Month()+1)<<5;
|
sl@0
|
67 |
TInt dosYears=(dateTime.Year()-1980)<<9;
|
sl@0
|
68 |
return dosDays|dosMonths|dosYears;
|
sl@0
|
69 |
}
|
sl@0
|
70 |
|
sl@0
|
71 |
TBuf8<12> DosNameToStdFormat(const TDesC8& aDosName)
|
sl@0
|
72 |
//
|
sl@0
|
73 |
// Converts xxx.yyy to standard format aaaaaaaayyy
|
sl@0
|
74 |
//
|
sl@0
|
75 |
{
|
sl@0
|
76 |
|
sl@0
|
77 |
__ASSERT_DEBUG(aDosName.Length()>=0 && aDosName.Length()<=12,Fault(EFatBadDosFormatName));
|
sl@0
|
78 |
TBuf8<12> result;
|
sl@0
|
79 |
Mem::Fill((TUint8*)result.Ptr(),result.MaxSize(),' ');
|
sl@0
|
80 |
TInt dotPos=aDosName.Locate('.');
|
sl@0
|
81 |
if (dotPos==KErrNotFound)
|
sl@0
|
82 |
{
|
sl@0
|
83 |
result=aDosName;
|
sl@0
|
84 |
result.SetLength(11);
|
sl@0
|
85 |
return result;
|
sl@0
|
86 |
}
|
sl@0
|
87 |
result=aDosName.Left(dotPos);
|
sl@0
|
88 |
result.SetLength(11);
|
sl@0
|
89 |
TPtr8 ext(&result[8],3);
|
sl@0
|
90 |
ext=aDosName.Right(aDosName.Length()-dotPos-1);
|
sl@0
|
91 |
return result;
|
sl@0
|
92 |
}
|
sl@0
|
93 |
|
sl@0
|
94 |
TBuf8<12> DosNameFromStdFormat(const TDesC8& aStdFormatName)
|
sl@0
|
95 |
//
|
sl@0
|
96 |
// Converts aaaaaaaayyy to dos name format xxx.yyy
|
sl@0
|
97 |
//
|
sl@0
|
98 |
{
|
sl@0
|
99 |
|
sl@0
|
100 |
__ASSERT_DEBUG(aStdFormatName.Length()==11,Fault(EFatBadStdFormatName));
|
sl@0
|
101 |
TBuf8<12> result;
|
sl@0
|
102 |
TInt nameLen=aStdFormatName.Locate(' ');
|
sl@0
|
103 |
if (nameLen>8 || nameLen==KErrNotFound)
|
sl@0
|
104 |
nameLen=8;
|
sl@0
|
105 |
result=aStdFormatName.Left(nameLen);
|
sl@0
|
106 |
TPtrC8 ext(&aStdFormatName[8],3);
|
sl@0
|
107 |
TInt extLen=ext.Locate(' ');
|
sl@0
|
108 |
if (extLen)
|
sl@0
|
109 |
result.Append(TChar('.'));
|
sl@0
|
110 |
if (extLen==KErrNotFound)
|
sl@0
|
111 |
extLen=3;
|
sl@0
|
112 |
result.Append(ext.Left(extLen));
|
sl@0
|
113 |
if(result.Length() && result[0]==0x05 )
|
sl@0
|
114 |
{
|
sl@0
|
115 |
result[0]=0xE5;
|
sl@0
|
116 |
}
|
sl@0
|
117 |
return result;
|
sl@0
|
118 |
}
|
sl@0
|
119 |
|
sl@0
|
120 |
TInt NumberOfVFatEntries(TInt aNameLength)
|
sl@0
|
121 |
//
|
sl@0
|
122 |
// Return the number of VFat entries required to describe a filename of length aNameLength
|
sl@0
|
123 |
//
|
sl@0
|
124 |
{
|
sl@0
|
125 |
TInt numberOfEntries=0;
|
sl@0
|
126 |
if (aNameLength%KMaxVFatEntryName)
|
sl@0
|
127 |
aNameLength++; // Include a zero terminator
|
sl@0
|
128 |
// If aNameLength is a exact multiple of KMaxVFatEntryName, don't bother
|
sl@0
|
129 |
// with a zero terminator - it just adds an unnecessary directory entry
|
sl@0
|
130 |
|
sl@0
|
131 |
numberOfEntries=(1+(aNameLength/KMaxVFatEntryName));
|
sl@0
|
132 |
|
sl@0
|
133 |
if (aNameLength%KMaxVFatEntryName)
|
sl@0
|
134 |
numberOfEntries++;
|
sl@0
|
135 |
|
sl@0
|
136 |
return(numberOfEntries);
|
sl@0
|
137 |
}
|
sl@0
|
138 |
|
sl@0
|
139 |
//-----------------------------------------------------------------------------
|
sl@0
|
140 |
/**
|
sl@0
|
141 |
Calculate DOS short name checksum
|
sl@0
|
142 |
@param aShortName short name descriptor (must be at least 11 bytes long)
|
sl@0
|
143 |
@return checksum
|
sl@0
|
144 |
*/
|
sl@0
|
145 |
TUint8 CalculateShortNameCheckSum(const TDesC8& aShortName)
|
sl@0
|
146 |
{
|
sl@0
|
147 |
|
sl@0
|
148 |
ASSERT(aShortName.Length() >= KFatDirNameSize);
|
sl@0
|
149 |
const TUint8* pName = aShortName.Ptr();
|
sl@0
|
150 |
|
sl@0
|
151 |
const TUint32 w0 = ((const TUint32*)pName)[0];
|
sl@0
|
152 |
const TUint32 w1 = ((const TUint32*)pName)[1];
|
sl@0
|
153 |
|
sl@0
|
154 |
TUint32 chkSum = w0 & 0xFF;
|
sl@0
|
155 |
|
sl@0
|
156 |
chkSum = (TUint8)(((chkSum<<7) | (chkSum>>1)) + ((w0 << 16) >> 24));
|
sl@0
|
157 |
chkSum = (TUint8)(((chkSum<<7) | (chkSum>>1)) + ((w0 << 8) >> 24));
|
sl@0
|
158 |
chkSum = (TUint8)(((chkSum<<7) | (chkSum>>1)) + ( w0 >> 24));
|
sl@0
|
159 |
|
sl@0
|
160 |
chkSum = (TUint8)(((chkSum<<7) | (chkSum>>1)) + (w1) & 0xFF);
|
sl@0
|
161 |
chkSum = (TUint8)(((chkSum<<7) | (chkSum>>1)) + ((w1 << 16) >> 24));
|
sl@0
|
162 |
chkSum = (TUint8)(((chkSum<<7) | (chkSum>>1)) + ((w1 << 8) >> 24));
|
sl@0
|
163 |
chkSum = (TUint8)(((chkSum<<7) | (chkSum>>1)) + ( w1 >> 24));
|
sl@0
|
164 |
|
sl@0
|
165 |
chkSum = (TUint8)(((chkSum<<7) | (chkSum>>1)) + pName[8]);
|
sl@0
|
166 |
chkSum = (TUint8)(((chkSum<<7) | (chkSum>>1)) + pName[9]);
|
sl@0
|
167 |
chkSum = (TUint8)(((chkSum<<7) | (chkSum>>1)) + pName[10]);
|
sl@0
|
168 |
|
sl@0
|
169 |
return (TUint8)chkSum;
|
sl@0
|
170 |
}
|
sl@0
|
171 |
|
sl@0
|
172 |
|
sl@0
|
173 |
|
sl@0
|
174 |
|
sl@0
|
175 |
|
sl@0
|
176 |
|