FileSystem.c
上传用户:super_houu
上传日期:2008-09-21
资源大小:4099k
文件大小:76k
- /****************************************************************************************
- * Copyright (c) 2002 ZORAN Corporation, All Rights Reserved
- * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF ZORAN CORPORATION
- *
- * File: $Workfile: FileSystem.c $
- *
- * Description:
- * ============
- *
- *
- * Log:
- * ====
- * $Revision: 31 $
- * Last Modified by $Author: Jerryc $ at $Modtime: 04-03-19 15:28 $
- ****************************************************************************************
- * Updates:
- ****************************************************************************************
- * $Log: /I76/I76_Common/I76_Reference/Playcore/FileSys/FileSystem.c $
- *
- * 31 04-03-19 15:28 Jerryc
- *
- * 30 04-03-19 15:27 Jerryc
- *
- * 29 04-03-19 14:40 Jerryc
- *
- * 28 04-03-19 11:03 Jerryc
- * replace SUPPORT_FLASH_CARD with ENABLE_FILEX.
- *
- * 27 04-03-16 11:11 Jerryc
- * filex structure is allocated from heap.
- *
- * 26 12/10/03 9:45a Leslie
- * change searching filesystem process.
- * signature: MikeX_1205_2003_B
- *
- * 25 11/26/03 3:38p Leslie
- * Free search infomation pool on FileSys_close() function.
- * signature: MikeX_1125_2003
- *
- * 24 11/19/03 10:44a Leslie
- * If current session haven't filesystem, then skip current session and
- * search next session.
- * signature:MikeX_1114_2003
- *
- * 23 11/07/03 5:57a Leslie
- * changed the search BEA01 identifier mode
- * MikeX_1105_2003
- *
- * 22 03-08-28 23:56 Leslie
- * Code cleanup
- *
- * 21 03-07-15 18:58 Jerryc
- * for CDROM don't use UDF_bridge, always use ISO9660.
- *
- * 20 03-06-03 18:22 Leonh
- * support long folder name
- *
- * 19 03-06-03 11:41 Jerryc
- * allocate filex in gns.
- *
- * 18 03-06-02 14:57 Jerryc
- * don't do _fx_media_close.
- *
- * 17 03-06-02 14:52 Jerryc
- * dynamic allocate memory for fileX.
- *
- * 16 5/30/03 4:57p Alexeib
- *
- * 14 03-05-30 11:43 Jerryc
- * fix compile warning.
- *
- * 13 03-05-29 18:11 Jerryc
- * support flash card
- *
- * 12 03-03-12 19:48 Jerryc
- * replace wcscat with wcsncat as wcscat not function properly.
- *
- * 11 2/07/03 10:40p Tomasp
- * - changed SW feature selection to compilation switch
- *
- * 10 03-02-02 19:19 Leslie
- * Fix the multi-session problem.
- *
- * 9 03-01-30 23:13 Leslie
- * Add new functions FileSys_SetCurrentDirICB and FileSys_GetCurrentDirICB
- *
- * 8 03-01-10 12:19 Leslie
- * Add builtin unicode support
- *
- * 12 9/05/02 16:16 Nirm
- * - Expanded FileSys_getDVDFileInfo() functionality, to increase
- * efficiency.
- *
- * 11 23/04/02 9:30 Nirm
- * - Added dependency in "Config.h".
- *
- * 10 13/03/02 21:27 Nirm
- * - Fixed an overflow of Current Path name, if the directory names are
- * too long to fit into the allocated Current-Path string length.
- *
- * 9 3/03/02 20:14 Nirm
- * - Added Multisession support.
- *
- * 8 7/02/02 10:42 Nirm
- * Added FileSys_getPathDelimiter().
- *
- * 7 30/01/02 18:15 Nirm
- * - Integrated UDF;
- * - Changed Search-ID to 16-bit.
- *
- * 6 27/01/02 17:48 Nirm
- * - Added automatic selection of the File-System type;
- * - Search-handles are 16-bit long instead of 32 bit;
- * - Added support for a Search-Info Pool.
- *
- * 5 21/01/02 22:06 Nirm
- * Fixed wrong path-management.
- *
- * 4 16/01/02 11:44 Atai
- * Change debug printing
- *
- * 3 13/01/02 15:59 Nirm
- * Disabled UDF support until UDF is integrated.
- *
- * 2 9/01/02 14:58 Nirm
- * Corrected Include-Paths.
- *
- * 1 12/27/01 14:19 Idan
- ****************************************************************************************/
- /////////////////////////////////////////////////////////////////////////////
- // FileSystem.c - Implementation of an Abstract interface to File Systems
- //
- // Author: Nir Milstein
- #include "Config.h" // Global Configuration - do not remove!
- #ifdef _DEBUG
- #undef IFTRACE
- #define IFTRACE if (gTraceFileSys)
- #include "DebugDbgMain.h"
- #endif
- #include "PlaycoreFileSysFileSystem.h"
- #include "PlaycoreFileSysFileSystem_Impl.h"
- #include "includestring_ex.h"
- #include "Drivedrv_api.h"
- #include "PlaycoreDataStructuresArray.h"
- #include "PlaycoreAuxCacheAuxCache.h"
- #include "PlaycoreFileSysISO9660ISO9660_API.h"
- #include "PlaycoreFileSysUDFUDF_API.h"
- #include "PlaycoreCoremaincoregdef.h"
- #include "Playcorenav_cddaPE_CD.h"
- #include "PlaycoreScPadScPadAlloc.h"
- #ifdef DVD_VR_SUPPORT
- #include "KernelEventDef.h"
- #include "PlaycoreNav_VrVr_nm.h"
- #endif
- #ifdef ENABLE_FILEX
- #include "DriveFE_Manager.h"
- #include "PlaycoreFileSysFileXHeaderFx_dir.h"
- #include "PlaycoreFileSysFileXHeaderFx_fil.h"
- #include "PlaycoreFileSysFileXHeaderFx_med.h"
- #include "PlaycoreFileSysFileXHeaderFx_sys.h"
- #include "PlaycoreFileSysFileXHeaderFx_uti.h"
- #include "drivecardreadercardreaderDriver.h"
- #include "mediacardsincluderegister.h"
- #include "playcoreexceptionexception.h"
- CARD_DETECT_TYPE card_type;
- #ifndef V882_FLASH_CARD
- CARD_DETECT_TYPE FileSys_GetCardType(void);
- #endif
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // Constants
- //#define MAX_PATH 128 // To support long folder name
- //<<<MikeX_1114_2003
- #define SKIP_INVALID_SESSION_HAVE_NOT_FILESYSTEM 1
- /////////////////////////////////////////////////////////////////////////////
- // Macros
- #define SEARCHINFO_POOL_REG_SZ(iSearchCnt) ((iSearchCnt + 7) / 8)
- /////////////////////////////////////////////////////////////////////////////
- // Globals and Singletons
- //#ifdef HW_POWER_ON_RESUME
- WORD NewChecksum= 0;
- //#endif
- LPCWSTR g_pszWildcardSearch= FILESYS_WILDCARD_SEARCH;
- static struct FileSystemInfo_TAG {
- // File-System Location related
- DWORD dwFileSysStartLBN;
- // File-System Type related
- enFileSysType eCurrFileSysType;
- UINT16 uRevision;
- // Path and Path-parsing related
- WCHAR cPathDelimiter;
- // WCHAR szCurrPath[MAX_PATH];
- //WCHAR * pszCurrPath;
- // Search-Info Pool related
- UINT32 hSearchInfoPool;
- BYTE aSearchInfoPoolRegistry[SEARCHINFO_POOL_REG_SZ(FILESYSTEM_MAX_CONCURRENT_SEARCHES)];
- } g_FSInfo;
- #ifdef ENABLE_FILEX
- #define FILEX_FILENAME_LENGTH FX_MAX_LONG_NAME_LEN
- #ifdef INTERNAL_MEM_CARD_READER
- #include "Mediacardsincludefs.h"
- #include "Mediacardsincluderegister.h"
- #include _FCU_LL_DIR_
- #define NUM_OF_CARD_TYPES 6
- typedef VOID (*MEDIA_DRIVER)(FX_MEDIA *);
- //The sequence in the array is defined by enum CARD_DETECT_TYPE.
- CONST MEDIA_DRIVER card_media_driver[NUM_OF_CARD_TYPES] = {
- NULL,
- FsSdDriver,
- FsMsDriver,
- FsCfDriver,
- FsSsfdcDriver,
- FsMsProDriver
- };
- #endif
- static FILEX * gpFileX = NULL;
- static void FileX_destruct(void);
- static BOOL CDROM_FileOpen(STRUCT_FILE * file_ptr, DWORD dwStartAddr, UINT32 cbFileSizeHigh, UINT32 cbFileSizeLow);
- static BOOL CDROM_FileSeek(STRUCT_FILE *file_ptr, UINT32 byte_offset);
- static UINT16 CDROM_FileRead(FX_FILE *file_ptr, BYTE *buffer_ptr, UINT16 request_size, UINT32 *actual_size);
- static BOOL CDROM_FileClose(STRUCT_FILE *file_ptr);
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // Public Methods
- /////////////////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////////////////
- // File-System Identification
- /////////////////////////////////////////////////////////////////////////////
- // FileSys_determineType()
- //
- // Description: Determines the type of File-System resident on the Medium.
- //
- // Input: None
- // Output: None
- // In/Out: None
- // Return: An enum of type enFileSysType, indicating the type of File-System
- // detected on the Medium.
- //
- // Remarks:
- // The supported types of File-System are:
- // - ISO-9660 (aka ECMA-119)
- // - UDF-1.02
- // - UDF-2.00
- // - UDF-Bridge (a hybrid ISO-9660 and one of UDF-1.02 or UDF-2.00)
- //
- // If none of the above is found, an Unknown type is reported.
- enFileSysType FileSys_determineType(void)
- {
- BOOL bSuccess=TRUE;
- // int iTotalTracksCnt;//Leslie_0823_2003_A: Comment out
- DWORD dwPossibleSessionLBN =0;
- DWORD dwLastSessionAddress = 0;
- enFileSysType eRetValue= eUnknown;
- g_FSInfo.dwFileSysStartLBN= 0;
- //<<<MikeX_1205_2003_B
- //get first track address of the last session
- if (!IS_DVD_MEDIA) {
- bSuccess = drv_get_last_session_address(&dwLastSessionAddress);
- if(bSuccess)
- bSuccess=drv_get_first_possible_session(&dwPossibleSessionLBN);
- while(bSuccess){
- if( dwPossibleSessionLBN >= dwLastSessionAddress )
- break;
- bSuccess=drv_get_next_possible_session(&dwPossibleSessionLBN);
- }
- }
- else
- bSuccess=drv_get_first_possible_session(&dwPossibleSessionLBN);
-
- //search from first track address to the last track in last session
- while (bSuccess) {
- bSuccess= FALSE;
- // Check if ISO-9660 is resident
- if (ISO9660_isResident(dwPossibleSessionLBN)) {
- g_FSInfo.uRevision= 0x0100;
- eRetValue= eISO9660;
- #ifdef FILESYSTEM_SUPPORT_UDF
- // Check if UDF is also resident (creating a UDF-Bridge)
- //if (UDF_isResident((dwPossibleSessionLBN+2), &g_FSInfo.uRevision))
- if (UDF_isResident((dwPossibleSessionLBN), &g_FSInfo.uRevision))//MikeX_1105_2003
- eRetValue= eUDF_Bridge;
- #endif //FILESYSTEM_SUPPORT_UDF
-
- //jerry cai, eUDF_Bridge doesn't work for CDROM, so use eISO9660.
- if(eUDF_Bridge == eRetValue && IS_CD_MEDIA)
- eRetValue = eISO9660;
- bSuccess= TRUE;
- }
- else
- #ifdef FILESYSTEM_SUPPORT_UDF
- // Check if UDF is resident
- if (UDF_isResident(dwPossibleSessionLBN, &g_FSInfo.uRevision)) {
- if ((0x0102 <= g_FSInfo.uRevision) && (g_FSInfo.uRevision < 0x0200))
- eRetValue= eUDF_102;
- else if (0x0200 <= g_FSInfo.uRevision)
- eRetValue= eUDF_200;
- bSuccess= TRUE;
- }
- #endif //FILESYSTEM_SUPPORT_UDF
- //<<<MikeX_1114_2003
- #ifdef SKIP_INVALID_SESSION_HAVE_NOT_FILESYSTEM
- //if current session haven't filesystem, then skip current session and find next session
- if( bSuccess )
- {
- g_FSInfo.dwFileSysStartLBN= dwPossibleSessionLBN;
- break;
- }
- #else
- // If no File-System instance was found, abort
- if (bSuccess)
- break;
- // Some File-System instance was found: record its address, and continue to the
- // next Session.
- g_FSInfo.dwFileSysStartLBN= dwPossibleSessionLBN;
- #endif
- //MikeX_1114_2003>>>
- bSuccess=drv_get_next_possible_session(&dwPossibleSessionLBN);
- }
- if( eRetValue != eUnknown )
- return eRetValue;
- //search filesystem from first track of the first session to the first track of the last session.
- while (bSuccess) {
- bSuccess= FALSE;
- // Check if ISO-9660 is resident
- if (ISO9660_isResident(dwPossibleSessionLBN)) {
- g_FSInfo.uRevision= 0x0100;
- eRetValue= eISO9660;
- #ifdef FILESYSTEM_SUPPORT_UDF
- // Check if UDF is also resident (creating a UDF-Bridge)
- //if (UDF_isResident((dwPossibleSessionLBN+2), &g_FSInfo.uRevision))
- if (UDF_isResident((dwPossibleSessionLBN), &g_FSInfo.uRevision))//MikeX_1105_2003
- eRetValue= eUDF_Bridge;
- #endif //FILESYSTEM_SUPPORT_UDF
-
- //jerry cai, eUDF_Bridge doesn't work for CDROM, so use eISO9660.
- if(eUDF_Bridge == eRetValue && IS_CD_MEDIA)
- eRetValue = eISO9660;
- bSuccess= TRUE;
- }
- else
- #ifdef FILESYSTEM_SUPPORT_UDF
- // Check if UDF is resident
- if (UDF_isResident(dwPossibleSessionLBN, &g_FSInfo.uRevision)) {
- if ((0x0102 <= g_FSInfo.uRevision) && (g_FSInfo.uRevision < 0x0200))
- eRetValue= eUDF_102;
- else if (0x0200 <= g_FSInfo.uRevision)
- eRetValue= eUDF_200;
- bSuccess= TRUE;
- }
- #endif //FILESYSTEM_SUPPORT_UDF
- //<<<MikeX_1114_2003
- #ifdef SKIP_INVALID_SESSION_HAVE_NOT_FILESYSTEM
- //if current session haven't filesystem, then skip current session and find next session
- if( bSuccess )
- {
- g_FSInfo.dwFileSysStartLBN= dwPossibleSessionLBN;
- break;
- }
- #else
- // If no File-System instance was found, abort
- if (bSuccess)
- break;
- // Some File-System instance was found: record its address, and continue to the
- // next Session.
- g_FSInfo.dwFileSysStartLBN= dwPossibleSessionLBN;
- #endif
- //MikeX_1114_2003>>>
- bSuccess= drv_get_next_possible_session(&dwPossibleSessionLBN);
- if(dwLastSessionAddress == dwPossibleSessionLBN)
- bSuccess = 0;
- }
- //MikeX_1205_2003_B>>>
- return eRetValue;
- }
- /////////////////////////////////////////////////////////////////////////////
- // FileSys_selectType()
- //
- // Description: Selects the type of File-System to use.
- //
- // Input: eNewType - An enum of type enFileSysType, which specifies the
- // type of File-System to use.
- // Output: None
- // In/Out: None
- // Return: TRUE if the File-System was selected successfully; FALSE otherwise.
- //
- // Remarks:
- // 1. This method must be called prior to initializing the File-System.
- // 2. The return value of FileSys_determineType() may be supplied to this
- // method without change.
- // 3. A FALSE return value means that the requested type of File-System is
- // incompatible with the type resident on the Medium. For example, an
- // attempt of selecting UDF-2.00 while the Medium holds UDF-1.02 will result
- // in failure, since these two versions of UDF are not compatible.
- // 4. The default behaviour when selecting UDF-Bridge is to use the instance
- // of UDF resident on the Medium. To force use of ISO-9660, supply a
- // value of eISO9660, rather than eUDF_Bridge.
- BOOL FileSys_selectType(enFileSysType eNewType)
- {
- int i;
- static BOOL bIsFirstTime= TRUE;
- BOOL bIsChoiceValid= TRUE;
- enFileSysType eExistingFileSys;
- UINT16 res;
- dbg_printf(("FileSys_selectType(%d) calling.n", eNewType));
- if (bIsFirstTime) {
- g_FSInfo.eCurrFileSysType= eUnknown;
- g_FSInfo.hSearchInfoPool= NULL;
- bIsFirstTime= FALSE;
- }
- #ifdef _DEBUG
- // Sanity check
- if (eUnknown == eNewType) {
- dbg_printf(("WARNING: FileSys_selectType() Failed [1]: Unknown Type.n"));
- return FALSE;
- }
- #endif //_DEBUG
- #ifdef ENABLE_FILEX
- if (eFileX == g_FSInfo.eCurrFileSysType && (eFileX == eNewType || eAny == eNewType))
- {
- return TRUE;
- }
- #endif
- #ifdef ENABLE_FILEX
- if(IS_PLAYING_CARD)
- {
- #ifdef I86_HW_FCU
- gpFileX = malloc(sizeof(FILEX));
- if(NULL == gpFileX)
- printf("Fatal: Low system resources on allocating gpFileX.n");
- #else
- gpFileX = (FILEX *)(FCU_FILEX_CACHE_START_ADDR);
- #endif
-
- fx_system_initialize();
- #ifdef EXTERNAL_CARD_READER
- if(FX_SUCCESS == fx_media_open(&(gpFileX->FileX_media),
- NULL,//*media_name
- _fx_ram_driver, //*media_driver
- NULL, //VOID *driver_info_ptr,
- &(gpFileX->ucFileXCacheBuff[0]),//VOID *memory_ptr,
- #ifdef I86_HW_FCU
- FCU_FILEX_CACHE_SIZE,//ULONG memory_size,
- #else
- FILEX_CACHE_SIZE,//ULONG memory_size,
- #endif
- 0)) //UINT partition)
- #else //internal card reader
- {
- int i;
- #ifdef V882_FLASH_CARD
- card_type = FcuSelectACardToPlay();
- #else
- card_type = FileSys_GetCardType();
- #endif
- #ifndef I86_HW_FCU
- #ifdef SEPERATE_CF_CARD_DETECT
- if(card_type == CARD_DETECT_CF)
- #ifdef I77_COMPANION_CHIP
- I77_AndPort(I77_GPIO_OUT_1, I77_GPIO_OUT_1, ~0x1 ); // Set bit/GPIO #8 to 1
- #else
- ClearGPIO(PIO_DATA_E, CARD_SEL);
- #endif
- else
- #ifdef I77_COMPANION_CHIP
- I77_OrPort(I77_GPIO_OUT_1, I77_GPIO_OUT_1, 0x1 ); // Set bit/GPIO #8 to 1
- #else
- SetGPIO(PIO_DATA_E, CARD_SEL);
- #endif
- #endif
- #endif
- if(card_type == NO_CARD_DETECT)
- res = FX_GENERAL_ERROR;
- else
- res = fx_media_open(&(gpFileX->FileX_media),
- NULL,//*media_name
- card_media_driver[card_type>>4], //*media_driver
- NULL, //VOID *driver_info_ptr,
- #ifdef I86_HW_FCU
- (void *)FCU_FILEX_CACHE_ADDR,//VOID *memory_ptr,
- FCU_FILEX_CACHE_SIZE,//ULONG memory_size,
- #else
- &(gpFileX->ucFileXCacheBuff[0]),//VOID *memory_ptr,
- FILEX_CACHE_SIZE,//ULONG memory_size,
- #endif
- 0); //UINT partition)
- //check MS pro card.
- if(res != FX_SUCCESS && card_type == CARD_DETECT_MS_MSPRO &&
- (!(Exception_catchAndRethrow(EXCEPTION_MEDIUM_EJECTED | EXCEPTION_POWER_DOWN_REQUEST) )))
- {
-
- usleep(100000ul); //JERRYC_2004AUG25
- res = fx_media_open(&(gpFileX->FileX_media),
- NULL,//*media_name
- card_media_driver[5], //*media_driver
- NULL, //VOID *driver_info_ptr,
- #ifdef I86_HW_FCU
- (void *)FCU_FILEX_CACHE_ADDR,//VOID *memory_ptr,
- FCU_FILEX_CACHE_SIZE,//ULONG memory_size,
- #else
- &(gpFileX->ucFileXCacheBuff[0]),//VOID *memory_ptr,
- FILEX_CACHE_SIZE,//ULONG memory_size,
- #endif
- 0); //UINT partition)
- }
- }
- if(res == FX_SUCCESS)
- #endif
- eExistingFileSys = eFileX;
- else{
-
- #ifdef I86_HW_FCU
- if(NULL != gpFileX)
- free(gpFileX);
- gpFileX = NULL;
- #endif
- eExistingFileSys = eUnknown;
- }
- }
- else
- #endif
- eExistingFileSys= FileSys_determineType();
- if (eUnknown == eExistingFileSys) {
- dbg_printf(("WARNING: FileSys_selectType() Failed [2]: No File-System found.n"));
- return FALSE;
- }
- // If the caller will take any Type, select the Existing Type
- if (eAny == eNewType)
- eNewType= eExistingFileSys;
- // Make sure that the caller's choice can be handled
- if (eNewType != eExistingFileSys) {
- // Prohibit any incompatibilities
- #ifdef FILESYSTEM_SUPPORT_UDF
- if (eUDF_Bridge == eExistingFileSys) {
- if ((eISO9660 == eNewType) ||
- ((eUDF_102 == eNewType) && (0x0102 == g_FSInfo.uRevision)) ||
- ((eUDF_200 == eNewType) && (0x0200 == g_FSInfo.uRevision)) )
- bIsChoiceValid= TRUE;
- else
- bIsChoiceValid= FALSE;
- }
- else
- bIsChoiceValid= FALSE;
- #else //FILESYSTEM_SUPPORT_UDF
- bIsChoiceValid= ((eUDF_Bridge == eExistingFileSys) && (eISO9660 == eNewType));
- #endif //FILESYSTEM_SUPPORT_UDF
- }
- if (! bIsChoiceValid) {
- dbg_printf(("WARNING: FileSys_selectType() Failed [3]: Invalid type.n"));
- return FALSE;
- }
- // Destroy the instance of the currently-selected Type, if any
- switch (g_FSInfo.eCurrFileSysType)
- {
- case eISO9660:
- ISO9660_destruct();
- break;
- case eUDF_Bridge: // Fall-Through!
- case eUDF_102: // Fall-Through!
- case eUDF_200:
- #ifdef FILESYSTEM_SUPPORT_UDF
- UDF_destruct();
- #endif //FILESYSTEM_SUPPORT_UDF
- break;
- #ifdef ENABLE_FILEX
- case eFileX:
- FileX_destruct();
- break;
- #endif
-
- }
- // Construct an instance of the newly-selected Type
- switch (eNewType)
- {
- case eISO9660:
- ISO9660_construct(g_FSInfo.dwFileSysStartLBN);
- break;
- case eUDF_Bridge: // Fall-Through!
- case eUDF_102: // Fall-Through!
- case eUDF_200:
- #ifdef FILESYSTEM_SUPPORT_UDF
- UDF_construct(g_FSInfo.dwFileSysStartLBN, g_FSInfo.uRevision);
- #endif //FILESYSTEM_SUPPORT_UDF
- break;
- #ifdef ENABLE_FILEX
- case eFileX:
- // FileX already constructed during determining type.
- break;
- #endif
- }
- g_FSInfo.eCurrFileSysType= eNewType;
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // FileSys_getSelectedType()
- //
- // Description: Retrieves the value of the currently-selected File-System type.
- //
- // Input: None
- // Output: None
- // In/Out: None
- // Return: An enum of type enFileSysType, representing the currently
- // selected type. eUnknown is returned if no supported type of
- // File-System was selected.
- //
- // Remarks: None
- enFileSysType FileSys_getSelectedType()
- {
- return g_FSInfo.eCurrFileSysType;
- }
- /////////////////////////////////////////////////////////////////////////////
- // Initialization
- /////////////////////////////////////////////////////////////////////////////
- // FileSys_initialize()
- //
- // Description: Initializes the currently-selected File-System.
- //
- // Input: bLongFilenameSupport - Determines whether or not Long-Filenames
- // Support is enabled.
- // Output: None
- // In/Out: None
- // Return: TRUE if the File-System was successfully initialized; FALSE
- // otherwise.
- //
- // Remarks:
- // 1. In case of failure, none of the Navigation or Queries methods may
- // be used.
- // 2. Long-Filenames Support is only relevant for ISO-9660. When the
- // selected File-System type is UDF or UDF-Bridge, this argument is
- // ignored, since UDF automatically supports Long-Filenames.
- BOOL FileSys_initialize(BOOL bLongFilenameSupport)
- {
- BOOL bSuccess;
- WCHAR buff = 0;
- dbg_printf(("FileSys_initialize(%s) calling.n", (bLongFilenameSupport ? "TRUE" : "FALSE")));
- #ifdef _DEBUG
- // Sanity check
- if (eUnknown == g_FSInfo.eCurrFileSysType) {
- dbg_printf(("WARNING: FileSys_initialize() Failed [1]: File-System type is unknown.n"));
- return FALSE;
- }
- #endif //_DEBUG
- // Reset the Volume-Name
- sc_SetBytes(SC_VOLUME_ID_ADDR, 0, 2, (BYTE*)&buff);
-
- // Reset the Path-delimiter
- g_FSInfo.cPathDelimiter= '\';
- // Reset the Current-Path
- sc_SetBytes(SC_CURRENT_PATHNAME_ADDR, 0, 2, (BYTE*)&buff);
- // Initialize the appropriate File-System
- switch (g_FSInfo.eCurrFileSysType)
- {
- case eISO9660:
- bSuccess= ISO9660_initialize(bLongFilenameSupport);
- break;
- case eUDF_Bridge: // Fall-Through!
- case eUDF_102: // Fall-Through!
- case eUDF_200:
- #ifdef FILESYSTEM_SUPPORT_UDF
- bSuccess= UDF_initialize(bLongFilenameSupport);
- #endif //FILESYSTEM_SUPPORT_UDF
- break;
- #ifdef ENABLE_FILEX
- case eFileX:
- //nothing to do
- bSuccess = TRUE;
- break;
- #endif
- }
- return bSuccess;
- }
- /////////////////////////////////////////////////////////////////////////////
- // FileSys_setPathDelimiter()
- //
- // Description: Sets the character to be used as the Path delimiter when
- // paths are supplied to the various calls.
- //
- // Input: cPathDelimiter - The character that serves as the Path delimiter.
- // Output: None
- // In/Out: None
- // Return: None
- //
- // Remarks: None
- void FileSys_setPathDelimiter(WCHAR cPathDelimiter)
- {
- g_FSInfo.cPathDelimiter= cPathDelimiter;
- return;
- }
- /////////////////////////////////////////////////////////////////////////////
- // FileSys_getPathDelimiter()
- //
- // Description: Retrieves the character being used as the Path delimiter.
- //
- // Input: None
- // Output: None
- // In/Out: None
- // Return: The Path-Delimiter character.
- //
- // Remarks: None
- WCHAR FileSys_getPathDelimiter(void)
- {
- return g_FSInfo.cPathDelimiter;
- }
- /////////////////////////////////////////////////////////////////////////////
- // Navigation
- /////////////////////////////////////////////////////////////////////////////
- // FileSys_goToRootDir()
- //
- // Description: Sets the current working-directory to the Root directory.
- //
- // Input: None
- // Output: None
- // In/Out: None
- // Return: TRUE if the current working-directory was successfully switched
- // to the Root; FALSE otherwise.
- //
- // Remarks: None
- BOOL FileSys_goToRootDir()
- {
- BOOL bSuccess;
- dbg_printf(("FileSys_goToRootDir() calling.n"));
- #ifdef _DEBUG
- // Sanity check
- if (eUnknown == g_FSInfo.eCurrFileSysType) {
- dbg_printf(("WARNING: FileSys_goToRootDir() Failed [1]: File-System type is unknown.n"));
- return FALSE;
- }
- #endif //_DEBUG
- switch (g_FSInfo.eCurrFileSysType)
- {
- case eISO9660:
- bSuccess= ISO9660_goToRootDir();
- break;
- case eUDF_Bridge: // Fall-Through!
- case eUDF_102: // Fall-Through!
- case eUDF_200:
- #ifdef FILESYSTEM_SUPPORT_UDF
- bSuccess= UDF_goToRootDir();
- #endif //FILESYSTEM_SUPPORT_UDF
- break;
- #ifdef ENABLE_FILEX
- case eFileX:
- bSuccess= (FX_SUCCESS == fx_directory_default_set(&(gpFileX->FileX_media), "\"));
- break;
- #endif
- }
- if (bSuccess)
- {
- WCHAR buff = 0;
- sc_SetBytes(SC_CURRENT_PATHNAME_ADDR, 0, 2, (BYTE*)&buff);
- }
- return bSuccess;
- }
- /////////////////////////////////////////////////////////////////////////////
- // FileSys_changeDir()
- //
- // Description: Changes the current working-directory to a desired directory.
- //
- // Input: i_pszDestDirName - A string holding the name of the destination
- // Directory.
- // Output: None
- // In/Out: None
- // Return: TRUE if the current working-directory was successfully changed;
- // FALSE otherwise.
- //
- // Remarks:
- // 1. The destination Directory must be a direct descendant of the current
- // working-directory.
- // 2. If a Directory-Path is supplied, the Path-delimiter must be identical
- // to the one supplied via the FileSys_setPathDelimiter() method.
- // 3. Only a single directory may be specified inside i_pszDestDirName.
- // I.e., i_pszDestDirName is treated as a name of a single directory
- // (directory hierarchy cannot be specified).
- BOOL FileSys_changeDir(LPCWSTR i_pszDestDirName)
- {
- BOOL bSuccess= TRUE;
- LPWSTR pszDirName, pszDelimiter;
- LPWSTR pszDirPath= NULL;
- dbg_printf(("FileSys_changeDir() calling.n"));
- #ifdef _DEBUG
- // Sanity check
- if (eUnknown == g_FSInfo.eCurrFileSysType) {
- dbg_printf(("WARNING: FileSys_changeDir() Failed [1]: File-System type is unknown.n"));
- return FALSE;
- }
- #endif //_DEBUG
- // Allocate a copy for the Destination Path, if required
- if (NULL != wcschr(i_pszDestDirName, g_FSInfo.cPathDelimiter)) {
- pszDirPath= (LPWSTR)malloc((1 + wcslen(i_pszDestDirName)) * sizeof(WCHAR));
- if (NULL == pszDirPath) {
- tr_printf(("FATAL: FileSys_changeDir() Failed [2]: Low system resources.n"));
- return FALSE;
- }
- // Make a local copy of the Destination Path
- wcscpy(pszDirPath, i_pszDestDirName);
- pszDirName= pszDirPath;
- }
- else {
- pszDirName= (LPWSTR)i_pszDestDirName;
- }
- // Store the Current Working-Directory, in case of failure
- switch (g_FSInfo.eCurrFileSysType)
- {
- case eISO9660:
- ISO9660_storeWorkingDirectory();
- break;
- case eUDF_Bridge: // Fall-Through!
- case eUDF_102: // Fall-Through!
- case eUDF_200:
- #ifdef FILESYSTEM_SUPPORT_UDF
- UDF_storeWorkingDirectory();
- #endif //FILESYSTEM_SUPPORT_UDF
- break;
- #ifdef ENABLE_FILEX
- case eFileX:
- //TODO: implement fx_storeWorkingDirectory();
- break;
- #endif
- }
- // Change directories, one at a time
- while (bSuccess) {
- if (g_FSInfo.cPathDelimiter)
- pszDelimiter= wcschr(pszDirName, g_FSInfo.cPathDelimiter);
- else
- pszDelimiter= NULL;
- // Break the Path such, that pszDirName points to a single Directory name
- if (NULL != pszDelimiter) {
- *(pszDelimiter++)= 0;
- }
- // Go one level down the hierarchy
- switch (g_FSInfo.eCurrFileSysType)
- {
- case eISO9660:
- bSuccess= ISO9660_changeDir(pszDirName);
- break;
- case eUDF_Bridge: // Fall-Through!
- case eUDF_102: // Fall-Through!
- case eUDF_200:
- #ifdef FILESYSTEM_SUPPORT_UDF
- bSuccess= UDF_changeDir(pszDirName);
- #endif //FILESYSTEM_SUPPORT_UDF
- break;
- #ifdef ENABLE_FILEX
- case eFileX:
- {
- char *pucBuff = (char *)malloc(1 + wcslen(pszDirName));
- if (NULL == pucBuff) {
- tr_printf(("FATAL: FileSys_changeDir() Failed [3]: Low system resources.n"));
- return FALSE;
- }
- _wcs2str(pszDirName, pucBuff, wcslen(pszDirName)+1);
- bSuccess= (FX_SUCCESS == fx_directory_default_set(&(gpFileX->FileX_media), pucBuff));
- free(pucBuff);
- }
- break;
- #endif
- }
- // Move to the next component on the Path, if one exists
- if (NULL == pszDelimiter)
- break;
- pszDirName= pszDelimiter;
- }
- if (NULL != pszDirPath)
- free(pszDirPath);
- // In case of failure, restore the original Working-Directory.
- if (! bSuccess) {
- switch (g_FSInfo.eCurrFileSysType)
- {
- case eISO9660:
- ISO9660_recallWorkingDirectory();
- break;
- case eUDF_Bridge: // Fall-Through!
- case eUDF_102: // Fall-Through!
- case eUDF_200:
- #ifdef FILESYSTEM_SUPPORT_UDF
- UDF_recallWorkingDirectory();
- #endif //FILESYSTEM_SUPPORT_UDF
- break;
- #ifdef ENABLE_FILEX
- case eFileX:
- //TODO: implement fx_recallWorkingDirectory.
- break;
- #endif
- }
- }
- else {
- // Update the Current Path
- WCHAR path[MAX_PATH];
- sc_GetBytes(SC_CURRENT_PATHNAME_ADDR, 0, MAX_PATH * sizeof(WCHAR), (BYTE*)path);
- if (MAX_PATH >= (2 + wcslen(path) + wcslen(i_pszDestDirName))) {
- wcsncat(path, &g_FSInfo.cPathDelimiter, 1);
- wcsncat(path, i_pszDestDirName, MAX_PATH - wcslen(path) - 1);
- sc_SetBytes(SC_CURRENT_PATHNAME_ADDR, 0, MAX_PATH * sizeof(WCHAR), (BYTE*)path);
- }
- else {
- dbg_printf(("WARNING: FileSys_changeDir(): Current-Path exceeds maximum length.n"));
- }
- }
- return bSuccess;
- }
- /////////////////////////////////////////////////////////////////////////////
- // FileSys_goUp()
- //
- // Description: Moves up one level in the Directories hierarchy.
- //
- // Input: None
- // Output: None
- // In/Out: None
- // Return: TRUE if the current working-directory was successfully changed;
- // FALSE otherwise.
- //
- // Remarks:
- // This method changes the current working-directory to its direct parent
- // in the Directories hierarchy. If the current working-directory is already
- // the Root when this method is called, no change is made.
- BOOL FileSys_goUp()
- {
- BOOL bSuccess;
- dbg_printf(("FileSys_goUp() calling.n"));
- #ifdef _DEBUG
- // Sanity check
- if (eUnknown == g_FSInfo.eCurrFileSysType) {
- dbg_printf(("WARNING: FileSys_goUp() Failed [1]: File-System type is unknown.n"));
- return FALSE;
- }
- #endif //_DEBUG
- switch (g_FSInfo.eCurrFileSysType)
- {
- case eISO9660:
- bSuccess= ISO9660_goUp();
- break;
- case eUDF_Bridge: // Fall-Through!
- case eUDF_102: // Fall-Through!
- case eUDF_200:
- #ifdef FILESYSTEM_SUPPORT_UDF
- bSuccess= UDF_goUp();
- #endif //FILESYSTEM_SUPPORT_UDF
- break;
-
- #ifdef ENABLE_FILEX
- case eFileX:
- bSuccess= (FX_SUCCESS == fx_directory_default_set(&(gpFileX->FileX_media), ".."));
- if(!bSuccess)
- bSuccess= (FX_SUCCESS == fx_directory_default_set(&(gpFileX->FileX_media), "\"));
- break;
- #endif
- }
- if (bSuccess) {
- // Update the Current Path
- WCHAR path[MAX_PATH];
- LPWSTR pszDelimiter;
- sc_GetBytes(SC_CURRENT_PATHNAME_ADDR, 0, MAX_PATH * sizeof(WCHAR), (BYTE*)path);
- pszDelimiter = wcsrchr(path, g_FSInfo.cPathDelimiter);
- if (NULL != pszDelimiter)
- *pszDelimiter= 0;
- sc_SetBytes(SC_CURRENT_PATHNAME_ADDR, 0, MAX_PATH * sizeof(WCHAR), (BYTE*)path);
- }
- return bSuccess;
- }
- /////////////////////////////////////////////////////////////////////////////
- // Queries
- /////////////////////////////////////////////////////////////////////////////
- // FileSys_getVolumeName()
- //
- // Description: Retrieves the Name of the Primary-Volume on the Medium.
- //
- // Input: None
- // Output: None
- // In/Out: None
- // Return: A pointer to a constant String, containing the Volume-Name.
- // A NULL string is returned if the File-System type is unknown.
- //
- // Remarks:
- // The returned String must not be modified or freed by the caller.
- void FileSys_getVolumeName(LPCWSTR volumeName)
- {
- //LPCWSTR pszVolumeName;
- dbg_printf(("FileSys_getVolumeName() calling.n"));
- #ifdef _DEBUG
- // Sanity check
- if (eUnknown == g_FSInfo.eCurrFileSysType) {
- dbg_printf(("WARNING: FileSys_getVolumeName() Failed [1]: File-System type is unknown.n"));
- return NULL;
- }
- #endif //_DEBUG
- switch (g_FSInfo.eCurrFileSysType)
- {
- case eISO9660:
- ISO9660_getVolumeName(volumeName);
- break;
- case eUDF_Bridge: // Fall-Through!
- case eUDF_102: // Fall-Through!
- case eUDF_200:
- #ifdef FILESYSTEM_SUPPORT_UDF
- UDF_getVolumeName(volumeName);
- #endif //FILESYSTEM_SUPPORT_UDF
- break;
- #ifdef ENABLE_FILEX
- case eFileX:
- {
- WCHAR buff=0;
- sc_SetBytes(SC_VOLUME_ID_ADDR, 0, 2, (BYTE*)&buff);
- //*volumeName = 0; // not supported yet.
- }
- break;
- #endif
- }
- return;
- }
- /////////////////////////////////////////////////////////////////////////////
- // FileSys_getCurrentPath()
- //
- // Description: Retrieves the full Path of the Current Working-Directory.
- //
- // Input: None
- // Output: None
- // In/Out: currPath
- // Return: None
- //
- // Remarks:
- // The returned String must not be modified or freed by the caller.
- void FileSys_getCurrentPath(LPCWSTR currPath)
- {
- sc_GetBytes(SC_CURRENT_PATHNAME_ADDR, 0, MAX_PATH * sizeof(WCHAR), (BYTE*)currPath);
- return;
- }
- /////////////////////////////////////////////////////////////////////////////
- // FileSys_fileExists()
- //
- // Description: Tests whether a certain file exists in the current working-
- // directory, or not.
- //
- // Input: i_pszFilename - A string holding the name of the File to test.
- // Output: None
- // In/Out: None
- // Return: TRUE if the requested File exists in the current working-directory;
- // FALSE otherwise.
- //
- // Remarks:
- // A return value of FALSE may also indicate that the currently-selected
- // File-System is unknown. The user is responsible for verifying correctness
- // by assuring that the File-System type was selected and the File-System
- // successfully initialized.
- BOOL FileSys_fileExists(LPCWSTR i_pszFilename)
- {
- BOOL bSuccess;
- dbg_printf(("FileSys_fileExists() calling.n"));
- #ifdef _DEBUG
- // Sanity check
- if (eUnknown == g_FSInfo.eCurrFileSysType) {
- dbg_printf(("WARNING: FileSys_fileExists() Failed [1]: File-System type is unknown.n"));
- return FALSE;
- }
- #endif //_DEBUG
- switch (g_FSInfo.eCurrFileSysType)
- {
- case eISO9660:
- bSuccess= ISO9660_fileExists(i_pszFilename);
- break;
- case eUDF_Bridge: // Fall-Through!
- case eUDF_102: // Fall-Through!
- case eUDF_200:
- #ifdef FILESYSTEM_SUPPORT_UDF
- bSuccess= UDF_fileExists(i_pszFilename);
- #endif //FILESYSTEM_SUPPORT_UDF
- break;
- #ifdef ENABLE_FILEX
- case eFileX:
- {
- char *pucBuff = (char *)malloc(1 + wcslen(i_pszFilename));
- if (NULL == pucBuff) {
- tr_printf(("FATAL: FileSys_changeDir() Failed [3]: Low system resources.n"));
- return FALSE;
- }
- _wcs2str(i_pszFilename, pucBuff, wcslen(i_pszFilename)+1);
- bSuccess= (FX_NOT_DIRECTORY == fx_directory_name_test(&(gpFileX->FileX_media), pucBuff));
- free(pucBuff);
- }
- break;
- #endif
- }
- return bSuccess;
- }
- /////////////////////////////////////////////////////////////////////////////
- // FileSys_getFileLocation()
- //
- // Description: Retrieves the location of a certain file (its start address).
- //
- // Input: i_pszFilename - A string holding the name of the requested File.
- // Output: o_pFileLocation - Points to a DWORD to receive the File's start
- // address.
- // In/Out: None
- // Return: TRUE if the requested File was located and its address retrieved;
- // FALSE otherwise.
- //
- // Remarks:
- // 1. A return value of FALSE indicates that the requested File does not
- // exist in the current working-directory.
- // 2. The File's start-address is given in terms of the Medium's native
- // addressing system. E.g., for Optical-Storage Media, the returned
- // address is expressed in terms of Logical-Block-Number (LBN).
- BOOL FileSys_getFileLocation(LPCWSTR i_pszFilename, DWORD *o_pFileLocation)
- {
- BOOL bSuccess;
- dbg_printf(("FileSys_getFileLocation() calling.n"));
- #ifdef _DEBUG
- // Sanity check
- if (eUnknown == g_FSInfo.eCurrFileSysType) {
- dbg_printf(("WARNING: FileSys_fileExists() Failed [1]: File-System type is unknown.n"));
- return FALSE;
- }
- #endif //_DEBUG
- switch (g_FSInfo.eCurrFileSysType)
- {
- case eISO9660:
- bSuccess= ISO9660_fileLocation(i_pszFilename, o_pFileLocation);
- break;
- case eUDF_Bridge: // Fall-Through!
- case eUDF_102: // Fall-Through!
- case eUDF_200:
- #ifdef FILESYSTEM_SUPPORT_UDF
- bSuccess= UDF_fileLocation(i_pszFilename, o_pFileLocation);
- #endif //FILESYSTEM_SUPPORT_UDF
- break;
- #ifdef ENABLE_FILEX
- case eFileX:
- //TODO: to be implemented.
- bSuccess = FALSE;
- break;
- #endif
- }
- return bSuccess;
- }
- /////////////////////////////////////////////////////////////////////////////
- // FileSys_getDVDFileInfo()
- //
- // Description: Retrieves DVD-Specific information about some file.
- //
- // Input: i_pszFilename - A string holding the name of the requested File,
- // or a pattern to match.
- // eType - An enumerator indicating the Type of DVD Information to
- // retrieve.
- // Output: o_pFileInfo - Points to a DVDFileInfo structure, to receive the
- // File's DVD-information upon successful completion;
- // o_pFindData - Points to a FindData structure, to receive the File's
- // details upon successful completion. May be NULL.
- // In/Out: None
- // Return: TRUE if the requested file was found and the required DVD
- // information was successfully retrieved;
- // FALSE if the file couldn't be found, or if the file has no
- // associated DVD information of the requested type.
- //
- // Remarks:
- // - The value of o_pFindData may be NULL, in which case the FindData
- // is not retrieved.
- BOOL FileSys_getDVDFileInfo(LPCWSTR i_pszFilename, enDVD_FileInfoType eType,
- DVDFileInfo *o_pFileInfo, FindData *o_pFindData)
- {
- BOOL bRetValue= FALSE;
- LPWSTR pszFilePath= NULL;
- LPCWSTR pszFilename= i_pszFilename;
- dbg_printf(("FileSys_getDVDFileInfo() calling.n"));
- #ifdef _DEBUG
- // Sanity check
- if (eUnknown == g_FSInfo.eCurrFileSysType) {
- dbg_printf(("WARNING: FileSys_getDVDFileInfo() Failed [1]: File-System type is unknown.n"));
- return FALSE;
- }
- #endif //_DEBUG
- // Isolate the File's Path, if the Path-Delimiter is set
- if (g_FSInfo.cPathDelimiter) {
- // Search for the File-Name component
- LPCWSTR pszDelimiter= (LPCWSTR)wcsrchr(i_pszFilename, g_FSInfo.cPathDelimiter);
- if (NULL != pszDelimiter) {
- UINT16 uPathLength= (UINT16)((pszDelimiter - i_pszFilename) / sizeof(WCHAR));
- // Set the Filename to point past the Path-Delimiter
- pszFilename= ++pszDelimiter;
- // Copy only the File's path
- pszFilePath= (LPWSTR)malloc((1 + uPathLength) * sizeof(WCHAR));
- if (NULL == pszFilePath) {
- tr_printf(("FATAL: FileSys_getDVDFileInfo() Failed [2]: Low system resources.n"));
- return FALSE;
- }
- wcsncpy(pszFilePath, i_pszFilename, uPathLength);
- pszFilePath[uPathLength]= 0;
- }
- }
- // Prepare for the query
- switch (g_FSInfo.eCurrFileSysType)
- {
- case eISO9660:
- // This query is unsupported by ISO-9660
- bRetValue= FALSE;
- break;
- case eUDF_Bridge: // Fall-Through!
- case eUDF_102: // Fall-Through!
- case eUDF_200:
- #ifdef FILESYSTEM_SUPPORT_UDF
- // Store the current Working-Directory
- UDF_storeWorkingDirectory();
- // Change Working-Directory to the File's Path
- if ((NULL != pszFilePath) && (! FileSys_changeDir(pszFilePath)))
- break;
- // Initiate the search
- bRetValue= UDF_getDVDFileInfo(pszFilename, eType, o_pFileInfo, o_pFindData);
- // Recall the original Working-Directory
- UDF_recallWorkingDirectory();
- #endif //FILESYSTEM_SUPPORT_UDF
- break;
- }
- // Free the File's Path string
- if (pszFilePath)
- free(pszFilePath);
- return bRetValue;
- }
- /////////////////////////////////////////////////////////////////////////////
- // FileSys_findFirstFile()
- //
- // Description: Initiates a search for a certain file, or collection of
- // files.
- //
- // Input: i_pszFilename - A string holding the name of the requested File,
- // or a pattern to match.
- // Output: o_pFindData - Points to a FindData structure, to receive the File's
- // details upon successful completion of the search.
- // In/Out: None
- // Return: A UINT16 which serves as the Handle to this search. This value
- // must be saved for later use with other find-related methods.
- // NULL is returned if the search fails.
- //
- // Remarks:
- // 1. The user must save the returned Handle in order to supply it to future
- // calls to any of the other find-related methods.
- // 2. If the returned Handle is NULL, then no File matching the supplied
- // name/pattern could be located in the current working-directory.
- // 3. If a Directory-Path is supplied, it is assumed to be relative to
- // the Current Working-Directory.
- // 4. The following patterns may be supplied in i_pszFilename:
- // - An empty string ("") - matches any File/Sub-Directory;
- // - Some non-empty string: treated as a Filename/Sub-Directory prefix.
- // For a string of length N, only the first N characters are used
- // for matching.
- // For example: supplying a value of i_pszFilename="A" would retrieve
- // the first File/Sub-Directory whose name begins with a Captial 'A',
- // if such a File/Sub-Directory exists.
- // 5. The search is Case-Sensitive.
- // 6. FileSys_findClose() must be called when no additional searches are needed.
- UINT16 FileSys_findFirstFile(LPCWSTR i_pszFilename, FindData *o_pFindData)
- {
- UINT16 uCurrPathLength;
- UINT16 uRetValue= NULL;
- LPWSTR pszFilePath= NULL;
- LPCWSTR pszFilename= i_pszFilename;
-
- dbg_printf(("FileSys_findFirstFile() calling.n"));
-
- {
- WCHAR path[MAX_PATH];
- sc_GetBytes(SC_CURRENT_PATHNAME_ADDR, 0, MAX_PATH * sizeof(WCHAR), (BYTE*)path);
- uCurrPathLength = wcslen(path);
- }
-
- #ifdef _DEBUG
- // Sanity check
- if (eUnknown == g_FSInfo.eCurrFileSysType) {
- dbg_printf(("WARNING: FileSys_findFirstFile() Failed [1]: File-System type is unknown.n"));
- return NULL;
- }
- #endif //_DEBUG
-
- // Isolate the File's Path, if the Path-Delimiter is set
- if (g_FSInfo.cPathDelimiter) {
- // Search for the File-Name component
- LPCWSTR pszDelimiter= (LPCWSTR)wcsrchr(i_pszFilename, g_FSInfo.cPathDelimiter);
-
- if (NULL != pszDelimiter) {
- UINT16 uPathLength= (UINT16)(pszDelimiter - i_pszFilename);
-
- // Set the Filename to point past the Path-Delimiter
- pszFilename= ++pszDelimiter;
-
- // Copy only the File's path
- pszFilePath= (LPWSTR)malloc((1 + uPathLength) * sizeof(WCHAR));
- if (NULL == pszFilePath) {
- tr_printf(("FATAL: FileSys_findFirstFile() Failed [2]: Low system resources.n"));
- return NULL;
- }
-
- wcsncpy(pszFilePath, i_pszFilename, uPathLength);
- pszFilePath[uPathLength]= 0;
- }
- }
-
- // Prepare for the search
- switch (g_FSInfo.eCurrFileSysType)
- {
- case eISO9660:
- // Store the current Working-Directory
- ISO9660_storeWorkingDirectory();
-
- // Change Working-Directory to the File's Path
- if ((NULL != pszFilePath) && (! FileSys_changeDir(pszFilePath)))
- break;
-
- // Initiate the search
- uRetValue= ISO9660_findFirstFile(pszFilename, o_pFindData);
-
- // Recall the original Working-Directory
- ISO9660_recallWorkingDirectory();
- break;
-
- case eUDF_Bridge: // Fall-Through!
- case eUDF_102: // Fall-Through!
- case eUDF_200:
- #ifdef FILESYSTEM_SUPPORT_UDF
- // Store the current Working-Directory
- UDF_storeWorkingDirectory();
-
- // Change Working-Directory to the File's Path
- if ((NULL != pszFilePath) && (! FileSys_changeDir(pszFilePath)))
- break;
-
- // Initiate the search
- uRetValue= UDF_findFirstFile(pszFilename, o_pFindData);
-
- // Recall the original Working-Directory
- UDF_recallWorkingDirectory();
- #endif //FILESYSTEM_SUPPORT_UDF
- break;
-
- #ifdef ENABLE_FILEX
- case eFileX:
- {
- char * directory_name;
- //TODO: add fx_storeWorkingDirectory();
-
- // Change Working-Directory to the File's Path
- if ((NULL != pszFilePath) && (! FileSys_changeDir(pszFilePath)))
- break;
- directory_name= (char *)malloc(1 + FILEX_FILENAME_LENGTH);
-
- if(NULL == directory_name)
- {
- tr_printf(("Fatal: FileSys_findFirstFile() Failed [3]: Low System resource.n"));
- break;
- }
-
- if(FILESYS_BLURRED_SEARCH == pszFilename[0]) // wildcard search
- {
- FX_DIR_ENTRY entry;
- /* Set the current entry to 0 in order to pickup the first entry. */
- gpFileX->FileX_media.fx_media_default_path.fx_path_current_entry = 0;
- if ( FX_SUCCESS != _fx_directory_next_entry_find_new(&(gpFileX->FileX_media), &entry ) )
- {
- uRetValue = NULL;
- } else
- {
- if ( FX_VOLUME&entry.fx_dir_entry_attributes )
- {
- o_pFindData-> uFileType = FILETYPE_VOLUME;
- } else
- {
- _str2wcs(entry.fx_dir_entry_name, o_pFindData->szFileID, 2*(1 + FILEX_FILENAME_LENGTH));
- if( FX_DIRECTORY&entry.fx_dir_entry_attributes )
- {
- o_pFindData-> uFileType = FILETYPE_DIRECTORY;
- } else
- {
- o_pFindData-> uFileType = FILETYPE_NORMAL;
-
- o_pFindData-> cbFileSizeHigh = 0;
- o_pFindData->dwStartAddr = entry.fx_dir_entry_cluster;
- o_pFindData->cbFileSizeLow = entry.fx_dir_entry_file_size;
- }
- }
- uRetValue = 1;
- }
- } else // search for a file with a given name.
- {
- FX_DIR_ENTRY entry;
- // <<<MikeX_1213_2004_A: support blurred searching
- BOOL bBlurredlySearch = FALSE;
- UINT8 uFileIDLength = wcslen(pszFilename);
- if(FILESYS_BLURRED_SEARCH == pszFilename[uFileIDLength-1] )
- {
- bBlurredlySearch = TRUE;
- uFileIDLength --;
- }
- //MikeX_1213_2004_A>>>
-
- /* Set the current entry to 0 in order to pickup the first entry. */
- uRetValue = NULL;
- gpFileX->FileX_media.fx_media_default_path.fx_path_current_entry = 0;
-
- while(1){
-
- if ( FX_SUCCESS != _fx_directory_next_entry_find_new(&(gpFileX->FileX_media), &entry ) )
- {
- break;
- } else
- {
- if ( FX_VOLUME&entry.fx_dir_entry_attributes )
- {
- continue;
- } else
- {
- _str2wcs(entry.fx_dir_entry_name, o_pFindData->szFileID, 2*(1 + FILEX_FILENAME_LENGTH));
-
- if( FX_DIRECTORY&entry.fx_dir_entry_attributes )
- {
- continue;
- } else
- {
-
- if( (wcsncmp(o_pFindData->szFileID, pszFilename, uFileIDLength) != 0) ||
- ( (!bBlurredlySearch) && (wcslen(o_pFindData->szFileID) != uFileIDLength))) //MikeX_1213_2004_A: support blurred searching
- continue;
-
- o_pFindData-> uFileType = FILETYPE_NORMAL;
-
- o_pFindData-> cbFileSizeHigh = 0;
- o_pFindData->dwStartAddr = entry.fx_dir_entry_cluster;
- o_pFindData->cbFileSizeLow = entry.fx_dir_entry_file_size;
- uRetValue = 1;
- break;
- }
- }
- }
-
- }
-
- }
- free(directory_name);
- }
- break;
-
- #endif
-
- }
-
- // Free the File's Path string
- if (NULL != pszFilePath) {
- free(pszFilePath);
-
- // Reconstruct the original Path, since it was changed by FileSys_changeDir()
- {
- WCHAR buff = 0;
- sc_SetBytes(SC_CURRENT_PATHNAME_ADDR, 0, 2, (BYTE*)&buff);
- }
- }
-
- return uRetValue;
- }
- /////////////////////////////////////////////////////////////////////////////
- // FileSys_findNextFile()
- //
- // Description: Continues a search that was previously initiated using a call
- // to FileSys_findFirstFile().
- //
- // Input: hFindFile - A Handle to a file-search, that was returned from
- // a previous call to FileSys_findFirstFile().
- // Output: o_pFindData - Points to a FindData structure, to receive the File's
- // details upon successful completion of the search.
- // In/Out: None
- // Return: TRUE if the search succeeded, and an additional File matching
- // the Filename/pattern was found. In this case, the supplied
- // o_pFindData contains updated information of the found File.
- // FALSE is returned if no more Files/Sub-Directories matching the
- // supplied Filename/pattern could be found. In this case, the
- // supplied o_pFindData is invalid.
- //
- // Remarks:
- // 1. This method continues a previous search from the point it left off.
- // 2. The search relates to the Directory that was supplied at the time the
- // search was initiated via FileSys_findFirstFile().
- // 3. The search uses the same Filename/pattern as was originally supplied
- // to FileSys_findFirstFile().
- // 4. FileSys_findClose() must be called when no additional searches are needed.
- BOOL FileSys_findNextFile(UINT16 hFindFile, FindData *o_pFindData)
- {
- BOOL bSuccess;
- dbg_printf(("FileSys_findNextFile() calling.n"));
- #ifdef _DEBUG
- // Sanity check
- if (eUnknown == g_FSInfo.eCurrFileSysType) {
- dbg_printf(("WARNING: FileSys_findNextFile() Failed [1]: File-System type is unknown.n"));
- return FALSE;
- }
- #endif //_DEBUG
- switch (g_FSInfo.eCurrFileSysType)
- {
- case eISO9660:
- bSuccess= ISO9660_findNextFile(hFindFile, o_pFindData);
- break;
- case eUDF_Bridge: // Fall-Through!
- case eUDF_102: // Fall-Through!
- case eUDF_200:
- #ifdef FILESYSTEM_SUPPORT_UDF
- bSuccess= UDF_findNextFile(hFindFile, o_pFindData);
- #endif //FILESYSTEM_SUPPORT_UDF
- break;
- #ifdef ENABLE_FILEX
- case eFileX:
- {
- FX_DIR_ENTRY entry;
- if ( FX_SUCCESS != _fx_directory_next_entry_find_new(&(gpFileX->FileX_media), &entry ) )
- return FALSE;
- if ( FX_VOLUME&entry.fx_dir_entry_attributes )
- {
- o_pFindData-> uFileType = FILETYPE_VOLUME;
- } else
- {
- _str2wcs(entry.fx_dir_entry_name, o_pFindData->szFileID, 2*(1 + FILEX_FILENAME_LENGTH));
- if( FX_DIRECTORY&entry.fx_dir_entry_attributes )
- {
- o_pFindData-> uFileType = FILETYPE_DIRECTORY;
- } else
- {
- o_pFindData-> uFileType = FILETYPE_NORMAL;
- o_pFindData-> cbFileSizeHigh = 0;
- o_pFindData->dwStartAddr = entry.fx_dir_entry_cluster;
- o_pFindData->cbFileSizeLow = entry.fx_dir_entry_file_size;
- }
- }
- return TRUE;
- }
- #endif
- }
- return bSuccess;
- }
- /////////////////////////////////////////////////////////////////////////////
- // FileSys_findClose()
- //
- // Description: Terminates a file-search.
- //
- // Input: hFindFile - A Handle to a file-search, that was returned from
- // a previous call to FileSys_findFirstFile().
- // Output: None
- // In/Out: None
- // Return: TRUE if the search was successfully terminated; FALSE othewise.
- //
- // Remarks:
- // Any search that is initiated via FileSys_findFirstFile() must be terminated
- // using a call to this method, in order to allow for proper release of
- // resources that were allocated for that search.
- BOOL FileSys_findClose(UINT16 hFindFile)
- {
- BOOL bSuccess;
- dbg_printf(("FileSys_findClose() calling.n"));
- #ifdef _DEBUG
- // Sanity check
- if (eUnknown == g_FSInfo.eCurrFileSysType) {
- dbg_printf(("WARNING: FileSys_findClose() Failed [1]: File-System type is unknown.n"));
- return FALSE;
- }
- #endif //_DEBUG
- switch (g_FSInfo.eCurrFileSysType)
- {
- case eISO9660:
- bSuccess= ISO9660_findClose(hFindFile);
- break;
- case eUDF_Bridge: // Fall-Through!
- case eUDF_102: // Fall-Through!
- case eUDF_200:
- #ifdef FILESYSTEM_SUPPORT_UDF
- bSuccess= UDF_findClose(hFindFile);
- #endif //FILESYSTEM_SUPPORT_UDF
- break;
-
- #ifdef ENABLE_FILEX
- case eFileX:
- //nothing to do.
- bSuccess = TRUE;
- break;
- #endif
-
- }
- return bSuccess;
- }
- #ifdef ENABLE_FILEX
- /*
- Desc: Open a file telling it's starting physical cluster number.
- for read only.
- In: STRUCT_FILE * file_ptr, pointer to the file control block.
- DWORD dwStartAddr, starting physical cluster number(or logical sector num for CDROM).
- UINT32 cbFileSizeHigh, high DWORD for file size in bytes.
- UINT32 cbFileSizeLow, low DWORD for file size in bytes.
-
- ret: TRUE, succeeds.
- FALSE, fails.
- */
- BOOL FileSys_FileOpen(STRUCT_FILE * file_ptr, DWORD dwStartAddr, UINT32 cbFileSizeHigh, UINT32 cbFileSizeLow)
- {
- BOOL bSuccess;
- dbg_printf(("FileSys_FileOpen() calling.n"));
-
- switch (g_FSInfo.eCurrFileSysType)
- {
- case eISO9660: // Fall-Through!
- case eUDF_Bridge: // Fall-Through!
- case eUDF_102: // Fall-Through!
- case eUDF_200:
- case eUnknown: //file system might be closed.
- bSuccess= CDROM_FileOpen(file_ptr, dwStartAddr, cbFileSizeHigh, cbFileSizeLow);
- break;
-
- case eFileX:
- bSuccess = (FX_SUCCESS == fx_file_open_by_addr(&(gpFileX->FileX_media), file_ptr, dwStartAddr, cbFileSizeLow));
- break;
- }
- return bSuccess;
- }
- /*
- Desc: Move the file read pointer to the specified offset.
- In: STRUCT_FILE * file_ptr, pointer to the file control block.
- UINT32 cbFileOffsetHigh, high DWORD for offset in bytes.
- UINT32 cbFileOffsetLow, low DWORD for offset in bytes.
- */
- BOOL FileSys_FileSeek(STRUCT_FILE * file_ptr, UINT32 cbFileOffsetHigh, UINT32 cbFileOffsetLow)
- {
- BOOL bSuccess;
- dbg_printf(("FileSys_FileSeek() calling.n"));
- switch (g_FSInfo.eCurrFileSysType)
- {
- case eISO9660: // Fall-Through!
- case eUDF_Bridge: // Fall-Through!
- case eUDF_102: // Fall-Through!
- case eUDF_200:
- case eUnknown: //file system might be closed.
- bSuccess= CDROM_FileSeek(file_ptr, cbFileOffsetLow);
- break;
- case eFileX:
- bSuccess = (FX_SUCCESS == fx_file_seek(file_ptr, cbFileOffsetLow));
- break;
- }
- return bSuccess;
- }
- /*
- Desc: Read bytes from file.
- In: STRUCT_FILE * file_ptr, pointer to the file to read.
- BYTE * read_buff, the destination buffer.
- UINT32 request_size, number of bytes to read.
- UINT32 * actual_size, destination for actual number of bytes read.
- ret: FileX errors.
- */
- UINT16 FileSys_FileRead(STRUCT_FILE * file_ptr, BYTE * read_buff, UINT32 request_size,UINT32 * actual_size)
- {
- UINT16 res;
- dbg_printf(("FileSys_FileRead() calling.n"));
-
- switch (g_FSInfo.eCurrFileSysType)
- {
- case eISO9660: // Fall-Through!
- case eUDF_Bridge: // Fall-Through!
- case eUDF_102: // Fall-Through!
- case eUDF_200:
- res= CDROM_FileRead(file_ptr, read_buff, request_size, actual_size);
- break;
-
- case eFileX:
- {
- res= fx_file_read(file_ptr, read_buff, request_size, actual_size);
-
- break;
- }
-
- case eUnknown: //file system might be closed.
- return FX_NOT_OPEN;
- }
- return res;
- }
- /*
- Desc: Close the file.
- In: STRUCT_FILE * file_ptr, pointer to the file to close.
- ret: TRUE, succeeds.
- FALSE, fails.
- */
- BOOL FileSys_FileClose(STRUCT_FILE * file_ptr)
- {
- BOOL res;
- dbg_printf(("FileSys_FileClose() calling.n"));
-
- switch (g_FSInfo.eCurrFileSysType)
- {
- case eISO9660: // Fall-Through!
- case eUDF_Bridge: // Fall-Through!
- case eUDF_102: // Fall-Through!
- case eUDF_200:
- case eUnknown: //file system might be closed.
- res= CDROM_FileClose(file_ptr);
- break;
-
- case eFileX:
- {
- res= (FX_SUCCESS == fx_file_close(file_ptr));
-
- break;
- }
-
- }
- return res;
- }
- /*
- Desc: Is file closed?
- In: STRUCT_FILE * file_ptr, the file to be checked.
- Out: TRUE, file is closed.
- FALSE, file is opened.
- */
- BOOL FileSys_IsFileClosed(STRUCT_FILE * file_ptr)
- {
- return (FX_FILE_ID != file_ptr->fx_file_id)? TRUE : FALSE;
- }
- #ifndef V882_FLASH_CARD
- /*
- Desc: Get card type.
- ret: card type.
- */
- CARD_DETECT_TYPE FileSys_GetCardType(void)
- {
- int i;
- CARD_DETECT_TYPE res, res1, res2;
- dbg_printf(("FileSys_GetCardType() calling.n"));
- #ifdef EXTERNAL_CARD_READER
- res= (MEDIA_REMOVED != card_reader_status());
- #endif
- #ifdef INTERNAL_MEM_CARD_READER
- for(i = 0; i < 100; i++)
- {
- usleep(10000);
- res= FcuMediaCardDetect();
- usleep(10000);
-
- res1= FcuMediaCardDetect();
-
- usleep(10000);
- res2= FcuMediaCardDetect();
- if(res == res1 && res1 == res2)
- break;
- }
- #endif
- return res;
- }
- #endif
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // Protected Methods
- /////////////////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////////////////
- // Search-Info Pool Management
- /////////////////////////////////////////////////////////////////////////////
- // _FileSys_resetSearchInfoPool()
- //
- // Description: Resets the Search-Info Pool.
- //
- // Input: uSearchInfoSize - The size, in Bytes, of a single Search-Info.
- // Output: None
- // In/Out: None
- // Return: TRUE if the Search-Info Pool was reset successfully;
- // FALSE otherwise.
- //
- // Remarks:
- // In case a Search-Info Pool already exists, the method destroys the
- // existing Pool, and creates a new one instead.
- BOOL _FileSys_resetSearchInfoPool(UINT8 uSearchInfoSize)
- {
- // Destroy any existing Search-Info Pool
- if (NULL != g_FSInfo.hSearchInfoPool)
- Array_destruct(g_FSInfo.hSearchInfoPool);
- // Construct the Search-Info Pool and clear it
- g_FSInfo.hSearchInfoPool= Array_construct(FILESYSTEM_MAX_CONCURRENT_SEARCHES,
- uSearchInfoSize, NULL);
- if (NULL == g_FSInfo.hSearchInfoPool) {
- dbg_printf(("WARNING: _FileSys_resetSearchInfoPool() Failed [1]: Low system resourcesn"));
- return FALSE;
- }
- Array_clear(g_FSInfo.hSearchInfoPool);
- // Clear the Search-Info Pool Registry
- memset(g_FSInfo.aSearchInfoPoolRegistry, 0, sizeof(g_FSInfo.aSearchInfoPoolRegistry));
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // _FileSys_allocateSearchInfo()
- //
- // Description: Allocates the next available slot from the Search-Info Pool.
- //
- // Input: None
- // Output: None
- // In/Out: None
- // Return: The ID of the newly allocated Search-Info; NULL if no available
- // Search-Info was found.
- //
- // Remarks:
- // The allocation is protected using a Semaphore, to guarantee consistency
- // of the Search-Info Pool Registry when called from multiple Tasks.
- UINT16 _FileSys_allocateSearchInfo(void)
- {
- UINT8 uRegistryPos, uSlotPos;
- UINT8 uSlotMask= 0x80;
- UINT16 uResult= NULL;
- BYTE *pRegistryByte;
- // TODO
- // Semapore_obtain()
- // Iterate over the Directory-Search Pool Registry, trying to find a
- // Byte that has at least one clear Bit.
- pRegistryByte= &g_FSInfo.aSearchInfoPoolRegistry[0];
- for (uRegistryPos=0;
- uRegistryPos < sizeof(g_FSInfo.aSearchInfoPoolRegistry);
- uRegistryPos++, pRegistryByte++)
- {
- if (0xFF != (*pRegistryByte))
- break;
- }
- // Check if anything was found
- if (0xFF != (*pRegistryByte)) {
- // Locate the first clear Bit inside the Registry-Byte just found
- for (uSlotPos=0; uSlotPos < 8; uSlotPos++) {
- if (0 == ((*pRegistryByte) & uSlotMask))
- break;
- // Move to the next Slot
- uSlotMask >>= 1;
- }
- // Check if a valid Slot was found
- if (FILESYSTEM_MAX_CONCURRENT_SEARCHES > ((uRegistryPos * 8) + uSlotPos)) {
- // Allocate the Slot
- *pRegistryByte |= uSlotMask;
- // Assign the serial-number of the Slot just allocated
- uResult= (1 + ((uRegistryPos * 8) + uSlotPos));
- }
- }
- // TODO:
- // Semaphore_release()
- return uResult;
- }
- /////////////////////////////////////////////////////////////////////////////
- // _FileSys_freeSearchInfo()
- //
- // Description: Frees a Search-Info Pool slot.
- //
- // Input: uSearchInfoID - The ID given to the Search-Info upon allocation.
- // Output: None
- // In/Out: None
- // Return: None
- //
- // Remarks:
- // The deallocation is protected using a Semaphore, to guarantee consistency
- // of the Search-Info Pool Registry when called from multiple Tasks.
- void _FileSys_freeSearchInfo(UINT16 uSearchInfoID)
- {
- UINT8 uRegitryPos, uSlotPos;
- // Make sure that the supplied Slot number is valid
- if ((NULL == uSearchInfoID) ||
- ((uSearchInfoID-1) >= FILESYSTEM_MAX_CONCURRENT_SEARCHES))
- {
- return;
- }
- // TODO:
- // Semaphore_obtain()
- // Calculate the position of the Registry Byte conmtaining this Slot
- uRegitryPos= ((uSearchInfoID-1) / 8);
- // Calculate the Slot position within the Registry Byte
- uSlotPos= ((uSearchInfoID-1) % 8);
- // Free the Slot
- g_FSInfo.aSearchInfoPoolRegistry[uRegitryPos] &= ~(0x80 >> uSlotPos);
- // TODO:
- // Semaphore_release()
- return;
- }
- /////////////////////////////////////////////////////////////////////////////
- // _FileSys_getSearchInfo()
- //
- // Description: Retrieves the contents of a previously allocated Search-Info.
- //
- // Input: uSearchInfoID - The ID of the Search-Info to retrieve.
- // Output: o_pSearchInfo - A container to hold the retrived Search-Info.
- // In/Out: None
- // Return: TRUE if the requested Search-Info was retrieved successfully;
- // FALSE otherwise.
- //
- // Remarks: None
- BOOL _FileSys_getSearchInfo(UINT16 uSearchInfoID, BYTE *o_pSearchInfo)
- {
- return Array_getAt(g_FSInfo.hSearchInfoPool, (uSearchInfoID-1), o_pSearchInfo);
- }
- /////////////////////////////////////////////////////////////////////////////
- // _FileSys_setSearchInfo()
- //
- // Description: Sets the contents of a previously allocated Search-Info.
- //
- // Input: uSearchInfoID - The ID of the Search-Info to set;
- // i_pSearchInfo - Points to a Search-Info to set.
- // Output: None
- // In/Out: None
- // Return: TRUE if the requested Search-Info was set successfully;
- // FALSE otherwise.
- //
- // Remarks: None
- BOOL _FileSys_setSearchInfo(UINT16 uSearchInfoID, const BYTE *i_pSearchInfo)
- {
- return Array_setAt(g_FSInfo.hSearchInfoPool, (uSearchInfoID-1), i_pSearchInfo);
- }
- #ifdef ENABLE_FILEX
- /*
- Desc: Open a file on CDROM media by it's start logical sector number.
- In: STRUCT_FILE * file, destination file pointer.
- DWORD dwStartAddr, start logical sector number.
- UINT32 cbFileSizeHigh, high DWORD of the file size, not used.
- UINT32 cbFileSizeLow, low DWORD of the file size.
- ret: always TRUE.
- */
- static BOOL CDROM_FileOpen(STRUCT_FILE * file_ptr, DWORD dwStartAddr, UINT32 cbFileSizeHigh, UINT32 cbFileSizeLow)
- {
- /* Protect against other threads accessing the media. */
- //FX_PROTECT
- file_ptr->fx_file_id = FX_FILE_ID;
-
- //file_ptr->fx_file_name = NULL; //not available
-
- /* Define the open mode request. */
- file_ptr->fx_file_open_mode = FX_OPEN_FOR_READ;
- /* Define the file modified field. */
- file_ptr->fx_file_modified = FX_FALSE;
- /* Define the complete directory entry structure. */
- //file_ptr->fx_file_dir_entry; //not available, not used by file read.
- /* Define the data storage parameters. */
- //file_ptr->fx_file_total_clusters;
- file_ptr->fx_file_first_physical_cluster = dwStartAddr;
- //file_ptr->fx_file_consecutive_cluster;
- //file_ptr->fx_file_last_physical_cluster;
- file_ptr->fx_file_current_physical_cluster = file_ptr->fx_file_first_physical_cluster;
-
- //file_ptr->fx_file_current_logical_sector = 0;
-
- file_ptr->fx_file_current_logical_offset = 0;
-
- file_ptr->fx_file_current_relative_cluster = 0;
-
- //file_ptr->fx_file_current_relative_sector = 0;
-
- file_ptr->fx_file_current_file_offset = 0;
-
- file_ptr->fx_file_current_file_size = cbFileSizeLow;
- file_ptr->fx_file_current_available_size = cbFileSizeLow;
- /* Remember the media that is associated with this file. */
- //file_ptr->fx_file_media_ptr = media_ptr;
- /* Define the pointers necessary to maintain the open file on
- the list of open files. */
- //file_ptr->fx_file_opened_next;
- //file_ptr->fx_file_opened_previous;
-
- /* Release media protection. */
- // FX_UNPROTECT
- /* Open is complete, return successful status. */
- return TRUE;
-
- }
- /*
- Desc: set the file read pointer to the specified offset for file ON CDROM media.
- In: STRUCT_FILE *file_ptr, pointer to the file.
- UINT32 byte_offset, offset in bytes.
- ret: TRUE, succeeds.
- FALSE, fails.
- */
- static BOOL CDROM_FileSeek(STRUCT_FILE *file_ptr, UINT32 byte_offset)
- {
- /* Protect against other threads accessing the media. */
- //FX_PROTECT
- /* First, determine if the file is still open. */
- if (file_ptr -> fx_file_id != FX_FILE_ID)
- {
- /* Return the file not open error status. */
- return FALSE;
- }
- if(byte_offset >= file_ptr->fx_file_current_available_size)
- return FALSE;
- file_ptr->fx_file_current_relative_cluster = byte_offset/LOGICAL_BLOCK_SIZE;
- file_ptr->fx_file_current_physical_cluster = file_ptr->fx_file_first_physical_cluster + file_ptr->fx_file_current_relative_cluster;
- file_ptr->fx_file_current_logical_offset = byte_offset%LOGICAL_BLOCK_SIZE;
-
-
- file_ptr->fx_file_current_file_offset = byte_offset;
-
-
-
- /* Release media protection. */
- // FX_UNPROTECT
- /* Open is complete, return successful status. */
- return TRUE;
-
- }
- /*
- Desc: read bytes from CDROM files.
- in: FX_FILE *file_ptr, pointer to the file to read.
- BYTE *buffer_ptr, the destination buffer pointer.
- UINT32 request_size, bytes to read.
- UINT32 *actual_size, bytes read.
- ret: FileX errors.
- */
- static UINT16 CDROM_FileRead(FX_FILE *file_ptr, BYTE *buffer_ptr, UINT16 request_size, UINT32 *actual_size)
- {
- /* First, determine if the file is still open. */
- if (file_ptr -> fx_file_id != FX_FILE_ID)
- {
- /* Return the file not open error status. */
- return(FX_NOT_OPEN);
- }
- /* Protect against other threads accessing the media. */
- // FX_PROTECT
- /* Next, determine if there is any more bytes to read in the file. */
- if (file_ptr -> fx_file_current_file_offset >=
- file_ptr -> fx_file_current_file_size)
- {
- /* Release media protection. */
- // FX_UNPROTECT
- /* The file is at the end, return the proper status and set the
- actual size to 0. */
- *actual_size = 0;
- return(FX_END_OF_FILE);
- }
- /* At this point there is something to read. */
- /* Determine if there are less bytes left in the file than that specified
- by the request. If so, ajust the requested size. */
- if (request_size >
- (file_ptr -> fx_file_current_file_size - file_ptr -> fx_file_current_file_offset))
- {
- /* Adjust the bytes remaining to what's available. */
- request_size = file_ptr -> fx_file_current_file_size - file_ptr -> fx_file_current_file_offset;
- }
- if(FALSE == AuxCache_GetBytes(file_ptr -> fx_file_current_physical_cluster, file_ptr->fx_file_current_logical_offset,
- request_size, buffer_ptr))
- {
- *actual_size = 0;
- return FX_IO_ERROR;
- }
- else
- {
- *actual_size = request_size;
- if(CDROM_FileSeek(file_ptr, file_ptr->fx_file_current_file_offset + request_size))
- return FX_SUCCESS;
- else
- return FX_IO_ERROR;
- }
-
- }
- /*
- Desc: Close CDROM file.
- In: STRUCT_FILE *file_ptr, pointer to the file to close.
- ret: TRUE, file is closed.
- FALSE, file is already closed.
- */
- static BOOL CDROM_FileClose(STRUCT_FILE *file_ptr)
- {
- /* First, determine if the file is still open. */
- if (file_ptr -> fx_file_id != FX_FILE_ID)
- {
- /* Return the file not open error status. */
- return FALSE;
- }
-
- /* Finally, Indicate that this file is closed. */
- file_ptr -> fx_file_id = FX_FILE_CLOSED_ID;
- return TRUE;
- }
- /*
- Desc: reset card reader.
- */
- extern UINT16 IDE_Reset (VOID);
- static void FileX_destruct(void)
- {
- fx_media_abort(&(gpFileX->FileX_media));
- #ifdef I86_HW_FCU
- if(NULL != gpFileX)
- free(gpFileX);
- gpFileX = NULL;
- #endif
- #ifdef EXTERNAL_CARD_READER
- IDE_Reset();
- #endif
- }
- #endif
- BOOL FileSys_close(void)
- {
- // Destroy the instance of the currently-selected Type, if any
- switch (g_FSInfo.eCurrFileSysType)
- {
- case eISO9660:
- ISO9660_destruct();
- break;
- case eUDF_Bridge: // Fall-Through!
- case eUDF_102: // Fall-Through!
- case eUDF_200:
- #ifdef FILESYSTEM_SUPPORT_UDF
- UDF_destruct();
- #endif //FILESYSTEM_SUPPORT_UDF
- break;
- #ifdef ENABLE_FILEX
- case eFileX:
- FileX_destruct();
- break;
- #endif
-
- }
- g_FSInfo.eCurrFileSysType= eUnknown;
- //<<<MikeX_1125_2003: free search infomation pool
- if (NULL != g_FSInfo.hSearchInfoPool)
- {
- Array_destruct(g_FSInfo.hSearchInfoPool);
- g_FSInfo.hSearchInfoPool = NULL;
- }
- //MikeX_1125_2003>>>
- }
- #ifdef DVD_VR_SUPPORT
- DWORD g_pDVDVR_PlayQueue; //Points to the Play Queue
- BYTE g_DVDVR_PlayQueue_Head; //point to the Play Queue head
- BYTE g_DVDVR_PlayQueue_Tail; // point to the Play Queue tail
- BYTE g_DVDVR_PlayQueue_Size; // extent number in the Play Queue
- BYTE g_DVDVR_ExtentsInFE; // extents number in the Front End
- DVDVR_PLAY_QUEUE_NODE g_lastPlayExtent;
- BOOL g_ExtentIsPlaying;
- /////////////////////////////////////////////////////////////////////////////
- // FileSys_DVDVR_getFileExtent()
- //
- // Description: cache the file extents table to the SDRAM.
- //
- // Input: i_pszFilename - A string holding the name of the requested File,
- // or a pattern to match.
- // Output: o_pFileExtent - Points to the Array which points to the extents
- // table of the file.
- // In/Out: None
- // Return: TRUE if the requested file was found and the extents table
- // was successfully retrieved; FALSE otherwise.
- //
- // Remarks:
- // - The value of o_pFileExtent may be NULL, in which case the o_pFileExtent
- // is not retrieved.
- BOOL FileSys_DVDVR_getFileExtent(LPCWSTR i_pszFilename, DWORD *o_pFileExtent)
- {
- BOOL bRetValue= FALSE;
- LPWSTR pszFilePath= NULL;
- LPCWSTR pszFilename= i_pszFilename;
- dbg_printf(("FileSys_getDVDVRFileExtent() calling.n"));
- #ifdef _DEBUG
- // Sanity check
- if (eUnknown == g_FSInfo.eCurrFileSysType) {
- dbg_printf(("WARNING: FileSys_getDVDVRFileExtent() Failed [1]: File-System type is unknown.n"));
- return FALSE;
- }
- #endif //_DEBUG
- g_ExtentIsPlaying = FALSE;
- // Isolate the File's Path, if the Path-Delimiter is set
- if (g_FSInfo.cPathDelimiter) {
- // Search for the File-Name component
- LPCWSTR pszDelimiter= (LPCWSTR)wcsrchr(i_pszFilename, g_FSInfo.cPathDelimiter);
- if (NULL != pszDelimiter) {
- UINT16 uPathLength= (UINT16)((pszDelimiter - i_pszFilename) / sizeof(WCHAR));
- // Set the Filename to point past the Path-Delimiter
- pszFilename= ++pszDelimiter;
- // Copy only the File's path
- pszFilePath= (LPWSTR)malloc((1 + uPathLength) * sizeof(WCHAR));
- if (NULL == pszFilePath) {
- tr_printf(("FATAL: FileSys_getDVDVRFileExtent() Failed [2]: Low system resources.n"));
- return FALSE;
- }
- wcsncpy(pszFilePath, i_pszFilename, uPathLength);
- pszFilePath[uPathLength]= 0;
- }
- }
- // Prepare for the query
- switch (g_FSInfo.eCurrFileSysType)
- {
- case eISO9660:
- // This query is unsupported by ISO-9660
- bRetValue= FALSE;
- break;
- case eUDF_Bridge: // Fall-Through!
- case eUDF_102: // Fall-Through!
- case eUDF_200:
- #ifdef FILESYSTEM_SUPPORT_UDF
- // Store the current Working-Directory
- UDF_storeWorkingDirectory();
- // Change Working-Directory to the File's Path
- if ((NULL != pszFilePath) && (! FileSys_changeDir(pszFilePath)))
- break;
- // Initiate the search
- bRetValue= UDF_getDVDVRFileExtent(pszFilename, o_pFileExtent);
- // Recall the original Working-Directory
- UDF_recallWorkingDirectory();
- #endif //FILESYSTEM_SUPPORT_UDF
- break;
- }
- // Free the File's Path string
- if (pszFilePath)
- free(pszFilePath);
- return bRetValue;
- }
- /////////////////////////////////////////////////////////////////////////////
- // FileSys_DVDVR_FreeFileExtent()
- //
- // Description: free the file extents table in the SDRAM.
- //
- // Input: i_pFileExtent - Points to the Array which points to the extents
- // table of the file.
- // Output: None
- // In/Out: None
- // Return: TRUE if success; FALSE otherwise.
- //
- // Remarks:
- // - The value of i_pFileExtent shouldn't be NULL.
- BOOL FileSys_DVDVR_FreeFileExtent(DWORD i_pFileExtent)
- {
- if(i_pFileExtent != (DWORD)NULL)
- Array_destruct(i_pFileExtent);
- else
- return FALSE;
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // FileSys_DVDVR_ReadFile()
- //
- // Description: read some bytes from a file
- //
- // Input: pFileHandle - points to the file extents table
- // dwOffset - the start byte offset in the file
- // dwSize - the bytes number want to read
- //
- // Output: o_pBuffer - Points to the buffer of the output data
- // In/Out: None
- // Return: TRUE if read successfully,FALSE otherwise
- //
- // Remarks:
- // - The pFileHandle should not be NULL, and the dwSize should over the file size.
- BOOL FileSys_DVDVR_ReadFile(DWORD pFileHandle, DWORD dwOffset, DWORD dwSize, BYTE* o_pBuffer)
- {
- dbg_printf(("FileSys_DVDVR_ReadFile(0x%08lx, 0x%08lx, 0x%08lx, 0x%08lx)n",pFileHandle, dwOffset, dwSize, o_pBuffer));
- if( g_FSInfo.eCurrFileSysType != eUDF_200 )
- {
- tr_printf(("FATAL: FileSys_ReadFile() Failed [1]: This function was only used for UDF 2.00.n"));
- return FALSE;
- }
- g_ExtentIsPlaying = FALSE;
- return UDF_ReadFile(pFileHandle, dwOffset, dwSize, o_pBuffer);
- }
- /////////////////////////////////////////////////////////////////////////////
- // UDF_PlayExtents()
- //
- // Description: play a part of a file.
- //
- // Input: pFileHandle - points to the extents table of the playback file
- // dwOffset - start sector number from the file begining
- // dwSize - playback size by sector
- // Output: None
- // In/Out: None
- // Return: TRUE if play successfully,FALSE otherwise
- //
- // Remarks:
- // - the pFileHandle shoulen't NULL.
- BOOL FileSys_DVDVR_PlayExtents(DWORD pFileHandle, DWORD dwOffset, DWORD dwSize)
- {
- dbg_printf(("FileSys_DVDVR_PlayExtents(0x%08lx, 0x%08lx, 0x%08lx)n",pFileHandle, dwOffset, dwSize));
- if( g_FSInfo.eCurrFileSysType != eUDF_200 )
- {
- tr_printf(("FATAL: FileSys_PlayExtents() Failed [1]: This function was only used for UDF 2.00.n"));
- return FALSE;
- }
- return UDF_PlayExtents(pFileHandle, dwOffset, dwSize);
- }
- /////////////////////////////////////////////////////////////////////////////
- // FileSys_DVDVR_PlayQueue_NextExtent()
- //
- // Description: play next extent in the Play Queue.
- //
- // Input: None
- // Output: None
- // In/Out: None
- // Return: TRUE if play successfully,FALSE otherwise
- //
- // Remarks:
- // - the Play Queue shouldn't be empty.
- BOOL FileSys_DVDVR_PlayQueue_NextExtent()
- {
- dbg_printf(("FileSys_DVDVR_PlayQueue_NextExtent()"));
- if(g_DVDVR_ExtentsInFE >0)
- {
- tr_printf(("FATAL:FileSys_DVDVR_PlayQueue_NextExtent() Failed [1]: There aren't playing items in FE!n"));
- return FALSE;
- }
- //g_DVDVR_ExtentsInFE--;//Move to DRV to decrease this value after DRV finished one extent.
- g_ExtentIsPlaying = FALSE;
-
- if( g_DVDVR_PlayQueue_Size == 0 && g_DVDVR_ExtentsInFE == 0 )
- return FALSE;
-
- UDF_TransferExtentToFE();
-
- if( g_DVDVR_PlayQueue_Size == 0 )
- { //this playback is only one extent.
- ie_send_ex(IE_CORE_PLAYBACK_FINISHIED,(void*)QUE_PlaybackFinished);
- }
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // FileSys_DVDVR_PlayQueue_NextExtent()
- //
- // Description: construct a Play Queue.
- //
- // Input: None
- // Output: None
- // In/Out: None
- // Return: TRUE if play successfully,FALSE otherwise
- //
- // Remarks:
- BOOL FileSys_DVDVR_PlayQueue_Construct()
- {
- dbg_printf(("FileSys_DVDVR_PlayQueue_Construct()"));
- g_pDVDVR_PlayQueue=Array_construct(DVDVR_PLAY_QUEUE_SIZE, sizeof(DVDVR_PLAY_QUEUE_NODE),NULL);
- if( g_pDVDVR_PlayQueue == (DWORD)NULL )
- {
- tr_printf(("FATAL: FileSys_PlayQueue_Construct() Failed [1]: Low system resources.n"));
- return FALSE;
- }
- Array_clear(g_pDVDVR_PlayQueue);
- g_DVDVR_PlayQueue_Head=0;
- g_DVDVR_PlayQueue_Tail=0;
- g_DVDVR_PlayQueue_Size=0;
- g_DVDVR_ExtentsInFE=0;
- g_ExtentIsPlaying = FALSE;
- g_lastPlayExtent.dwStartLBN = 0UL;
- g_lastPlayExtent.dwLength = 0UL;
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // FileSys_DVDVR_PlayQueue_Clear()
- //
- // Description: clear the Play Queue.
- //
- // Input: None
- // Output: None
- // In/Out: None
- // Return: TRUE if play successfully,FALSE otherwise
- //
- // Remarks:
- void FileSys_DVDVR_PlayQueue_Clear()
- {
- dbg_printf(("FileSys_DVDVR_PlayQueue_Clear()"));
- Array_clear(g_pDVDVR_PlayQueue);
- g_DVDVR_PlayQueue_Head=0;
- g_DVDVR_PlayQueue_Tail=0;
- g_DVDVR_PlayQueue_Size=0;
- g_DVDVR_ExtentsInFE=0;
- g_ExtentIsPlaying = FALSE;
- g_lastPlayExtent.dwStartLBN = 0UL;
- g_lastPlayExtent.dwLength = 0UL;
- return;
- }
- /////////////////////////////////////////////////////////////////////////////
- // FileSys_DVDVR_PlayQueue_Destruct()
- //
- // Description: destruct the Play Queue.
- //
- // Input: None
- // Output: None
- // In/Out: None
- // Return: TRUE if play successfully,FALSE otherwise
- //
- // Remarks:
- void FileSys_DVDVR_PlayQueue_Destruct()
- {
- dbg_printf(("FileSys_DVDVR_PlayQueue_Destruct()"));
- Array_destruct(g_pDVDVR_PlayQueue);
- g_DVDVR_PlayQueue_Head=0;
- g_DVDVR_PlayQueue_Tail=0;
- g_DVDVR_PlayQueue_Size=0;
- g_DVDVR_ExtentsInFE=0;
- g_ExtentIsPlaying = FALSE;
- g_lastPlayExtent.dwStartLBN = 0UL;
- g_lastPlayExtent.dwLength = 0UL;
- return;
- }
- #endif