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"