UDF_API.c
上传用户:super_houu
上传日期:2008-09-21
资源大小:4099k
文件大小:122k
- /****************************************************************************************
- * Copyright (c) 2002 ZORAN Corporation, All Rights Reserved
- * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF ZORAN CORPORATION
- *
- * File: $Workfile: UDF_API.c $
- *
- * Description:
- * ============
- *
- *
- * Log:
- * ====
- * $Revision: 12 $
- * Last Modified by $Author: Mikex $ at $Modtime: 04-03-20 21:00 $
- ****************************************************************************************
- * Updates:
- ****************************************************************************************
- * $Log: /I76/I76_Common/I76_Reference/Playcore/FileSys/UDF/UDF_API.c $
- *
- * 12 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
- *
- * 11 12/22/03 7:52p Leslie
- * Allow the file length is zero, and don't return false.
- *
- * 10 11/19/03 10:24a Leslie
- * Convert the file ID lower-case to upper-case to compare.
- * signature: MikeX_1119_2003
- *
- * 9 11/07/03 5:57a Leslie
- * changed the search BEA01 identifier mode
- * MikeX_1105_2003
- *
- * 8 03-03-31 16:46 Hannahh
- * To clean the warnings
- *
- * 7 2/07/03 10:45p Tomasp
- * - changed SW feature selection to compilation switch
- *
- * 6 03-01-10 12:20 Leslie
- * Add builtin unicode support
- *
- * 4 4/06/02 15:30 Nirm
- * - Fixed a bug in _initializeUDF102(): Partition-Size is expressed in
- * Sectors, not Bytes.
- *
- * 3 9/05/02 16:16 Nirm
- * - Expanded UDF_getDVDFileInfo() functionality, to increase efficiency.
- *
- * 2 23/04/02 9:30 Nirm
- * - Added dependency in "Config.h".
- *
- * 1 30/01/02 18:12 Nirm
- ****************************************************************************************/
- /////////////////////////////////////////////////////////////////////////////
- // UDF_API.c - Implementation of the UDF-2.00 File-System For DVD Players
- //
- // Author: Nir Milstein
- #include "Config.h" // Global Configuration - do not remove!
- #ifdef FILESYSTEM_SUPPORT_UDF
- #ifdef _DEBUG
- #undef IFTRACE
- #define IFTRACE if (gTraceFileSys)
- #include "DebugDbgMain.h"
- #endif
- #include "Includemath-macro.h"
- #include "PlaycoreFileSysFileSystem_Impl.h"
- #include "PlaycoreFileSysUDFUDF_API.h"
- #include "PlaycoreFileSysUDFECMA167.h"
- #include "PlaycoreFileSysUDFUDF_102.h"
- #include "PlaycoreFileSysUDFUDF_200.h"
- #include "PlaycoreAuxCacheAuxCache.h"
- #include "PlaycoreScPadscmgr.h"
- #include "PlaycoreCoremaincoregdef.h"
- #include "PlaycoreFileSysFileSystem.h"
- #ifdef DVD_VR_SUPPORT
- #include "PlaycoreFileSysUDFdvd_vr.h"
- #include "PlaycoreDataStructuresArray.h"
- #include "Drivedrv_api.h"
- #include "KernelEventDef.h"
- #include "PlaycoreNav_VrVr_nm.h"
- #include "PlaycoreScPadScllmgr.h"
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // Constants
- #define DIRECTORY_FILEIDLIST_SZ 256
- #define FILE_EXTENT_LENGTH 0xFFFFFFFFUL
- /////////////////////////////////////////////////////////////////////////////
- // Macros
- #ifdef MOTOROLA
- #define LE_WORD(wLittleEndian) (WORD)((wLittleEndian << 8) | (wLittleEndian >> 8))
- #define LE_DWORD(dwLittleEndian) (DWORD)((dwLittleEndian >> 24) |
- ((dwLittleEndian >> 8) & 0xFF00) |
- ((dwLittleEndian & 0xFF00) << 8) |
- ((dwLittleEndian & 0xFF) << 24))
- #else
- #define LE_WORD(wLittleEndian) (WORD)wLittleEndian
- #define LE_DWORD(dwLittleEndian) (DWORD)dwLittleEndian
- #endif //MOTOROLA
- /////////////////////////////////////////////////////////////////////////////
- // Globals and Singletons
- /*
- //static struct UDFInfo_TAG {
- typedef struct {
- // Revision Number
- UINT16 uRevision;
- // Session information
- DWORD dwSessionStartLBN;
- // Volume information
- DWORD dwLBA_Offset;
- DWORD dwMainPartitionLocation;
- // Short_ad sadMainPartitionUnallocSpaceBitmap;
- #ifdef UDF_SUPPORT_UDF201
- BOOL bUseSparingManagement;
- struct SparingTable *pMainPartitionSparingTable;
- UINT16 uSparingPacketLength;
- #endif //UDF_SUPPORT_UDF201
- DWORD dwRootDirICB;
- DWORD dwCurrDirICB;
- // Current Working-Directory storage
- BOOL bCWDStored;
- DWORD dwCWDStorage;
- }UDFInfo_TAG;// g_UDFInfo;
- */
- UDFInfo_TAG * g_pUDFInfo;
- #ifdef DVD_VR_SUPPORT
- DWORD g_DVDVR_SparingTableSize=0;
- CONST DWORD g_DVDVR_SpringTableAddr=((DWORD)SC_BASE_ADDR>>1) + ((DWORD)SC_DVDVR_NAV_ADDR);
- #endif
- #define IS_SHORT_ALLOC_DESC(pEntry) (ICB_FLAGS_AD_SHORT== (pEntry->icbTag.wFlags & ICB_FLAGS_ALLOC_MASK))
- #define IS_LONG_ALLOC_DESC(pEntry) (ICB_FLAGS_AD_LONG== (pEntry->icbTag.wFlags & ICB_FLAGS_ALLOC_MASK))
- #define IS_EXTENDED_ALLOC_DESC(pEntry) (ICB_FLAGS_AD_EXTENDED== (pEntry->icbTag.wFlags & ICB_FLAGS_ALLOC_MASK))
- #define IS_IN_ICB_ALLOC_DESC(pEntry) (ICB_FLAGS_AD_IN_ICB== (pEntry->icbTag.wFlags & ICB_FLAGS_ALLOC_MASK))
- /////////////////////////////////////////////////////////////////////////////
- // Internal Structures / Types
- typedef struct UDF_DirectorySearchInfo_TAG {
- // Directory Location and Size related
- DWORD dwDirICB; // Location of the Directory
- DWORD dwDirectorySize; // In Bytes
- // Search Criteria related
- LPWSTR pszFileID; // The Pattern/Name to search for
- UINT8 uFileCharacteristicsMask; // A Mask to apply to File-Characteristics
- UINT8 uFileCharacteristics; // The required File-Characteristics
- // Search Status/Position related
- WORD hFileIDDescList;
- UINT32 cbDescListOffset; // In Bytes from the Directory's start
- UINT32 cbCurrDescOffset; // In Bytes from the Directory's start
- } DirectorySearchInfo;
- /////////////////////////////////////////////////////////////////////////////
- // Forward-Declarations of Private-Services
- static BOOL _initializeUDF102(void);
- static BOOL _initializeUDF200(void);
- static DWORD _absoluteLBA(DWORD dwMainPartitionLBA);
- static UINT16 _findFirstFileIDDesc(LPCWSTR i_pszFileID, UINT8 uFileCharacteristicsMask,
- UINT8 uFileCharacteristics,
- struct FileIDDesc **o_pFileIDDescPtr);
- static BOOL _fileIDDescList_getBytes(DirectorySearchInfo *io_pInfo, UINT32 cbOffset,
- UINT8 cbBytesCnt, BYTE *o_pDestBuffer);
- static BOOL _findNextFileIDDesc(UINT16 uSearchID, struct FileIDDesc **o_pFileIDDescPtr);
- static BOOL _findClose(UINT16 uSearchID);
- static BOOL _getFileAttributes(const struct FileIDDesc *i_pFileIDDesc,
- FindData *o_pFindData);
- LPWSTR _str2wcs(LPCSTR pszSource, LPWSTR pszDest, unsigned int cbDestSize);
- /////////////////////////////////////////////////////////////////////////////
- // Detection
- /////////////////////////////////////////////////////////////////////////////
- // UDF_isResident()
- //
- // Description: Tests a given LBN to detect whether or not an instance of
- // UDF is resident on the Medium at that location.
- //
- // Input: dwCandidateLBN - The candidate LBN to test.
- // Output: o_pUDFRevision - Receives the Revision of the found instance.
- // In/Out: None
- // Return: TRUE if a UDF 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 UDF.
- BOOL UDF_isResident(DWORD dwCandidateLBN, UINT16 *o_pUDFRevision)
- {
- struct GenericVolumeStructureDesc_Base gvsdVolumeDesc;
- BOOL isUDFFS=TRUE;
- Tag Anchor_Des;
- DWORD TrackLBN = dwCandidateLBN;
- dbg_printf(("UDF_isResident(0x%08x, ..) calling.n", dwCandidateLBN));
- {//<<<MikeX_1105_2003: Check the BEA01 position
- BYTE number;
- for(number=0;number<16;number++)
- {
- if (! AuxCache_GetBytes((dwCandidateLBN + number + VOLUME_RECOGNITION_SEQUENCE_START_LSN), 0,
- sizeof(gvsdVolumeDesc), (BYTE*)&gvsdVolumeDesc))
- {
- dbg_printf(("WARNING: UDF_isResident() Failed [0]n"));
- isUDFFS = FALSE;
- }
- // Check for an ISO-9660 Standard-ID
- if (0 == strncmp((LPCSTR)gvsdVolumeDesc.aStandardID, STANDARD_ID_CD001, STANDARD_ID_LEN))
- continue;
- if (0 == strncmp((LPCSTR)gvsdVolumeDesc.aStandardID, STANDARD_ID_BEA01, STANDARD_ID_LEN))
- break;
- dbg_printf(("WARNING: UDF_isResident() Failed [0]n"));
- return FALSE;
- }
- dwCandidateLBN += number;
- }//MikeX_1105_2003>>>
- // 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: UDF_isResident() Failed [1]n"));
- return FALSE;
- }
- // Test for a Beginning of Extended Area
- if (0 != strncmp((LPCSTR)gvsdVolumeDesc.aStandardID, STANDARD_ID_BEA01, STANDARD_ID_LEN))
- isUDFFS = FALSE;
- // The Medium contains UDF; now check which Revision of UDF
- if (! AuxCache_GetBytes((dwCandidateLBN + VOLUME_RECOGNITION_SEQUENCE_START_LSN + 1), 0,
- sizeof(gvsdVolumeDesc), (BYTE*)&gvsdVolumeDesc))
- {
- dbg_printf(("WARNING: UDF_isResident() Failed [2]n"));
- return FALSE;
- }
- if (0 == strncmp((LPCSTR)gvsdVolumeDesc.aStandardID, STANDARD_ID_NSR02, STANDARD_ID_LEN))
- *o_pUDFRevision= 0x0102;
- else if (0 == strncmp((LPCSTR)gvsdVolumeDesc.aStandardID, STANDARD_ID_NSR03, STANDARD_ID_LEN))
- #ifndef DVD_VR_SUPPORT
- *o_pUDFRevision= 0x0102;//MikeX_0524_2004_A:patch for some special discs which used UDF 1.02 with NSR03.
- #else
- *o_pUDFRevision= 0x0200;
- #endif
- else
- *o_pUDFRevision= 0x0000;
- //MikeX_0617_2004_A: Patch!!! Can play the DVD disc without PVD.
- if(!isUDFFS)
- {
- if (!AuxCache_GetBytes((TrackLBN + FIRST_ANCHOR_POINT_LSN), 0, sizeof(Tag), (BYTE*)&Anchor_Des))
- {
- dbg_printf(("WARNING: UDF_isResident() Failed [3]n"));
- return FALSE;
- }
- if (Anchor_Des.uTagID == 0x0002)
- {
- BYTE checksum=0;
- int i;
- for(i=0; i<16; i++)
- {
- if (i != 4)
- {
- checksum += ((BYTE*)&Anchor_Des)[i];
- }
- }
- if (checksum == Anchor_Des.uTagChecksum)
- {
- isUDFFS = TRUE;
- }
- if (Anchor_Des.uDescriptorVersion == 0x0002)
- {
- *o_pUDFRevision = 0x0102;
- }
- else if (Anchor_Des.uDescriptorVersion == 0x0003)
- {
- *o_pUDFRevision = 0x0102;
- }
- else
- {
- *o_pUDFRevision = 0x0000;
- }
- }
- }
- return isUDFFS;
- }
- /////////////////////////////////////////////////////////////////////////////
- // Construction / Destruction
- /////////////////////////////////////////////////////////////////////////////
- // UDF_construct()
- //
- // Description: Constructs the File-System, and allocates system resources
- // needed for correct operation.
- //
- // Input: dwSessionStartLBN - The Start-LBN of the current Session;
- // uRevision - The UDF-Revision to support.
- // Output: None
- // In/Out: None
- // Return: None
- //
- // Remarks:
- // This method must be called prior to initialization of the File-System.
- void UDF_construct(DWORD dwSessionStartLBN, UINT16 uRevision)
- {
- dbg_printf(("UDF_construct(0x%08x, %04x) calling.n", dwSessionStartLBN, uRevision));
- if( g_pUDFInfo != NULL)
- {
- free(g_pUDFInfo);
- }
- g_pUDFInfo = (FileInfo *)malloc(sizeof(FileInfo));
- if(NULL == g_pUDFInfo)
- {
- tr_printf(("ISO9660_construct() failed--alloc memory for g_pUDFInfo failed.n"));
- return;
- }
- // Record the Session-Start Address
- g_pUDFInfo->dwSessionStartLBN= dwSessionStartLBN;
- // Record the UDF-Revision to support
- g_pUDFInfo->uRevision= uRevision;
- // Reset the Search-Info Pool
- if (! _FileSys_resetSearchInfoPool(sizeof(DirectorySearchInfo))) {
- tr_printf(("FATAL: UDF_construct() Failed [1]n"));
- }
- return;
- }
- /////////////////////////////////////////////////////////////////////////////
- // UDF_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 UDF_destruct(void)
- {
- dbg_printf(("UDF_destruct() calling.n"));
- #ifdef DVD_VR_SUPPORT
- // Destroy Partition Sparing Table.
- if( (UINT32)NULL != g_pUDFInfo->pMainPartitionSparingTable && FALSE != g_pUDFInfo->bUseSparingManagement )
- {
- Array_destruct((UINT32)(g_pUDFInfo->pMainPartitionSparingTable));
- g_pUDFInfo->pMainPartitionSparingTable = (UINT32)NULL;
- g_DVDVR_SparingTableSize=0;
-
- }
- g_pUDFInfo->bUseSparingManagement= FALSE;
- #endif
- if(NULL != g_pUDFInfo)
- {
- free(g_pUDFInfo);
- g_pUDFInfo = NULL;
- }
- return;
- }
- /////////////////////////////////////////////////////////////////////////////
- // Initialization
- /////////////////////////////////////////////////////////////////////////////
- // UDF_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. The parameter bLongFilenameSupport is ignored, since UDF always
- // supports Long Filenames.
- #pragma argsused
- BOOL UDF_initialize(BOOL bLongFilenameSupport)
- {
- dbg_printf(("UDF_initialize() calling.n"));
- if (0x0102 == g_pUDFInfo->uRevision)
- return _initializeUDF102();
-
- if (0x0200 <= g_pUDFInfo->uRevision)
- return _initializeUDF200();
- tr_printf(("FATAL: UDF_initialize() Failed [1]: Unsupported Revision.n"));
- return FALSE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // Navigation
- /////////////////////////////////////////////////////////////////////////////
- // UDF_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 UDF_goToRootDir(void)
- {
- dbg_printf(("UDF_goToRootDir() calling.n"));
- g_pUDFInfo->dwCurrDirICB= g_pUDFInfo->dwRootDirICB;
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // UDF_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 UDF_changeDir(LPCWSTR i_pszDestDirName)
- {
- UINT16 hFileIDFind;
- struct FileIDDesc *pDestDirDesc;
- dbg_printf(("UDF_changeDir() calling.n"));
- // Try to locate a File-ID Descriptor corresponding to the required Directory
- hFileIDFind= _findFirstFileIDDesc(i_pszDestDirName, (FILE_CHAR_DIRECTORY | FILE_CHAR_PARENT),
- FILE_CHAR_DIRECTORY, &pDestDirDesc);
- if (NULL == hFileIDFind)
- return FALSE;
- // The appropriate Directory was found: record the location of its ICB for
- // future use.
- g_pUDFInfo->dwCurrDirICB= LE_DWORD((pDestDirDesc->ladICB).lbaExtentLocation.uLogicalBlockNumber);
- // Free the Directory-Record and terminate the search
- free(pDestDirDesc);
- _findClose(hFileIDFind);
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // UDF_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 UDF_goUp(void)
- {
- UINT16 hFileIDFind;
- struct FileIDDesc *pParentDirDesc;
- dbg_printf(("UDF_goUp() calling.n"));
- // Try to locate a File-ID Descriptor corresponding to the Parent Directory
- hFileIDFind= _findFirstFileIDDesc(L"", FILE_CHAR_PARENT,
- FILE_CHAR_PARENT, &pParentDirDesc);
- if (NULL == hFileIDFind)
- return FALSE;
- // The Parent Directory was found: record the location of its ICB for
- // future use.
- g_pUDFInfo->dwCurrDirICB= ((pParentDirDesc->ladICB).lbaExtentLocation.uLogicalBlockNumber);
- // Free the Directory-Record and terminate the search
- free(pParentDirDesc);
- _findClose(hFileIDFind);
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // UDF_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 UDF_recallWorkingDirectory().
- // This method is useful for peeking into different directories, and then
- // restoring the original Working-Directory.
- void UDF_storeWorkingDirectory(void)
- {
- // Store the Working-Directory and set the Storage indicator
- g_pUDFInfo->dwCWDStorage= g_pUDFInfo->dwCurrDirICB;
- g_pUDFInfo->bCWDStored= TRUE;
- return;
- }
- /////////////////////////////////////////////////////////////////////////////
- // UDF_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 UDF_storeWorkingDirectory().
- void UDF_recallWorkingDirectory(void)
- {
- // Restore the Working-Directory
- if (g_pUDFInfo->bCWDStored)
- g_pUDFInfo->dwCurrDirICB= g_pUDFInfo->dwCWDStorage;
- // Clear the Storage indicator
- g_pUDFInfo->bCWDStored= FALSE;
- return;
- }
- /////////////////////////////////////////////////////////////////////////////
- // Queries
- /////////////////////////////////////////////////////////////////////////////
- // UDF_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 UDF_getVolumeName(LPCWSTR volumeName)
- {
- sc_GetBytes(SC_VOLUME_ID_ADDR, 0, FILESYSTEM_MAX_VOLUME_NAME*sizeof(WCHAR), (BYTE*)volumeName);
- return;
- }
- /////////////////////////////////////////////////////////////////////////////
- // UDF_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 UDF_fileExists(LPCWSTR i_pszFilename)
- {
- UINT16 hFileIDFind;
- struct FileIDDesc *pDestDirDesc;
- dbg_printf(("UDF_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.
- hFileIDFind= _findFirstFileIDDesc(i_pszFilename,
- (FILE_CHAR_DIRECTORY | FILE_CHAR_PARENT | FILE_CHAR_HIDDEN | FILE_CHAR_DELETED),
- 0x0, &pDestDirDesc);
- if (NULL == hFileIDFind)
- return FALSE;
- // Free the Directory-Record and terminate the search
- free(pDestDirDesc);
- _findClose(hFileIDFind);
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // UDF_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 UDF_fileLocation(LPCWSTR i_pszFilename, DWORD *o_pFileLocation)
- {
- BOOL bSuccess;
- UINT16 hFileIDFind;
- FindData fdFileInfo;
- struct FileIDDesc *pFileDesc;
- dbg_printf(("UDF_fileLocation() 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.
- hFileIDFind= _findFirstFileIDDesc(i_pszFilename,
- (FILE_CHAR_DIRECTORY | FILE_CHAR_PARENT /*| FILE_CHAR_HIDDEN */| FILE_CHAR_DELETED),
- 0x0, &pFileDesc);
- if (NULL == hFileIDFind)
- return FALSE;
- bSuccess= _getFileAttributes(pFileDesc, &fdFileInfo);
- // Free the File-Record and terminate the search
- free(pFileDesc);
- _findClose(hFileIDFind);
- // Prepare the result
- if (bSuccess)
- *o_pFileLocation= fdFileInfo.dwStartAddr;
- else
- *o_pFileLocation= NULL;
-
- return bSuccess;
- }
- /////////////////////////////////////////////////////////////////////////////
- // UDF_getDVDFileInfo()
- //
- // Description: Retrieves DVD-Specific information about some file.
- //
- // Input: i_pszFilename - A string holding the name of the requested File,
- // or a pattern to match.
- // eType - An enumerator indicating the Type of DVD Information to
- // retrieve.
- // Output: o_pFileInfo - Points to a DVDFileInfo structure, to receive the
- // File's DVD-information upon successful completion;
- // o_pFindData - Points to a FindData structure, to receive the File's
- // details upon successful completion. May be NULL.
- // In/Out: None
- // Return: TRUE if the requested file was found and the required DVD
- // information was successfully retrieved;
- // FALSE if the file couldn't be found, or if the file has no
- // associated DVD information of the requested type.
- //
- // Remarks:
- // - The value of o_pFindData may be NULL, in which case the FindData
- // is not retrieved.
- BOOL UDF_getDVDFileInfo(LPCWSTR i_pszFilename, enDVD_FileInfoType eType,
- DVDFileInfo *o_pFileInfo, FindData *o_pFindData)
- {
- BOOL bSuccess;
- DWORD dwFileEntryAddr;
- UINT16 hFileIDFind;
- LPCSTR pszAttrID;
- struct FileIDDesc *pFileDesc;
- struct TerminalEntry *pEntry;
- struct ExtendedAttributeHeaderDesc *pExtAttrHdr;
- struct ImplUseExtendedAttribute *pCurrExtAttr;
- UINT32 dwExtAttrsPos;
- UINT32 dwEndOfExtAttrs;
- dbg_printf(("UDF_getDVDFileInfo() calling.n"));
- // Try to locate a File-ID Descriptor corresponding to the required File; Specify
- // that the required file must not be a Parent, must not be a Directory, and should
- // be undeleted.
- hFileIDFind= _findFirstFileIDDesc(i_pszFilename,
- (FILE_CHAR_PARENT | FILE_CHAR_DIRECTORY | FILE_CHAR_DELETED),
- 0x0, &pFileDesc);
- if (NULL == hFileIDFind)
- return FALSE;
- dwFileEntryAddr= _absoluteLBA(LE_DWORD(pFileDesc->ladICB.lbaExtentLocation.uLogicalBlockNumber));
- // If necessary, fill-in the Find-Data information for this file
- if ((NULL != o_pFindData) &&
- ! _getFileAttributes(pFileDesc, o_pFindData))
- {
- dbg_printf(("WARNING: UDF_findFirstFile() Failed [1]n"));
- memset(o_pFindData, 0, sizeof(FindData));
- }
- // Free the File-Record and terminate the search
- free(pFileDesc);
- _findClose(hFileIDFind);
- // Load the File's File-Entry. Use a Terminal-Entry at first, just to peek
- // into the type of Descriptor that is at hand (File-Entry / Extended-File-Entry).
- pEntry= (struct TerminalEntry *)malloc(sizeof(struct TerminalEntry));
- if (NULL == pEntry) {
- tr_printf(("FATAL: UDF_findFirstFile() Failed [2]: Low system resourcesn"));
- return FALSE;
- }
- // Read the File-Entry
- if (! AuxCache_GetBytes(dwFileEntryAddr, 0, sizeof(struct TerminalEntry), (BYTE*)pEntry)) {
- dbg_printf(("WARNING: UDF_findFirstFile() Failed [3]: Low system resourcesn"));
- free(pEntry);
- return FALSE;
- }
- // Compute the Extended-Attributes Header Descriptor Entry according to the Descriptor type,
- // and extract it.
- dwExtAttrsPos= 0;
- if (TAG_ID_FILE_ENTRY == LE_WORD(pEntry->tgDescTag.uTagID)) {
- // Retrieve the Length of Extended Attributes and establish their boundaries
- UINT32 cbLengthOfExtAttrs;
- if (AuxCache_GetBytes(dwFileEntryAddr, FILE_ENTRY_L_EXTATTR_OFFSET,
- sizeof(cbLengthOfExtAttrs), (BYTE*)&cbLengthOfExtAttrs))
- {
- dwExtAttrsPos= FILE_ENTRY_EXTATTRS_OFFSET;
- dwEndOfExtAttrs= (dwExtAttrsPos + LE_DWORD(cbLengthOfExtAttrs));
- }
- }
- else if (TAG_ID_EXT_FILE_ENTRY == LE_WORD(pEntry->tgDescTag.uTagID)) {
- // Retrieve the Length of Extended Attributes and establish their boundaries
- UINT32 cbLengthOfExtAttrs;
- if (AuxCache_GetBytes(dwFileEntryAddr, EXT_FILE_ENTRY_L_EXTATTR_OFFSET,
- sizeof(cbLengthOfExtAttrs), (BYTE*)&cbLengthOfExtAttrs))
- {
- dwExtAttrsPos= EXT_FILE_ENTRY_EXTATTRS_OFFSET;
- dwEndOfExtAttrs= (dwExtAttrsPos + LE_DWORD(cbLengthOfExtAttrs));
- }
- }
- // Now examine the Extended-Attributes Header Descriptor, and extract the first
- // Implementation Extended-Attribute.
- pExtAttrHdr= (struct ExtendedAttributeHeaderDesc *)pEntry;
- if (! AuxCache_GetBytes(dwFileEntryAddr, dwExtAttrsPos,
- sizeof(struct ExtendedAttributeHeaderDesc), (BYTE*)pExtAttrHdr))
- {
- dbg_printf(("WARNING: UDF_findFirstFile() Failed [4]n"));
- dwExtAttrsPos= 0;
- }
- if ((0 == dwExtAttrsPos) ||
- (TAG_ID_EXT_ATTR_HDR_DESC != LE_WORD(pExtAttrHdr->tgDescTag.uTagID)))
- {
- dbg_printf(("WARNING: UDF_findFirstFile() Failed [5]n"));
- free(pEntry);
- return FALSE;
- }
- // Adjust the dwExtAttrsPos to point at the beginning of the
- // Implementation Extended-Attributes.
- dwExtAttrsPos += LE_DWORD(pExtAttrHdr->cbImplAttrLocation);
- free(pEntry);
- // Prepare the Attribute-ID to look for
- switch (eType)
- {
- case eFreeEASpace:
- pszAttrID= UDF_ID_DVD_FREE_EA;
- break;
- case eCGMS:
- pszAttrID= UDF_ID_DVD_IMPL;
- break;
- }
- // Allocate a single Implementation-Use Extended Attribute
- pCurrExtAttr= (struct ImplUseExtendedAttribute *)malloc(sizeof(struct ImplUseExtendedAttribute));
- if (NULL == pCurrExtAttr) {
- dbg_printf(("WARNING: UDF_findFirstFile() Failed [6]: Low system resourcesn"));
- return FALSE;
- }
- // Iterate over the various Implementation Attributes, until an Attribute is found,
- // which matches the required Type.
- while (dwExtAttrsPos < dwEndOfExtAttrs) {
- if (! AuxCache_GetBytes(dwFileEntryAddr, dwExtAttrsPos,
- sizeof(struct ImplUseExtendedAttribute), (BYTE*)pCurrExtAttr))
- {
- break;
- }
- if ((ATTR_TYPE_IMPL == LE_DWORD(pCurrExtAttr->uAttrType)) &&
- (0 == strcmp(pszAttrID, (LPCSTR)pCurrExtAttr->ridImplID.aIdentifier)))
- break;
- // Continue to the next Attribute
- dwExtAttrsPos += LE_DWORD(pCurrExtAttr->cbAttrLength);
- }
- free(pCurrExtAttr);
- // Check if the requested Attribute was found, or not
- if (dwExtAttrsPos < dwEndOfExtAttrs) {
- dwExtAttrsPos += sizeof(struct ImplUseExtendedAttribute);
- // Extract the requested information from the Attribute
- switch (eType)
- {
- case eFreeEASpace:
- {
- struct ExtendedAttrImplUse_DVD_FreeEASpace freeEASpace;
- if (AuxCache_GetBytes(dwFileEntryAddr, dwExtAttrsPos, sizeof(freeEASpace),
- (BYTE*)&freeEASpace))
- {
- o_pFileInfo->eInfoType= eFreeEASpace;
- o_pFileInfo->Info.cbFreeEASpace= (UINT16)LE_DWORD(freeEASpace.uFreeEASpace);
- }
- }
- break;
- case eCGMS:
- {
- struct ExtendedAttrImplUse_DVD_CGMS cgmsInfo;
- if (AuxCache_GetBytes(dwFileEntryAddr, dwExtAttrsPos, sizeof(cgmsInfo),
- (BYTE*)&cgmsInfo))
- {
- o_pFileInfo->eInfoType= eCGMS;
- o_pFileInfo->Info.cmiCGMS.ucCGMSInfo= cgmsInfo.ucCGMSInfo;
- o_pFileInfo->Info.cmiCGMS.uDataStructureType= cgmsInfo.uDataStructureType;
- memcpy(o_pFileInfo->Info.cmiCGMS.aProtectionSystemInfo,
- cgmsInfo.aProtectionSystemInfo, 4);
- }
- }
- break;
- }
- bSuccess= TRUE;
- }
- else
- bSuccess= FALSE;
- return bSuccess;
- }
- /////////////////////////////////////////////////////////////////////////////
- // UDF_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 UINT32 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. UDF_findClose() must be called when no additional searches are needed.
- UINT16 UDF_findFirstFile(LPCWSTR i_pszPattern, FindData *o_pFindData)
- {
- UINT16 hFileIDFind;
- struct FileIDDesc *pFileDesc;
- dbg_printf(("UDF_findFirstFile() calling.n"));
- // Try to locate a File-ID Descriptor corresponding to the required File; Specify
- // that the required file must not be a Parent, and should be undeleted.
- hFileIDFind= _findFirstFileIDDesc(i_pszPattern,
- (FILE_CHAR_PARENT | FILE_CHAR_DELETED),
- 0x0, &pFileDesc);
- if (NULL == hFileIDFind)
- return NULL;
- if (! _getFileAttributes(pFileDesc, o_pFindData)) {
- _findClose(hFileIDFind);
- hFileIDFind= NULL;
- }
- free(pFileDesc);
- return hFileIDFind;
- }
- /////////////////////////////////////////////////////////////////////////////
- // UDF_findNextFile()
- //
- // Description: Continues a search that was previously initiated using a call
- // to UDF_findFirstFile().
- //
- // Input: hFindFile - A Handle to a file-search, that was returned from
- // a previous call to UDF_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 UDF_findFirstFile().
- // 3. The search uses the same Filename/pattern as was originally supplied
- // to UDF_findFirstFile().
- // 4. UDF_findClose() must be called when no additional searches are needed.
- BOOL UDF_findNextFile(UINT16 hFindFile, FindData *o_pFindData)
- {
- BOOL bSuccess;
- struct FileIDDesc *pFileDesc;
- dbg_printf(("UDF_findNextFile() calling.n"));
- if (! _findNextFileIDDesc(hFindFile, &pFileDesc))
- return FALSE;
- bSuccess= _getFileAttributes(pFileDesc, o_pFindData);
- free(pFileDesc);
- return bSuccess;
- }
- /////////////////////////////////////////////////////////////////////////////
- // UDF_findClose()
- //
- // Description: Terminates a file-search.
- //
- // Input: hFindFile - A Handle to a file-search, that was returned from
- // a previous call to UDF_findFirstFile().
- // Output: None
- // In/Out: None
- // Return: TRUE if the search was successfully terminated; FALSE othewise.
- //
- // Remarks:
- // Any search that is initiated via UDF_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 UDF_findClose(UINT16 hFileFind)
- {
- dbg_printf(("UDF_findClose() calling.n"));
- return _findClose(hFileFind);
- }
- #ifdef DVD_VR_SUPPORT
- BYTE* g_pCache=NULL;
- DWORD currSector=0L;
- DWORD currOffset = 0L;
- #define CACHE_SIZE 512
- BOOL _GetBytefromCache(DWORD sectorNum, DWORD offset, WORD size, BYTE* buff)
- {
- if( (sectorNum != currSector) || (offset < currOffset) || (offset +size > currOffset + CACHE_SIZE))
- {
- if(!AuxCache_GetBytes(sectorNum, offset, CACHE_SIZE, g_pCache) )
- return FALSE;
- currSector = sectorNum;
- currOffset = offset;
- }
- memcpy( buff, g_pCache+offset - currOffset, size);
- return TRUE;
- }
- BOOL _get_extent_descriptor(DWORD array,DWORD location)
- {
- DWORD length=0;
- WORD upperBound;
- DWORD dwAllocDesPos = 24;
- {
- WORD wDescriptorID;
- if ( (!AuxCache_GetBytes(_absoluteLBA(location), 0, sizeof(WORD), (BYTE*)&wDescriptorID)) || (LE_WORD(wDescriptorID) != TAG_ID_ALLOC_EXTENT_DESC) )
- {
- dbg_printf(("WARNING: _get_extent_descriptor() Failed [1]n"));
- return FALSE;
- }
- }
- upperBound = Array_getSize(array);
-
- if (_GetBytefromCache(_absoluteLBA(location), ALLOCATION_EXTENT_LENGTH_OFFSET, sizeof(DWORD), (BYTE*)&length))
- {
- Extent_ad CrtExtentAD;
- length /= sizeof(Extent_ad);
- Array_reconstruct(array, (WORD)(length + Array_getCapacity(array) - 1));
- {
- Array_getAt(array, 0, &CrtExtentAD);
- CrtExtentAD.dwExtentLength += length -1;
- Array_setAt(array, 0, &CrtExtentAD);
- }
- length = (DWORD)Array_getCapacity(array);
- for(;upperBound < (WORD)length; upperBound++)
- {
- if (!_GetBytefromCache(_absoluteLBA(location), dwAllocDesPos, sizeof(Extent_ad), (BYTE*)&CrtExtentAD))
- {
- dbg_printf(("WARNING: _get_extent_descriptor() Failed [2]n"));
- return FALSE;
- }
- if( (CrtExtentAD.dwExtentLength >> 30) == 3)
- _get_extent_descriptor(array, CrtExtentAD.dwExtentLocation);
- else
- Array_setAt(array, upperBound, &CrtExtentAD);
- dwAllocDesPos += sizeof(Extent_ad);
- }
- }
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // UDF_getDVDVRFileExtent()
- //
- // Description: cache real-time file entry extents table to scratch-pad
- //
- // Input: i_pszFilename - A string holding the name of the requested File,
- // or a pattern to match.
- // Output: o_pFileExtentList - Points to the array which cache the extents table
- // In/Out: None
- // Return: TRUE if the requested file was found and the extents table was
- // successfully retrieved;
- // FALSE if the file couldn't be found, or if the file has no
- // extents table.
- //
- // Remarks:
- // - The value of o_pFileExtentList may be NULL, in which case the extents table
- // is not retrieved.
- BOOL UDF_getDVDVRFileExtent(LPCWSTR i_pszFilename, DWORD* o_pFileExtentList)
- {
- BOOL bSuccess=TRUE;
- DWORD dwFileEntryAddr;
- UINT16 hFileIDFind;
- struct FileIDDesc *pFileDesc;
- struct TerminalEntry *pEntry;
- DWORD dwFileExtentCacheAddr = g_DVDVR_SpringTableAddr + g_DVDVR_SparingTableSize;
- UINT32 dwAllocDesPos=0;
- UINT32 dwEndOfAllocDes=0;
- UINT32 dwFileExtentCnt;
- Extent_ad CrtExtentAD;
- int iCnt;
- dbg_printf(("UDF_getDVDVRFileExtent() calling.n"));
- // Try to locate a File-ID Descriptor corresponding to the required File; Specify
- // that the required file must not be a Parent, must not be a Directory, and should
- // be undeleted.
- hFileIDFind= _findFirstFileIDDesc(i_pszFilename,
- (FILE_CHAR_PARENT | FILE_CHAR_DIRECTORY | FILE_CHAR_DELETED),
- 0x0, &pFileDesc);
- if (NULL == hFileIDFind)
- return FALSE;
- dwFileEntryAddr= _absoluteLBA(LE_DWORD(pFileDesc->ladICB.lbaExtentLocation.uLogicalBlockNumber));
- // Free the File-Record and terminate the search
- free(pFileDesc);
- _findClose(hFileIDFind);
- // Load the File's File-Entry. Use a Terminal-Entry at first, just to peek
- // into the type of Descriptor that is at hand (File-Entry / Extended-File-Entry).
- pEntry= (struct TerminalEntry *)malloc(sizeof(struct TerminalEntry));
- if (NULL == pEntry) {
- tr_printf(("FATAL: UDF_getDVDVRFileExtent() Failed [1]: Low system resourcesn"));
- return FALSE;
- }
- // Read the File-Entry
- if (! AuxCache_GetBytes(dwFileEntryAddr, 0, sizeof(struct TerminalEntry), (BYTE*)pEntry)) {
- dbg_printf(("WARNING: UDF_getDVDVRFileExtent() Failed [2]: Low system resourcesn"));
- free(pEntry);
- return FALSE;
- }
- if (TAG_ID_FILE_ENTRY == LE_WORD(pEntry->tgDescTag.uTagID)) {
- // Retrieve the Length of Extended Attributes and establish their boundaries
- UINT32 cbLengthOfExtAttrs,cbLengthOfAllocDes;
- if (AuxCache_GetBytes(dwFileEntryAddr, FILE_ENTRY_L_EXTATTR_OFFSET,
- sizeof(cbLengthOfExtAttrs), (BYTE*)&cbLengthOfExtAttrs))
- dwAllocDesPos= FILE_ENTRY_EXTATTRS_OFFSET+LE_DWORD(cbLengthOfExtAttrs);
- else
- bSuccess=FALSE;
- if (AuxCache_GetBytes(dwFileEntryAddr, FILE_ENTRY_L_ALLOCDESC_OFFSET,
- sizeof(cbLengthOfAllocDes), (BYTE*)&cbLengthOfAllocDes))
- dwEndOfAllocDes= (dwAllocDesPos + LE_DWORD(cbLengthOfAllocDes));
- else
- bSuccess=FALSE;
- }
- else if (TAG_ID_EXT_FILE_ENTRY == LE_WORD(pEntry->tgDescTag.uTagID)) {
- // Retrieve the Length of Extended Attributes and establish their boundaries
- UINT32 cbLengthOfExtAttrs,cbLengthOfAllocDes;
- if (AuxCache_GetBytes(dwFileEntryAddr, EXT_FILE_ENTRY_L_EXTATTR_OFFSET,
- sizeof(cbLengthOfExtAttrs), (BYTE*)&cbLengthOfExtAttrs))
- dwAllocDesPos= EXT_FILE_ENTRY_EXTATTRS_OFFSET+LE_DWORD(cbLengthOfExtAttrs);
- else
- bSuccess=FALSE;
- if (AuxCache_GetBytes(dwFileEntryAddr, EXT_FILE_ENTRY_L_ALLOCDESC_OFFSET,
- sizeof(cbLengthOfAllocDes), (BYTE*)&cbLengthOfAllocDes))
- dwEndOfAllocDes= (dwAllocDesPos + LE_DWORD(cbLengthOfAllocDes));
- else
- bSuccess=FALSE;
- }
- free(pEntry);
- if(!bSuccess)
- return FALSE;
- g_pCache = (BYTE*)malloc(CACHE_SIZE);
- if(g_pCache == NULL)
- {
- tr_printf(("FATAL: UDF_getDVDVRFileExtent() Failed [3]: Low system resourcesn"));
- return FALSE;
-
- }
- dwFileExtentCnt=(dwEndOfAllocDes-dwAllocDesPos+sizeof(Extent_ad)-1)/sizeof(Extent_ad);
-
- *o_pFileExtentList=Array_constructEx(dwFileExtentCnt+1, sizeof(Extent_ad), &dwFileExtentCacheAddr);
- if(*o_pFileExtentList == (DWORD)NULL)
- {
- tr_printf(("FATAL: UDF_getDVDVRFileExtent() Failed [4]: Low system resourcesn"));
- free(g_pCache);
- return FALSE;
- }
- CrtExtentAD.dwExtentLength=dwFileExtentCnt;
- CrtExtentAD.dwExtentLocation=0;
- Array_setAt(*o_pFileExtentList, 0, &CrtExtentAD);
-
- for(iCnt=1;iCnt<=dwFileExtentCnt;iCnt++)
- {
- if (!_GetBytefromCache(dwFileEntryAddr, dwAllocDesPos, sizeof(Extent_ad), (BYTE*)&CrtExtentAD))
- {
- dbg_printf(("WARNING: UDF_getDVDVRFileExtent() Failed [5]: Low system resourcesn"));
- free(g_pCache);
- return FALSE;
- }
- if( (CrtExtentAD.dwExtentLength >> 30) == 3)
- _get_extent_descriptor(*o_pFileExtentList, CrtExtentAD.dwExtentLocation);
- else
- Array_setAt(*o_pFileExtentList, iCnt, &CrtExtentAD);
- dwAllocDesPos += sizeof(Extent_ad);
- }
- Array_getAt(*o_pFileExtentList, 0, &CrtExtentAD);
- g_DVDVR_SparingTableSize += (CrtExtentAD.dwExtentLength +1)*2;
- free(g_pCache);
- return bSuccess;
- }
- /////////////////////////////////////////////////////////////////////////////
- // _readSectors()
- //
- // Description: read a sector by sparing table.
- //
- // Input: LBN: start Logical Block Number
- // dwOff: start bytes offset
- // dwSize: the bytes number want to read
- //
- // Output: o_pBuff: point to the output data
- // In/Out: None
- // Return: TRUE if reading was successfully; FALSE othewise.
- //
- // Remarks:
- //
- BOOL _readSectors(DWORD LBN, DWORD dwOff, DWORD dwSize, BYTE* o_pBuff)
- {
-
- while( dwSize > 0 )
- {
- WORD dwReadSize = MIN(dwSize, LOGICAL_BLOCK_SIZE - dwOff%LOGICAL_BLOCK_SIZE);
- if(!AuxCache_GetBytes( _absoluteLBA( LBN+dwOff / LOGICAL_BLOCK_SIZE ),
- dwOff % LOGICAL_BLOCK_SIZE, dwReadSize, o_pBuff))
- return FALSE;
- dwOff += dwReadSize;
- o_pBuff += dwReadSize;
- dwSize -= dwReadSize;
- }
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // UDF_ReadFile()
- //
- // Description: read some bytes from a file
- //
- // Input: pFileHandle - points to the file extents table
- // dwOffset - the start byte offset in the file
- // dwSize - the bytes number want to read
- //
- // Output: o_pBuffer - Points to the buffer of the output data
- // In/Out: None
- // Return: TRUE if read successfully,FALSE otherwise
- //
- // Remarks:
- // - The pFileHandle should not be NULL, and the dwSize should over the file size.
- BOOL UDF_ReadFile(DWORD pFileHandle, DWORD dwOffset, DWORD dwSize, BYTE* o_pBuffer)
- {
- int i=1;
- Extent_ad tempExtent;
- DWORD dwFileExtentCnt,dwFileCrtOffset=0;
-
- if((DWORD)NULL==pFileHandle)
- {
- tr_printf(("FATAL: UDF_ReadFile() Failed [1]: pFileHandle is NULL.n"));
- return FALSE;
- }
- Array_getAt(pFileHandle, 0, (BYTE*)(&tempExtent));
- dwFileExtentCnt=tempExtent.dwExtentLength;
- while( i<=dwFileExtentCnt && dwSize>0 && Array_getAt(pFileHandle, i, (BYTE*)(&tempExtent)) )
- {
- tempExtent.dwExtentLength &= ~ALLOCATION_EXTENT_INTERPRETATION;
- if( tempExtent.dwExtentLength == 0 || tempExtent.dwExtentLocation == 0 )
- return FALSE; // It should not run to here.
- if( dwOffset <= dwFileCrtOffset + tempExtent.dwExtentLength )
- {
- DWORD dwReadSize;
- dwReadSize = MIN( dwSize, dwFileCrtOffset+tempExtent.dwExtentLength-dwOffset );
- if(!_readSectors(tempExtent.dwExtentLocation, dwOffset - dwFileCrtOffset, dwReadSize, o_pBuffer))
- return FALSE;
- dwOffset += dwReadSize;
- o_pBuffer += dwReadSize;
- dwSize -= dwReadSize;
- }
- dwFileCrtOffset += tempExtent.dwExtentLength;
- i++;
- }
- if( dwSize > 0 )
- {
- tr_printf(("FATAL: UDF_ReadFile() Failed [2]: Over range.n"));
- return FALSE;
- }
- return TRUE;
- }
- extern DWORD g_pDVDVR_PlayQueue;
- extern BYTE g_DVDVR_PlayQueue_Head;
- extern BYTE g_DVDVR_PlayQueue_Tail;
- extern BYTE g_DVDVR_PlayQueue_Size;
- extern BYTE g_DVDVR_ExtentsInFE;
- extern DVDVR_PLAY_QUEUE_NODE g_lastPlayExtent;
- extern BOOL g_ExtentIsPlaying;
- /////////////////////////////////////////////////////////////////////////////
- // UDF_TransferExtentToFE()
- //
- // Description: transfer extent to the Front End
- //
- // Input: None
- // Output: None
- // In/Out: None
- // Return: TRUE if transfer successfully,FALSE otherwise
- //
- // Remarks:
- BOOL UDF_TransferExtentToFE()
- {
- DVDVR_PLAY_QUEUE_NODE node;
- dbg_printf(("UDF_TransferExtentToFE()n"));
- while((g_DVDVR_ExtentsInFE<MAX_PLAY_EXTENT_IN_FE)&&(g_DVDVR_PlayQueue_Size>0)&&gns.dvdvr.bIsSegFinishDone)
- {
- Array_getAt(g_pDVDVR_PlayQueue, g_DVDVR_PlayQueue_Head, (BYTE*)(&node));
- if( drv_play_dvd( node.dwStartLBN, node.dwLength, DRVF_PLAY_DVD_AV_DATA ) )
- {
- {
- DWORD sta=node.dwStartLBN;
- drv_lsn2psn(&sta);
- DEC_LL_SetDVDStartEndSector( sta, node.dwLength );
- }
- gns.dvdvr.bIsDriveDone=FALSE;
- g_DVDVR_PlayQueue_Head = ( g_DVDVR_PlayQueue_Head+1 ) % DVDVR_PLAY_QUEUE_SIZE;
- g_DVDVR_PlayQueue_Size--;
- g_DVDVR_ExtentsInFE++;
- g_lastPlayExtent.dwStartLBN = node.dwStartLBN;
- g_lastPlayExtent.dwLength = node.dwLength;
- g_ExtentIsPlaying = TRUE;
- }
- else
- return FALSE;
- }
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // UDF_TransferExtentToFE()
- //
- // Description: add a new extent to the Play Queue.
- //
- // Input: dwStart - start LBN of the extent
- // dwLength - sector number of the extent
- // Output: None
- // In/Out: None
- // Return: TRUE if transfer successfully,FALSE otherwise
- //
- // Remarks:
- // - If the Front End haven't extent to be played, then transfer this extent to the Front End.
- BOOL _addExtentToPlayQueue(DWORD dwStart, DWORD dwLength)
- {
- DVDVR_PLAY_QUEUE_NODE node;
- dbg_printf(("_addExtentToPlayQueue(0x%08lx, 0x%08lx)n",dwStart, dwLength));
- if( g_DVDVR_PlayQueue_Size >= DVDVR_PLAY_QUEUE_SIZE )
- {
- tr_printf(("FATAL: _addExtentToPlayQueue() Failed [1]: Play quere was full.n"));
- return FALSE;
- }
-
- node.dwStartLBN=dwStart;
- node.dwLength=dwLength;
- Array_setAt(g_pDVDVR_PlayQueue, g_DVDVR_PlayQueue_Tail, (BYTE*)(&node));
- g_DVDVR_PlayQueue_Tail= (g_DVDVR_PlayQueue_Tail+1) % DVDVR_PLAY_QUEUE_SIZE;
- g_DVDVR_PlayQueue_Size++;
- //UDF_TransferExtentToFE();
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // UDF_PlayExtents()
- //
- // Description: play a part of a file.
- //
- // Input: pFileHandle - points to the extents table of the playback file
- // dwOffset - start sector number from the file begining
- // dwSize - playback size by sector
- // Output: None
- // In/Out: None
- // Return: TRUE if play successfully,FALSE otherwise
- //
- // Remarks:
- BOOL UDF_PlayExtents(DWORD pFileHandle, DWORD dwOffset, DWORD dwSize)
- {
- int i=1;
- Extent_ad tempExtent;
- DWORD dwFileExtentCnt,dwCrtLBN=0,dwPlayLength=0;
-
- if((DWORD)NULL==pFileHandle)
- {
- tr_printf(("FATAL: UDF_PlayExtents() Failed [1]: pFileHandle is NULL.n"));
- return FALSE;
- }
- //dwCrtLBN = dwOffset + g_pUDFInfo->dwMainPartitionLocation;
- Array_getAt(pFileHandle, 0, (BYTE*)(&tempExtent));
- dwFileExtentCnt=tempExtent.dwExtentLength;
- while( i<=dwFileExtentCnt && dwSize>0 && Array_getAt(pFileHandle, i, (BYTE*)(&tempExtent)) )
- {
- tempExtent.dwExtentLength &= ~ALLOCATION_EXTENT_INTERPRETATION;
- if( tempExtent.dwExtentLength == 0 || tempExtent.dwExtentLocation == 0 )
- return FALSE; // It should not run to here.
- tempExtent.dwExtentLocation += g_pUDFInfo->dwMainPartitionLocation;
- tempExtent.dwExtentLength = (tempExtent.dwExtentLength+LOGICAL_BLOCK_SIZE-1)/ LOGICAL_BLOCK_SIZE;
- if( dwOffset < dwCrtLBN + tempExtent.dwExtentLength )
- {
- dwPlayLength = MIN( dwSize, dwCrtLBN+tempExtent.dwExtentLength-dwOffset );
- if( !_addExtentToPlayQueue(tempExtent.dwExtentLocation+dwOffset-dwCrtLBN, dwPlayLength) )
- return FALSE;
- dwOffset += dwPlayLength;
- dwSize -= dwPlayLength;
- }
- dwCrtLBN += tempExtent.dwExtentLength;
- i++;
- }
- UDF_TransferExtentToFE();
- if( g_DVDVR_PlayQueue_Size == 0 )
- { //this playback is only one extent.
- ie_send_ex(IE_CORE_PLAYBACK_FINISHIED,(void*)QUE_PlaybackFinished);
- }
- if( dwSize > 0 )
- {
- tr_printf(("FATAL: UDF_PlayExtents() Failed [2]: Over range.n"));
- return FALSE;
- }
- return TRUE;
- }
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // Private Services
- /////////////////////////////////////////////////////////////////////////////
- // _initializeUDF102()
- //
- // Description: Initializes a UDF-1.02 File-System.
- //
- // Input: bIsUDFBridge - Indicates whether or not the UDF instance is
- // recorded in UDF-Bridge format.
- // Output: None
- // In/Out: None
- // Return: TRUE if the initialization was successful; FALSE othewise.
- //
- // Remarks:
- // 1. Depending on whether or not UDF was recorded in UDF-Bridge format,
- // the absolute address of the Volume-Recognition-Sequence is determined.
- // 2. The method will look for the NSR02 descriptor, indicating UDF-1.02.
- #define DESC_BUFFER_SZ 33
- BOOL _initializeUDF102(void)
- {
- BOOL bNSRFound= FALSE;
- BOOL bRootDirEstablished= FALSE;
- UINT16 uMVDS_Size= 0;
- //UINT16 uFSDS_Size= 0;
- UINT32 ulPartitionSize= 0;
- DWORD dwMVDS_Location, dwFSDS_Location;
- DWORD dwCurrDescLBN;
- BYTE *pDescBuffer;
- Tag *pDescTag;
- struct GenericVolumeStructureDesc_Base *pCurrDescHdr;
- struct AnchorVolumeDescPtr *pAnchorVolDescPtr;
- dbg_printf(("_initializeUDF102() calling.n"));
- // Allocate space for a generic Descriptor base
- pCurrDescHdr= (struct GenericVolumeStructureDesc_Base*)malloc(sizeof(struct GenericVolumeStructureDesc_Base));
- if (NULL == pCurrDescHdr) {
- dbg_printf(("WARNING: _initializeUDF102() Failed [1]: Low system resourcesn"));
- return FALSE;
- }
- // Verify Integrity of the Volume Recognition Sequence, by searching for
- // the first Volume-Structure Descriptor ("NSR" Descriptor)
- dwCurrDescLBN= (g_pUDFInfo->dwSessionStartLBN + VOLUME_RECOGNITION_SEQUENCE_START_LSN);
- while (dwCurrDescLBN < g_pUDFInfo->dwSessionStartLBN + VOLUME_RECOGNITION_SEQUENCE_START_LSN+16)
- {
- // Read the Descriptor's Header in order to determine the type of the descriptor
- if (! AuxCache_GetBytes(dwCurrDescLBN, 0, sizeof(struct GenericVolumeStructureDesc_Base),
- (BYTE*)pCurrDescHdr))
- {
- dbg_printf(("WARNING: _initializeUDF102() Failed [2]n"));
- break;
- }
- #ifdef _DEBUG
- // Check for a Beginning Extended Area Descriptor
- if (0 == strncmp((LPCSTR)pCurrDescHdr->aStandardID, STANDARD_ID_BEA01, STANDARD_ID_LEN)) {
- dbg_printf(("Beginning of Extended Area Descriptor found.n"));
- dwCurrDescLBN++; // Skip to the next Descriptor
- continue;
- }
- // Check for a Boot Descriptor
- if (0 == strncmp((LPCSTR)pCurrDescHdr->aStandardID, STANDARD_ID_BOOT2, STANDARD_ID_LEN)) {
- dbg_printf(("Boot Descriptor found.n"));
- dwCurrDescLBN++; // Skip to the next Descriptor
- continue;
- }
- #endif //_DEBUG
- // Check for an NSR02 Descriptor
- if (0 == strncmp((LPCSTR)pCurrDescHdr->aStandardID, STANDARD_ID_NSR02, STANDARD_ID_LEN)) {
- bNSRFound= TRUE;
- break;
- }
- //<<MikeX_0524_2004_A: Check for an NSR03 Descriptor
- if (0 == strncmp((LPCSTR)pCurrDescHdr->aStandardID, STANDARD_ID_NSR03, STANDARD_ID_LEN)) {
- bNSRFound= TRUE;
- break;
- }
- //MikeX_0524_2004_A>>
- // Check for a Terminating Extended Area Descriptor
- if (0 == strncmp((LPCSTR)pCurrDescHdr->aStandardID, STANDARD_ID_TEA01, STANDARD_ID_LEN)) {
- dbg_printf(("Volume-Recognition-Sequence Termination found.n"));
- break;
- }
- // Any other Descriptor is not of interest -- just skip to the next one
- dbg_printf(("Skipping Volume-Descriptor of type: 0x%02x.n", pCurrDescHdr->uStructureType));
- dwCurrDescLBN++;
- } //endof while
- free(pCurrDescHdr);
- //MikeX_0617_2004_A: Patch!!! Can play the DVD disc without PVD.
- /* if (! bNSRFound) {
- dbg_printf(("WARNING: _initializeUDF102() Failed [3]n"));
- return FALSE;
- }
- */
- // Allocate space for a Descriptor Buffer, that will hold a Descriptor-fraction
- pDescBuffer= (BYTE*)malloc(DESC_BUFFER_SZ);
- if (NULL == pDescBuffer) {
- dbg_printf(("WARNING: _initializeUDF102() Failed [4]: Low system resorucesn"));
- return FALSE;
- }
- // Locate the First Anchor-Point which contains an Anchor Volume-Descriptor Pointer
- if (! AuxCache_GetBytes((g_pUDFInfo->dwSessionStartLBN + FIRST_ANCHOR_POINT_LSN), 0,
- DESC_BUFFER_SZ, pDescBuffer))
- {
- dbg_printf(("WARNING: _initializeUDF102() Failed [5]n"));
- free(pDescBuffer);
- return FALSE;
- }
- pAnchorVolDescPtr= (struct AnchorVolumeDescPtr *)pDescBuffer;
- // Verify Integrity of the Anchor Volume-Descriptor Pointer
- if ((TAG_ID_ANCHOR_VOLUME_DESC_PTR != LE_WORD(pAnchorVolDescPtr->tgDescTag.uTagID)) ||
- (FIRST_ANCHOR_POINT_LSN != LE_DWORD(pAnchorVolDescPtr->tgDescTag.dwTagLocation)))
- {
- dbg_printf(("WARNING: _initializeUDF102() Failed [6]n"));
- free(pDescBuffer);
- return FALSE;
- }
- // Extract the Location and Length of the Main Volume Descriptor Sequence (MVDS)
- dwMVDS_Location= LE_DWORD(pAnchorVolDescPtr->exMainVolumeDescSequenceExtent.dwExtentLocation);
- uMVDS_Size= (UINT16)((LE_DWORD(pAnchorVolDescPtr->exMainVolumeDescSequenceExtent.dwExtentLength) - 1) / LOGICAL_BLOCK_SIZE);
- // Check for a possible Error
- if ((0 == dwMVDS_Location) || (0 == uMVDS_Size)) {
- // Extract the Reserve Descriptor information
- dwMVDS_Location= LE_DWORD(pAnchorVolDescPtr->exReserveVolumeDescSequenceExtent.dwExtentLocation);
- uMVDS_Size= (UINT16)((LE_DWORD(pAnchorVolDescPtr->exReserveVolumeDescSequenceExtent.dwExtentLength) - 1) / (UINT32)LOGICAL_BLOCK_SIZE);
- // Make sure that a Reserve Descriptor is indeed available
- if (0 == uMVDS_Size) {
- dbg_printf(("WARNING: _initializeUDF102() Failed [7]n"));
- free(pDescBuffer);
- return FALSE;
- }
- }
- // Enumerate the Main Volume Descriptor Sequence, one Descriptor at a time,
- // until all required information is obtained.
- dwCurrDescLBN= dwMVDS_Location;
- while (uMVDS_Size)
- {
- if (! AuxCache_GetBytes(dwCurrDescLBN, 0, DESC_BUFFER_SZ, pDescBuffer)) {
- dbg_printf(("WARNING: _initializeUDF102() Failed [8]n"));
- break;
- }
- pDescTag= (Tag*)pDescBuffer;
- // Check for a Primary-Volume Descriptor
- if (TAG_ID_PRIMARY_VOLUME_DESC == LE_WORD(pDescTag->uTagID)) {
- char szPrimaryVolumeName[32];
- WCHAR szwPrimaryVolumeName[32];
- dbg_printf(("Primary Volume Descriptor found.n"));
- // Copy the Primary-Volume Name
- AuxCache_GetBytes(dwCurrDescLBN, (1+PRIMARY_VOLUME_DESC_INFO_OFFSET), 31,
- (BYTE*)szPrimaryVolumeName);
- szPrimaryVolumeName[31]= 0;
- _str2wcs(szPrimaryVolumeName, szwPrimaryVolumeName, sizeof(szwPrimaryVolumeName));
- sc_SetBytes(SC_VOLUME_ID_ADDR, 0, FILESYSTEM_MAX_VOLUME_NAME*sizeof(WCHAR), szwPrimaryVolumeName);
- #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 atemp[8];
- NewChecksum = 0;
- for (i=0;i<31;i++)
- NewChecksum += szPrimaryVolumeName[i];
- AuxCache_GetBytes(dwCurrDescLBN, (1+VOLUME_SET_IDENTIFIER), 8,
- (BYTE*)atemp);
- for(i=0;i<8;i++)
- NewChecksum+=atemp[i];
- }
- #endif //HW_POWER_ON_RESUME
- dbg_printf(("Volume-ID: '%s'n", szPrimaryVolumeName));
- }
- // Check for a Partition-Descriptor
- if (TAG_ID_PARTITION_DESC == LE_WORD(pDescTag->uTagID)) {
- struct {
- UINT32 dwPartitionStartingLocation;
- UINT32 uPartitionLength;
- } PartitionDescInfo;
- AuxCache_GetBytes(dwCurrDescLBN, PARTITION_DESC_INFO_OFFSET, sizeof(PartitionDescInfo),
- (BYTE*)&PartitionDescInfo);
- g_pUDFInfo->dwMainPartitionLocation= LE_DWORD(PartitionDescInfo.dwPartitionStartingLocation);
- ulPartitionSize= LE_DWORD(PartitionDescInfo.uPartitionLength);
- }
- // Check for a Logical-Volume Descriptor
- if (TAG_ID_LOGICAL_VOLUME_DESC == LE_WORD(pDescTag->uTagID)) {
- Long_ad ladFSDInfo;
- // Cast the Contents-Use to a Long_ad (DVD-RW Part 2, Section 2.6.7)
- AuxCache_GetBytes(dwCurrDescLBN, LOGICAL_VOLUME_DESC_INFO_OFFSET, sizeof(Long_ad),
- (BYTE*)&ladFSDInfo);
- dwFSDS_Location= LE_WORD(ladFSDInfo.lbaExtentLocation.uLogicalBlockNumber);
- //uFSDS_Size= (UINT16)((LE_DWORD(ladFSDInfo.cbExtentLength) + (UINT32)LOGICAL_BLOCK_SIZE - 1) / (UINT32)LOGICAL_BLOCK_SIZE);//Hamadk_0908_2003_a:Fixed a bug in intializing of the file system
- }
- // Check for a Terminating Descriptor
- if (TAG_ID_TERMINATING_DESC == LE_WORD(pDescTag->uTagID))
- break;
- // Move to the next Descriptor
- dwCurrDescLBN++;
- uMVDS_Size--;
- }
- // Make sure that there is enough information to access the File-Set Descriptor
- if ((0 == uMVDS_Size) || (0 == ulPartitionSize)/* || (0 == uFSDS_Size)*/) {
- free(pDescBuffer);
- dbg_printf(("WARNING: _initializeUDF102() Failed [9]n"));
- return FALSE;
- }
- // Establish the absolute LBA of the File-Set Descriptor Sequence, which is also
- // the fixed Offset needed to be added to any LBN in order to get the absoulte
- // LBA of Files and Directories.
- g_pUDFInfo->dwLBA_Offset= (g_pUDFInfo->dwMainPartitionLocation + dwFSDS_Location);
- // Enumerate the File-Set Descriptor Sequence, until a File-Set Descriptor is found.
- // From that File-Set Descriptor, extract the ICB corresponding to the Root-Directory.
- dwCurrDescLBN= g_pUDFInfo->dwLBA_Offset;
-
- //Get the File Set Descriptor directly without checking if the size read our from logical volume descriptor.
- //while (uFSDS_Size) {
- if (! AuxCache_GetBytes(dwCurrDescLBN, 0, DESC_BUFFER_SZ, pDescBuffer)) {
- dbg_printf(("WARNING: _initializeUDF102() Failed [10]n"));
- // break;
- }
- pDescTag= (Tag*)pDescBuffer;
- if (TAG_ID_FILE_SET_DESC == LE_WORD(pDescTag->uTagID)) {
- Long_ad ladRootDirICB;
- // Extract the location of the Root Directory
- AuxCache_GetBytes(dwCurrDescLBN, FILE_SET_DESC_INFO_OFFSET, sizeof(Long_ad),
- (BYTE*)&ladRootDirICB);
- g_pUDFInfo->dwRootDirICB= LE_DWORD(ladRootDirICB.lbaExtentLocation.uLogicalBlockNumber);
- bRootDirEstablished= TRUE;
- //break;
- }
- if (TAG_ID_TERMINATING_DESC == LE_WORD(pDescTag->uTagID))
- //break;
- // Move to the next Descriptor
- //dwCurrDescLBN++;
- //uFSDS_Size--;
- //}
- // When this point is reached, the entire File-Set Descriptor Sequence has been
- // scanned, and the Root-Directory's ICB possibly established.
- free(pDescBuffer);
- // Set the Current Directory to the Root-Directory, if it was established.
- if (bRootDirEstablished)
- g_pUDFInfo->dwCurrDirICB= g_pUDFInfo->dwRootDirICB;
- g_pUDFInfo->uRevision= 0x0102;
- return bRootDirEstablished;
- }
- /////////////////////////////////////////////////////////////////////////////
- // _initializeUDF200()
- //
- // Description: Initializes a UDF-2.00 File-System.
- //
- // Input: bIsUDFBridge - Indicates whether or not the UDF instance is
- // recorded in UDF-Bridge format.
- // Output: None
- // In/Out: None
- // Return: TRUE if the initialization was successful; FALSE othewise.
- //
- // Remarks:
- // 1. Depending on whether or not UDF was recorded in UDF-Bridge format,
- // the absolute address of the Volume-Recognition-Sequence is determined.
- // 2. The method will look for the NSR03 descriptor, indicating UDF-2.00 and
- // higher.
- // 3. The Integrity of the Volume is verified using the Logical-Volume-
- // Integrity Descriptor.
- // 4. The Sparable-Partition and Sparing-Table are established.
- BOOL _initializeUDF200(void)
- {
- #ifndef UDF_SUPPORT_UDF201
-
- return FALSE;
- #else
- /*
- BOOL bNSRFound= FALSE;
- BOOL bVolumeIntegrityVerified= FALSE;
- BOOL bRootDirEstablished= FALSE;
- UINT16 uMVDS_Size= 0;
- UINT16 uPartitionSize= 0;
- UINT16 uPartitionNumber;
- UINT16 uLVIS_Size= 0;
- UINT16 uFSDS_Size= 0;
- DWORD dwMVDS_Location, dwLVIS_Location, dwFSDS_Location;
- DWORD dwCurrDescLBN;
- BYTE *pDescBuffer;
- Tag *pDescTag;
- struct GenericVolumeStructureDesc *pCurrDesc;
- struct AnchorVolumeDescPtr *pAnchorVolDescPtr;
- dbg_printf(("_initializeUDF200() calling.n"));
- // Allocate space for a generic Descriptor (all Descriptors are not larger than
- // a single Logical-Block).
- pDescBuffer= (BYTE*)malloc(LOGICAL_BLOCK_SIZE);
- if (NULL == pDescBuffer) {
- dbg_printf(("WARNING: _initializeUDF200() Failed [1]n"));
- return FALSE;
- }
- // Verify Integrity of the Volume Recognition Sequence, by searching for
- // the first Volume-Structure Descriptor ("NSR" Descriptor)
- dwCurrDescLBN= (g_pUDFInfo->dwSessionStartLBN + VOLUME_RECOGNITION_SEQUENCE_START_LSN);
- while (TRUE) {
- if (! AuxCache_GetBytes(dwCurrDescLBN, 0, LOGICAL_BLOCK_SIZE, pDescBuffer)) {
- free(pDescBuffer);
- dbg_printf(("WARNING: _initializeUDF200() Failed [2]n"));
- return FALSE;
- }
- pCurrDesc= (struct GenericVolumeStructureDesc*)pDescBuffer;
- // Check for a Beginning Extended Aread Descriptor
- if (0 == strncmp((LPCSTR)pCurrDesc->aStandardID, STANDARD_ID_BEA01, STANDARD_ID_LEN)) {
- dwCurrDescLBN++; // Skip to the next Descriptor
- continue;
- }
- // Check for a Boot Descriptor
- if (0 == strncmp((LPCSTR)pCurrDesc->aStandardID, STANDARD_ID_BOOT2, STANDARD_ID_LEN)) {
- dwCurrDescLBN++; // Skip to the next Descriptor
- continue;
- }
- // Check for an NSR03 Descriptor
- if (0 == strncmp((LPCSTR)pCurrDesc->aStandardID, STANDARD_ID_NSR03, STANDARD_ID_LEN)) {
- bNSRFound= TRUE;
- break;
- }
- // Check for a Terminating Extended Area Descriptor
- if (0 == strncmp((LPCSTR)pCurrDesc->aStandardID, STANDARD_ID_TEA01, STANDARD_ID_LEN))
- break;
- // Any other Descriptor is not of interest -- just skip to the next one
- dwCurrDescLBN++;
- }
- if (! bNSRFound) {
- free(pDescBuffer);
- dbg_printf(("WARNING: _initializeUDF200() Failed [3]n"));
- return FALSE;
- }
- // Locate the First Anchor-Point which contains an Anchor Volume-Descriptor Pointer
- if (! AuxCache_GetBytes(FIRST_ANCHOR_POINT_LSN, 0, LOGICAL_BLOCK_SIZE, pDescBuffer)) {
- free(pDescBuffer);
- dbg_printf(("WARNING: _initializeUDF200() Failed [4]n"));
- return FALSE;
- }
- pAnchorVolDescPtr= (struct AnchorVolumeDescPtr *)pDescBuffer;
- // Verify Integrity of the Anchor Volume-Descriptor Pointer
- if ((TAG_ID_ANCHOR_VOLUME_DESC_PTR != LE_WORD(pAnchorVolDescPtr->tgDescTag.uTagID)) ||
- (FIRST_ANCHOR_POINT_LSN != LE_DWORD(pAnchorVolDescPtr->tgDescTag.dwTagLocation))) {
- free(pDescBuffer);
- dbg_printf(("WARNING: _initializeUDF200() Failed [5]n"));
- return FALSE;
- }
- // Extract the Location and Length of the Main Volume Descriptor Sequence (MVDS)
- dwMVDS_Location= LE_DWORD(pAnchorVolDescPtr->exMainVolumeDescSequenceExtent.dwExtentLocation);
- uMVDS_Size= (UINT16)((LE_DWORD(pAnchorVolDescPtr->exMainVolumeDescSequenceExtent.dwExtentLength) - 1) / (UINT32)LOGICAL_BLOCK_SIZE);
- // Check for a possible Error
- if ((0 == dwMVDS_Location) || (0 == uMVDS_Size)) {
- // Extract the Reserve Descriptor information
- dwMVDS_Location= LE_DWORD(pAnchorVolDescPtr->exReserveVolumeDescSequenceExtent.dwExtentLocation);
- uMVDS_Size= (UINT16)((LE_DWORD(pAnchorVolDescPtr->exReserveVolumeDescSequenceExtent.dwExtentLength) - 1) / (UINT32)LOGICAL_BLOCK_SIZE);
- // Make sure that a Reserve Descriptor is indeed available
- if (0 == uMVDS_Size)
- return FALSE;
- }
- // Enumerate the Main Volume Descriptor Sequence, one Descriptor at a time,
- // until all required information is obtained.
- dwCurrDescLBN= dwMVDS_Location;
- while (uMVDS_Size) {
- if (! AuxCache_GetBytes(dwCurrDescLBN, 0, LOGICAL_BLOCK_SIZE, pDescBuffer)) {
- free(pDescBuffer);
- dbg_printf(("WARNING: _initializeUDF200() Failed [6]n"));
- return FALSE;
- }
- pDescTag= (Tag*)pDescBuffer;
- // Check for a Primary-Volume Descriptor
- if (TAG_ID_PRIMARY_VOLUME_DESC == LE_WORD(pDescTag->uTagID)) {
- struct PrimaryVolumeDesc *pPVD= (struct PrimaryVolumeDesc *)pDescBuffer;
- dbg_printf(("Primary Volume Descriptor found.n"));
- // Copy the Primary-Volume Name
- strncpy(g_pUDFInfo->szPrimaryVolumeName, (LPCSTR)&pPVD->sVolumeID[1], 31);
- g_pUDFInfo->szPrimaryVolumeName[31]= 0;
- dbg_printf(("Volume-ID: '%s'n", g_pUDFInfo->szPrimaryVolumeName));
- dbg_printf(("Volume-Set ID: '%s'n", (LPCSTR)&pPVD->sVolumeSetID[1]));
- dbg_printf(("Volume recorded on: %d/%02d/%04d %02d:%02d:%02d.n",
- pPVD->tsRecording.uDay, pPVD->tsRecording.uMonth, LE_WORD(pPVD->tsRecording.iYear),
- pPVD->tsRecording.uHour, pPVD->tsRecording.uMinute, pPVD->tsRecording.uSecond));
- }
- // Check for a Partition-Descriptor
- if (TAG_ID_PARTITION_DESC == LE_WORD(pDescTag->uTagID)) {
- struct PartitionDesc *pPartitionDesc= (struct PartitionDesc *)pDescBuffer;
- struct PartitionHeaderDesc *pPartitionHdrDesc;
- g_pUDFInfo->dwMainPartitionLocation= LE_DWORD(pPartitionDesc->dwPartitionStartingLocation);
- uPartitionSize= (UINT16)((LE_DWORD(pPartitionDesc->uPartitionLength) - 1) / (UINT32)LOGICAL_BLOCK_SIZE);
- uPartitionNumber= pPartitionDesc->uPartitionNumber;
- // Cast the Contents-Use to a Partition-Header Descriptor, and extract
- // the necessary info (DVD-RW Part 2, Section 2.6.6)
- pPartitionHdrDesc= (struct PartitionHeaderDesc *)pPartitionDesc->aPartitionContentsUse;
- g_pUDFInfo->sadMainPartitionUnallocSpaceBitmap= pPartitionHdrDesc->sadUnallocSpaceBitmap;
-
- // Note: Additional information about the Partition will be obtained from the
- // Logical Volume Descriptor.
- }
- // Check for a Logical-Volume Descriptor
- if (TAG_ID_LOGICAL_VOLUME_DESC == LE_WORD(pDescTag->uTagID)) {
- DWORD uPartitionMapsCnt;
- struct LogicalVolumeDesc *pLVD= (struct LogicalVolumeDesc *)pDescBuffer;
- struct PartitionMapGeneric *pGenPartitionMap;
- struct PartitionMapType2_SparablePartition *pSparablePartitionMap= NULL;
- // Cast the Contents-Use to a Long_ad (DVD-RW Part 2, Section 2.6.7)
- Long_ad *pFSDInfo= (Long_ad*)pLVD->aLogicalVolumeContentsUse;
- dwFSDS_Location= LE_WORD(pFSDInfo->lbaExtentLocation.uLogicalBlockNumber);
- uFSDS_Size= (UINT16)((LE_DWORD(pFSDInfo->cbExtentLength) - 1) / (UINT32)LOGICAL_BLOCK_SIZE);
- // Extract the location and size of the Logical Volume Integrity Sequence
- dwLVIS_Location= LE_DWORD(pLVD->exIntegritySequenceExtent.dwExtentLocation);
- uLVIS_Size= (UINT16)((LE_DWORD(pLVD->exIntegritySequenceExtent.dwExtentLength) - 1) / (UINT32)LOGICAL_BLOCK_SIZE);
- // Gather some additional Partition information, by examining the Partition-Maps
- uPartitionMapsCnt= LE_DWORD(pLVD->uNumberOfPartitionMaps);
- pGenPartitionMap= (struct PartitionMapGeneric*)(pDescBuffer + sizeof(struct LogicalVolumeDesc));
- // Seek for a Type2 Partition-Map, describing the Sparable Partition corresponding
- // to the Main Partition.
- g_pUDFInfo->bUseSparingManagement= FALSE;
- g_pUDFInfo->pMainPartitionSparingTable= NULL;
- while (uPartitionMapsCnt) {
- if (PARTITION_MAP_TYPE_2 == pGenPartitionMap->uPartitionMapType) {
- // Cast to a Sparable-Partition Map
- pSparablePartitionMap= (struct PartitionMapType2_SparablePartition *)pGenPartitionMap;
- // Make sure that it's the correct type
- if (0 == strcmp(ENTITYID_SPARABLE_PARTITION, (LPCSTR)pSparablePartitionMap->eidPartitionTypeID.aIdentifier)) {
- g_pUDFInfo->bUseSparingManagement= TRUE;
- break;
- }
- }
- // Move to the next Partition-Map
- ((BYTE*)pGenPartitionMap) += pGenPartitionMap->cbPartitionMapLength;
- uPartitionMapsCnt--;
- }
- // Check if the Sparable Partition Map was located
- if ( g_pUDFInfo->bUseSparingManagement &&
- (0 != uPartitionMapsCnt) &&
- (uPartitionNumber == pSparablePartitionMap->uPartitionNumber) &&
- (0 != pSparablePartitionMap->cbSparingTableSize) )
- {
- DWORD dwSparingTableAddr= 0;
- DWORD cbSparingTableSize= 0;
- // Extract the necessary information and allocate space for the Sparing-Table
- g_pUDFInfo->uSparingPacketLength= LE_WORD(pSparablePartitionMap->uPacketLength);
- dwSparingTableAddr= LE_DWORD(pSparablePartitionMap->aLocationsOfSparingTables[0]);
- cbSparingTableSize= LE_DWORD(pSparablePartitionMap->cbSparingTableSize);
- g_pUDFInfo->pMainPartitionSparingTable= (struct SparingTable*)malloc((UINT16)cbSparingTableSize);
- if (NULL == g_pUDFInfo->pMainPartitionSparingTable) {
- uPartitionSize= 0;
- break;
- }
- // Load the Sparing-Table
- if (! AuxCache_GetBytes(dwSparingTableAddr, 0, (UINT16)cbSparingTableSize, (BYTE*)g_pUDFInfo->pMainPartitionSparingTable))
- {
- free(g_pUDFInfo->pMainPartitionSparingTable);
- uPartitionSize= 0;
- break;
- }
- }
- }
- // Check for a Terminating Descriptor
- if (TAG_ID_TERMINATING_DESC == LE_WORD(pDescTag->uTagID))
- break;
- // Move to the next Descriptor
- dwCurrDescLBN++;
- uMVDS_Size--;
- }
- // Make sure that there is enough information to access the File-Set Descriptor
- if ((0 == uMVDS_Size) || (0 == uPartitionSize) || (0 == uFSDS_Size)) {
- free(pDescBuffer);
- dbg_printf(("WARNING: _initializeUDF200() Failed [7]n"));
- return FALSE;
- }
- // Enumerate the Logical Volume Integrity Sequence, until a Close Logical Volume
- // Integrity Descriptor is found.
- // In that Descriptor, examine and validate the UDF Revision.
- dwCurrDescLBN= dwLVIS_Location;
- while (uLVIS_Size) {
- if (! AuxCache_GetBytes(dwCurrDescLBN, 0, LOGICAL_BLOCK_SIZE, pDescBuffer)) {
- free(pDescBuffer);
- dbg_printf(("WARNING: _initializeUDF200() Failed [8]n"));
- return FALSE;
- }
- pDescTag= (Tag*)pDescBuffer;
- if (TAG_ID_LOGICAL_VOLUME_INTEGRITY == LE_WORD(pDescTag->uTagID)) {
- struct LogicalVolumeIntegrityDesc *pLVID= (struct LogicalVolumeIntegrityDesc *)pDescBuffer;
- if (INTEGRITY_TYPE_CLOSE == LE_DWORD(pLVID->dwIntegrityType)) {
- struct LogicalVolumeIntegrityDescImplUse *pImplUse=
- (struct LogicalVolumeIntegrityDescImplUse*)((BYTE*)pLVID +
- sizeof(struct LogicalVolumeIntegrityDesc) +
- (8 * (UINT16)LE_DWORD(pLVID->uNumberOfPartitions)));
- // Verify the appropriate UDF Revision
- if (0x0200 == LE_WORD(pImplUse->uMinimumUDFReadRevision))
- bVolumeIntegrityVerified= TRUE;
- }
- }
- if (TAG_ID_TERMINATING_DESC == LE_WORD(pDescTag->uTagID))
- break;
- // Move to the next Descriptor
- dwCurrDescLBN++;
- uLVIS_Size--;
- }
- // Make sure that the Volume's Integrity was verified
- if (! bVolumeIntegrityVerified) {
- free(pDescBuffer);
- dbg_printf(("WARNING: _initializeUDF200() Failed [9]n"));
- return FALSE;
- }
- // Establish the absolute LBA of the File-Set Descriptor Sequence, which is also
- // the fixed Offset needed to be added to any LBN in order to get the absoulte
- // LBA of Files and Directories.
- g_pUDFInfo->dwLBA_Offset= _absoluteLBA(dwFSDS_Location);
- // Enumerate the File-Set Descriptor Sequence, until a File-Set Descriptor is found.
- // From that File-Set Descriptor, extract the ICB corresponding to the Root-Directory.
- dwCurrDescLBN= dwFSDS_Location;
- while (uFSDS_Size) {
- if (! AuxCache_GetBytes(_absoluteLBA(dwCurrDescLBN), 0, LOGICAL_BLOCK_SIZE, pDescBuffer)) {
- free(pDescBuffer);
- dbg_printf(("WARNING: _initializeUDF200() Failed [10]n"));
- return FALSE;
- }
- pDescTag= (Tag*)pDescBuffer;
- if (TAG_ID_FILE_SET_DESC == LE_WORD(pDescTag->uTagID)) {
- // Extract the location of the Root Directory
- struct FileSetDesc *pFSD= (struct FileSetDesc *)pDescBuffer;
- g_pUDFInfo->ladRootDirICB= pFSD->ladRootDirICB;
- bRootDirEstablished= TRUE;
- break;
- }
- if (TAG_ID_TERMINATING_DESC == LE_WORD(pDescTag->uTagID))
- break;
- // Move to the next Descriptor
- dwCurrDescLBN++;
- uFSDS_Size--;
- }
- // When this point is reached, the entire File-Set Descriptor Sequence has been
- // scanned, and the Root-Directory's ICB possibly established.
- free(pDescBuffer);
- // Set the Current Directory to the Root-Directory, if it was established.
- if (bRootDirEstablished)
- g_pUDFInfo->ladCurrDirICB= g_pUDFInfo->ladRootDirICB;
- g_pUDFInfo->uRevision= 0x0200;
- return bRootDirEstablished;
- */
- #ifdef DVD_VR_SUPPORT
- BOOL bNSRFound= FALSE;
- BOOL bVolumeIntegrityVerified= FALSE;
- BOOL bRootDirEstablished= FALSE;
- UINT16 uMVDS_Size= 0;
- UINT16 uPartitionSize= 0;
- UINT16 uPartitionNumber;
- UINT16 uLVIS_Size= 0;
- UINT16 uFSDS_Size= 0;
- DWORD dwMVDS_Location, dwLVIS_Location, dwFSDS_Location;
- DWORD dwCurrDescLBN;
- BYTE *pDescBuffer;
- Tag *pDescTag;
- struct GenericVolumeStructureDesc *pCurrDesc;
- struct AnchorVolumeDescPtr *pAnchorVolDescPtr;
- dbg_printf(("_initializeUDF200() calling.n"));
- // Allocate space for a generic Descriptor (all Descriptors are not larger than
- // a single Logical-Block).
- pDescBuffer= (BYTE*)malloc(VOLUME_RECOGNITION_SIZE);
- if (NULL == pDescBuffer) {
- dbg_printf(("WARNING: _initializeUDF200() Failed [1]n"));
- return FALSE;
- }
- // Verify Integrity of the Volume Recognition Sequence, by searching for
- // the first Volume-Structure Descriptor ("NSR" Descriptor)
- dwCurrDescLBN= (g_pUDFInfo->dwSessionStartLBN + VOLUME_RECOGNITION_SEQUENCE_START_LSN);
- while (TRUE) {
- if (! AuxCache_GetBytes(dwCurrDescLBN, 0, VOLUME_RECOGNITION_SIZE, pDescBuffer)) {
- free(pDescBuffer);
- dbg_printf(("WARNING: _initializeUDF200() Failed [2]n"));
- return FALSE;
- }
- pCurrDesc= (struct GenericVolumeStructureDesc*)pDescBuffer;
- // Check for a Beginning Extended Aread Descriptor
- if (0 == strncmp((LPCSTR)pCurrDesc->aStandardID, STANDARD_ID_BEA01, STANDARD_ID_LEN)) {
- dwCurrDescLBN++; // Skip to the next Descriptor
- continue;
- }
- // Check for a Boot Descriptor
- if (0 == strncmp((LPCSTR)pCurrDesc->aStandardID, STANDARD_ID_BOOT2, STANDARD_ID_LEN)) {
- dwCurrDescLBN++; // Skip to the next Descriptor
- continue;
- }
- // Check for an NSR03 Descriptor
- if (0 == strncmp((LPCSTR)pCurrDesc->aStandardID, STANDARD_ID_NSR03, STANDARD_ID_LEN)) {
- bNSRFound= TRUE;
- break;
- }
- // Check for a Terminating Extended Area Descriptor
- if (0 == strncmp((LPCSTR)pCurrDesc->aStandardID, STANDARD_ID_TEA01, STANDARD_ID_LEN))
- break;
- // Any other Descriptor is not of interest -- just skip to the next one
- dwCurrDescLBN++;
- }
- if (! bNSRFound) {
- free(pDescBuffer);
- dbg_printf(("WARNING: _initializeUDF200() Failed [3]n"));
- return FALSE;
- }
-
- free(pDescBuffer);
- pDescBuffer= (BYTE*)malloc(ANCHOR_VOLUME_DESCRIPTOR_POINTER_SIZE);
- if (NULL == pDescBuffer) {
- dbg_printf(("WARNING: _initializeUDF200() Failed [1]: Low system resourcen"));
- return FALSE;
- }
- // Locate the First Anchor-Point which contains an Anchor Volume-Descriptor Pointer
- if (! AuxCache_GetBytes(FIRST_ANCHOR_POINT_LSN, 0, ANCHOR_VOLUME_DESCRIPTOR_POINTER_SIZE, pDescBuffer)) {
- free(pDescBuffer);
- dbg_printf(("WARNING: _initializeUDF200() Failed [4]n"));
- return FALSE;
- }
- pAnchorVolDescPtr= (struct AnchorVolumeDescPtr *)pDescBuffer;
- // Verify Integrity of the Anchor Volume-Descriptor Pointer
- if ((TAG_ID_ANCHOR_VOLUME_DESC_PTR != LE_WORD(pAnchorVolDescPtr->tgDescTag.uTagID)) ||
- (FIRST_ANCHOR_POINT_LSN != LE_DWORD(pAnchorVolDescPtr->tgDescTag.dwTagLocation))) {
- free(pDescBuffer);
- dbg_printf(("WARNING: _initializeUDF200() Failed [5]n"));
- return FALSE;
- }
- // Extract the Location and Length of the Main Volume Descriptor Sequence (MVDS)
- dwMVDS_Location= LE_DWORD(pAnchorVolDescPtr->exMainVolumeDescSequenceExtent.dwExtentLocation);
- uMVDS_Size= (UINT16)((LE_DWORD(pAnchorVolDescPtr->exMainVolumeDescSequenceExtent.dwExtentLength) - 1) / (UINT32)LOGICAL_BLOCK_SIZE);
- // Check for a possible Error
- if ((0 == dwMVDS_Location) || (0 == uMVDS_Size)) {
- // Extract the Reserve Descriptor information
- dwMVDS_Location= LE_DWORD(pAnchorVolDescPtr->exReserveVolumeDescSequenceExtent.dwExtentLocation);
- uMVDS_Size= (UINT16)((LE_DWORD(pAnchorVolDescPtr->exReserveVolumeDescSequenceExtent.dwExtentLength) - 1) / (UINT32)LOGICAL_BLOCK_SIZE);
- // Make sure that a Reserve Descriptor is indeed available
- if (0 == uMVDS_Size)
- return FALSE;
- }
-
- free(pDescBuffer);
- pDescBuffer= (BYTE*)malloc(VOLUME_DESCRIPTOR_SIZE);
- if (NULL == pDescBuffer) {
- dbg_printf(("WARNING: _initializeUDF200() Failed [1]: Low system resourcen"));
- return FALSE;
- }
- // Enumerate the Main Volume Descriptor Sequence, one Descriptor at a time,
- // until all required information is obtained.
- dwCurrDescLBN= dwMVDS_Location;
- while (uMVDS_Size) {
- if (! AuxCache_GetBytes(dwCurrDescLBN, 0, VOLUME_DESCRIPTOR_SIZE, pDescBuffer)) {
- free(pDescBuffer);
- dbg_printf(("WARNING: _initializeUDF200() Failed [6]n"));
- return FALSE;
- }
- pDescTag= (Tag*)pDescBuffer;
- // Check for a Primary-Volume Descriptor
- if (TAG_ID_PRIMARY_VOLUME_DESC == LE_WORD(pDescTag->uTagID)) {
- struct PrimaryVolumeDesc *pPVD= (struct PrimaryVolumeDesc *)pDescBuffer;
- dbg_printf(("Primary Volume Descriptor found.n"));
- dbg_printf(("Volume-ID: '%s'n", (LPCSTR)&pPVD->sVolumeID[1]));
- dbg_printf(("Volume-Set ID: '%s'n", (LPCSTR)&pPVD->sVolumeSetID[1]));
- dbg_printf(("Volume recorded on: %d/%02d/%04d %02d:%02d:%02d.n",
- pPVD->tsRecording.uDay, pPVD->tsRecording.uMonth, LE_WORD(pPVD->tsRecording.iYear),
- pPVD->tsRecording.uHour, pPVD->tsRecording.uMinute, pPVD->tsRecording.uSecond));
- }
- // Check for a Partition-Descriptor
- if (TAG_ID_PARTITION_DESC == LE_WORD(pDescTag->uTagID)) {
- struct PartitionDesc *pPartitionDesc= (struct PartitionDesc *)pDescBuffer;
- struct PartitionHeaderDesc *pPartitionHdrDesc;
- g_pUDFInfo->dwMainPartitionLocation= LE_DWORD(pPartitionDesc->dwPartitionStartingLocation);
- uPartitionSize= (UINT16)((LE_DWORD(pPartitionDesc->uPartitionLength) - 1) / (UINT32)LOGICAL_BLOCK_SIZE);
- uPartitionNumber= pPartitionDesc->uPartitionNumber;
- // Cast the Contents-Use to a Partition-Header Descriptor, and extract
- // the necessary info (DVD-RW Part 2, Section 2.6.6)
- pPartitionHdrDesc= (struct PartitionHeaderDesc *)pPartitionDesc->aPartitionContentsUse;
- // Note: Additional information about the Partition will be obtained from the
- // Logical Volume Descriptor.
- }
- // Check for a Logical-Volume Descriptor
- if (TAG_ID_LOGICAL_VOLUME_DESC == LE_WORD(pDescTag->uTagID)) {
- DWORD uPartitionMapsCnt;
- struct LogicalVolumeDesc *pLVD= (struct LogicalVolumeDesc *)pDescBuffer;
- struct PartitionMapGeneric *pGenPartitionMap;
- struct PartitionMapType2_SparablePartition *pSparablePartitionMap= NULL;
- // Cast the Contents-Use to a Long_ad (DVD-RW Part 2, Section 2.6.7)
- Long_ad *pFSDInfo= (Long_ad*)pLVD->aLogicalVolumeContentsUse;
- dwFSDS_Location= LE_WORD(pFSDInfo->lbaExtentLocation.uLogicalBlockNumber);
- uFSDS_Size= (UINT16)((LE_DWORD(pFSDInfo->cbExtentLength) - 1) / (UINT32)LOGICAL_BLOCK_SIZE);
- // Extract the location and size of the Logical Volume Integrity Sequence
- dwLVIS_Location= LE_DWORD(pLVD->exIntegritySequenceExtent.dwExtentLocation);
- uLVIS_Size= (UINT16)((LE_DWORD(pLVD->exIntegritySequenceExtent.dwExtentLength) + LOGICAL_BLOCK_SIZE - 1) / (UINT32)LOGICAL_BLOCK_SIZE);
- // Gather some additional Partition information, by examining the Partition-Maps
- uPartitionMapsCnt= LE_DWORD(pLVD->uNumberOfPartitionMaps);
- pGenPartitionMap= (struct PartitionMapGeneric*)(pDescBuffer + sizeof(struct LogicalVolumeDesc));
- // Seek for a Type2 Partition-Map, describing the Sparable Partition corresponding
- // to the Main Partition.
- if( (UINT32)NULL != g_pUDFInfo->pMainPartitionSparingTable && FALSE != g_pUDFInfo->bUseSparingManagement )
- {
- Array_destruct((UINT32)(g_pUDFInfo->pMainPartitionSparingTable));
- g_pUDFInfo->pMainPartitionSparingTable = (UINT32)NULL;
- g_DVDVR_SparingTableSize=0;
- }
- g_pUDFInfo->bUseSparingManagement= FALSE;
- while (uPartitionMapsCnt) {
- if (PARTITION_MAP_TYPE_2 == pGenPartitionMap->uPartitionMapType) {
- // Cast to a Sparable-Partition Map
- pSparablePartitionMap= (struct PartitionMapType2_SparablePartition *)pGenPartitionMap;
- // Make sure that it's the correct type
- if (0 == strcmp(ENTITYID_SPARABLE_PARTITION, (LPCSTR)pSparablePartitionMap->eidPartitionTypeID.aIdentifier)) {
- g_pUDFInfo->bUseSparingManagement= TRUE;
- break;
- }
- }
- // Move to the next Partition-Map
- ((BYTE*)pGenPartitionMap) += pGenPartitionMap->cbPartitionMapLength;
- uPartitionMapsCnt--;
- }
- // Check if the Sparable Partition Map was located
- if ( g_pUDFInfo->bUseSparingManagement &&
- (0 != uPartitionMapsCnt) &&
- (uPartitionNumber == pSparablePartitionMap->uPartitionNumber) &&
- (0 != pSparablePartitionMap->cbSparingTableSize) )
- {
- DWORD dwSparingTableAddr= 0;
- DWORD cbSparingTableSize= 0;
- BYTE buffer[8];
- DWORD i;
- DWORD dwSparingTableArrayAddr = g_DVDVR_SpringTableAddr;
- // Extract the necessary information and allocate space for the Sparing-Table
- g_pUDFInfo->uSparingPacketLength= LE_WORD(pSparablePartitionMap->uPacketLength);
- dwSparingTableAddr= LE_DWORD(pSparablePartitionMap->aLocationsOfSparingTables[0]);
- cbSparingTableSize= LE_DWORD(pSparablePartitionMap->cbSparingTableSize);
- g_pUDFInfo->pMainPartitionSparingTable= Array_constructEx(
- (UINT16)(cbSparingTableSize+SPARING_TABLE_MAP_ENTRY_SIZE-1)/SPARING_TABLE_MAP_ENTRY_SIZE,
- SPARING_TABLE_MAP_ENTRY_SIZE,&dwSparingTableArrayAddr);
- if ((UINT32)NULL == g_pUDFInfo->pMainPartitionSparingTable) {
- dbg_printf(("WARNING: _initializeUDF200() Failed [1]: Low system resourcen"));
- uPartitionSize= 0;
- break;
- }
-
- g_DVDVR_SparingTableSize = (DWORD) CONTAINER_COUNT( ( (UINT16)(cbSparingTableSize+
- SPARING_TABLE_MAP_ENTRY_SIZE-1) / SPARING_TABLE_MAP_ENTRY_SIZE ) * SPARING_TABLE_MAP_ENTRY_SIZE );
- // Load the Sparing-Table
- for( i=0 ; i<(cbSparingTableSize+SPARING_TABLE_MAP_ENTRY_SIZE-1)/SPARING_TABLE_MAP_ENTRY_SIZE ;i++ )
- if (!AuxCache_GetBytes(dwSparingTableAddr, i*SPARING_TABLE_MAP_ENTRY_SIZE, (UINT16)SPARING_TABLE_MAP_ENTRY_SIZE, buffer)
- || !Array_setAt(((UINT32)(g_pUDFInfo->pMainPartitionSparingTable)), i, buffer))
- {
- Array_destruct((UINT32)(g_pUDFInfo->pMainPartitionSparingTable));
- g_pUDFInfo->pMainPartitionSparingTable = (UINT32)NULL;
- g_pUDFInfo->bUseSparingManagement= FALSE;
- g_DVDVR_SparingTableSize=0;
- uPartitionSize= 0;
- break;
- }
- }
- }
- // Check for a Terminating Descriptor
- if (TAG_ID_TERMINATING_DESC == LE_WORD(pDescTag->uTagID))
- break;
- // Move to the next Descriptor
- dwCurrDescLBN++;
- uMVDS_Size--;
- }
- // Make sure that there is enough information to access the File-Set Descriptor
- if ((0 == uMVDS_Size) || (0 == uPartitionSize) || (0 == uFSDS_Size)) {
- free(pDescBuffer);
- dbg_printf(("WARNING: _initializeUDF200() Failed [7]n"));
- return FALSE;
- }
-
- free(pDescBuffer);
- pDescBuffer= (BYTE*)malloc(LOGICAL_VOLUME_INTEGRITY_DESCRIPTOR_SIZE);
- if (NULL == pDescBuffer) {
- dbg_printf(("WARNING: _initializeUDF200() Failed [1]: Low system resourcen"));
- return FALSE;
- }
- // Enumerate the Logical Volume Integrity Sequence, until a Close Logical Volume
- // Integrity Descriptor is found.
- // In that Descriptor, examine and validate the UDF Revision.
- dwCurrDescLBN= dwLVIS_Location;
- while (uLVIS_Size) {
- if (! AuxCache_GetBytes(dwCurrDescLBN, 0, LOGICAL_VOLUME_INTEGRITY_DESCRIPTOR_SIZE, pDescBuffer)) {
- free(pDescBuffer);
- dbg_printf(("WARNING: _initializeUDF200() Failed [8]n"));
- return FALSE;
- }
- pDescTag= (Tag*)pDescBuffer;
- if (TAG_ID_LOGICAL_VOLUME_INTEGRITY == LE_WORD(pDescTag->uTagID)) {
- struct LogicalVolumeIntegrityDesc *pLVID= (struct LogicalVolumeIntegrityDesc *)pDescBuffer;
- if (INTEGRITY_TYPE_CLOSE == LE_DWORD(pLVID->dwIntegrityType)) {
- struct LogicalVolumeIntegrityDescImplUse *pImplUse=
- (struct LogicalVolumeIntegrityDescImplUse*)malloc(sizeof( struct LogicalVolumeIntegrityDescImplUse));
-
- if( NULL == pImplUse){
- dbg_printf(("WARNING: _initializeUDF200() Failed [1]: Low system resourcen"));
- free(pDescBuffer);
- return FALSE;
- }
-
- if (! AuxCache_GetBytes(dwCurrDescLBN,
- sizeof(struct LogicalVolumeIntegrityDesc)+(8*(UINT16)LE_DWORD(pLVID->uNumberOfPartitions)),
- sizeof(struct LogicalVolumeIntegrityDescImplUse), pImplUse))
- {
- free(pImplUse);
- free(pDescBuffer);
- dbg_printf(("WARNING: _initializeUDF200() Failed [8]n"));
- return FALSE;
- }
- // Verify the appropriate UDF Revision
- //if (0x0200 == LE_WORD(pImplUse->uMinimumUDFReadRevision))
- bVolumeIntegrityVerified= TRUE;
- free(pImplUse);
- }
- }
- if (TAG_ID_TERMINATING_DESC == LE_WORD(pDescTag->uTagID))
- break;
- // Move to the next Descriptor
- dwCurrDescLBN++;
- uLVIS_Size--;
- }
- // Make sure that the Volume's Integrity was verified
- if (! bVolumeIntegrityVerified) {
- free(pDescBuffer);
- dbg_printf(("WARNING: _initializeUDF200() Failed [9]n"));
- return FALSE;
- }
- free(pDescBuffer);
- // Establish the absolute LBA of the File-Set Descriptor Sequence, which is also
- // the fixed Offset needed to be added to any LBN in order to get the absoulte
- // LBA of Files and Directories.
- g_pUDFInfo->dwLBA_Offset= _absoluteLBA(dwFSDS_Location);
-
- pDescBuffer= (BYTE*)malloc(VOLUME_DESCRIPTOR_SIZE);
- if (NULL == pDescBuffer) {
- dbg_printf(("WARNING: _initializeUDF200() Failed [1]: Low system resourcen"));
- return FALSE;
- }
- // Enumerate the File-Set Descriptor Sequence, until a File-Set Descriptor is found.
- // From that File-Set Descriptor, extract the ICB corresponding to the Root-Directory.
- dwCurrDescLBN= dwFSDS_Location;
- while (uFSDS_Size) {
- if (! AuxCache_GetBytes(_absoluteLBA(dwCurrDescLBN), 0, VOLUME_DESCRIPTOR_SIZE, pDescBuffer)) {
- free(pDescBuffer);
- dbg_printf(("WARNING: _initializeUDF200() Failed [10]n"));
- return FALSE;
- }
- pDescTag= (Tag*)pDescBuffer;
- if (TAG_ID_FILE_SET_DESC == LE_WORD(pDescTag->uTagID)) {
- // Extract the location of the Root Directory
- struct FileSetDesc *pFSD= (struct FileSetDesc *)pDescBuffer;
- g_pUDFInfo->dwRootDirICB= LE_DWORD(pFSD->ladRootDirICB.lbaExtentLocation.uLogicalBlockNumber);
- bRootDirEstablished= TRUE;
- break;
- }
- if (TAG_ID_TERMINATING_DESC == LE_WORD(pDescTag->uTagID))
- break;
- // Move to the next Descriptor
- dwCurrDescLBN++;
- uFSDS_Size--;
- }
- // When this point is reached, the entire File-Set Descriptor Sequence has been
- // scanned, and the Root-Directory's ICB possibly established.
- free(pDescBuffer);
- // Set the Current Directory to the Root-Directory, if it was established.
- if (bRootDirEstablished)
- g_pUDFInfo->dwCurrDirICB= g_pUDFInfo->dwRootDirICB;
- g_pUDFInfo->uRevision= 0x0200;
- return bRootDirEstablished;
-
- #else
- return FALSE;
- #endif//DVD_VR_SUPPORT
- #endif //UDF_SUPPORT_UDF201
- }
- /////////////////////////////////////////////////////////////////////////////
- // _absoluteLBA()
- //
- // Description: Computes the absolute address of a given Relative Logical-
- // Block Address.
- //
- // Input: dwRelativeLBA - A DWORD which represents a relative address.
- // Output: None
- // In/Out: None
- // Return: The absolute address corresponding to the relative one.
- //
- // Remarks:
- // 1. If the current UDF Revision is lass than 2.00, then no Sparing Management
- // is available. In this case, the Absolute Address is a linear offset
- // from the beginning of the Main Partition.
- // 2. For UDF-2.00 and higher, if no Sparing-Management is in use, the
- // Absolute Address is the same as with UDF Revisions preceding 2.00.
- // 3. If Sparing-Management is in use, then the Sparing-Table is scanned
- // to determine whether the given Relative address belongs to a
- // Spared Packet.
- // 4. If the given Relative adderss is part of a Spared Packet, then
- // the Absolute address is the appropriate offset from the start of the
- // spare packet, as specified in the Sparing-Table entry.
- // 5. Otherwise, the Absolute address is as a linear offset from the Main
- // Sparable Partition.
- static DWORD _absoluteLBA(DWORD dwRelativeLBA)
- {
- DWORD dwAbsoluteLocation= (g_pUDFInfo->dwMainPartitionLocation + dwRelativeLBA);
- #ifndef UDF_SUPPORT_UDF201
- return dwAbsoluteLocation;
- #else
- #ifdef DVD_VR_SUPPORT
- UINT16 uCurrMapEntryPos,uReallocationTableLength;
- DWORD dwOriginalLocation;
- struct SparingTableMapEntry stmeCurrMapEntry;
- // If no Sparing-Management is enabled, then the Absolute LBA is computed
- // from the beginning of the containing Main-Partition.
- // Note: Sparing-Management is only relevanr for UDF-2.00 and higher.
- if ((0x0200 != g_pUDFInfo->uRevision) || (! g_pUDFInfo->bUseSparingManagement))
- return dwAbsoluteLocation;
- if(!Array_getAt(((UINT32)(g_pUDFInfo->pMainPartitionSparingTable)), SPARING_TABLE_RTL_OFFSET, (BYTE*)&stmeCurrMapEntry))
- return dwAbsoluteLocation;
- uReallocationTableLength = LE_WORD((WORD)stmeCurrMapEntry.dwOriginalLocation);
-
- // Sparing-Management is being used: go over the Sparing-Table to find out
- // if the supplied Relative-LBA belongs to a spared packet.
- for (uCurrMapEntryPos=0; uCurrMapEntryPos < uReallocationTableLength; uCurrMapEntryPos++)
- {
- if(!Array_getAt(((UINT32)(g_pUDFInfo->pMainPartitionSparingTable)), uCurrMapEntryPos, (BYTE *)&stmeCurrMapEntry))
- return dwAbsoluteLocation;
- dwOriginalLocation= LE_DWORD(stmeCurrMapEntry.dwOriginalLocation);
- if(dwOriginalLocation == 0xffffffffUL)
- break;
- if ((dwRelativeLBA >= dwOriginalLocation) &&
- (dwRelativeLBA < (dwOriginalLocation + g_pUDFInfo->uSparingPacketLength))) {
- // The Absolute address is a linear offset from the start of the Spare Packet,
- // as specified in the MappedLocation field of the Sparing-Table Entry.
- dwAbsoluteLocation= (LE_DWORD(stmeCurrMapEntry.dwMappedLocation) +
- (dwRelativeLBA - dwOriginalLocation));
- }
- }
- return dwAbsoluteLocation;
-
- #else
- UINT16 uCurrMapEntryPos;
- // If no Sparing-Management is enabled, then the Absolute LBA is computed
- // from the beginning of the containing Main-Partition.
- // Note: Sparing-Management is only relevanr for UDF-2.00 and higher.
- if ((0x0200 != g_pUDFInfo->uRevision) || (! g_pUDFInfo->bUseSparingManagement))
- return dwAbsoluteLocation;
- /*
- // Sparing-Management is being used: go over the Sparing-Table to find out
- // if the supplied Relative-LBA belongs to a spared packet.
- for (uCurrMapEntryPos=0;
- uCurrMapEntryPos < LE_WORD(g_pUDFInfo->pMainPartitionSparingTable->uReallocationTableLength);
- uCurrMapEntryPos++)
- {
- DWORD dwOriginalLocation;
- struct SparingTableMapEntry stmeCurrMapEntry= g_pUDFInfo->pMainPartitionSparingTable->aMapEntries[uCurrMapEntryPos];
- dwOriginalLocation= LE_DWORD(stmeCurrMapEntry.dwOriginalLocation);
- if ((dwRelativeLBA >= dwOriginalLocation) &&
- (dwRelativeLBA < (dwOriginalLocation + g_pUDFInfo->uSparingPacketLength))) {
- // The Absolute address is a linear offset from the start of the Spare Packet,
- // as specified in the MappedLocation field of the Sparing-Table Entry.
- dwAbsoluteLocation= (LE_DWORD(stmeCurrMapEntry.dwMappedLocation) +
- (dwRelativeLBA - dwOriginalLocation));
- }
- }
- return dwAbsoluteLocation;
- */
- return 0L;
- #endif //DVD_VR_SUPPORT
- #endif //UDF_SUPPORT_UDF201
- }
- /////////////////////////////////////////////////////////////////////////////
- // _findFirstFileIDDesc()
- //
- // Description: Initiates a search for the first occurrence of a File-ID
- // Descriptor structure describing a File/Sub-Directory that
- // meets the supplied criteria.
- //
- // Input: i_pszFileID - A string holding the requested Filename/pattern.
- // uFileCharacteristicsMask - A Mask to apply to the File's Characteristics.
- // uFileCharacteristics - A combination of Characteristics, that should match.
- // Output: o_pFileIDDescPtr - Points to a FileIDDesc Pointer, to receive
- // the File-ID Descriptor 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 UDF_findFirstFile().
- // 2. uFileCharacteristicsMask is a Mask that is applied to any File-ID
- // Descriptor whose File-ID mathces the supplied Filename/pattern.
- // This mask is applied to that item's Characteristics.
- // 3. uFileCharacteristics is compared against the Masked Characteristics
- // 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.
- // 6. The search is limited to the current working-directory.
- // 7. The search is Case-Sensitive.
- // 9. The returned File-ID Descriptor Pointer should be considered persistant
- // across calls. The caller needs to make sure that o_pFileIDDescPtr
- // is freed when it is no longer needed.
- // 8. _findClose() must be called when no additional searches are needed.
- static UINT16 _findFirstFileIDDesc(LPCWSTR i_pszFileID, UINT8 uFileCharacteristicsMask,
- UINT8 uFileCharacteristics,
- struct FileIDDesc **o_pFileIDDescPtr)
- {
- BOOL bSuccess;
- BOOL bWildcardSearch;
- UINT16 uFileIDDescListSizeInCont;
- UINT16 uSearchID;
- UINT16 uAllocDescsOffset;
- DWORD dwDirFileEntryAddr, dwDirectoryStartAddr, dwDirectorySize;
- Short_ad sadDirAD;
- struct TerminalEntry *pEntry;
- DirectorySearchInfo dsiInfo;
- // Allocate space for a Terminal Entry
- pEntry= (struct TerminalEntry *)malloc(sizeof(struct TerminalEntry));
- if (NULL == pEntry) {
- tr_printf(("FATAL: _findFirstFileIDDesc() Failed [1]: Low system resources.n"));
- return NULL;
- }
- // Extract the File-Entry of the Current Directory
- dwDirFileEntryAddr= _absoluteLBA(g_pUDFInfo->dwCurrDirICB);
- if (! AuxCache_GetBytes(dwDirFileEntryAddr, 0, sizeof(struct TerminalEntry), (BYTE*)pEntry)) {
- dbg_printf(("WARNING: _findFirstFileIDDesc() Failed [2]n"));
- free(pEntry);
- return NULL;
- }
- // Examine only the Descriptor's Tag and icbTag, in order to establish what kind of
- // Descriptor is at hand.
- if(!IS_SHORT_ALLOC_DESC(pEntry)&&!IS_LONG_ALLOC_DESC(pEntry)&&!IS_IN_ICB_ALLOC_DESC(pEntry))
- {
- dbg_printf(("WARNING: _findFirstFileIDDesc() Failed [3]: Unsupported Allocation-Scheme.n"));
- free(pEntry);
- return NULL;
- }
- // Calculate the offset of the Allocation-Descriptor of the Directory;
- // This offset is: (sizeof(FileEntry or ExtFileEntry) + cbLengthOfExtAttrs).
- uAllocDescsOffset= 0;
- if (TAG_ID_FILE_ENTRY == LE_WORD(pEntry->tgDescTag.uTagID)) {
- UINT32 cbLengthOfExtAttrs;
- if (AuxCache_GetBytes(dwDirFileEntryAddr, FILE_ENTRY_L_EXTATTR_OFFSET,
- sizeof(cbLengthOfExtAttrs), (BYTE*)&cbLengthOfExtAttrs))
- {
- uAllocDescsOffset= (sizeof(struct FileEntry) +
- (UINT16)LE_DWORD(cbLengthOfExtAttrs));
- }
- }
- else if (TAG_ID_EXT_FILE_ENTRY == LE_WORD(pEntry->tgDescTag.uTagID)) {
- UINT32 cbLengthOfExtAttrs;
- if (AuxCache_GetBytes(dwDirFileEntryAddr, EXT_FILE_ENTRY_L_EXTATTR_OFFSET,
- sizeof(cbLengthOfExtAttrs), (BYTE*)&cbLengthOfExtAttrs))
- {
- uAllocDescsOffset= (sizeof(struct ExtFileEntry) +
- (UINT16)LE_DWORD(cbLengthOfExtAttrs));
- }
- }
- if(!IS_IN_ICB_ALLOC_DESC(pEntry))
- {
- // Extract the Allocation-Descriptor of the Directory
- if ((0 == uAllocDescsOffset) ||
- ! AuxCache_GetBytes(dwDirFileEntryAddr, uAllocDescsOffset, sizeof(sadDirAD),
- (BYTE*)&sadDirAD))
- {
- // The ICB was neither a File-Entry nor an Extended-File-Entry: there's nothing
- // that can be done.
- dbg_printf(("WARNING: _findFirstFileIDDesc() Failed [4]n"));
- return NULL;
- }
- // Calculate the Start Address of the Directory itself
- dwDirectorySize= LE_DWORD(sadDirAD.cbExtentLength);
- if (0 == dwDirectorySize) {
- dbg_printf(("WARNING: _findFirstFileIDDesc() Failed [5]n"));
- return NULL;
- }
- dwDirectoryStartAddr= _absoluteLBA(LE_DWORD(sadDirAD.dwExtentPosition));
- // Allocate space for the File-ID Descriptors List Cache
- uFileIDDescListSizeInCont= CONTAINER_COUNT(DIRECTORY_FILEIDLIST_SZ);
- dsiInfo.hFileIDDescList= sc_Malloc(uFileIDDescListSizeInCont);
- if (NULL_HANDLE == dsiInfo.hFileIDDescList) {
- tr_printf(("FATAL: _findFirstFileIDDesc() Failed [6]: Low system resourcesn"));
- return NULL;
- }
- // Cache the beginning of the Directory's contents (File-ID Descriptors List)
- if (! sc_CopyFromDisc(dwDirectoryStartAddr, 0, DIRECTORY_FILEIDLIST_SZ,
- dsiInfo.hFileIDDescList))
- {
- dbg_printf(("WARNING: _findFirstFileIDDesc() Failed [7]n"));
- sc_Free(dsiInfo.hFileIDDescList, uFileIDDescListSizeInCont);
- return NULL;
- }
- dsiInfo.cbDescListOffset= 0;
- dsiInfo.cbCurrDescOffset= 0;
- }
- else
- {
- UINT32 cbLengthofAllocDesc;
- if (AuxCache_GetBytes(dwDirFileEntryAddr, FILE_ENTRY_L_ALLOCDESC_OFFSET,
- sizeof(cbLengthofAllocDesc), (BYTE*)&cbLengthofAllocDesc))
- {
- dwDirectorySize= (UINT16)LE_DWORD(cbLengthofAllocDesc);
- }
- uFileIDDescListSizeInCont= /*CONTAINER_COUNT((UINT16)dwDirectorySize);//*/CONTAINER_COUNT(DIRECTORY_FILEIDLIST_SZ);
- dsiInfo.hFileIDDescList= sc_Malloc(uFileIDDescListSizeInCont);
- if (NULL_HANDLE == dsiInfo.hFileIDDescList)
- {
- tr_printf(("FATAL: _findFirstFileIDDesc() Failed [6]: Low system resourcesn"));
- return NULL;
- }
- if (! sc_CopyFromDisc(dwDirFileEntryAddr, uAllocDescsOffset, DIRECTORY_FILEIDLIST_SZ,
- dsiInfo.hFileIDDescList))
- {
- dbg_printf(("WARNING: _findFirstFileIDDesc() Failed [7]n"));
- sc_Free(dsiInfo.hFileIDDescList, uFileIDDescListSizeInCont);
- return NULL;
- }
- dsiInfo.cbCurrDescOffset= uAllocDescsOffset;
- dsiInfo.cbDescListOffset= uAllocDescsOffset;
- dwDirectorySize+=uAllocDescsOffset;
- dwDirectoryStartAddr = dwDirFileEntryAddr;
- }
-
- free(pEntry);
- // Copy the necessary information into the DirSearchInfo, and initialize it
- dsiInfo.dwDirICB= dwDirectoryStartAddr;
- dsiInfo.dwDirectorySize= dwDirectorySize;
- // 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: _findFirstFileIDDesc() Failed [8]: Low system resourcesn"));
- sc_Free(dsiInfo.hFileIDDescList, uFileIDDescListSizeInCont);
- return NULL;
- }
- wcscpy(dsiInfo.pszFileID, i_pszFileID);
- }
- // Continue to copy necessary information into the DirSearchInfo, and initialize it.
- dsiInfo.uFileCharacteristicsMask= uFileCharacteristicsMask;
- dsiInfo.uFileCharacteristics= uFileCharacteristics;
- // Allocate a Search-Info
- uSearchID= _FileSys_allocateSearchInfo();
- if (NULL == uSearchID) {
- dbg_printf(("WARNING: _findFirstFileIDDesc() Failed [9]: No available Search-Info IDn"));
-
- if (! bWildcardSearch)
- free(dsiInfo.pszFileID);
- sc_Free(dsiInfo.hFileIDDescList, uFileIDDescListSizeInCont);
- return NULL;
- }
- // Register the Directory-Search Info in the Search-Info Pool
- bSuccess= _FileSys_setSearchInfo(uSearchID, (const BYTE*)&dsiInfo);
- if (! bSuccess) {
- dbg_printf(("FATAL: _findFirstFileIDDesc() Failed [10]: Cannot register new Searchn"));
- }
- // Now, the information in pDirInfo is stable and complete: perform the search
- if (bSuccess && ! _findNextFileIDDesc(uSearchID, o_pFileIDDescPtr)) {
- dbg_printf(("WARNING: _findFirstFileIDDesc() Failed [11]n"));
- bSuccess= FALSE;
- }
- if (! bSuccess) {
- if (! bWildcardSearch)
- free(dsiInfo.pszFileID);
- sc_Free(dsiInfo.hFileIDDescList, uFileIDDescListSizeInCont);
- _FileSys_freeSearchInfo(uSearchID);
- return NULL;
- }
- return uSearchID;
- }
- /////////////////////////////////////////////////////////////////////////////
- // _fileID_Cut()
- //
- // Description: Cut the fileID to specific length.
- //
- // Input: i_fileID_len - The source fileID length.
- // i_pSourceBuffer - Source buff contains the source fileID.
- // Output: o_fileID_len - Dest fileID length.
- // o_pDestBuffer - Dest buff contains the fileID with the proper length
- // Return: TRUE if the requested data was successfully cut;
- // FALSE otherwise.
- BOOL _fileID_Cut(UINT8 i_fileID_len, BYTE* i_pSourceBuffer, UINT8 o_fileID_len, BYTE* o_pDestBuffer)
- {
- if( 0 == i_pSourceBuffer[0] )
- o_pDestBuffer[0]=0;
- else if( UNICODE_COMPRESSIONID_SINGLE_BYTE == i_pSourceBuffer[0] )
- {
- int iSuffixLen=1;
- BYTE* bp=i_pSourceBuffer+i_fileID_len-1;
- do
- {
- if( *bp == '.' )
- break;
- bp--;
- iSuffixLen++;
- }
- while( bp != i_pSourceBuffer );
- memcpy( o_pDestBuffer, i_pSourceBuffer, o_fileID_len );
- if( iSuffixLen < i_fileID_len && iSuffixLen < o_fileID_len - 2 )
- memcpy( o_pDestBuffer+o_fileID_len-iSuffixLen, i_pSourceBuffer+i_fileID_len-iSuffixLen, iSuffixLen);
- }
- else if( UNICODE_COMPRESSIONID_DOUBLE_BYTE == i_pSourceBuffer[0] )
- {
- int iSuffixLen=1;
- WORD* bp=(WORD*)(i_pSourceBuffer+i_fileID_len-2);
- do
- {
- #ifdef MOTOROLA
- if( *bp == 0x002e ) //'.' in double byte.
- #else
- if( *bp == 0x2e00 )
- #endif //MOTOROLA
- break;
- bp--;
- iSuffixLen++;
- }
- while( (BYTE*)bp != i_pSourceBuffer+1 );
- iSuffixLen *= 2;
- memcpy( o_pDestBuffer, i_pSourceBuffer, o_fileID_len );
- if( iSuffixLen < i_fileID_len && iSuffixLen < o_fileID_len - 3 )
- memcpy( o_pDestBuffer+o_fileID_len-iSuffixLen, i_pSourceBuffer+i_fileID_len-iSuffixLen, iSuffixLen);
- }
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // _fileIDDescList_getBytes()
- //
- // Description: Retrieves Bytes from a File-ID Descriptor-List associated
- // with an open Directory-Search.
- //
- // Input: cbOffset - The offset of the requested Bytes from the List's start;
- // cbBytesCnt - The number of requested Bytes.
- // Output: o_pDestBuffer - Points to a destination Buffer, that will contain
- // the requested Bytes upon successful completion.
- // In/Out: io_pInfo - Points to the DirectorySearchInfo associated with
- // the Search whose List should be used.
- // Return: TRUE if the requested data was successfully retrieved;
- // FALSE otherwise.
- static BOOL _fileIDDescList_getBytes(DirectorySearchInfo *io_pInfo, UINT32 cbOffset,
- UINT8 cbBytesCnt, BYTE *o_pDestBuffer)
- {
- // Check if there's a Cache-Hit: if the Cache contains at least cbBytesCnt from
- // the requested Offset.
- if(cbBytesCnt>=DIRECTORY_FILEIDLIST_SZ-1)
- return FALSE;
- // Note: The Cache is assumed to be at least 256 Bytes in size, and cbBytesCnt
- // cannot exceed 256 Bytes.
- if ((cbOffset < io_pInfo->cbDescListOffset) ||
- ((cbOffset + cbBytesCnt) > (io_pInfo->cbDescListOffset + DIRECTORY_FILEIDLIST_SZ)))
- {
- // Cache-Miss: Fill-in the Cache, starting from the requested Offset, thus
- // ensuring that the request can be satisfied.
- if (! sc_CopyFromDisc(io_pInfo->dwDirICB, cbOffset, DIRECTORY_FILEIDLIST_SZ,
- io_pInfo->hFileIDDescList))
- {
- dbg_printf(("WARNING: _fileIDDescList_getBytes() Failed [1]n"));
- return FALSE;
- }
- // Adjust the Cache-base to the new Offset
- io_pInfo->cbDescListOffset= cbOffset;
- }
- // At this point, the Cache is guaranteed to contain enough data that would satisfy
- // the request. Copy the requested Bytes.
-
- // because the file name can't more than MAX_SUPPORT_FILE_ID_LENGTH(128) bytes, so cut off the tail or the file name
- //if( cbBytesCnt <= MAX_SUPPORT_FILE_ID_LENGTH )
- sc_GetBytes(io_pInfo->hFileIDDescList, (UINT16)(cbOffset - io_pInfo->cbDescListOffset),
- cbBytesCnt, o_pDestBuffer);
- //else
- //{
- // BYTE* buff=NULL;
- // buff=(BYTE*)MEM_Allocate(DEFAULT_HEAP, cbBytesCnt);
- // if(buff == NULL)
- // {
- // dbg_printf(("WARNING: _fileIDDescList_getBytes() Failed [2]: Low system resources.n"));
- // return FALSE;
- // }
- // sc_GetBytes(io_pInfo->hFileIDDescList, (UINT16)(cbOffset - io_pInfo->cbDescListOffset),
- // cbBytesCnt, buff);
- // _fileID_Cut(cbBytesCnt, buff, MAX_SUPPORT_FILE_ID_LENGTH+1, o_pDestBuffer);
- //
- // MEM_Free(DEFAULT_HEAP,buff);
- //}
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // _findNextFileIDDesc()
- //
- // Description: Continues a search that was previously initiated via a call
- // to _findFirstFileIDDesc().
- //
- // Input: uSearchID - The ID of a search, that was returned from a
- // previous call to _findFirstFileIDDesc().
- // Output: o_pFileIDDescPtr - Points to a FileIDDesc Pointer, to receive
- // the File-ID Descriptor of a matching
- // File/Sub-Directory.
- // In/Out: None
- // Return: TRUE if the search succeeded, and an additional File-ID Descriptor
- // matching the criteria was found. In this case, the supplied
- // o_pFileIDDescPtr 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_pFileIDDescPtr 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 _findFirstFileIDDesc().
- // 3. The search uses the same criteria as were originally supplied to
- // _findFirstFileIDDesc().
- // 4. The returned File-ID Descriptor Pointer should be considered persistant
- // across calls. The caller has to make sure that o_pFileIDDescPtr
- // is freed when it is no longer needed.
- // 5. _findClose() must be called when no additional searches are needed.
- static BOOL _findNextFileIDDesc(UINT16 uSearchID, struct FileIDDesc **o_pFileIDDescPtr)
- {
- BOOL bFileIDFound;
- UINT8 uFileIDLength;
- WCHAR szUnicodeFileID[(MAX_ID_LENGTH / sizeof(WCHAR)) + 1];
- LPCWSTR pszFileID;
- struct FileIDDesc *pCurrFileIDDesc;
- //<<<MikeX_1213_2004_A:compare the files' length when searching files.
- DirectorySearchInfo dsiInfo;
- UINT8 uFoundFileIDLength;
- 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 --;
- }
- // Reset the result
- *o_pFileIDDescPtr= NULL;
- // Prepare a descriptor-container
- pCurrFileIDDesc= (struct FileIDDesc *)malloc(sizeof(struct FileIDDesc) + MAX_ID_LENGTH + 2);
- if (NULL == pCurrFileIDDesc) {
- tr_printf(("FATAL: _findNextFileIDDesc() Failed [1]: Low system resourcesn"));
- return FALSE;
- }
- // Scan the File-ID Descriptors List, as long as the entire Directory has not been
- // enumerated, and there is no match.
- bFileIDFound= FALSE;
- while ( (dsiInfo.cbCurrDescOffset < dsiInfo.dwDirectorySize) && (! bFileIDFound) )
- {
- UINT8 cbCurrFileIDDescSize;
- // Read the contents of the Current File-ID Descriptor
- if (! _fileIDDescList_getBytes(&dsiInfo, dsiInfo.cbCurrDescOffset,
- sizeof(struct FileIDDesc), (BYTE*)pCurrFileIDDesc))
- {
- dbg_printf(("WARNING: _findNextFileIDDesc() Failed [2]n"));
- break;
- }
- cbCurrFileIDDescSize= (sizeof(struct FileIDDesc) + pCurrFileIDDesc->cbLengthOfFileID +
- LE_WORD(pCurrFileIDDesc->cbLengthOfImplUse));
- // Collect the File-ID, and place it into the sFileID field of the Current Descriptor,
- // ignoring the aImplUse field (which is not needed).
- if (! _fileIDDescList_getBytes(&dsiInfo,
- (dsiInfo.cbCurrDescOffset + sizeof(struct FileIDDesc) +
- LE_WORD(pCurrFileIDDesc->cbLengthOfImplUse)),
- pCurrFileIDDesc->cbLengthOfFileID,
- (BYTE*)&(pCurrFileIDDesc->sFileID)))
- {
- dbg_printf(("WARNING: _findNextFileIDDesc() Failed [3]n"));
- break;
- }
- // Collect the current File-ID
- pszFileID= (LPCWSTR)szUnicodeFileID;
-
- //Hannah_0524_2005
- // Convert the File-ID into UNICODE, if required
- if (0 == pCurrFileIDDesc->cbLengthOfFileID) {
- // An empty File-ID
- szUnicodeFileID[0]= 0;
- }
- else if (UNICODE_COMPRESSIONID_SINGLE_BYTE == pCurrFileIDDesc->sFileID[0]) {
- if( pCurrFileIDDesc->cbLengthOfFileID> MAX_ID_LENGTH/sizeof(WCHAR) +1 )
- {
- BYTE* buff = NULL;
- BYTE len = pCurrFileIDDesc->cbLengthOfFileID;
-
- buff=(BYTE*)malloc(len +1);
- if(buff == NULL)
- {
- dbg_printf(("WARNING: _findNextFileRecord() Failed [5]:Low system resourcesn"));
- break;
- }
- memcpy(buff, pCurrFileIDDesc->sFileID, pCurrFileIDDesc->cbLengthOfFileID);
- buff[len] = 0;
- _fileID_Cut(len/*+1*/, buff, MAX_ID_LENGTH/sizeof(WCHAR)+1, (BYTE*)pCurrFileIDDesc->sFileID);
- free(buff);
- pCurrFileIDDesc->cbLengthOfFileID = MAX_ID_LENGTH/sizeof(WCHAR)+1;
- }
- //pCurrFileIDDesc->cbLengthOfFileID = MIN(MAX_ID_LENGTH/sizeof(WCHAR),(pCurrFileIDDesc->cbLengthOfFileID)); //Hannah_0322
- // The File-ID is given in ANSI-ASCII: convert it into UNICODE
- _str2wcs((LPCSTR)&pCurrFileIDDesc->sFileID[1], szUnicodeFileID,
- ((pCurrFileIDDesc->cbLengthOfFileID) * sizeof(WCHAR)));
- }
- else if (UNICODE_COMPRESSIONID_DOUBLE_BYTE == pCurrFileIDDesc->sFileID[0]) {
- if( pCurrFileIDDesc->cbLengthOfFileID> MAX_ID_LENGTH +1 )
- {
- BYTE* buff = NULL;
- BYTE len = pCurrFileIDDesc->cbLengthOfFileID;
-
- buff=(BYTE*)malloc(len +2);
- if(buff == NULL)
- {
- dbg_printf(("WARNING: _findNextFileRecord() Failed [5]:Low system resourcesn"));
- break;
- }
- memcpy(buff, pCurrFileIDDesc->sFileID, pCurrFileIDDesc->cbLengthOfFileID);
- buff[len] = 0;
- buff[len+1] = 0;
- _fileID_Cut(len/*+1*/, buff, MAX_ID_LENGTH+1, (BYTE*)pCurrFileIDDesc->sFileID);
- free(buff);
- pCurrFileIDDesc->cbLengthOfFileID = MAX_ID_LENGTH+1;
- }
- // The File-ID is given in UNICODE: manipulate as required
- pCurrFileIDDesc->sFileID[pCurrFileIDDesc->cbLengthOfFileID]= 0;
- pCurrFileIDDesc->sFileID[pCurrFileIDDesc->cbLengthOfFileID+1]= 0;
- #ifdef MOTOROLA
- pszFileID= (LPCWSTR)&pCurrFileIDDesc->sFileID[1];
- #else
- swab((LPSTR)&pCurrFileIDDesc->sFileID[1], (LPSTR)szUnicodeFileID,
- (pCurrFileIDDesc->cbLengthOfFileID + 1));
- #endif //MOTOROLA
- }
- //Hannah_0524_2005
- else {
- // The File-ID is given in an unsupported compression; copy "as is"
- memcpy(szUnicodeFileID, pCurrFileIDDesc->sFileID, pCurrFileIDDesc->cbLengthOfFileID);
- szUnicodeFileID[(pCurrFileIDDesc->cbLengthOfFileID - 1) / sizeof(WCHAR)]= 0;
- }
- if (TAG_ID_FILE_ID_DESC != LE_WORD(pCurrFileIDDesc->tgDescTag.uTagID)) {
- dbg_printf(("WARNING: _findNextFileIDDesc() Failed [4]n"));
- break;
- }
- // Check if an appropriate FileID Descriptor was found, according to
- // both the File-ID and the File-Characteristics.
- #if 0 // Robin_1112_2004, "*" mean any char/string, RB_TBD
- if (dsiInfo.uFileCharacteristics == (pCurrFileIDDesc->uFileCharacteristics & dsiInfo.uFileCharacteristicsMask))
- {
- if ((0 != uFileIDLength && dsiInfo.pszFileID[uFileIDLength-1] == '*') && (0 == _wcsnicmp(dsiInfo.pszFileID, pszFileID, uFileIDLength-1)) )
- bFileIDFound= TRUE;
- else if ((uFileIDLength == wcslen(pszFileID) || 0 == uFileIDLength) && (0 == _wcsnicmp(dsiInfo.pszFileID, pszFileID, uFileIDLength)) )
- bFileIDFound= TRUE;
- }
- #else
- //<<<MikeX_1213_2004_A:compare the files' length when searching files.
- if( 0 != pCurrFileIDDesc->cbLengthOfFileID )
- {
- if (UNICODE_COMPRESSIONID_SINGLE_BYTE == pCurrFileIDDesc->sFileID[0])
- uFoundFileIDLength = pCurrFileIDDesc->cbLengthOfFileID - 1;
- else if (UNICODE_COMPRESSIONID_DOUBLE_BYTE == pCurrFileIDDesc->sFileID[0])
- uFoundFileIDLength = (pCurrFileIDDesc->cbLengthOfFileID - 1) / sizeof(WCHAR);
- else
- uFoundFileIDLength = 0;
- }
- else
- uFoundFileIDLength = 0;
- if( 0 == uFoundFileIDLength || 0 == uFileIDLength )
- uFoundFileIDLength = uFileIDLength;
- //MikeX_1213_2004_A>>>
- if ( (dsiInfo.uFileCharacteristics == (pCurrFileIDDesc->uFileCharacteristics & dsiInfo.uFileCharacteristicsMask)) &&
- (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.
- {
- bFileIDFound= TRUE;
- }
- #endif
- // Continue to the next Directory-entry
- dsiInfo.cbCurrDescOffset += (4 * ((cbCurrFileIDDescSize + 3) / 4));
- }
- if (bFileIDFound) {
- // Assign the result
- *o_pFileIDDescPtr= pCurrFileIDDesc;
- }
- 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.cbCurrDescOffset= dsiInfo.dwDirectorySize;
- // Free the memory
- free(pCurrFileIDDesc);
- }
- // Update the Directory-Search Info in the Search-Pool
- if (! _FileSys_setSearchInfo(uSearchID, (const BYTE*)&dsiInfo)) {
- dbg_printf(("WARNING: _findNextFileIDDesc() Failed [5]n"));
- }
- return bFileIDFound;
- }
- /////////////////////////////////////////////////////////////////////////////
- // _findClose()
- //
- // Description: Terminates a search.
- //
- // Input: hDirInfo - A Handle to a search, that was returned from a
- // previous call to _findFirstFileIDDesc().
- // Output: None
- // In/Out: None
- // Return: TRUE if the search was successfully terminated; FALSE othewise.
- //
- // Remarks:
- // Any search that is initiated via _findFirstFileIDDesc() must be terminated
- // using a call to this method, in order to allow for proper release of
- // resources that were allocated for that search.
- 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.hFileIDDescList, CONTAINER_COUNT(DIRECTORY_FILEIDLIST_SZ));
- _FileSys_freeSearchInfo(uSearchID);
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // _getFileAttributes()
- //
- // Description: Translates a native File-ID Descriptor into a
- // FindData structure.
- //
- // Input: FileIDDesc - Points to a FileIDDesc structure to translate.
- // Output: o_pFindData - Points to a FindData structure to receive the
- // translated information.
- // In/Out: None
- // Return: TRUE if the Descriptor was successfully translated; FALSE othewise.
- //
- // Remarks: None
- static BOOL _getFileAttributes(const struct FileIDDesc *i_pFileIDDesc,
- FindData *o_pFindData)
- {
- DWORD dwFileEntryAddr;
- DWORD cbLengthOfExtAttrs, cbLengthOfAllocDescs;
- //DWORD cbInfoLengthHigh, cbInfoLengthLow;
- Alloc_desc adFile;
- BYTE cbDescLength;
- BYTE bDescNum;
- UINT32 dwTmpExtentLength;
- UINT32 dwTmpExtentPosition;
- UINT8 cbEntrySize;
- struct TerminalEntry *pEntry;
- struct {
- UINT32 dwFirst;
- UINT32 dwSecond;
- } QuadWord;
- // Load the File's File-Entry. Use a Teriminal-Entry at first, just to peek
- // into the type of Descriptor that is at hand (File-Entry / Extended-File-Entry).
- pEntry= (struct TerminalEntry *)malloc(sizeof(struct TerminalEntry));
- if (NULL == pEntry) {
- dbg_printf(("WARNING: _getFileAttributes() Failed [1]n"));
- return FALSE;
- }
- dwFileEntryAddr= _absoluteLBA(LE_DWORD(i_pFileIDDesc->ladICB.lbaExtentLocation.uLogicalBlockNumber));
- if (! AuxCache_GetBytes(dwFileEntryAddr, 0, sizeof(struct TerminalEntry), (BYTE*)pEntry)) {
- dbg_printf(("WARNING: _getFileAttributes() Failed [2]n"));
- free(pEntry);
- return FALSE;
- }
- // Fill-in the File's Type from the File-Entry
- o_pFindData->uFileType= pEntry->icbTag.uFileType;
- // Compute the size of the Entry according to the Descriptor type, and extract
- // the length of the Extended Attributes inside the Descriptor.
- if (TAG_ID_FILE_ENTRY == LE_WORD(pEntry->tgDescTag.uTagID)) {
- cbEntrySize= sizeof(struct FileEntry);
- if (AuxCache_GetBytes(dwFileEntryAddr, FILE_ENTRY_L_EXTATTR_OFFSET,
- sizeof(QuadWord), (BYTE*)&QuadWord))
- {
- cbLengthOfExtAttrs= LE_DWORD(QuadWord.dwFirst);
- cbLengthOfAllocDescs= LE_DWORD(QuadWord.dwSecond);
- }
- }
- else if (TAG_ID_EXT_FILE_ENTRY == LE_WORD(pEntry->tgDescTag.uTagID)) {
- cbEntrySize= sizeof(struct ExtFileEntry);
- if (AuxCache_GetBytes(dwFileEntryAddr, EXT_FILE_ENTRY_L_EXTATTR_OFFSET,
- sizeof(QuadWord), (BYTE*)&QuadWord))
- {
- cbLengthOfExtAttrs= LE_DWORD(QuadWord.dwFirst);
- cbLengthOfAllocDescs= LE_DWORD(QuadWord.dwSecond);
- }
- }
- else {
- dbg_printf(("WARNING: _getFileAttributes() Failed [3]n"));
- free(pEntry);
- return FALSE;
- }
- /*
- if (AuxCache_GetBytes(dwFileEntryAddr, FILE_ENTRY_INFOLENGTH_OFFSET,
- sizeof(QuadWord), (BYTE*)&QuadWord))
- {
- #ifdef MOTOROLA
- cbInfoLengthHigh= LE_DWORD(QuadWord.dwFirst);
- cbInfoLengthLow= LE_DWORD(QuadWord.dwSecond);
- #else
- cbInfoLengthHigh= LE_DWORD(QuadWord.dwSecond);
- cbInfoLengthLow= LE_DWORD(QuadWord.dwFirst);
- #endif //MOTOROLA
- }
- */
- // Calculate the Starting-Address of the File, according to the type of Allocation
- // Descriptor. Set the File's Size accordingly.
- if (IS_IN_ICB_ALLOC_DESC(pEntry)) {
- // The File's Body starts inside this File-Entry
- o_pFindData->dwStartAddr= LE_DWORD(i_pFileIDDesc->ladICB.lbaExtentLocation.uLogicalBlockNumber);//dwFileEntryAddr;//(dwFileEntryAddr +cbLengthOfExtAttrs);
- o_pFindData->cbFileSizeHigh= 0;
- o_pFindData->cbFileSizeLow= cbLengthOfAllocDescs;
- }
- else
- {
- if(IS_SHORT_ALLOC_DESC(pEntry))
- cbDescLength = sizeof(Short_ad);
- else if(IS_LONG_ALLOC_DESC(pEntry))
- cbDescLength = sizeof(Long_ad);
- if (! AuxCache_GetBytes(dwFileEntryAddr, (cbEntrySize + (UINT16)cbLengthOfExtAttrs),
- cbDescLength, (BYTE*)&adFile))
- {
- dbg_printf(("WARNING: _getFileAttributes() Failed [4]n"));
- memset(&adFile, 0, cbDescLength);
- }
- if(ICB_FILETYPE_DIRECTORY == o_pFindData->uFileType) //directory
- o_pFindData->dwStartAddr= LE_DWORD(i_pFileIDDesc->ladICB.lbaExtentLocation.uLogicalBlockNumber);
- else //File
- {
- if(IS_SHORT_ALLOC_DESC(pEntry))
- o_pFindData->dwStartAddr= _absoluteLBA(LE_DWORD(adFile.sadFile.dwExtentPosition));
- else
- o_pFindData->dwStartAddr= _absoluteLBA(LE_DWORD(adFile.ladFile.lbaExtentLocation.uLogicalBlockNumber));
- }
- {
- if(IS_SHORT_ALLOC_DESC(pEntry))
- o_pFindData->cbFileSizeLow = adFile.sadFile.cbExtentLength;
- else
- o_pFindData->cbFileSizeLow = adFile.ladFile.cbExtentLength;
- for(bDescNum = 1;bDescNum<cbLengthOfAllocDescs/ sizeof(Short_ad);bDescNum++)
- {
- if(IS_SHORT_ALLOC_DESC(pEntry))
- {
- dwTmpExtentLength = adFile.sadFile.cbExtentLength;
- dwTmpExtentPosition = adFile.sadFile.dwExtentPosition;
- }
- else
- {
- dwTmpExtentLength = adFile.ladFile.cbExtentLength;
- dwTmpExtentPosition = adFile.ladFile.lbaExtentLocation.uLogicalBlockNumber;
- }
- if (!AuxCache_GetBytes(dwFileEntryAddr, (cbEntrySize + (UINT16)cbLengthOfExtAttrs)+bDescNum* cbDescLength,
- cbDescLength, (BYTE*)&adFile))
- break;
- else
- {
- if((IS_SHORT_ALLOC_DESC(pEntry))&&((dwTmpExtentPosition+dwTmpExtentLength/LOGICAL_BLOCK_SIZE) ==adFile.sadFile.dwExtentPosition))
- {
- if(FILE_EXTENT_LENGTH - (o_pFindData->cbFileSizeLow+adFile.sadFile.cbExtentLength)>=LOGICAL_BLOCK_SIZE)
- o_pFindData->cbFileSizeLow+=adFile.sadFile.cbExtentLength;
- else
- {
- o_pFindData->cbFileSizeLow = FILE_EXTENT_LENGTH - LOGICAL_BLOCK_SIZE+1;
- break;
- }
- }
- else if(IS_LONG_ALLOC_DESC(pEntry)&&((dwTmpExtentPosition+dwTmpExtentLength/LOGICAL_BLOCK_SIZE) ==adFile.ladFile.lbaExtentLocation.uLogicalBlockNumber))
- {
- if(FILE_EXTENT_LENGTH - (o_pFindData->cbFileSizeLow+adFile.ladFile.cbExtentLength)>=LOGICAL_BLOCK_SIZE)
- o_pFindData->cbFileSizeLow+=adFile.ladFile.cbExtentLength;
- else
- {
- o_pFindData->cbFileSizeLow = FILE_EXTENT_LENGTH - LOGICAL_BLOCK_SIZE+1;
- break;
- }
- }
- else //The extent is not continous
- break;
- }
- }
- o_pFindData->cbFileSizeHigh= 0;
- }
- }
- #if 0
- if(IS_EXTENDED_ALLOC_DESC(pEntry))
- {
- struct ExtAllocDesc extFile;
-
- if (! AuxCache_GetBytes(dwFileEntryAddr, (cbEntrySize + (UINT16)cbLengthOfExtAttrs),
- sizeof(struct ExtAllocDesc), (BYTE*)&extFile))
- {
- dbg_printf(("WARNING: _getFileAttributes() Failed [4]n"));
- memset(&extFile, 0, sizeof(extFile));
- }
- if(ICB_FILETYPE_DIRECTORY == o_pFindData->uFileType) //directory
- o_pFindData->dwStartAddr= LE_DWORD(i_pFileIDDesc->ladICB.lbaExtentLocation.uLogicalBlockNumber);
- else //File
- o_pFindData->dwStartAddr= _absoluteLBA(LE_DWORD(extFile.lbaExtentLocation.uLogicalBlockNumber));
- // Read the continuous extent until it reaches size of 4G-2K.
- {
- o_pFindData->cbFileSizeLow = extFile.cbExtentLength;
- for(bDescNum = 1;bDescNum<cbLengthOfAllocDescs/bDescLength;bDescNum++)
- {
- dwTmpExtentLength = extFile.cbExtentLength;
- dwTmpExtentPosition = extFile.lbaExtentLocation.uLogicalBlockNumber;
- if (AuxCache_GetBytes(dwFileEntryAddr, (cbEntrySize + (UINT16)cbLengthOfExtAttrs)+bDescNum* sizeof(struct ExtAllocDesc),
- sizeof(extFile), (BYTE*)&extFile))
- if((dwTmpExtentPosition+dwTmpExtentLength/LOGICAL_BLOCK_SIZE) ==extFile.lbaExtentLocation.uLogicalBlockNumber)
- {
- if(FILE_EXTENT_LENGTH - (o_pFindData->cbFileSizeLow+extFile.cbExtentLength)>=LOGICAL_BLOCK_SIZE)
- o_pFindData->cbFileSizeLow+=extFile.cbExtentLength;
- else
- {
- o_pFindData->cbFileSizeLow = FILE_EXTENT_LENGTH - LOGICAL_BLOCK_SIZE;
- break;
- }
- }
- }
- o_pFindData->cbFileSizeHigh= 0;
- }
- }
- #endif
- free(pEntry);
- // Extract the File-ID
- if (UNICODE_COMPRESSIONID_SINGLE_BYTE == i_pFileIDDesc->sFileID[0]) {
- // The File-ID is given in ANSI-ASCII: convert it into UNICODE
- _str2wcs((LPCSTR)&i_pFileIDDesc->sFileID[1], o_pFindData->szFileID,
- (i_pFileIDDesc->cbLengthOfFileID * sizeof(WCHAR)));
- }
- else if (UNICODE_COMPRESSIONID_DOUBLE_BYTE == i_pFileIDDesc->sFileID[0]) {
- // The File-ID is given in UNICODE: manipulate as required
- #ifdef MOTOROLA
- memcpy(o_pFindData->szFileID, &i_pFileIDDesc->sFileID[1],
- (i_pFileRec->cbLengthOfFileID - 1));
- #else
- swab((LPSTR)&i_pFileIDDesc->sFileID[1], (LPSTR)o_pFindData->szFileID,
- (i_pFileIDDesc->cbLengthOfFileID - 1));
- #endif //MOTOROLA
- o_pFindData->szFileID[(i_pFileIDDesc->cbLengthOfFileID - 1) / sizeof(WCHAR)]= 0;
- }
- else {
- // The File-ID is given in an unsupported compression; copy "as is"
- memcpy(o_pFindData->szFileID, &i_pFileIDDesc->sFileID[1],
- (i_pFileIDDesc->cbLengthOfFileID - 1));
- o_pFindData->szFileID[(i_pFileIDDesc->cbLengthOfFileID - 1) / sizeof(WCHAR)]= 0;
- }
- return TRUE;
- }
- #endif //FILESYSTEM_SUPPORT_UDF