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