os/kernelhwsrv/kerneltest/e32test/lffs/loadlffs.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 1998-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
// e32test\lffs\loadlffs.cpp
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include <f32file.h>
sl@0
    19
sl@0
    20
LOCAL_D RFs TheFs;
sl@0
    21
sl@0
    22
LOCAL_C void FormatLFFS(TDes &drive)
sl@0
    23
	{
sl@0
    24
sl@0
    25
    RFormat format;
sl@0
    26
    TInt    count;
sl@0
    27
    TInt    r;
sl@0
    28
    
sl@0
    29
    RDebug::Print(_L("Format LFFS drive %S\r\n"), &drive);
sl@0
    30
    r = format.Open(TheFs, drive, EHighDensity, count);
sl@0
    31
    
sl@0
    32
    while (count)
sl@0
    33
		{
sl@0
    34
        format.Next(count);
sl@0
    35
    	}
sl@0
    36
    
sl@0
    37
    format.Close();
sl@0
    38
	}
sl@0
    39
sl@0
    40
sl@0
    41
//LOCAL_C void ForceMediaRemount( TMediaDevice aMedia )
sl@0
    42
//	//
sl@0
    43
//	// Force a remount on next access
sl@0
    44
//	//
sl@0
    45
//	{
sl@0
    46
//	UserSvr::ForceRemountMedia( aMedia );
sl@0
    47
//	}
sl@0
    48
sl@0
    49
sl@0
    50
sl@0
    51
TInt MountLFFS()
sl@0
    52
	{
sl@0
    53
    RDebug::Print(_L("Read machine information"));
sl@0
    54
    
sl@0
    55
    TInt LFFSdriveNumber;
sl@0
    56
    TBuf<4> LFFSdriveLetter;
sl@0
    57
    
sl@0
    58
    LFFSdriveLetter.Zero();
sl@0
    59
    LFFSdriveLetter.Append(_L("K:\\"));
sl@0
    60
    LFFSdriveNumber = EDriveK;
sl@0
    61
    
sl@0
    62
    RDebug::Print(_L("Load device driver: MEDLFS"));
sl@0
    63
    TInt r=User::LoadPhysicalDevice(_L("MEDLFS"));
sl@0
    64
    if(r != KErrNone && r != KErrAlreadyExists)
sl@0
    65
		{
sl@0
    66
		RDebug::Print(_L("Loading device driver failed"));
sl@0
    67
		return(-1);
sl@0
    68
		}
sl@0
    69
	
sl@0
    70
    RDebug::Print(_L("Add file system: ELFFS"));
sl@0
    71
    r=TheFs.AddFileSystem(_L("ELFFS"));
sl@0
    72
    if(r != KErrNone && r != KErrAlreadyExists)
sl@0
    73
		RDebug::Print(_L("Failed to add ELFFS"));
sl@0
    74
	
sl@0
    75
    
sl@0
    76
    TFullName name;
sl@0
    77
    r = TheFs.FileSystemName(name, LFFSdriveNumber);
sl@0
    78
    
sl@0
    79
    if (name.Length() != 0)
sl@0
    80
		{
sl@0
    81
        RDebug::Print(_L("Dismounting %S on drive %S\r\n"), &name, &LFFSdriveLetter);
sl@0
    82
        r=TheFs.DismountFileSystem(name, LFFSdriveNumber);
sl@0
    83
		RDebug::Print(_L("Dismount ret=%d"), r);
sl@0
    84
    	}
sl@0
    85
sl@0
    86
//    ForceMediaRemount( EFixedMedia1 );
sl@0
    87
sl@0
    88
    RDebug::Print(_L("Mount LFFS on drive %S\r\n"), &LFFSdriveLetter);
sl@0
    89
    r=TheFs.MountFileSystem(_L("Lffs"), LFFSdriveNumber);
sl@0
    90
	RDebug::Print(_L("Mount r=%d"),r);
sl@0
    91
//uncommented	
sl@0
    92
    if (r == KErrCorrupt || r == KErrNotReady) 
sl@0
    93
		{
sl@0
    94
		RDebug::Print(_L("FS Corrupt, formatting"));
sl@0
    95
	  	FormatLFFS(LFFSdriveLetter);
sl@0
    96
    	}
sl@0
    97
 ///to here   
sl@0
    98
    TheFs.SetSessionPath(LFFSdriveLetter);
sl@0
    99
    return(LFFSdriveNumber);
sl@0
   100
	}
sl@0
   101
sl@0
   102
GLDEF_C TInt E32Main()
sl@0
   103
//
sl@0
   104
// Load the LFFS on C:
sl@0
   105
//
sl@0
   106
	{
sl@0
   107
sl@0
   108
    CTrapCleanup* cleanup;
sl@0
   109
    cleanup=CTrapCleanup::New();
sl@0
   110
sl@0
   111
	TInt r=TheFs.Connect();
sl@0
   112
	RDebug::Print(_L("Connect ret %d"),r);
sl@0
   113
	
sl@0
   114
	TRAP(r,MountLFFS());
sl@0
   115
	RDebug::Print(_L("Mount LFFS ret %d"),r);
sl@0
   116
	
sl@0
   117
    TheFs.Close();
sl@0
   118
    delete cleanup;
sl@0
   119
    return(KErrNone);
sl@0
   120
	}
sl@0
   121