imgtools/imglib/filesystem/source/filesysteminterface.cpp
changeset 2 39c28ec933dd
child 6 787612182dd0
equal deleted inserted replaced
1:820b22e13ff1 2:39c28ec933dd
       
     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,
       
    66 				const_cast<char *>(aImageFileName),
       
    67 				const_cast<char *>(__FILE__), __LINE__);
       
    68 		}
       
    69 		switch(aFileSystem)
       
    70 		{
       
    71 			case EFAT16:
       
    72 				iFileSystem = new CFat16FileSystem;
       
    73 				break;
       
    74 			
       
    75 			case EFAT32:
       
    76 				iFileSystem= new CFat32FileSystem;
       
    77 				break;
       
    78 			default:
       
    79 				return EFSNotSupported;
       
    80 				break;
       
    81 
       
    82 		}
       
    83 		iFileSystem->Execute(aPartitionSize,*aNodeList,iOutputStream,aConfigurableFatAttributes);
       
    84 		delete iFileSystem;
       
    85 		iFileSystem = NULL;
       
    86 		iOutputStream.close();
       
    87 		MessageHandler::CleanUp();
       
    88 	}
       
    89 	catch(ErrorHandler &error)
       
    90 	{
       
    91 		iOutputStream.close();
       
    92 		delete iFileSystem;
       
    93 		iFileSystem = NULL;
       
    94 		MessageHandler::StartLogging (aLogFileName);
       
    95 		error.Report();
       
    96 		MessageHandler::CleanUp();
       
    97 		return EFileSystemError;
       
    98 	}
       
    99 	/**
       
   100 	Irrespective of successful or unsuccessful data drive image generation ROFSBUILD
       
   101 	may try to generate images for successive oby file input.
       
   102 	During this course unhandled exceptions may cause leaving some memory on heap 
       
   103 	unused. so the unhandled exceptions handling is used to free the memory allocated 
       
   104 	on heap. 
       
   105 	*/
       
   106 	catch(...)
       
   107 	{
       
   108 		iOutputStream.close();
       
   109 		delete iFileSystem;
       
   110 		iFileSystem = NULL;
       
   111 		return EFileSystemError;
       
   112 	}
       
   113 	return 0;
       
   114 }
       
   115 
       
   116 
       
   117 /**
       
   118 Constructor of Class ConfigurableFatAttributes
       
   119 
       
   120 @internalComponent
       
   121 @released
       
   122 */
       
   123 ConfigurableFatAttributes::ConfigurableFatAttributes()
       
   124 {
       
   125 	iDriveSectorSize = 0;
       
   126 	iDriveNoOfFATs = 0;
       
   127 }