📄 loader_app.cpp
字号:
* @param tLoader The loader handle.
* @param pcPath Path name or file name
* @param tAccessType Permissions to check for. This can be a bitwise inclusive or of access permissions
* READ, WRITE, EXECUTE or it can be an existence test.
* @param pbPermit Pointer to flag that gets set if the access is permitted.
*/
LOADER_ERR LoaderFileAccess(LOADER_HANDLE tLoader, const char *pcPath, LOADER_FILE_ACCESS_TYPE tAccessType, BYTE *pbPermit)
{
LOADER_ERR loader_error;
LoaderData* loaderData;
loaderData = (LoaderData*) tLoader;
assert ( tLoader != NULL );
assert ( pbPermit != NULL );
assert ( pcPath != NULL );
DBGPRINT(DEBUG_ON(DEBUG_TRACE), ("LoaderFileAccess\n"));
if (tAccessType != LOADER_FILE_ACCESS_EXIST)
{
DbgPrint(("LoaderFileAccess() - operation not implemented\n"));
return ( LOADER_FAILURE );
}
OS_SemTake(loaderData->loaderMutex, OS_WAIT_FOREVER);
loader_error = LOADER_SUCCESS;
if ( loaderData->win32Loader->FileExists(LoaderStripMountPrefix(pcPath), pbPermit) != WIN32LOADER_SUCCESS )
{
loader_error = LOADER_FAILURE;
}
OS_SemGive(loaderData->loaderMutex);
return ( loader_error );
}
/**
* Open a file from the disc.
*
* @param tLoader The loader handle.
* @param pcFileName File name.
* @param hFileHandle Pointer to handle to the file that is opened.
*/
LOADER_ERR LoaderFileOpen(LOADER_HANDLE tLoader, const char *pcFileName, LOADER_FILE_HANDLE *hFileHandle)
{
LOADER_ERR loader_error;
LoaderData* loaderData;
loaderData = (LoaderData*) tLoader;
assert ( tLoader != NULL );
assert ( pcFileName != NULL );
DBGPRINT(DEBUG_ON(DEBUG_TRACE), ("LoaderFileOpen: %s\n",pcFileName));
OS_SemTake(loaderData->loaderMutex, OS_WAIT_FOREVER);
loader_error = LOADER_SUCCESS;
if ( loaderData->win32Loader->FileOpen(LoaderStripMountPrefix(pcFileName), hFileHandle) != WIN32LOADER_SUCCESS )
{
loader_error = LOADER_FAILURE;
}
OS_SemGive(loaderData->loaderMutex);
return ( loader_error );
}
/**
* Close a file.
*
* @param tLoader The loader handle.
* @param hFileHandle Handle to the file to close.
*/
LOADER_ERR LoaderFileClose(LOADER_HANDLE tLoader, LOADER_FILE_HANDLE hFileHandle)
{
LOADER_ERR loader_error;
LoaderData* loaderData;
loaderData = (LoaderData*) tLoader;
assert ( tLoader != NULL );
DBGPRINT(DEBUG_ON(DEBUG_TRACE), ("LoaderFileClose\n"));
OS_SemTake(loaderData->loaderMutex, OS_WAIT_FOREVER);
loader_error = LOADER_SUCCESS;
if ( loaderData->win32Loader->FileClose(hFileHandle) != WIN32LOADER_SUCCESS )
{
loader_error = LOADER_FAILURE;
}
OS_SemGive(loaderData->loaderMutex);
return ( loader_error );
}
/**
* Seek to a specified position in a file.
*
* @param tLoader The loader handle.
* @param hFileHandle Handle to the file.
* @param tSeek Seek type; from beginning of file, from current position in file, or from end of file.
* @param ulOffset Offset relative to seek type.
*/
LOADER_ERR LoaderFileSeek(LOADER_HANDLE tLoader, LOADER_FILE_HANDLE hFileHandle, LOADER_SEEK_TYPE tSeek, LONGLONG llOffset)
{
LOADER_ERR loader_error;
LoaderData* loaderData;
WIN32LOADER_SEEK_TYPE win32SeekType;
DBGPRINT(DEBUG_ON(DEBUG_TRACE), ("LoaderFileSeek (position: %I64d, seek type: %d\n",llOffset,tSeek));
loaderData = (LoaderData*) tLoader;
assert ( tLoader != NULL );
OS_SemTake(loaderData->loaderMutex, OS_WAIT_FOREVER);
switch ( tSeek )
{
case LOADER_SEEK_CURRENT: win32SeekType = WIN32LOADER_SEEK_TYPE_CUR; break;
case LOADER_SEEK_END: win32SeekType = WIN32LOADER_SEEK_TYPE_END; break;
case LOADER_SEEK_SET: win32SeekType = WIN32LOADER_SEEK_TYPE_SET; break;
}
loader_error = LOADER_SUCCESS;
if ( loaderData->win32Loader->FileSeek(hFileHandle, win32SeekType, llOffset) != WIN32LOADER_SUCCESS )
{
loader_error = LOADER_FAILURE;
}
OS_SemGive(loaderData->loaderMutex);
return ( loader_error );
}
/**
* Report the current position into the file.
*
* @param tLoader The loader handle.
* @param hFileHandle Handle to the file.
* @param ullPosition The current position.
*/
LOADER_ERR LoaderFileTell(LOADER_HANDLE tLoader, LOADER_FILE_HANDLE hFileHandle, ULONGLONG *ullPosition)
{
LOADER_ERR loader_error;
LoaderData* loaderData;
DBGPRINT(DEBUG_ON(DEBUG_TRACE), ("LoaderFileTell\n"));
loaderData = (LoaderData*) tLoader;
assert ( tLoader != NULL );
OS_SemTake(loaderData->loaderMutex, OS_WAIT_FOREVER);
loader_error = LOADER_SUCCESS;
if ( loaderData->win32Loader->FileTell(hFileHandle, ullPosition) != WIN32LOADER_SUCCESS )
{
loader_error = LOADER_FAILURE;
}
OS_SemGive(loaderData->loaderMutex);
return ( loader_error );
}
/**
* Determine a file's total size.
*
* @param tLoader The loader handle.
* @param hFileHandle Handle to the file.
* @param ullSize Size of the given file.
*/
LOADER_ERR LoaderFileSize(LOADER_HANDLE tLoader, char* fileName, ULONGLONG* ullSize)
{
UNUSED_PARAM(tLoader);
UNUSED_PARAM(fileName);
UNUSED_PARAM(ullSize);
DBGPRINT(DEBUG_ON(DEBUG_TRACE), ("LoaderFileSize\n"));
DbgPrint(("LoaderFileSize - not implemented\n"));
assert ( 1 == 0 );
return ( LOADER_FAILURE );
}
/**
* Read from a file.
*
* @param tLoader The loader handle.
* @param hFileHandle Handle to the file.
* @param pvBuffer Buffer to read data into.
* @param ulSize Size of buffer and size of data to read from file.
* @param pulReadSize Pointer to variable that gets set to the number of bytes read from file.
*
* Note: If file position is at end of file before the read, this function fails. If position indicator reaches
* the end of file during a read, this function returns success, and the number of bytes read is
* stored in the variable pointed to by pulReadSize. If EOF is not reached during a read,
* the value pointed to by pulReadSize is equal to ulSize. If pulReadSize is NULL, it is simply ignored.
*/
LOADER_ERR LoaderFileRead(LOADER_HANDLE tLoader, LOADER_FILE_HANDLE hFileHandle, PVOID pvBuffer, ULONG ulSize, ULONG *pulReadSize)
{
LOADER_ERR loader_error;
LoaderData* loaderData;
loaderData = (LoaderData*) tLoader;
assert ( tLoader != NULL );
DBGPRINT(DEBUG_ON(DEBUG_TRACE), ("LoaderFileRead (%u bytes)\n",ulSize));
if ( ulSize > 1024 )
{
ulSize += 0;
}
OS_SemTake(loaderData->loaderMutex, OS_WAIT_FOREVER);
loader_error = LOADER_SUCCESS;
if ( loaderData->win32Loader->FileRead(hFileHandle, pvBuffer, ulSize, pulReadSize ) != WIN32LOADER_SUCCESS )
{
loader_error = LOADER_FAILURE;
}
OS_SemGive(loaderData->loaderMutex);
return ( loader_error );
}
/**
* Determine if a file marker is at the end of a file.
*
* @param tLoader The loader handle.
* @param hFileHandle Handle to the file.
* @param pbEOF Pointer to flag that gets set if file marker is at end of file.
*/
LOADER_ERR LoaderFileCheckEOF(LOADER_HANDLE tLoader, LOADER_FILE_HANDLE hFileHandle, BYTE *pbEOF)
{
LOADER_ERR loader_error;
LoaderData* loaderData;
DBGPRINT(DEBUG_ON(DEBUG_TRACE), ("LoaderFileCheckEOF\n"));
loaderData = (LoaderData*) tLoader;
assert ( tLoader != NULL );
OS_SemTake(loaderData->loaderMutex, OS_WAIT_FOREVER);
loader_error = LOADER_SUCCESS;
if ( loaderData->win32Loader->FileCheckEOF(hFileHandle, pbEOF) != WIN32LOADER_SUCCESS )
{
loader_error = LOADER_FAILURE;
}
OS_SemGive(loaderData->loaderMutex);
return ( loader_error );
}
/**
* Open a file from the disc.
*
* @param tLoader - The loader handle.
* @param pcFileName - File name.
* @param hFileHandle - Pointer to handle to the file that is opened.
*/
LOADER_ERR LoaderFileOpenAV(LOADER_HANDLE tLoader, const char *pcFileName, LOADER_FILE_HANDLE *hFileHandle)
{
return ( LoaderFileOpen(tLoader, pcFileName, hFileHandle));
}
/**
* Checks if the unit is ready. If the unit is not ready, fReady is set to
* false and the function returns. If the unit is ready, fReady is set to
* true and the loader startup is completed.
*
* @param tLoader - The loader handle.
* @param fReady - gets set to true if unit is ready, false otherwise
*/
LOADER_ERR LoaderTestUnitReady(LOADER_HANDLE tLoader, BOOLEAN *fReady)
{
LoaderData* loaderData;
DiscType discType;
DBGPRINT(DEBUG_ON(DEBUG_TRACE), ("LoaderTestUnitReady\n"));
loaderData = (LoaderData*) tLoader;
assert ( loaderData != NULL );
OS_SemTake(loaderData->loaderMutex, OS_WAIT_FOREVER);
if ( loaderData->win32Loader->GetDiscType(&discType) != WIN32LOADER_SUCCESS )
{
*fReady = FALSE;
}
else
{
*fReady = TRUE;
}
OS_SemGive(loaderData->loaderMutex);
return ( LOADER_SUCCESS );
}
LOADER_ERR LoaderReadCopyrightType(LOADER_HANDLE tLoader, BYTE *pbType)
{
LoaderData* loaderData;
BOOLEAN encrypted;
DBGPRINT(DEBUG_ON(DEBUG_TRACE), ("LoaderReadCopyrightType\n"));
loaderData = (LoaderData*) tLoader;
assert ( loaderData != NULL );
OS_SemTake(loaderData->loaderMutex, OS_WAIT_FOREVER);
*pbType = LOADER_COPYRIGHT_TYPE_NONE;
if ( loaderData->win32Loader->IsDVDDiscEncrypted((bool*)&encrypted) == WIN32LOADER_SUCCESS )
{
if ( encrypted )
{
*pbType = LOADER_COPYRIGHT_TYPE_CSS;
}
else
{
*pbType = LOADER_COPYRIGHT_TYPE_NONE;
}
}
OS_SemGive(loaderData->loaderMutex);
return ( LOADER_SUCCESS );
}
/**
* Reads a specific number of blocks from the storage media at the specified
* sector (streaming).
*
* @param tLoader - The loader handle.
* @param ulLBA - Sector offset to begin the read from.
* @param pbData - Pointer to a buffer to receive the data.
* @param ulNumBlocks - Number of sector sized blocks to be read. 0 and positive numbers only.
*/
LOADER_ERR LoaderSectorReadAV(LOADER_HANDLE tLoader, ULONG ulLBA, BYTE *pbData, ULONG ulNumBlocks)
{
DBGPRINT(DEBUG_ON(DEBUG_TRACE), ("LoaderSectorReadAV\n"));
return( LoaderSectorRead(tLoader, ulLBA, pbData, ulNumBlocks));
}
/**
* Select the specified disc layer.
*
*
* @param
* LOADER_HANDLE tLoader - Loader handle
*
* @param
* int layer - Specified layer
*
* @retval
* LOADER_ERR as appropriate
*/
LOADER_ERR LoaderChangeLayer(LOADER_HANDLE tLoader, int layer)
{
LOADER_ERR tStatus = LOADER_SUCCESS;
DEBUG_BREAKPOINT;
/* Validate the incoming parameters */
if (tLoader == NULL)
{
DBGPRINT(DEBUG_ON(DBG_ERROR), ("%s(): **** ERROR - NULL loader handle\n", __FUNCTION__));
tStatus = LOADER_FAILURE;
goto loader_change_layer_exit;
}
else if ( (layer < 0) || (layer >= LOADER_SUPPORTED_NUMBER_OF_LAYERS) )
{
DBGPRINT(DEBUG_ON(DBG_ERROR), ("%s(): **** ERROR - Invalid layer (%d)\n", __FUNCTION__, layer));
tStatus = LOADER_FAILURE;
goto loader_change_layer_exit;
}
loader_change_layer_exit:
/* Return status */
return (tStatus);
}
/**
* Return the layer format type information.
*
* NOTE: The loader type must be HYBRID for this information to have any meaning.
*
* @param
* LOADER_HANDLE tLoader - Loader handle
*
* @param
* LOADER_TYPE *ptDestination - Destination of the layer format type information
*
* @retval
* LOADER_ERR as appropriate
*/
LOADER_ERR LoaderGetLayerFormatTypeInformation(LOADER_HANDLE tLoader, LOADER_TYPE *ptDestination)
{
LOADER_ERR tStatus = LOADER_SUCCESS;
DEBUG_BREAKPOINT;
/* Validate the incoming parameters */
if (tLoader == NULL)
{
DBGPRINT(DEBUG_ON(DBG_ERROR), ("%s(): **** ERROR - NULL loader handle\n", __FUNCTION__));
tStatus = LOADER_FAILURE;
goto loader_get_layer_format_type_information_exit;
}
else if (ptDestination == NULL)
{
DBGPRINT(DEBUG_ON(DBG_ERROR), ("%s(): **** ERROR - NULL destination pointer\n", __FUNCTION__));
tStatus = LOADER_FAILURE;
goto loader_get_layer_format_type_information_exit;
}
// else if (((LOADER_HANDLE*)tLoader)->LoaderType != LOADER_TYPE_HYBRID)
{
DBGPRINT(DEBUG_ON(DBG_ERROR), ("%s(): **** WARNING - Not a hybrid disc, information has no meaning\n", __FUNCTION__));
}
loader_get_layer_format_type_information_exit:
/* Return status */
return (tStatus);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -