ISO9660_API.c
上传用户:super_houu
上传日期:2008-09-21
资源大小:4099k
文件大小:70k
- /****************************************************************************************
- * Copyright (c) 2002 ZORAN Corporation, All Rights Reserved
- * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF ZORAN CORPORATION
- *
- * File: $Workfile: ISO9660_API.c $
- *
- * Description:
- * ============
- *
- *
- * Log:
- * ====
- * $Revision: 22 $
- * Last Modified by $Author: Mikex $ at $Modtime: 04-03-20 20:36 $
- ****************************************************************************************
- * Updates:
- ****************************************************************************************
- * $Log: /I76/I76_Common/I76_Reference/Playcore/FileSys/ISO9660/ISO9660_API.c $
- *
- * 22 04-03-20 21:00 Mikex
- * Cut the file name longer than 128 bytes.
- * example: if the file name length is 130
- * origenal: abc...xyz.mp3
- * before: abc...xyz.m
- * now: abc...x.mp3
- *
- * 21 11/19/03 10:25a Leslie
- *
- * 20 03-07-17 17:11 Jerryc
- * support finding files with name length of 63 and 64.
- *
- * 19 03-07-15 18:57 Jerryc
- * ISO9660_checkValid will not return FLASE if some pathTable records are
- * empty.
- *
- * 18 7/08/03 3:39p Mikex
- * delete the CHECK_ISO9660_PATHTABLE define switch
- *
- * 17 7/08/03 3:14p Mikex
- * change function ISO9660_checkValid for having several iso9660 PVD disc.
- *
- * 16 03-07-06 1:55 Leslie
- * Add CHECK_ISO9660_PATHTABLE
- *
- * 15 7/03/03 7:37p Mikex
- *
- * 14 7/03/03 2:16p Mikex
- * add a function ISO9660_checkValid to check whether the ISO9660 file
- * system was ok or not. the function was transferred by
- * ISO9660_initialize function.
- *
- * 13 7/01/03 6:28p Mikex
- * add ISO9660_getFilesFirst, ISO9660_getFilesNext and
- * ISO9660_getFilesClose function to get all files in one directory
- *
- * 12 2/07/03 10:41p Tomasp
- * - changed SW feature selection to compilation switch
- *
- * 11 03-01-30 23:12 Leslie
- * Add functions ISO9660_GetcurrentDirICB and ISO9660_SetcurrentDirICB
- *
- * 10 03-01-10 12:20 Leslie
- * Add builtin unicode support
- *
- * 9 10/31/02 17:22 Hamadk
- * Check of the parameter in filesystem intializing
- *
- * 10 23/04/02 9:30 Nirm
- * - Added dependency in "Config.h".
- *
- * 9 13/03/02 21:25 Nirm
- * Fixed an endless-loop problem in _findNextFileRecord(): If a directory
- * padding spans beyond a sector-boundary (due to authoring error), the
- * sector-boundary wouldn't be crossed. This is a result of the caching
- * mechanism.
- * A special check was added to assure correct sector-boundary crossing.
- *
- * 8 4/02/02 10:54 Nirm
- * Unused External-Memory is freed, to reduce memory consumption.
- *
- * 7 30/01/02 18:16 Nirm
- * Updated debugging-messages.
- *
- * 6 27/01/02 17:47 Nirm
- * - Added ISO9660_construct() and ISO9660_destruct(), to allow proper
- * allocation and deallocation of system resources;
- * - Modifications and optimizations to memory consumption.
- *
- * 5 16/01/02 11:46 Atai
- * Change Debug printing
- *
- * 4 1/10/02 18:08 Idan
- * added optimization - avoid memory allocation when wild card search is
- * requested.
- *
- * 3 1/10/02 15:32 Idan
- * FindFirstFile, FindNextFile, GoUp, ChangeDirectory, GetFileAttributes
- * and all memory allocatations are working properly.
- *
- * 2 12/31/01 19:46 Idan
- * initializing the ISO9660 FS is working.
- *
- * 1 12/27/01 14:19 Idan
- *
- ****************************************************************************************/
- /////////////////////////////////////////////////////////////////////////////
- // ISO9660_API.c - Implementation of the ISO-9660 File-System For DVD/S-VCD
- // Players.
- //
- // Author: Nir Milstein
- #include "Config.h" // Global Configuration - do not remove!
- #ifdef _DEBUG
- #undef IFTRACE
- #define IFTRACE if (gTraceFileSys)
- #include "DebugDbgMain.h"
- #endif //_DEBUG
- #include "Includemath-macro.h"
- #include "Includestring_ex.h"
- #include "PlaycoreFileSysFileSystem_Impl.h"
- #include "PlaycoreFileSysIso9660ISO9660_API.h"
- #include "PlaycoreFileSysIso9660ECMA119.h"
- #include "PlaycoreDataStructuresArray.h"
- #include "PlaycoreAuxCacheAuxCache.h"
- #include "PlaycoreScPadscmgr.h"
- #include "PlaycoreCoremaincoregdef.h"
- #include "PlaycoreFileSysFileSystem.h"
- #ifdef MACESTROLINK_SUPPORT
- #include "drivefe_manager.h"
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // Constants
- #define DIRECTORY_RECLIST_SZ (5 * (sizeof(struct DirFileRecord) + MAX_ID_LENGTH))
- /////////////////////////////////////////////////////////////////////////////
- // Macros
- #ifdef MOTOROLA
- #define BB_WORD(wBothBytes) (WORD)(wBothBytes ## .wBE16)
- #define BB_DWORD(dwBothBytes) (DWORD)(dwBothBytes ## .dwBE32)
- #else
- #define BB_WORD(wBothBytes) (WORD)(wBothBytes ## .wLE16)
- #define BB_DWORD(dwBothBytes) (DWORD)(dwBothBytes ## .dwLE32)
- #endif //MOTOROLA
- /////////////////////////////////////////////////////////////////////////////
- // Globals and Singletons
- /*
- //static struct ISO9660_TAG {
- typedef struct {
- // Session information
- DWORD dwSessionStartLBN;
- // Unicode support
- BOOL bIsUsingUnicode;
- // Volume information
- DWORD dwRootDirICB;
- DWORD dwCurrDirICB;
- // Current Working-Directory storage
- BOOL bCWDStored;
- DWORD dwCWDStorage;
- // Directory Hierarchy Tree
- UINT16 uDirectoryCnt;
- UINT32 hDirTree;
- } ISO9660_TAG;//g_ISO9660Info;
- */
- ISO9660_TAG * g_pISO9660Info;
- /////////////////////////////////////////////////////////////////////////////
- // Internal Structures / Types
- typedef struct ISO9660_DirectorySearchInfo_TAG {
- // Directory Location and Size related
- DWORD dwDirICB; // Location of the Directory
- UINT16 uDirNumber; // Serial Number
- DWORD dwDirectorySize; // In Bytes
- // Search Criteria related
- LPWSTR pszFileID; // The Pattern/Name to search for
- UINT8 uFileFlagsMask; // A Mask to apply to File-Flags
- UINT8 uFileFlags; // The required File-Flags
- // Search Status/Position related
- WORD hDirFileRecordList;
- UINT32 cbRecListOffset; // In Bytes from the Directory's start
- UINT16 cbCurrRecOffset; // In Bytes from the Record-List start
- } DirectorySearchInfo;
- typedef struct DirectoryNode_TAG {
- UINT16 uParentDirNumber;
- DWORD dwDirICB;
- } DirectoryNode;
- #define MAX_FILEREC_SIZE (sizeof(struct DirFileRecord) + MAX_ID_LENGTH + 2)
- /////////////////////////////////////////////////////////////////////////////
- // Forward-Declarations of Private-Services
- static BOOL _buildDirectoryTree(DWORD dwPathTableAddress, DWORD dwPathTableSize);
- static UINT16 _findFirstFileRecord(LPCWSTR i_pszFileID, UINT8 uFileFlagsMask,
- UINT8 uFileFlags,
- struct DirFileRecord **o_pFileRecordPtr);
- static BOOL _findNextFileRecord(UINT16 uSearchID, struct DirFileRecord **o_pFileRecordPtr);
- static BOOL _findClose(UINT16 uSearchID);
- static void _getFileAttributes(const struct DirFileRecord *i_pFileRec, FindData *o_pFindData);
- /////////////////////////////////////////////////////////////////////////////
- // Detection
- /////////////////////////////////////////////////////////////////////////////
- // ISO9660_isResident()
- //
- // Description: Tests a given LBN to detect whether or not an instance of
- // ISO-9660 is resident on the Medium at that location.
- //
- // Input: dwCandidateLBN - The candidate LBN to test.
- // Output: None
- // In/Out: None
- // Return: TRUE if an ISO-9660 instance was found at the specified LBN;
- // FALSE otherwise.
- //
- // Remarks:
- // The method assumes that the given LBN is the beginning of a
- // Volume-Recognition Sequence, and searches for the Standard-ID associated
- // with ISO-9660.
- BOOL ISO9660_isResident(DWORD dwCandidateLBN)
- {
- struct GenericVolumeStructureDesc_Base gvsdVolumeDesc;
- dbg_printf(("ISO9660_isResident(0x%08x) calling.n", dwCandidateLBN));
- // Load the first Volume-Structure Descriptor within the Volume-Recognition-Sequence
- if (! AuxCache_GetBytes((dwCandidateLBN + VOLUME_RECOGNITION_SEQUENCE_START_LSN), 0,
- sizeof(gvsdVolumeDesc), (BYTE*)&gvsdVolumeDesc))
- {
- dbg_printf(("WARNING: ISO9660_isResident() Failed [1]n"));
- return FALSE;
- }
- // Check for an ISO-9660 Standard-ID
- if (0 == strncmp((LPCSTR)gvsdVolumeDesc.aStandardID, STANDARD_ID_CD001, STANDARD_ID_LEN))
- return TRUE;
- return FALSE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // Construction / Destruction
- /////////////////////////////////////////////////////////////////////////////
- // ISO9660_construct()
- //
- // Description: Constructs the File-System, and allocates system resources
- // needed for correct operation.
- //
- // Input: dwSessionStartLBN - The Start-LBN of the current Session.
- // Output: None
- // In/Out: None
- // Return: None
- //
- // Remarks:
- // This method must be called prior to initialization of the File-System.
- void ISO9660_construct(DWORD dwSessionStartLBN)
- {
- dbg_printf(("ISO9660_construct(0x%08x) calling.n", dwSessionStartLBN));
- if( g_pISO9660Info != NULL)
- {
- free(g_pISO9660Info);
- }
- g_pISO9660Info = (FileInfo *)malloc(sizeof(FileInfo));
- if(NULL == g_pISO9660Info)
- {
- tr_printf(("ISO9660_construct() failed--alloc memory for g_pISO9660Info failed.n"));
- return;
- }
- // Record the Session-Start Address
- g_pISO9660Info->dwSessionStartLBN= dwSessionStartLBN;
- // Initialize the Directory-Tree Handle
- g_pISO9660Info->hDirTree= NULL;
- // Reset the Search-Info Pool
- if (! _FileSys_resetSearchInfoPool(sizeof(DirectorySearchInfo))) {
- tr_printf(("FATAL: ISO9660_construct() Failed [1]n"));
- }
- return;
- }
- /////////////////////////////////////////////////////////////////////////////
- // ISO9660_destruct()
- //
- // Description: Destructs the File-System, and frees system resources
- // allocated during the operation.
- //
- // Input: None
- // Output: None
- // In/Out: None
- // Return: None
- //
- // Remarks:
- // This method should be called when the File-System is no longer needed.
- void ISO9660_destruct(void)
- {
- dbg_printf(("ISO9660_destruct() callingn"));
- // Free the Directory-Tree
- if (NULL != g_pISO9660Info->hDirTree) {
- Array_destruct(g_pISO9660Info->hDirTree);
- g_pISO9660Info->hDirTree= NULL;
- }
- if(NULL != g_pISO9660Info)
- {
- free(g_pISO9660Info);
- g_pISO9660Info = NULL;
- }
- return;
- }
- /////////////////////////////////////////////////////////////////////////////
- // Initialization
- /////////////////////////////////////////////////////////////////////////////
- // ISO9660_initialize()
- //
- // Description: Initializes the File-System and switches to the Root
- // directory.
- //
- // 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. Supplying a value of FALSE in bLongFilenameSupport forces use
- // of Filenames in 8.3 format, even if the Medium carries a Joliet
- // extension for Long-Filenames.
- // 3. The File-System information is taken from the last Closed-Session on
- // the Medium.
- BOOL ISO9660_initialize(BOOL bLongFilenameSupport)
- {
- BOOL bRootDirEstablished= FALSE;
- DWORD dwCurrDescLBN;
- struct GenericVolumeStructureDesc_Base *pCurrDescHdr;
- struct VolumeDesc_Partial *pPartialVolDesc;
- dbg_printf(("ISO9660_initialize() calling.n"));
- if(!ISO9660_checkValid())
- return FALSE;
- // Allocate space for a generic Descriptor base
- pCurrDescHdr= (struct GenericVolumeStructureDesc_Base*)malloc(sizeof(struct GenericVolumeStructureDesc_Base));
- if (NULL == pCurrDescHdr) {
- tr_printf(("FATAL: ISO9660_initialize() Failed [1]: Low system resourcesn"));
- return FALSE;
- }
- // Allocate space for a Partial Volume Descriptor (will be used for Primary or Supplemantary
- // Volume descriptors).
- pPartialVolDesc = (struct VolumeDesc_Partial*)malloc(sizeof(struct VolumeDesc_Partial));
- if (NULL == pPartialVolDesc) {
- tr_printf(("FATAL: ISO9660_initialize() Failed [2]: Low system resourcesn"));
- free(pCurrDescHdr);
- return FALSE;
- }
- g_pISO9660Info->bIsUsingUnicode= FALSE;
- // Start searching for the Primary or Supplementary Volume Descriptor, while verifying the
- // integrity of the Volume-Recognition Sequence.
- dwCurrDescLBN= (g_pISO9660Info->dwSessionStartLBN + VOLUME_RECOGNITION_SEQUENCE_START_LSN);
- while (TRUE)
- {
- // Read the first few bytes in order to determine the type of the descriptor
- if (! AuxCache_GetBytes(dwCurrDescLBN, 0, sizeof(struct GenericVolumeStructureDesc_Base),
- (BYTE *)pCurrDescHdr))
- {
- dbg_printf(("WARNING: ISO9660_initialize() Failed [3]n"));
- break;
- }
- // Check for a Primary-Volume
- if (DESC_TYPE_PRIMARY_VOLUME == pCurrDescHdr->uVolumeDescType)
- {
- // Read the essential part of the descriptor
- if (! AuxCache_GetBytes(dwCurrDescLBN, PARTIAL_VOLUME_DESC_OFFSET,
- sizeof(struct VolumeDesc_Partial), (BYTE *)pPartialVolDesc))
- {
- dbg_printf(("WARNING: ISO9660_initialize() Failed [4]n"));
- break;
- }
- #ifdef HW_POWER_ON_RESUME
- {
- // Calculate checksum here for poweron resume
- // Calculating checksum using simple mechanism of adding each byte of the
- int i;
- BYTE * pTmp = 0;
- pTmp = (BYTE*)&pPartialVolDesc->dwVolumeSpaceSize;
- NewChecksum = 0;
- for (i=0;i<32;i++)
- NewChecksum+=pPartialVolDesc->sVolumeID[i];
- for (i=0;i<8;i++)
- NewChecksum += *pTmp++; //Add 8 bytes of volume space size.
- }
- #endif//HW_POWER_ON_RESUME
- // Collect information of the Root-Directory
- g_pISO9660Info->dwRootDirICB= BB_DWORD(pPartialVolDesc->rdrRootDir.dwExtentLocation);
- bRootDirEstablished= TRUE;
- dbg_printf(("Primary Volume Descriptor found.n"));
- // Copy the Primary-Volume Name
- pPartialVolDesc->sVolumeID[SHORT_ID_LENGTH]= 0;
- sc_SetBytes(SC_VOLUME_ID_ADDR, 0, FILESYSTEM_MAX_VOLUME_NAME*sizeof(WCHAR), pPartialVolDesc->sVolumeID);
- dbg_printf(("Volume-ID: '%s'n", (LPCSTR)pPartialVolDesc->sVolumeID));
- // Build the Directory-Hierarchy Tree, based on the M-Type Path-Table or the L-Type Path-Table
- #ifdef MOTOROLA
- if (! _buildDirectoryTree(pPartialVolDesc->dwLoactionOfMPathTable, BB_DWORD(pPartialVolDesc->dwPathTableSize))) {
- dbg_printf(("Failed to build the Directory-Hierarchy Tree.n"));
- }
- #else
- if (! _buildDirectoryTree(pPartialVolDesc->dwLocationOfLPathTable, BB_DWORD(pPartialVolDesc->dwPathTableSize))) {
- dbg_printf(("Failed to build the Directory-Hierarchy Tree.n"));
- }
- #endif //MOTOROLA
- dwCurrDescLBN++; // Move to the next Descriptor
- continue;
- }
- // Check for a Supplementary Volume
- if (DESC_TYPE_SUPPL_VOLUME == pCurrDescHdr->uVolumeDescType)
- {
- if (! AuxCache_GetBytes(dwCurrDescLBN, PARTIAL_VOLUME_DESC_OFFSET,
- sizeof(struct VolumeDesc_Partial), (BYTE *)pPartialVolDesc))
- {
- dbg_printf(("WARNING: ISO9660_initialize() Failed [5]n"));
- break;
- }
- // Check if the Supplementary Volume describes a Joliet extension to ISO-9660
- if ((0x25 == pPartialVolDesc->aEscapeSequences[0]) &&
- (0x2F == pPartialVolDesc->aEscapeSequences[1]))
- {
- BYTE ucJolietLevel= pPartialVolDesc->aEscapeSequences[2];
- if ((0x40 == ucJolietLevel) || (0x43 == ucJolietLevel) || (0x45 == ucJolietLevel)) {
- dbg_printf(("Joliet Extension Level-%d detected.n",
- ((0x40 == ucJolietLevel) ? 1 : ((0x43 == ucJolietLevel) ? 2 : 3))));
- // Collect information of the Supplementary Root-Directory
- if (bLongFilenameSupport)
- {
- g_pISO9660Info->dwRootDirICB= BB_DWORD(pPartialVolDesc->rdrRootDir.dwExtentLocation);
- g_pISO9660Info->bIsUsingUnicode= TRUE;
- bRootDirEstablished= TRUE;
- // Collect the Directory-Hierarchy Tree, based on the M/L-Type Path-Table
- #ifdef MOTOROLA
- if (! _buildDirectoryTree(pPartialVolDesc->dwLoactionOfMPathTable, BB_DWORD(pPartialVolDesc->dwPathTableSize))) {
- dbg_printf(("Failed to build the Directory-Hierarchy Tree.n"));
- }
- #else
- if (! _buildDirectoryTree(pPartialVolDesc->dwLocationOfLPathTable, BB_DWORD(pPartialVolDesc->dwPathTableSize))) {
- dbg_printf(("Failed to build the Directory-Hierarchy Tree.n"));
- }
- #endif //MOTOROLA
- }
- }
- else {
- dbg_printf(("Unexpected Joliet Extension Level found. Ignored.n"));
- }
- }
- dwCurrDescLBN++; // Skip to the next Descriptor
- continue;
- }
- // Check for a Terminator
- if (( (DESC_TYPE_BOOT != pCurrDescHdr->uVolumeDescType) &&
- (DESC_TYPE_PRIMARY_VOLUME != pCurrDescHdr->uVolumeDescType) &&
- (DESC_TYPE_SUPPL_VOLUME != pCurrDescHdr->uVolumeDescType) &&
- (DESC_TYPE_VOLUME_PARTITION != pCurrDescHdr->uVolumeDescType) ) ||
- ((dwCurrDescLBN - g_pISO9660Info->dwSessionStartLBN) >= 20))
- {
- dbg_printf(("Volume-Recognition-Sequence Termination found.n"));
- break;
- }
- #ifdef _DEBUG
- // Check for a Boot-Record
- if (DESC_TYPE_BOOT == pCurrDescHdr->uVolumeDescType) {
- dbg_printf(("Boot Descriptor found.n"));
- dwCurrDescLBN++; // Skip to the next Descriptor
- continue;
- }
- // Check for a Volume-Partition
- if (DESC_TYPE_VOLUME_PARTITION == pCurrDescHdr->uVolumeDescType) {
- dbg_printf(("Volume-Partition Descriptor found.n"));
- dwCurrDescLBN++; // Skip to the next Descriptor
- continue;
- }
- #endif //_DEBUG
- // Any other type -- skip
- dbg_printf(("Skipping Volume-Descriptor of type: 0x%02x.n", pCurrDescHdr->uVolumeDescType));
- dwCurrDescLBN++;
- } //endof while()
- // When this point is reached, the entire File-Set Descriptor Sequence has been
- // scanned, and the Root-Directory's ICB possibly established.
- free(pCurrDescHdr);
- free(pPartialVolDesc);
- // Set the Current Directory to the Root-Directory, if it was established.
- if (bRootDirEstablished)
- g_pISO9660Info->dwCurrDirICB= g_pISO9660Info->dwRootDirICB;
- // Currently, no CWD is stored
- g_pISO9660Info->bCWDStored= FALSE;
- return bRootDirEstablished;
- }
- /////////////////////////////////////////////////////////////////////////////
- // Navigation
- /////////////////////////////////////////////////////////////////////////////
- // ISO9660_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 ISO9660_goToRootDir(void)
- {
- dbg_printf(("ISO9660_goToRootDir() calling.n"));
- g_pISO9660Info->dwCurrDirICB= g_pISO9660Info->dwRootDirICB;
- return TRUE;
- }
- DWORD ISO9660_GetcurrentDirICB(void)
- {
- return g_pISO9660Info->dwCurrDirICB;
- }
- void ISO9660_SetCurrentDirICB(DWORD CurrentDirICB)
- {
- g_pISO9660Info->dwCurrDirICB = CurrentDirICB;
- }
- /////////////////////////////////////////////////////////////////////////////
- // ISO9660_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. 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 ISO9660_changeDir(LPCWSTR i_pszDestDirName)
- {
- UINT16 hFileRecFind;
- struct DirFileRecord *pDestDirRec;
- dbg_printf(("ISO9660_changeDir() calling.n"));
- // Try to locate a Directory/File Record corresponding to the required Directory
- hFileRecFind= _findFirstFileRecord(i_pszDestDirName, FILE_FLAGS_DIRECTORY,
- FILE_FLAGS_DIRECTORY, &pDestDirRec);
- if (NULL == hFileRecFind)
- return FALSE;
- // The appropriate Directory was found: record the location of its ICB for
- // future use.
- g_pISO9660Info->dwCurrDirICB= BB_DWORD(pDestDirRec->dwExtentLocation);
-
- // Free the file record and terminate the search
- free(pDestDirRec);
- _findClose(hFileRecFind);
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // ISO9660_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 ISO9660_goUp(void)
- {
- WCHAR szParentDirname[2];
- UINT16 hFileRecFind;
- struct DirFileRecord *pParentDirRec;
- dbg_printf(("ISO9660_goUp() calling.n"));
- // Prohibit climbing up from the Root Directory
- if (g_pISO9660Info->dwRootDirICB == g_pISO9660Info->dwCurrDirICB)
- return TRUE;
- // Locate the Parent-Directory of the Current Directory
- _str2wcs(FILE_FILEID_PARENT, szParentDirname, sizeof(szParentDirname));
- hFileRecFind= _findFirstFileRecord((LPCWSTR)szParentDirname, FILE_FLAGS_DIRECTORY,
- FILE_FLAGS_DIRECTORY, &pParentDirRec);
- if (NULL == hFileRecFind)
- return FALSE;
- // Record the location of the Parent-Directory
- g_pISO9660Info->dwCurrDirICB= BB_DWORD(pParentDirRec->dwExtentLocation);
- // Free the file record and terminate the search
- free(pParentDirRec);
- _findClose(hFileRecFind);
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // ISO9660_storeWorkingDirectory()
- //
- // Description: Stores the position of the Current Working Directory.
- //
- // Input: None
- // Output: None
- // In/Out: None
- // Return: None
- //
- // Remarks:
- // The position of the Current Directory is unconditionally stored, and may
- // be later recalled via ISO0660_recallWorkingDirectory().
- // This method is useful for peeking into different directories, and then
- // restoring the original Working-Directory.
- void ISO9660_storeWorkingDirectory(void)
- {
- // Store the Working-Directory and set the Storage indicator
- g_pISO9660Info->dwCWDStorage= g_pISO9660Info->dwCurrDirICB;
- g_pISO9660Info->bCWDStored= TRUE;
- return;
- }
- /////////////////////////////////////////////////////////////////////////////
- // ISO0660_recallWorkingDirectory()
- //
- // Description: Recalls the position of the Current Working Directory.
- //
- // Input: None
- // Output: None
- // In/Out: None
- // Return: None
- //
- // Remarks:
- // The position of the Current Directory is stored only if it has been
- // previously stored via ISO9660_storeWorkingDirectory().
- void ISO9660_recallWorkingDirectory(void)
- {
- // Restore the Working-Directory
- if (g_pISO9660Info->bCWDStored)
- g_pISO9660Info->dwCurrDirICB= g_pISO9660Info->dwCWDStorage;
- // Clear the Storage indicator
- g_pISO9660Info->bCWDStored= FALSE;
- return;
- }
- /////////////////////////////////////////////////////////////////////////////
- // Queries
- /////////////////////////////////////////////////////////////////////////////
- // ISO9660_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.
- //
- // Remarks:
- // The returned String must not be modified or freed by the caller.
- void ISO9660_getVolumeName(LPCWSTR volumeName)
- {
- sc_GetBytes(SC_VOLUME_ID_ADDR, 0, FILESYSTEM_MAX_VOLUME_NAME*sizeof(WCHAR), (BYTE*)volumeName);
- return;
- }
- /////////////////////////////////////////////////////////////////////////////
- // ISO9660_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 ISO9660_fileExists(LPCWSTR i_pszFilename)
- {
- UINT16 hFileRecFind;
- struct DirFileRecord *pDestDirRec;
- dbg_printf(("ISO9660_fileExists() calling.n"));
- // Try to locate a File-ID Descriptor corresponding to the required File; Specify
- // that the required file must be non-directory, not hidden, not a Parent, and undeleted.
- hFileRecFind= _findFirstFileRecord(i_pszFilename,
- (FILE_FLAGS_DIRECTORY | FILE_FLAGS_HIDDEN),
- 0x0, &pDestDirRec);
- if (NULL == hFileRecFind)
- return FALSE;
- // Free the file record and terminate the search
- free(pDestDirRec);
- _findClose(hFileRecFind);
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // ISO9660_fileLocation()
- //
- // 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 ISO9660_fileLocation(LPCWSTR i_pszFilename, DWORD *o_pFileLocation)
- {
- UINT16 hFileRecFind;
- struct DirFileRecord *pFileRec;
- dbg_printf(("ISO9660_fileLocation() calling.n"));
- // Try to locate a Directory/File Record corresponding to the required File; Specify
- // that the required file must be non-directory and not hidden.
- hFileRecFind= _findFirstFileRecord(i_pszFilename,
- (FILE_FLAGS_DIRECTORY | FILE_FLAGS_HIDDEN),
- 0x0, &pFileRec);
- if (NULL == hFileRecFind)
- return FALSE;
- *o_pFileLocation= BB_DWORD(pFileRec->dwExtentLocation);
- // Free the file record and terminate the search
- free(pFileRec);
- _findClose(hFileRecFind);
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // ISO9660_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. The search is limited to the current working-directory only.
- // 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. ISO9660_findClose() must be called when no additional searches are needed.
- UINT16 ISO9660_findFirstFile(LPCWSTR i_pszPattern, FindData *o_pFindData)
- {
- UINT16 hFileRecFind;
- struct DirFileRecord *pFileRec;
- dbg_printf(("ISO9660_findFirstFile() calling.n"));
- // Try to locate a Directory/File Record corresponding to the required File.
- // There are no restrictions over the file's Attributes (find any File/Directory).
- hFileRecFind= _findFirstFileRecord(i_pszPattern, 0x0, 0x0, &pFileRec);
- if (NULL == hFileRecFind)
- return NULL;
- // Acquire the found item's Attributes
- _getFileAttributes((const struct DirFileRecord *)pFileRec, o_pFindData);
- // Free the found record
- free(pFileRec);
- return hFileRecFind;
- }
- /////////////////////////////////////////////////////////////////////////////
- // ISO9660_findNextFile()
- //
- // Description: Continues a search that was previously initiated using a call
- // to ISO9660_findFirstFile().
- //
- // Input: hFindFile - A Handle to a file-search, that was returned from
- // a previous call to ISO9660_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 the current working-
- // directory at the time the search was initiated via ISO9660_findFirstFile().
- // 3. The search uses the same Filename/pattern as was originally supplied
- // to ISO9660_findFirstFile().
- // 4. ISO9660_findClose() must be called when no additional searches are needed.
- BOOL ISO9660_findNextFile(UINT16 hFindFile, FindData *o_pFindData)
- {
- struct DirFileRecord *pFileRec;
- dbg_printf(("ISO9660_findNextFile() calling.n"));
- // Continue the Search
- if (! _findNextFileRecord((WORD)hFindFile, &pFileRec))
- return FALSE;
- // Acquire the found item's Attributes
- _getFileAttributes((const struct DirFileRecord *)pFileRec, o_pFindData);
- // Free the found record
- free(pFileRec);
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // ISO9660_findClose()
- //
- // Description: Terminates a file-search.
- //
- // Input: hFindFile - A Handle to a file-search, that was returned from
- // a previous call to ISO9660_findFirstFile().
- // Output: None
- // In/Out: None
- // Return: TRUE if the search was successfully terminated; FALSE othewise.
- //
- // Remarks:
- // Any search that is initiated via ISO9660_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 ISO9660_findClose(UINT16 hFileFind)
- {
- dbg_printf(("ISO9660_findClose() calling.n"));
- return _findClose((WORD)hFileFind);
- }
- /////////////////////////////////////////////////////////////////////////////
- // ISO9660_getFilesFirst()
- //
- // Description: Get all files in the indicated directory.
- //
- // Input: LPCWSTR i_pszFilename: The directory name which want to get from
- // UINT16 uGetFileCount: The files count which want get
- //
- // Output: UINT16 *o_uGetFileNum: The files count which has been get
- // FindData *o_pGetData: Points to a FindData structure, to receive the File's
- // details upon successful completion of the search.
- //
- // In/Out: None
- // Return: A UINT16, which is the ID of the search, and should be passed
- // to future calls to any of the search-related methods.
- // NULL is returned if no File matching the requested criteria could
- // be found.
- //
- // Remarks:
- // Any search that is initiated via ISO9660_getFilesFirst() must be terminated
- // using a call to this method, in order to allow for proper release of
- // resources that were allocated for that search.
- // If the call to ISO9660_getFilesFirst() returned NULL, it is prohibited
- // to call ISO9660_getFilesClose().
- // If you want to get current directory, you can give the i_pszFilename with L""
- // If you want to get parent directory, you can give the i_pszFilename with L"1"
- // If you want to get root directory, you can give the i_pszFilename with L"\"
- UINT16 ISO9660_getFilesFirst(LPCWSTR i_pszFilename, UINT16 uGetFileCount, UINT16 *o_uGetFileNum, FindData *o_pGetData)
- {
- BOOL bSuccess;
- UINT16 hFileRecFind;
- struct DirFileRecord *pFileRec;
- DirectorySearchInfo dsiInfo;
- UINT16 uSearchID;
-
- dbg_printf(("ISO9660_getFilesFirst() calling.n"));
- if( (i_pszFilename[0]==(WCHAR)'\' || i_pszFilename[0]==(WCHAR)'')
- && i_pszFilename[1]==0)
- {
- if(i_pszFilename[0]==(WCHAR)'\' && i_pszFilename[1]==0)
- dsiInfo.dwDirICB=g_pISO9660Info->dwRootDirICB;
- else
- dsiInfo.dwDirICB=g_pISO9660Info->dwCurrDirICB;
- pFileRec=(struct DirFileRecord*)malloc(sizeof(struct DirFileRecord)+1);
- if (NULL == pFileRec)
- {
- dbg_printf(("WARNING: ISO9660_getFilesFirst() Failed [1]:n"));
- *o_uGetFileNum=0;
- return NULL;
- }
-
- if(!AuxCache_GetBytes(dsiInfo.dwDirICB, 0, sizeof(struct DirFileRecord)+1, (BYTE*)pFileRec))
- {
- dbg_printf(("WARNING: ISO9660_getFilesFirst() Failed [2]:n"));
- free(pFileRec);
- *o_uGetFileNum=0;
- return NULL;
- }
- if(1 == pFileRec->cbLengthOfFileID && 0 == pFileRec->sFileID[0])
- dsiInfo.dwDirectorySize = BB_DWORD( pFileRec->dwDataLength );
- else
- {
- dbg_printf(("WARNING: ISO9660_getFilesFirst() Failed [3]: Directory record was error.n"));
- free(pFileRec);
- *o_uGetFileNum=0;
- return NULL;
- }
- free(pFileRec);
- }
- else
- {
- hFileRecFind= _findFirstFileRecord(i_pszFilename,FILE_FLAGS_DIRECTORY,
- FILE_FLAGS_DIRECTORY, &pFileRec);
- if (NULL == hFileRecFind)
- {
- dbg_printf(("WARNING: ISO9660_getFilesFirst() Failed [4]: Directory no found.n"));
- *o_uGetFileNum=0;
- return NULL;
- }
- dsiInfo.dwDirICB = BB_DWORD( pFileRec->dwExtentLocation );
- dsiInfo.dwDirectorySize = BB_DWORD( pFileRec->dwDataLength );
-
- // Free the file record and terminate the search
- free(pFileRec);
- _findClose(hFileRecFind);
- }
-
- dsiInfo.uDirNumber = 0;
- dsiInfo.pszFileID = NULL;
- dsiInfo.uFileFlagsMask = 0;
- dsiInfo.uFileFlags = 0;
- dsiInfo.hDirFileRecordList = 0;
- dsiInfo.cbRecListOffset = 0;
- dsiInfo.cbCurrRecOffset = 0;
- // Allocate a Search-Info
- uSearchID= _FileSys_allocateSearchInfo();
- if (NULL == uSearchID) {
- dbg_printf(("WARNING: ISO9660_getFilesFirst() Failed [5]: No available Search-Info IDn"));
- *o_uGetFileNum=0;
- return NULL;
- }
- // Register the Directory-Search Info in the Search-Info Pool
- bSuccess= _FileSys_setSearchInfo(uSearchID, (const BYTE*)&dsiInfo);
- if (! bSuccess) {
- dbg_printf(("FATAL: ISO9660_getFilesFirst() Failed [6]: Cannot register new Searchn"));
- }
- // Now, the information in dsiInfo is stable and complete: perform the search
- if (bSuccess)
- if(!(*o_uGetFileNum = ISO9660_getFilesNext(uSearchID, uGetFileCount, o_pGetData)))
- {
- dbg_printf(("WARNING: ISO9660_getFilesFirst() Failed [7]: Could not find a matchn"));
- bSuccess= FALSE;
- }
- if (! bSuccess) {
- _FileSys_freeSearchInfo(uSearchID);
- *o_uGetFileNum=0;
- return NULL;
- }
- return uSearchID;
- }
- /////////////////////////////////////////////////////////////////////////////
- // ISO9660_getFilesNext()
- //
- // Description: Continues to get the files that was previously initiated using a call
- // to ISO9660_getFilesFirst().
- //
- // Input: UINT16 hFindFile: A Handle to a file-search, that was returned from
- // a previous call to ISO9660_getFilesFirst().
- // UINT16 uGetFileCount:
- // Output: FindData *o_pGetData: Points to a FindData structure, to receive the File's
- // details upon successful completion of the search.
- // In/Out: None
- // Return: >0 if the search succeeded, and return the get files count.
- // and the o_pGetData is valid.
- // 0 is returned if no more Files could be get. In this case, the
- // supplied o_pGetData 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 the current working-
- // directory at the time the search was initiated via ISO9660_getFilesFirst().
- // 3. The search uses the same Filename/pattern as was originally supplied
- // to ISO9660_findFirstFile().
- // 4. ISO9660_findClose() must be called when no additional searches are needed.
- UINT16 ISO9660_getFilesNext(UINT16 uSearchID,UINT16 uGetFileCount, FindData *o_pGetData)
- {
- UINT16 uGetNum=0;
- struct DirFileRecord *pRec;
- DirectorySearchInfo dsiInfo;
- LPWSTR pszSeparator2;
- dbg_printf(("ISO9660_getFilesNext() calling.n"));
- // Retrieve the Directory-Search Info from the Search-Pool
- if ((NULL == uSearchID) ||
- ! _FileSys_getSearchInfo(uSearchID, (BYTE*)&dsiInfo))
- {
- dbg_printf(("WARNING: ISO9660_getFilesNext() Failed [1]: Directory no found.n"));
- return FALSE;
- }
- if(dsiInfo.cbRecListOffset >= dsiInfo.dwDirectorySize)
- {
- dbg_printf(("WARNING: ISO9660_getFilesNext() Failed [2]: This directory has already get all files.n"));
- return 0;
- }
- pRec= (struct DirFileRecord *)malloc(MAX_FILEREC_SIZE);
- if (NULL == pRec) {
- tr_printf(("FATAL: ISO9660_getFilesNext() Failed [3]: Low system resourcesn"));
- return NULL;
- }
- for(uGetNum=0;( uGetNum<uGetFileCount ) && ( dsiInfo.cbRecListOffset < dsiInfo.dwDirectorySize );
- uGetNum++)
- {
- if (! AuxCache_GetBytes(dsiInfo.dwDirICB+dsiInfo.cbRecListOffset/2048, dsiInfo.cbRecListOffset%2048,
- MAX_FILEREC_SIZE, (BYTE*)pRec))
- {
- dbg_printf(("WARNING: ISO9660_getFilesNext() Failed [4]n"));
- free(pRec);
- return NULL;
- }
- if( 0 == pRec->cbLengthOfDirRecord )
- {
- dsiInfo.cbRecListOffset = (dsiInfo.cbRecListOffset/2048 + 1) * 2048;
- uGetNum--;
- continue;
- }
- else
- dsiInfo.cbRecListOffset += pRec->cbLengthOfDirRecord;
- _getFileAttributes(pRec,&(o_pGetData[uGetNum]));
- }
- free(pRec);
- // Update the Directory-Search Info in the Search-Pool
- if (! _FileSys_setSearchInfo(uSearchID, (const BYTE*)&dsiInfo)) {
- dbg_printf(("WARNING: ISO9660_getFilesNext() Failed [5]n"));
- }
- return uGetNum;
- }
- /////////////////////////////////////////////////////////////////////////////
- // ISO9660_getFilesClose()
- //
- // Description: Terminates a file-get.
- //
- // Input: hFindFile - A Handle to a file-search, that was returned from
- // a previous call to ISO9660_getFilesFirst().
- // Output: None
- // In/Out: None
- // Return: TRUE if the search was successfully terminated; FALSE othewise.
- //
- // Remarks:
- // Any search that is initiated via ISO9660_getFilesFirst() 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 ISO9660_getFilesClose(UINT16 uSearchID)
- {
- DirectorySearchInfo dsiInfo;
-
- dbg_printf(("ISO9660_getFilesClose() calling.n"));
- // Retrieve the Directory-Search Info from the Search-Pool
- if ((NULL == uSearchID) ||
- ! _FileSys_getSearchInfo(uSearchID, (BYTE*)&dsiInfo))
- {
- return FALSE;
- }
- _FileSys_freeSearchInfo(uSearchID);
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // ISO9660_checkValid()
- //
- // Description: Check whether the ISO9660 file system was valid or not
- //
- // Input: None
- // Output: None
- // In/Out: None
- // Return: TRUE if the ISO9660 File-System was valid; FALSE otherwise.
- //
- // Remarks:
- // 1. Check whether the ISO9660 path table was empty or not
- //
- BOOL ISO9660_checkValid()
- {
- BOOL iso9660_valid=TRUE;
- DWORD dwCurrDescLBN;
- DWORD dwRootDirICB,dwPathTableICB,dwPathTableSize;
- DWORD dwTemp;
- DWORD dwOffset=0;
- struct PathTableRecord *pCurrRec;
- struct GenericVolumeStructureDesc_Base *pCurrDescHdr;
- struct VolumeDesc_Partial *pPartialVolDesc;
- dbg_printf(("ISO9660_checkValid() calling.n"));
- // Allocate space for a generic Descriptor base
- pCurrDescHdr= (struct GenericVolumeStructureDesc_Base*)malloc(sizeof(struct GenericVolumeStructureDesc_Base));
- if (NULL == pCurrDescHdr) {
- tr_printf(("FATAL: ISO9660_checkValid() Failed [1]: Low system resourcesn"));
- return FALSE;
- }
- // Allocate space for a Partial Volume Descriptor (will be used for Primary or Supplemantary
- // Volume descriptors).
- pPartialVolDesc = (struct VolumeDesc_Partial*)malloc(sizeof(struct VolumeDesc_Partial));
- if (NULL == pPartialVolDesc) {
- tr_printf(("FATAL: ISO9660_checkValid() Failed [2]: Low system resourcesn"));
- free(pCurrDescHdr);
- return FALSE;
- }
- // Start searching for the Primary or Supplementary Volume Descriptor, while verifying the
- // integrity of the Volume-Recognition Sequence.
- dwCurrDescLBN= (g_pISO9660Info->dwSessionStartLBN + VOLUME_RECOGNITION_SEQUENCE_START_LSN);
- while (TRUE)
- {
- // Read the first few bytes in order to determine the type of the descriptor
- if (! AuxCache_GetBytes(dwCurrDescLBN, 0, sizeof(struct GenericVolumeStructureDesc_Base),
- (BYTE *)pCurrDescHdr))
- {
- dbg_printf(("WARNING: ISO9660_checkValid() Failed [3]n"));
- break;
- }
-
- // Check for a Primary-Volume
- if (DESC_TYPE_PRIMARY_VOLUME == pCurrDescHdr->uVolumeDescType)
- {
- // Read the essential part of the descriptor
- if (! AuxCache_GetBytes(dwCurrDescLBN, PARTIAL_VOLUME_DESC_OFFSET,
- sizeof(struct VolumeDesc_Partial), (BYTE *)pPartialVolDesc))
- {
- dbg_printf(("WARNING: ISO9660_checkValid() Failed [4]n"));
- iso9660_valid=FALSE;
- break;
- }
- // Collect information of the Root-Directory
- dwRootDirICB = BB_DWORD(pPartialVolDesc->rdrRootDir.dwExtentLocation);
- // Build the Directory-Hierarchy Tree, based on the M-Type Path-Table or the L-Type Path-Table
- #ifdef MOTOROLA
- dwPathTableICB = pPartialVolDesc->dwLoactionOfMPathTable;
- #else
- dwPathTableICB = pPartialVolDesc->dwLocationOfLPathTable;
- #endif //MOTOROLA
- dwPathTableSize = BB_DWORD(pPartialVolDesc->dwPathTableSize);
- dwOffset=0;
- while(TRUE)
- {
- // Allocate room for a single Path-Table Record, used for iteration
- pCurrRec= (struct PathTableRecord *)malloc(sizeof(struct PathTableRecord));
- if (NULL == pCurrRec) {
- dbg_printf(("WARNING: ISO9660_checkValid() Failed [5]n"));
- break;
- }
- if (! AuxCache_GetBytes(dwPathTableICB, dwOffset,
- sizeof(struct PathTableRecord), (BYTE *)pCurrRec))
- {
- dbg_printf(("WARNING: ISO9660_checkValid() Failed [6]n"));
- free(pCurrRec);
- iso9660_valid=FALSE;
- break;
- }
- if (0 == pCurrRec->cbLengthOfDirID && 0 == pCurrRec->dwExtentLocation && 0 == pCurrRec->uParentDirNumber)
- {
- dbg_printf(("WARNING: ISO9660_checkValid() Failed [7]: The Path Table is Empty!n"));
- free(pCurrRec);
- if(0 == dwOffset) //jerry cai, only if the first record is invalid, the file system is invalid.
- iso9660_valid=FALSE;
- break;
- }
- dwOffset += (sizeof(struct PathTableRecord) + pCurrRec->cbLengthOfDirID);
- if (pCurrRec->cbLengthOfDirID & 0x1)
- dwOffset++;
- free(pCurrRec);
- if(dwOffset>=dwPathTableSize)
- break;
- }
- dwCurrDescLBN++; // Move to the next Descriptor
- continue;
- }
- // Check for a Terminator
- if (( (DESC_TYPE_BOOT != pCurrDescHdr->uVolumeDescType) &&
- (DESC_TYPE_PRIMARY_VOLUME != pCurrDescHdr->uVolumeDescType) &&
- (DESC_TYPE_SUPPL_VOLUME != pCurrDescHdr->uVolumeDescType) &&
- (DESC_TYPE_VOLUME_PARTITION != pCurrDescHdr->uVolumeDescType) ) ||
- ((dwCurrDescLBN - g_pISO9660Info->dwSessionStartLBN) >= 20))
- {
- dbg_printf(("Volume-Recognition-Sequence Termination found.n"));
- break;
- }
- // Any other type -- skip
- dbg_printf(("Skipping Volume-Descriptor of type: 0x%02x.n", pCurrDescHdr->uVolumeDescType));
- dwCurrDescLBN++;
- } //endof while()
- // When this point is reached, the entire File-Set Descriptor Sequence has been
- // scanned, and the Root-Directory's ICB possibly established.
- free(pCurrDescHdr);
- free(pPartialVolDesc);
- return iso9660_valid;
- }
- /////////////////////////////////////////////////////////////////////////////
- // Private Services
- /////////////////////////////////////////////////////////////////////////////
- // _buildDirectoryTree()
- //
- // Description: Builds an Array describing the Directories, based on the
- // Volume Descriptor's Path-Table.
- //
- // Input: dwPathTableAddress - Holds the starting address of the Path-Table.
- // dwPathTableSize - Holds the size of the Path-Table.
- // Output: None
- // In/Out: None
- // Return: TRUE if the entire Path Table was extracted; FALSE otherwise.
- //
- // Remarks: None
- static BOOL _buildDirectoryTree(DWORD dwPathTableAddress, DWORD dwPathTableSize)
- {
- UINT16 uDirsCnt= 0;
- UINT16 uMaxDirsCnt= (UINT16)(dwPathTableSize / sizeof(struct PathTableRecord));
- DWORD cbCurrRecOffset= 0;
- BOOL bSuccess= TRUE;
- struct PathTableRecord *pCurrRec;
- // Allocate room for a single Path-Table Record, used for iteration
- pCurrRec= (struct PathTableRecord *)malloc(sizeof(struct PathTableRecord));
- if (NULL == pCurrRec) {
- dbg_printf(("WARNING: _buildDirectoryTree() Failed [1]n"));
- return FALSE;
- }
- // If the Directories Tree was previously allocated, free that allocation
- if (NULL != g_pISO9660Info->hDirTree)
- Array_destruct(g_pISO9660Info->hDirTree);
- // Allocate the Array that will hold the Directories-Tree
- g_pISO9660Info->hDirTree= Array_construct(uMaxDirsCnt, sizeof(DirectoryNode), NULL);
- if (NULL == g_pISO9660Info->hDirTree) {
- dbg_printf(("WARNING: _buildDirectoryTree() Failed [2]: Low system resources.n"));
- free(pCurrRec);
- return FALSE;
- }
- // Start scanning the Path-Table, adding new Directories Nodes to the array along the way
- while (cbCurrRecOffset < dwPathTableSize) {
- DirectoryNode dnCurrDir;
- // Read Path-Table's base contents
- if (! AuxCache_GetBytes(dwPathTableAddress, cbCurrRecOffset, sizeof(struct PathTableRecord),
- (BYTE*)pCurrRec))
- {
- dbg_printf(("WARNING: _buildDirectoryTree() Failed [3]n"));
- bSuccess= FALSE;
- break;
- }
- // Copy the Parent-Directory Number and the Extent-Location
- dnCurrDir.uParentDirNumber= pCurrRec->uParentDirNumber;
- dnCurrDir.dwDirICB= pCurrRec->dwExtentLocation;
- // Set the new Directory-Node
- if (! Array_setAt(g_pISO9660Info->hDirTree, uDirsCnt++, (BYTE*)&dnCurrDir)) {
- dbg_printf(("WARNING: _buildDirectoryTree() Failed [4]n"));
- bSuccess= FALSE;
- break;
- }
- // Move to the next Record
- cbCurrRecOffset += (sizeof(struct PathTableRecord) + pCurrRec->cbLengthOfDirID);
- if (pCurrRec->cbLengthOfDirID & 0x1)
- cbCurrRecOffset++;
- }
- free(pCurrRec);
- // Get rid of any Extra-Memory, that was not actually used
- Array_freeExtra(g_pISO9660Info->hDirTree);
- if (bSuccess) {
- // Record the total number of Directories
- g_pISO9660Info->uDirectoryCnt= uDirsCnt;
- }
- else {
- Array_destruct(g_pISO9660Info->hDirTree);
- g_pISO9660Info->hDirTree= NULL;
- }
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // _findFirstFileRecord()
- //
- // Description: Initiates a search for the first occurrence of a File-Record
- // structure describing a File/Sub-Directory that meets the
- // supplied criteria.
- //
- // Input: i_pszFileID - A string holding the requested Filename/pattern.
- // uFileFlagsMask - A Mask to apply to the File's Flags.
- // uFileFlags - A combination of Flags, that should match.
- // Output: o_pFileRecordPtr - Points to a DirFileRecord Pointer, to receive
- // the File-Record of a matching File/Sub-Directory.
- // In/Out: None
- // Return: A UINT16, which is the ID of the search, and should be passed
- // to future calls to any of the search-related methods.
- // NULL is returned if no File matching the requested criteria could
- // be found.
- //
- // Remarks:
- // 1. The supplied i_pszFileID can be a Filename or a pattern, as described
- // in the documentation for ISO9660_findFirstFile().
- // 2. uFileFlagsMask is a Mask that is applied to any File-Record whose
- // File-ID mathces the supplied Filename/pattern. This mask is applied
- // to that item's Flags.
- // 3. uFileFlags is compared against the Masked Flags of a matching item.
- // If there is a match, then the whole item is considered to match the
- // requested criteria.
- // 4. The returned ID should be saved for future use with search-related
- // methods.
- // 5. A return value of NULL indicates that no File/Sub-Directory matching
- // the requested criteria could be found. That might happen also because there
- // isn't enough memory in the system.
- // 6. The search is limited to the current working-directory.
- // 7. The search is Case-Sensitive.
- // 8. The returned File-Record Pointer should be considered persistant
- // across calls. The caller has to make sure that o_pFileRecordPtr
- // is freed when it is no longer needed.
- // 9. _findClose() must be called when no additional searches are needed.
- static UINT16 _findFirstFileRecord(LPCWSTR i_pszFileID, UINT8 uFileFlagsMask,
- UINT8 uFileFlags,
- struct DirFileRecord **o_pFileRecordPtr)
- {
- BOOL bSuccess;
- BOOL bWildcardSearch;
- UINT8 cbFirstRecordSize;
- UINT16 uDirFileRecListSizeInCont;
- UINT16 uDirNodePos;
- UINT16 uSearchID;
- DWORD dwCurrDirSize;
- struct ReservedDirRecord *pRec;
- DirectorySearchInfo dsiInfo;
- // Find the size of the first record and the size of the entire directory.
- // Load only the self descriptor and then save both sizes in local variables.
- // After that there is no need to keep the self descriptor anymore.
- pRec= (struct ReservedDirRecord *)malloc(sizeof(struct ReservedDirRecord));
- if (NULL == pRec) {
- tr_printf(("FATAL: _findFirstFileRecord() Failed [1]: Low system resourcesn"));
- return NULL;
- }
- if (! AuxCache_GetBytes(g_pISO9660Info->dwCurrDirICB, 0, sizeof(struct ReservedDirRecord),
- (BYTE*)pRec))
- {
- dbg_printf(("WARNING: _findFirstFileRecord() Failed [2]n"));
- free(pRec);
- return NULL;
- }
- // Collect the Directory's Size and the size of the first record
- dwCurrDirSize= BB_DWORD(pRec->dwDataLength);
- cbFirstRecordSize= pRec->cbLengthOfDirRecord;
- free(pRec);
- // Check if the Directory has anything in it. I.e., if its size is larger
- // than the length of the first Record (which is the self-descriptor).
- if (dwCurrDirSize == (DWORD)cbFirstRecordSize) {
- // If the Current Directory is Empty, there's no point in continuing the search
- dbg_printf(("Empty Directory found.n"));
- return NULL;
- }
- // Allocate space for the Records List Cache
- uDirFileRecListSizeInCont= CONTAINER_COUNT(DIRECTORY_RECLIST_SZ);
- dsiInfo.hDirFileRecordList= sc_Malloc(uDirFileRecListSizeInCont);
- if (NULL_HANDLE == dsiInfo.hDirFileRecordList) {
- tr_printf(("FATAL: _findFirstFileRecord() Failed [3]: Low system resourcesn"));
- return NULL;
- }
- // Cache the beginning of the Directory's contents (Record-List)
- if (! sc_CopyFromDisc(g_pISO9660Info->dwCurrDirICB, cbFirstRecordSize, DIRECTORY_RECLIST_SZ,
- dsiInfo.hDirFileRecordList))
- {
- dbg_printf(("WARNING: _findFirstFileRecord() Failed [4]n"));
- sc_Free(dsiInfo.hDirFileRecordList, uDirFileRecListSizeInCont);
- return NULL;
- }
- // Copy the necessary information into the DirSearchInfo, and initialize it
- dsiInfo.dwDirICB= g_pISO9660Info->dwCurrDirICB;
- dsiInfo.dwDirectorySize= dwCurrDirSize;
- // In case of a Wildcard search, use a static string for File-ID, instead of allocating
- // memory.
- bWildcardSearch= ((0 == i_pszFileID[0]) ? TRUE : FALSE);
- if (bWildcardSearch) {
- dsiInfo.pszFileID= (LPWSTR)g_pszWildcardSearch;
- }
- else {
- dsiInfo.pszFileID= (LPWSTR)malloc((1 + wcslen(i_pszFileID)) * sizeof(WCHAR));
- if (NULL == dsiInfo.pszFileID) {
- tr_printf(("FATAL: _findFirstFileRecord() Failed [5]: Low system resourcesn"));
- sc_Free(dsiInfo.hDirFileRecordList, uDirFileRecListSizeInCont);
- return NULL;
- }
- wcscpy(dsiInfo.pszFileID, i_pszFileID);
- }
- // Continue to copy necessary information into the DirSearchInfo, and initialize it.
- dsiInfo.uFileFlagsMask= uFileFlagsMask;
- dsiInfo.uFileFlags= uFileFlags;
- // Locate the Directory-Node corresponding to the Current Directory within
- // the Directory-Hierarchy Tree.
- for (uDirNodePos=0; uDirNodePos < g_pISO9660Info->uDirectoryCnt; uDirNodePos++) {
- DirectoryNode dnCurrDir;
- // Retrieve the Current Directory-Node
- if (! Array_getAt(g_pISO9660Info->hDirTree, uDirNodePos, (BYTE*)&dnCurrDir)) {
- dbg_printf(("WARNING: _findFirstFileRecord() Failed [6]n"));
- break;
- }
- if (g_pISO9660Info->dwCurrDirICB == dnCurrDir.dwDirICB) {
- dsiInfo.uDirNumber= uDirNodePos;
- break;
- }
- }
- // Calculate the first Record to examine. This record is the Second record
- // on the Record-List, since the first Record always describes the Current Directory
- // and is not of interest.
- dsiInfo.cbRecListOffset= cbFirstRecordSize;
- dsiInfo.cbCurrRecOffset= 0;
- // Allocate a Search-Info
- uSearchID= _FileSys_allocateSearchInfo();
- if (NULL == uSearchID) {
- dbg_printf(("WARNING: _findFirstFileRecord() Failed [7]: No available Search-Info IDn"));
-
- if (! bWildcardSearch)
- free(dsiInfo.pszFileID);
- sc_Free(dsiInfo.hDirFileRecordList, uDirFileRecListSizeInCont);
- return NULL;
- }
- // Register the Directory-Search Info in the Search-Info Pool
- bSuccess= _FileSys_setSearchInfo(uSearchID, (const BYTE*)&dsiInfo);
- if (! bSuccess) {
- dbg_printf(("FATAL: _findFirstFileRecord() Failed [8]: Cannot register new Searchn"));
- }
- // Now, the information in dsiInfo is stable and complete: perform the search
- if (bSuccess && ! _findNextFileRecord(uSearchID, o_pFileRecordPtr)) {
- dbg_printf(("WARNING: _findFirstFileRecord() Failed [9]: Could not find a matchn"));
- bSuccess= FALSE;
- }
- if (! bSuccess) {
- if (! bWildcardSearch)
- free(dsiInfo.pszFileID);
- sc_Free(dsiInfo.hDirFileRecordList, uDirFileRecListSizeInCont);
- _FileSys_freeSearchInfo(uSearchID);
- return NULL;
- }
- return uSearchID;
- }
- /////////////////////////////////////////////////////////////////////////////
- // _findNextFileRecord()
- //
- // Description: Continues a search that was previously initiated via a call
- // to _findFirstFileRecord().
- //
- // Input: uSearchID - The ID of a search, that was returned from a
- // previous call to _findFirstFileRecord().
- // Output: o_pFileRecordPtr - Points to a DirFileRecord Pointer, to receive
- // the File-Record of a matching File/Sub-Directory.
- // In/Out: None
- // Return: TRUE if the search succeeded, and an additional File-Record matching
- // the criteria was found. In this case, the supplied o_pFileRecordPtr
- // contains a valid pointer.
- // FALSE is returned if no more Files/Sub-Directories matching the
- // supplied criteria could be found. In this case, the supplied
- // o_pFileRecordPtr 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 the current working-
- // directory at the time the search was initiated via _findFirstFileRecord().
- // 3. The search uses the same criteria as were originally supplied to
- // _findFirstFileRecord().
- // 4. The returned File-Record Pointer should be considered persistant
- // across calls. The caller has to make sure that o_pFileRecordPtr
- // is freed when it is no longer needed.
- // 5. _findClose() must be called when no additional searches are needed.
- static BOOL _findNextFileRecord(UINT16 uSearchID, struct DirFileRecord **o_pFileRecordPtr)
- {
- UINT8 uFileIDLength;
- BOOL bFileRecFound;
- BOOL bSearchIncludesDirs;
- WCHAR szUnicodeFileID[(MAX_ID_LENGTH / sizeof(WCHAR)) + 1];
- LPCWSTR pszFileID;
- struct DirFileRecord *pCurrFileRec;
- DirectorySearchInfo dsiInfo;
- //<<<MikeX_1213_2004_A:compare the files' length when searching files.
- UINT8 uFoundFileIDLength;
- WCHAR* pwcFoundFileVersionChar;
- BOOL bBlurredlySearch = FALSE;
- //MikeX_1213_2004_A>>>
- // Retrieve the Directory-Search Info from the Search-Pool
- if ((NULL == uSearchID) ||
- ! _FileSys_getSearchInfo(uSearchID, (BYTE*)&dsiInfo))
- {
- return FALSE;
- }
- uFileIDLength= wcslen(dsiInfo.pszFileID);
- // MikeX_1213_2004_A: support blurred searching
- if( FILESYS_BLURRED_SEARCH == dsiInfo.pszFileID[uFileIDLength-1] )
- {
- bBlurredlySearch = TRUE;
- uFileIDLength --;
- }
- bSearchIncludesDirs= (dsiInfo.uFileFlags == (FILE_FLAGS_DIRECTORY & dsiInfo.uFileFlagsMask));
- // Reset the result
- *o_pFileRecordPtr= NULL;
- // Prepare a descriptor-container
- pCurrFileRec= (struct DirFileRecord *)malloc(MAX_FILEREC_SIZE);
- if (NULL == pCurrFileRec) {
- tr_printf(("FATAL: _findNextFileRecord() Failed [1]: Low system resourcesn"));
- return FALSE;
- }
- // Scan the Directory, as long as it is not exhausted, and there is no match
- bFileRecFound= FALSE;
- while ( ((dsiInfo.cbRecListOffset + dsiInfo.cbCurrRecOffset) < dsiInfo.dwDirectorySize) &&
- (! bFileRecFound) )
- {
- UINT8 cbRequiredDataSize;
- // Extract the Length of the Current Record, which is the first Byte of the Record
- sc_GetBytes(dsiInfo.hDirFileRecordList, dsiInfo.cbCurrRecOffset, 1, &cbRequiredDataSize);
- // If the Length of the Current Record is Zero, then the required data is One Byte long
- if (0 == cbRequiredDataSize)
- cbRequiredDataSize++;
- // Check if the remaining space until the end of the Record-List Cache is large enough
- // to accomodate for the Current Record. If not, cache an additional Record-List chunk.
- if ((DIRECTORY_RECLIST_SZ - dsiInfo.cbCurrRecOffset) < cbRequiredDataSize) {
- dsiInfo.cbRecListOffset += dsiInfo.cbCurrRecOffset;
- dsiInfo.cbCurrRecOffset= 0;
- if (! sc_CopyFromDisc(dsiInfo.dwDirICB, dsiInfo.cbRecListOffset,
- DIRECTORY_RECLIST_SZ, dsiInfo.hDirFileRecordList))
- {
- dbg_printf(("WARNING: _findNextFileRecord() Failed [2]n"));
- break;
- }
- // Set the Required Data Size to the Maximum Record size, in order to avoid
- // having to read this size again from the Record-List Cache.
- cbRequiredDataSize= MAX_FILEREC_SIZE;
- }
- // Collect the next DirFileRecord
- sc_GetBytes(dsiInfo.hDirFileRecordList, dsiInfo.cbCurrRecOffset,
- MIN(cbRequiredDataSize, MAX_FILEREC_SIZE), (BYTE*)pCurrFileRec);
- // Check the Length of the current Record: if it is Zero, then either the End-Of-Directory
- // was encountered, or a Sector-Boundary needs to be crossed.
- if (0 == pCurrFileRec->cbLengthOfDirRecord) {
- // ECMA-119 guarantees, that each Record shall end in the same Sector in which it was
- // started. If there isn't enough space, the Record will be moved to the succeeding
- // Sector, and the current Sector will be Zero-padded.
- DWORD dwCurrSectorBoundary=
- ( ((dsiInfo.cbRecListOffset + dsiInfo.cbCurrRecOffset + LOGICAL_BLOCK_SIZE - 1) /
- LOGICAL_BLOCK_SIZE) * LOGICAL_BLOCK_SIZE );
- // If the Current Record-Offest is Zero, then move to the next closest Sector
- if (0 == dsiInfo.cbCurrRecOffset)
- dwCurrSectorBoundary += LOGICAL_BLOCK_SIZE;
- // If the current Sector boundary exceeds the Directory's size, then End-Of-Directory
- // was encountered.
- if (dwCurrSectorBoundary >= dsiInfo.dwDirectorySize)
- break;
- // The Sector boundary must be crossed:
- // Set cbCurrRecOffset to DIRECTORY_RECLIST_SZ, thus forcing caching of a Record-List
- // chunk; adjust cbRecListOffset such, that the next caching will occur
- // at the beginning of the succeeding Sector.
- dsiInfo.cbRecListOffset= (dwCurrSectorBoundary - DIRECTORY_RECLIST_SZ);
- dsiInfo.cbCurrRecOffset= DIRECTORY_RECLIST_SZ;
- // Force collection of the next DirFileRecord from the freshly-loaded cache
- continue;
- }
- // If the search includes Sub-Directories, and provided that the Current Directory-
- // File Record is not reported as a Directory, cross-check this against the
- // information from the Directory-Hierarchy Tree (Path table).
- // This is a precaution required to overcome authoring-errors in the File-Flags field
- // (which is the only criterion for determining the Type of this Record).
- if (bSearchIncludesDirs && (0 == (pCurrFileRec->uFlags & FILE_FLAGS_DIRECTORY))) {
- UINT16 uDirNodePos;
- // Iterate over all the Directory-Tree, and try to locate this Record in it.
- for (uDirNodePos=0; uDirNodePos < g_pISO9660Info->uDirectoryCnt; uDirNodePos++) {
- DirectoryNode dnCurrDir;
- // Retrieve the Current Directory-Node
- if (! Array_getAt(g_pISO9660Info->hDirTree, uDirNodePos, (BYTE*)&dnCurrDir)) {
- dbg_printf(("WARNING: _findNextFileRecord() Failed [3]n"));
- break;
- }
- // Check if the Directory has the same location as this Record, and if
- // its Parent is the current Directory.
- if ( (BB_DWORD(pCurrFileRec->dwExtentLocation) == dnCurrDir.dwDirICB) &&
- (dsiInfo.uDirNumber == (dnCurrDir.uParentDirNumber - 1)) )
- {
- // A misreported directory was found: force this Record's Flags field to
- // identify a Directory.
- pCurrFileRec->uFlags= FILE_FLAGS_DIRECTORY;
- }
- }
- }
- // Collect the current File-ID
- pszFileID= (LPCWSTR)szUnicodeFileID;
- //<<<Hannah_0524_2005 Cut the file length properly according to the different system.
- {
- extern BOOL _fileID_Cut(UINT8 i_fileID_len, BYTE* i_pSourceBuffer, UINT8 o_fileID_len, BYTE* o_pDestBuffer);
- if(!g_pISO9660Info->bIsUsingUnicode) //ROMEO
- {
- if( pCurrFileRec->cbLengthOfFileID > MAX_ID_LENGTH/sizeof(WCHAR) )
- {
- BYTE* buff = NULL;
- BYTE len = pCurrFileRec->cbLengthOfFileID+1;
-
- buff=(BYTE*)malloc(len +1);
- if(buff == NULL)
- {
- dbg_printf(("WARNING: _findNextFileRecord() Failed [5]:Low system resourcesn"));
- break;
- }
- buff[0] = 0x08; //UNICODE_COMPRESSIONID_DOUBLE_BYTE
- sc_GetBytes(dsiInfo.hDirFileRecordList, dsiInfo.cbCurrRecOffset + sizeof(struct DirFileRecord),
- len-1, buff+1);
- _fileID_Cut(len, buff, MAX_ID_LENGTH/sizeof(WCHAR)+1, pCurrFileRec->sFileID-1);
- pCurrFileRec->cbLengthOfFileID = MAX_ID_LENGTH/sizeof(WCHAR);
- free(buff);
-
- }
- }
- else
- {
- if( pCurrFileRec->cbLengthOfFileID > MAX_ID_LENGTH )
- {
- BYTE* buff = NULL;
- BYTE len = pCurrFileRec->cbLengthOfFileID+1;
-
- buff=(BYTE*)malloc(len + 2);
- if(buff == NULL)
- {
- dbg_printf(("WARNING: _findNextFileRecord() Failed [6]:Low system resourcesn"));
- break;
- }
- buff[0] = 0x10; //UNICODE_COMPRESSIONID_DOUBLE_BYTE
- sc_GetBytes(dsiInfo.hDirFileRecordList, dsiInfo.cbCurrRecOffset + sizeof(struct DirFileRecord),
- len-1, buff+1);
- _fileID_Cut(len, buff, MAX_ID_LENGTH+1, pCurrFileRec->sFileID-1);
- pCurrFileRec->cbLengthOfFileID = MAX_ID_LENGTH;
- free(buff);
- }
- }
-
- }
- //Hannah_0524_2005>>>
- //ZCH JC2003-7-17, limit pCurrFileRec->cbLengthOfFileID within MAX_ID_LENGTH, pCurrFileRec->cbLengthOfFileID is sometimes beyond MAX_ID_LENGTH because the addition of ";1"
- //if(pCurrFileRec->cbLengthOfFileID > MAX_ID_LENGTH)
- //pCurrFileRec->cbLengthOfFileID = MAX_ID_LENGTH;
- // Convert the File-ID into UNICODE, if UNICODE is not in use or the current File-ID is
- // one character long.
- if (!g_pISO9660Info->bIsUsingUnicode || (1 == pCurrFileRec->cbLengthOfFileID)) {
- // The File-ID is given in ANSI-ASCII: convert it into UNICODE
- _str2wcs((LPCSTR)pCurrFileRec->sFileID, szUnicodeFileID,
- ((pCurrFileRec->cbLengthOfFileID + 1) * sizeof(WCHAR)));
- }
- else {
- // The File-ID is given in UNICODE: manipulate as required
- pCurrFileRec->sFileID[pCurrFileRec->cbLengthOfFileID]= 0;
- pCurrFileRec->sFileID[pCurrFileRec->cbLengthOfFileID+1]= 0;
- #ifdef MOTOROLA
- pszFileID= (LPCWSTR)pCurrFileRec->sFileID;
- #else
- swab((LPSTR)pCurrFileRec->sFileID, (LPSTR)szUnicodeFileID,
- (pCurrFileRec->cbLengthOfFileID + 2));
- #endif //MOTOROLA
- }
- // Check if an appropriate Directory-File Record was found, according to
- // both the (UNICODE-normalized) File-ID and the File-Flags.
- #if 0 // Robin_1112_2004, "*" mean any char/string, RB_TBD
- if (dsiInfo.uFileFlags == (pCurrFileRec->uFlags & dsiInfo.uFileFlagsMask))
- {
- if ((0 != uFileIDLength && dsiInfo.pszFileID[uFileIDLength-1] == '*') && (0 == _wcsnicmp(dsiInfo.pszFileID, pszFileID, uFileIDLength-1)) )
- bFileRecFound= TRUE;
- else if ((uFileIDLength == wcslen(pszFileID) || 0 == uFileIDLength) && (0 == _wcsnicmp(dsiInfo.pszFileID, pszFileID, uFileIDLength)) )
- bFileRecFound= TRUE;
- }
- #else
- //<<<MikeX_1213_2004_A:compare the files' length when searching files.
- if( g_pISO9660Info->bIsUsingUnicode )
- uFoundFileIDLength = pCurrFileRec->cbLengthOfFileID/sizeof(WCHAR);
- else
- uFoundFileIDLength = pCurrFileRec->cbLengthOfFileID;
- pwcFoundFileVersionChar = wcsrchr(pszFileID, L';');
- if( 0 != pwcFoundFileVersionChar )
- uFoundFileIDLength = (UINT8)(pwcFoundFileVersionChar - pszFileID);
- if( 0 == uFoundFileIDLength || 0 == uFileIDLength )
- uFoundFileIDLength = uFileIDLength;
- //MikeX_1213_2004_A>>>
- #ifdef MACESTROLINK_SUPPORT
- if ( (dsiInfo.uFileFlags == (pCurrFileRec->uFlags & dsiInfo.uFileFlagsMask)) &&
- (0 == _wcsnicmp(dsiInfo.pszFileID, pszFileID, uFileIDLength))&& //MikeX_1119_2003: convert the file ID lower-case to upper-case.
- (bBlurredlySearch || (uFoundFileIDLength == uFileIDLength)||IS_PLAYING_MLNK)) //Hansen_2004_12_30 Macestrolink can not compare file's length
- #else
- if ( (dsiInfo.uFileFlags == (pCurrFileRec->uFlags & dsiInfo.uFileFlagsMask)) &&
- (0 == _wcsnicmp(dsiInfo.pszFileID, pszFileID, uFileIDLength))&& //MikeX_1119_2003: convert the file ID lower-case to upper-case.
- (bBlurredlySearch || (uFoundFileIDLength == uFileIDLength))) //MikeX_1213_2004_A:compare the files' length when searching files.
- #endif
- {
- bFileRecFound= TRUE;
- }
- #endif
- // Continue to the next Directory/File Record
- dsiInfo.cbCurrRecOffset += pCurrFileRec->cbLengthOfDirRecord;
- }//endof while
- if (bFileRecFound) {
- // Assign the result
- *o_pFileRecordPtr= pCurrFileRec;
- }
- else {
- // No match was found - this Directory has been exhausted: mark that the entire
- // contents was read, so that future calls will return immediately.
- dsiInfo.cbRecListOffset= dsiInfo.dwDirectorySize;
- dsiInfo.cbCurrRecOffset= 0;
- // Free the memory
- free(pCurrFileRec);
- }
- // Update the Directory-Search Info in the Search-Pool
- if (! _FileSys_setSearchInfo(uSearchID, (const BYTE*)&dsiInfo)) {
- dbg_printf(("WARNING: _findNextFileRecord() Failed [4]n"));
- }
- return bFileRecFound;
- }
- /////////////////////////////////////////////////////////////////////////////
- // _findClose()
- //
- // Description: Terminates a search.
- //
- // Input: uSearchID - The ID of a search, that was returned from a
- // previous call to _findFirstFileRecord().
- // Output: None
- // In/Out: None
- // Return: TRUE if the search was successfully terminated; FALSE othewise.
- //
- // Remarks:
- // Any search that is initiated via _findFirstFileRecord() must be terminated
- // using a call to this method, in order to allow for proper release of
- // resources that were allocated for that search.
- // If the call to _findFirstFileRecord() returned NULL, it is prohibited
- // to call _findClose().
- static BOOL _findClose(UINT16 uSearchID)
- {
- DirectorySearchInfo dsiInfo;
- // Retrieve the Directory-Search Info from the Search-Pool
- if ((NULL == uSearchID) ||
- ! _FileSys_getSearchInfo(uSearchID, (BYTE*)&dsiInfo))
- {
- return FALSE;
- }
- if (dsiInfo.pszFileID != g_pszWildcardSearch)
- free(dsiInfo.pszFileID);
- sc_Free(dsiInfo.hDirFileRecordList, CONTAINER_COUNT(DIRECTORY_RECLIST_SZ));
- _FileSys_freeSearchInfo(uSearchID);
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // _getFileAttributes()
- //
- // Description: Translates a native File-Record into a FindData structure.
- //
- // Input: i_pFileRec - Points to a DirFileRecord structure to translate.
- // Output: o_pFindData - Points to a FindData structure to receive the
- // translated information.
- // In/Out: None
- // Return: None
- // Remarks: None
- static void _getFileAttributes(const struct DirFileRecord *i_pFileRec,
- FindData *o_pFindData)
- {
- LPWSTR pszSeparator2;
- // Now it's safe to access the Record
- o_pFindData->uFileType= ((i_pFileRec->uFlags & FILE_FLAGS_DIRECTORY) ?
- FILETYPE_DIRECTORY : FILETYPE_NORMAL);
- o_pFindData->dwStartAddr= BB_DWORD(i_pFileRec->dwExtentLocation);
- o_pFindData->cbFileSizeHigh= 0;
- o_pFindData->cbFileSizeLow= BB_DWORD(i_pFileRec->dwDataLength);
- // Extract the File-ID
- if (!g_pISO9660Info->bIsUsingUnicode || (1 == i_pFileRec->cbLengthOfFileID)) {
- // The File-ID is given in ANSI-ASCII: convert it into UNICODE
- _str2wcs((LPCSTR)i_pFileRec->sFileID, o_pFindData->szFileID,
- ((i_pFileRec->cbLengthOfFileID + 1) * sizeof(WCHAR)));
- }
- else {
- // The File-ID is given in UNICODE: manipulate as required
- #ifdef MOTOROLA
- memcpy(o_pFindData->szFileID, i_pFileRec->sFileID, i_pFileRec->cbLengthOfFileID);
- #else
- swab((LPSTR)i_pFileRec->sFileID, (LPSTR)o_pFindData->szFileID, i_pFileRec->cbLengthOfFileID);
- #endif //MOTOROLA
- o_pFindData->szFileID[i_pFileRec->cbLengthOfFileID / sizeof(WCHAR)]= 0;
- }
- // Eliminate the SEPARATOR2 from the end
- pszSeparator2= wcsrchr(o_pFindData->szFileID, SEPARATOR2);
- if (NULL != pszSeparator2)
- *pszSeparator2= 0;
- return;
- }