データベースに余分なヘッダが追加できるように、ファイル名の代わりにシーク済みFSFileを取るようにした

git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/TwlIPL/trunk@1163 b08762b0-b915-fc4b-9d8c-17b2551a87ff
This commit is contained in:
yutaka 2008-04-16 09:55:42 +00:00
parent e0ba8d3d76
commit b03934fb02
4 changed files with 33 additions and 43 deletions

View File

@ -139,67 +139,41 @@ BOOL DHT_CheckDatabase(const DHTFile* pDHT)
return TRUE;
}
BOOL DHT_PrepareDatabase(DHTFile* pDHT, const char* filepath)
BOOL DHT_PrepareDatabase(DHTFile* pDHT, FSFile* fp)
{
FSFile file;
s32 result;
s32 length;
u8 title[4] = { 'H','N','G','A' };
PROFILE_INIT();
if ( filepath )
if ( fp )
{
// ファイルオープン
PROFILE_COUNT();
if (!FS_OpenFileEx(&file, filepath, FS_FILEMODE_R))
{
OS_TPrintf("Cannot open %s.\n", filepath);
return FALSE;
}
// ヘッダ読み込み
PROFILE_COUNT();
result = FS_ReadFile(&file, &pDHT->header, sizeof(DHTHeader));
result = FS_ReadFile(fp, &pDHT->header, sizeof(DHTHeader));
if ( result != sizeof(DHTHeader) )
{
OS_TPrintf("Cannot read the header of %s (result=%d).\n", filepath, result);
OS_TPrintf("Cannot read the DHT header (result=%d).\n", result);
return FALSE;
}
// magic_codeが HNGA のときはROM_Header分だけシークし直す
if ( pDHT->header.magic_code == *(u32*)title )
{
if ( !FS_SeekFile(&file, sizeof(ROM_Header), FS_SEEK_SET) )
{
OS_TPrintf("Cannot seek to the header of %s.\n", filepath);
return FALSE;
}
// 再びヘッダ読み込み
result = FS_ReadFile(&file, &pDHT->header, sizeof(DHTHeader));
if ( result != sizeof(DHTHeader) )
{
OS_TPrintf("Cannot read the header of %s (result=%d).\n", filepath, result);
return FALSE;
}
}
// サイズチェック
PROFILE_COUNT();
length = (s32)DHT_GetDatabaseLength(pDHT);
if ( FS_GetFileLength(&file) < length ) // パディングがあり得る
if ( FS_GetFileLength(fp) < length ) // パディングがあり得る
{
OS_TPrintf("Invalid %s size (%d < %d).\n", filepath, FS_GetFileLength(&file), length);
OS_TPrintf("Invalid DHT file size (%d < %d).\n", FS_GetFileLength(fp), length);
return FALSE;
}
// ヘッダ分を削除
length -= sizeof(DHTHeader);
// データベース読み込み
PROFILE_COUNT();
result = FS_ReadFile(&file, pDHT->database, length);
result = FS_ReadFile(fp, pDHT->database, length);
if ( result != length )
{
OS_TPrintf("Cannot read the database of %s (result=%d).\n", filepath, result);
OS_TPrintf("Cannot read the DHT database (result=%d).\n", result);
return FALSE;
}
FS_CloseFile(&file);
}
// データベースの検証

View File

@ -104,7 +104,7 @@ void SYSM_InitPXI( u32 mcu_prio )
#ifdef SDK_ARM9
static BOOL GetDatabaseFilepath(char *path)
{
u8 title[4] = { 'H','N','G','A' };
u8 title[4] = { 'H','N','H','A' };
#if( USE_LCFG_STRING == 0 )
char *title0 = "HNGA";
@ -154,8 +154,16 @@ void SYSMi_PrepareDatabase(void)
char path[256];
if ( GetDatabaseFilepath( path ) )
{
DHT_PrepareDatabase(dht, path);
DC_FlushRange(dht, DHT_GetDatabaseLength(dht));
FSFile file;
if ( FS_OpenFileEx(&file, path, FS_FILEMODE_R) )
{
if ( FS_SeekFile(&file, sizeof(ROM_Header), FS_SEEK_SET) )
{
DHT_PrepareDatabase(dht, &file);
DC_FlushRange(dht, DHT_GetDatabaseLength(dht));
}
FS_CloseFile(&file);
}
}
else
{

View File

@ -183,11 +183,18 @@ void TwlMain(void)
(void)GX_VBlankIntr(TRUE);
FS_Init(FS_DMA_NOT_USE);
// 署名ロード
if ( !DHT_PrepareDatabase(dht, HASH_PATH) )
{
OS_TPanic("Cannot prepare the database.\n");
FSFile file;
if ( !FS_OpenFileEx(&file, HASH_PATH, FS_FILEMODE_R) )
{
OS_TPanic("Cannot open %s.\n", HASH_PATH);
}
// 署名ロード
if ( !DHT_PrepareDatabase(dht, &file) )
{
OS_TPanic("Cannot prepare the database.\n");
}
FS_CloseFile(&file);
}
// {”Ô

View File

@ -65,11 +65,12 @@ BOOL DHT_CheckDatabase(const DHTFile* pDHT);
Description: FS関数を利用して全データベースを読み込みと検証を行う
Arguments: pDHT
filepath (NULLで格納済みと判定())
fp
DHTHeaderの先頭までシーク済みである必要がある
Returns: TRUE
*---------------------------------------------------------------------------*/
BOOL DHT_PrepareDatabase(DHTFile* pDHT, const char* filepath);
BOOL DHT_PrepareDatabase(DHTFile* pDHT, FSFile* fp);
/*---------------------------------------------------------------------------*
Name: DHT_GetDatabase