imgtools/imglib/filesystem/source/filesysteminterface.cpp
changeset 0 044383f39525
child 590 360bd6b35136
equal deleted inserted replaced
-1:000000000000 0:044383f39525
       
     1 /*
       
     2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 * This class provides the interface to external tools which can
       
    16 * use FileSystem component library. Upon external request this class 
       
    17 * classifies the request type either FAT16 or FAT32 and invokes 
       
    18 * the specific functions to generate the FAT image.
       
    19 * @internalComponent
       
    20 * @released
       
    21 *
       
    22 */
       
    23 
       
    24 #include"errorhandler.h"
       
    25 #include"filesysteminterface.h"
       
    26 #include"fat16filesystem.h"
       
    27 #include"fat32filesystem.h"
       
    28 #include"dirregion.h"
       
    29 
       
    30 
       
    31 //static member definition
       
    32 
       
    33 Ofstream CFileSystemInterFace::iOutputStream;
       
    34 
       
    35 /**
       
    36 API exposed by the  FileSystem component to be used by an external component(s).
       
    37 This is method to be used by the external component for passing information required 
       
    38 by the FileSystem component
       
    39 
       
    40 @internalComponent
       
    41 @released
       
    42 
       
    43 @param aNodeList Directory structure 
       
    44 @param aFileSystem file system type
       
    45 @param aImageFileName image file name 
       
    46 @param aLogFileName log file name 
       
    47 @param aPartitionSize partition size in bytes
       
    48 */
       
    49 FILESYSTEM_API int CFileSystemInterFace::CreateFilesystem(EntryList* aNodeList , 
       
    50 										   TFileSystem aFileSystem,
       
    51 										   char* aImageFileName, 
       
    52 										   char* aLogFileName,
       
    53 										   ConfigurableFatAttributes* aConfigurableFatAttributes,
       
    54 										   Long64 aPartitionSize)
       
    55 {
       
    56 	
       
    57 	
       
    58 	CFileSystem* iFileSystem = NULL;
       
    59 	try
       
    60 	{
       
    61 		MessageHandler::StartLogging (aLogFileName);
       
    62 		iOutputStream.open(aImageFileName,ios::out|ios::binary);
       
    63 		if(iOutputStream.fail() == true )
       
    64 		{
       
    65 			throw ErrorHandler(FILEOPENERROR,aImageFileName,__FILE__, __LINE__);
       
    66 		}
       
    67 		switch(aFileSystem)
       
    68 		{
       
    69 			case EFAT16:
       
    70 				iFileSystem = new CFat16FileSystem;
       
    71 				break;
       
    72 			
       
    73 			case EFAT32:
       
    74 				iFileSystem= new CFat32FileSystem;
       
    75 				break;
       
    76 			default:
       
    77 				return EFSNotSupported;
       
    78 				break;
       
    79 
       
    80 		}
       
    81 		iFileSystem->Execute(aPartitionSize,*aNodeList,iOutputStream,aConfigurableFatAttributes);
       
    82 		delete iFileSystem;
       
    83 		iFileSystem = NULL;
       
    84 		iOutputStream.close();
       
    85 		MessageHandler::CleanUp();
       
    86 	}
       
    87 	catch(ErrorHandler &error)
       
    88 	{
       
    89 		iOutputStream.close();
       
    90 		delete iFileSystem;
       
    91 		iFileSystem = NULL;
       
    92 		MessageHandler::StartLogging (aLogFileName);
       
    93 		error.Report();
       
    94 		MessageHandler::CleanUp();
       
    95 		return EFileSystemError;
       
    96 	}
       
    97 	/**
       
    98 	Irrespective of successful or unsuccessful data drive image generation ROFSBUILD
       
    99 	may try to generate images for successive oby file input.
       
   100 	During this course unhandled exceptions may cause leaving some memory on heap 
       
   101 	unused. so the unhandled exceptions handling is used to free the memory allocated 
       
   102 	on heap. 
       
   103 	*/
       
   104 	catch(...)
       
   105 	{
       
   106 		iOutputStream.close();
       
   107 		delete iFileSystem;
       
   108 		iFileSystem = NULL;
       
   109 		return EFileSystemError;
       
   110 	}
       
   111 	return 0;
       
   112 }
       
   113 
       
   114 
       
   115 /**
       
   116 Constructor of Class ConfigurableFatAttributes
       
   117 
       
   118 @internalComponent
       
   119 @released
       
   120 */
       
   121 ConfigurableFatAttributes::ConfigurableFatAttributes()
       
   122 {
       
   123 	iDriveSectorSize = 0;
       
   124 	iDriveNoOfFATs = 0;
       
   125 }