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 |
#include <f32file.h>
|
|
17 |
|
|
18 |
#include "rusbhostmsdevice.h"
|
|
19 |
#include "rextfilesystem.h"
|
|
20 |
#include "tmslog.h"
|
|
21 |
|
|
22 |
|
|
23 |
_LIT(KFsNm, "elocal");
|
|
24 |
|
|
25 |
RExtFileSystem::RExtFileSystem()
|
|
26 |
{
|
|
27 |
__MSFNLOG
|
|
28 |
}
|
|
29 |
|
|
30 |
RExtFileSystem::~RExtFileSystem()
|
|
31 |
{
|
|
32 |
__MSFNLOG
|
|
33 |
}
|
|
34 |
|
|
35 |
|
|
36 |
void RExtFileSystem::OpenL()
|
|
37 |
{
|
|
38 |
__MSFNLOG
|
|
39 |
RFs fs;
|
|
40 |
User::LeaveIfError(fs.Connect());
|
|
41 |
CleanupClosePushL(fs);
|
|
42 |
|
|
43 |
TInt err;
|
|
44 |
err = fs.AddFileSystem(KFsNm);
|
|
45 |
if (err != KErrAlreadyExists)
|
|
46 |
User::LeaveIfError(err);
|
|
47 |
|
|
48 |
err = fs.AddFileSystem(_L("ELOCAL"));
|
|
49 |
if (!(KErrAlreadyExists == err || KErrCorrupt == err))
|
|
50 |
User::LeaveIfError(err);
|
|
51 |
|
|
52 |
err = fs.AddProxyDrive(_L("usbhostms.pxy"));
|
|
53 |
if (!(KErrAlreadyExists == err || KErrCorrupt == err))
|
|
54 |
User::LeaveIfError(err);
|
|
55 |
|
|
56 |
CleanupStack::PopAndDestroy(&fs);
|
|
57 |
}
|
|
58 |
|
|
59 |
|
|
60 |
void RExtFileSystem::CloseL()
|
|
61 |
{
|
|
62 |
__MSFNLOG
|
|
63 |
RFs fs;
|
|
64 |
User::LeaveIfError(fs.Connect());
|
|
65 |
CleanupClosePushL(fs);
|
|
66 |
TInt err = fs.RemoveProxyDrive(_L("usbhostms"));
|
|
67 |
CleanupStack::PopAndDestroy(&fs);
|
|
68 |
}
|
|
69 |
|
|
70 |
|
|
71 |
void RExtFileSystem::MountL(RUsbHostMsDevice& aDevice,
|
|
72 |
TDriveNumber aDriveNumber,
|
|
73 |
TToken aToken,
|
|
74 |
TLun aLun)
|
|
75 |
{
|
|
76 |
__MSFNLOG
|
|
77 |
|
|
78 |
TTime start;
|
|
79 |
TTime end;
|
|
80 |
|
|
81 |
start.HomeTime();
|
|
82 |
|
|
83 |
RFs fs;
|
|
84 |
User::LeaveIfError(fs.Connect());
|
|
85 |
CleanupClosePushL(fs);
|
|
86 |
|
|
87 |
TInt err;
|
|
88 |
err = aDevice.MountLun(aLun, aDriveNumber);
|
|
89 |
if (!(KErrAlreadyExists == err || KErrNotReady == err))
|
|
90 |
{
|
|
91 |
__PRINT1(_L("** Error: MountLun returned %d **"), err);
|
|
92 |
RDebug::Print(_L("** Error: MountLun returned %d **"), err);
|
|
93 |
User::LeaveIfError(err);
|
|
94 |
}
|
|
95 |
|
|
96 |
CleanupStack::PopAndDestroy(&fs);
|
|
97 |
|
|
98 |
end.HomeTime();
|
|
99 |
|
|
100 |
TTimeIntervalSeconds timeTaken;
|
|
101 |
end.SecondsFrom(start, timeTaken);
|
|
102 |
TUint totalTime = timeTaken.Int();
|
|
103 |
RDebug::Print(_L("Mount has taken %dHrs:%dmins:%dsecs\n"),
|
|
104 |
totalTime/3600,
|
|
105 |
(totalTime/60)%60,
|
|
106 |
totalTime%60);
|
|
107 |
}
|
|
108 |
|
|
109 |
|
|
110 |
void RExtFileSystem::DismountL(RUsbHostMsDevice& aDevice, TDriveNumber aDriveNumber)
|
|
111 |
{
|
|
112 |
__MSFNLOG
|
|
113 |
RFs fs;
|
|
114 |
User::LeaveIfError(fs.Connect());
|
|
115 |
__PRINT(_L("DismountFileSystem"));
|
|
116 |
//TInt err = aDevice.DismountLun(aDriveNumber);
|
|
117 |
aDevice.DismountLun(aDriveNumber);
|
|
118 |
fs.Close();
|
|
119 |
}
|
|
120 |
|
|
121 |
|
|
122 |
TDriveNumber RExtFileSystem::GetDriveL()
|
|
123 |
{
|
|
124 |
RFs fs;
|
|
125 |
User::LeaveIfError(fs.Connect());
|
|
126 |
TDriveList driveList;
|
|
127 |
fs.DriveList(driveList);
|
|
128 |
fs.Close();
|
|
129 |
|
|
130 |
TInt drive;
|
|
131 |
for (drive = EDriveG; drive <= EDriveZ; drive++)
|
|
132 |
{
|
|
133 |
// Skip K drive which is reserved for LFFS but shows as being free
|
|
134 |
if (drive == EDriveK)
|
|
135 |
{
|
|
136 |
continue;
|
|
137 |
}
|
|
138 |
if (driveList[drive] == 0)
|
|
139 |
{
|
|
140 |
break;
|
|
141 |
}
|
|
142 |
}
|
|
143 |
|
|
144 |
if (drive > EDriveZ)
|
|
145 |
{
|
|
146 |
RDebug::Print(_L("####### NOT Found free drive"));
|
|
147 |
User::Leave(KErrInUse);
|
|
148 |
}
|
|
149 |
|
|
150 |
__PRINT1(_L("Found free drive @ %d"), drive);
|
|
151 |
RDebug::Print(_L("####### Found free drive @ %d"), drive);
|
|
152 |
return static_cast<TDriveNumber>(drive);
|
|
153 |
}
|