os/security/cryptoservices/filebasedcertificateandkeystores/source/generic/server/fstokenutil.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of the License "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
#include "fstokenutil.h"
sl@0
    20
#include <f32file.h>
sl@0
    21
#include <s32file.h>
sl@0
    22
sl@0
    23
// RMessage::Panic() also completes the message. This is:
sl@0
    24
// (a) important for efficient cleanup within the kernel
sl@0
    25
// (b) a problem if the message is completed a second time
sl@0
    26
void PanicClient(const RMessage2& aMessage, ETokenTypeServerPanic aPanic)
sl@0
    27
	{
sl@0
    28
	_LIT(KPanicClient,"TTSERVERCLIENT");
sl@0
    29
	aMessage.Panic(KPanicClient,aPanic);
sl@0
    30
	}
sl@0
    31
sl@0
    32
void PanicServer(ETokenTypeServerPanic aPanicCode)
sl@0
    33
	{
sl@0
    34
	_LIT(KPanicServer,"TOKENTYPESERVER");
sl@0
    35
	User::Panic(KPanicServer, aPanicCode);
sl@0
    36
	}
sl@0
    37
sl@0
    38
/// Rom drive where the initial store data is
sl@0
    39
_LIT(KFileStoreROMDrive, "Z:");
sl@0
    40
sl@0
    41
TBool FileUtils::ExistsL(RFs& aFs, const TDesC& aFile)
sl@0
    42
	{
sl@0
    43
	TBool result = EFalse;
sl@0
    44
	TBool open;
sl@0
    45
	TInt err = aFs.IsFileOpen(aFile, open);
sl@0
    46
	
sl@0
    47
	if (err == KErrNone)
sl@0
    48
		{
sl@0
    49
		result = ETrue;
sl@0
    50
		}
sl@0
    51
	else if (err != KErrNotFound && err != KErrPathNotFound)
sl@0
    52
		{
sl@0
    53
		User::Leave(err);
sl@0
    54
		}
sl@0
    55
sl@0
    56
	return result;
sl@0
    57
	}
sl@0
    58
sl@0
    59
void FileUtils::EnsurePathL(RFs& aFs, const TDesC& aFile)
sl@0
    60
	{
sl@0
    61
	TInt err = aFs.MkDirAll(aFile);
sl@0
    62
	if (err != KErrNone && err != KErrAlreadyExists)
sl@0
    63
		{
sl@0
    64
		User::Leave(err);
sl@0
    65
		}
sl@0
    66
	}
sl@0
    67
sl@0
    68
void FileUtils::CopyL(RFs& aFs, const TDesC& aSouce, const TDesC& aDest)
sl@0
    69
	{
sl@0
    70
	RFileReadStream in;
sl@0
    71
	User::LeaveIfError(in.Open(aFs, aSouce, EFileRead | EFileShareReadersOnly));
sl@0
    72
	CleanupClosePushL(in);
sl@0
    73
sl@0
    74
	RFileWriteStream out;
sl@0
    75
	User::LeaveIfError(out.Replace(aFs, aDest, EFileWrite | EFileShareExclusive));
sl@0
    76
	CleanupClosePushL(out);
sl@0
    77
sl@0
    78
	in.ReadL(out);	
sl@0
    79
	CleanupStack::PopAndDestroy(2, &in);
sl@0
    80
	}
sl@0
    81
sl@0
    82
void FileUtils::MakePrivateFilenameL(RFs& aFs, const TDesC& aLeafName, TDes& aNameOut)
sl@0
    83
	{
sl@0
    84
	aNameOut.SetLength(0);	
sl@0
    85
	aNameOut.Append(RFs::GetSystemDriveChar());
sl@0
    86
sl@0
    87
	aNameOut.Append(':');
sl@0
    88
sl@0
    89
	// Get private path
sl@0
    90
	TBuf<20> privatePath;
sl@0
    91
	aFs.PrivatePath(privatePath);
sl@0
    92
	aNameOut.Append(privatePath);
sl@0
    93
	
sl@0
    94
	aNameOut.Append(aLeafName);
sl@0
    95
	}
sl@0
    96
sl@0
    97
void FileUtils::MakePrivateROMFilenameL(RFs& aFs, const TDesC& aLeafName, TDes& aNameOut)
sl@0
    98
	{
sl@0
    99
	aNameOut.Copy(KFileStoreROMDrive);
sl@0
   100
sl@0
   101
	// Get private path
sl@0
   102
	TBuf<20> privatePath;
sl@0
   103
	aFs.PrivatePath(privatePath);
sl@0
   104
	aNameOut.Append(privatePath);
sl@0
   105
	
sl@0
   106
	aNameOut.Append(aLeafName);
sl@0
   107
	}